Exemple #1
0
        private static bool TryLoadVersion(ZipArchive archive, out Version version)
        {
            foreach (var entry in archive.Entries)
            {
                if (entry.FullName.EndsWith(@"data/base/info.json"))
                {
                    using (var stream = entry.Open())
                    {
                        try
                        {
                            var infoFile = InfoFile.FromJsonStream(stream);
                            version = infoFile.Version;
                            return(infoFile.IsValid);
                        }
                        catch (Exception ex)
                        {
                            App.Instance.WriteExceptionLog(ex);
                            version = null;
                            return(false);
                        }
                    }
                }
            }

            version = null;
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Tries to deserialize a given stream into an info file object.
        /// </summary>
        /// <param name="stream">The stream to deserialize.</param>
        /// <param name="infoFile">Out. The deserialized info file if the operation was successful.</param>
        /// <returns>Returns true if deserialization succeeded, otherwise false.</returns>
        private static bool TryDeserializeInfoFileFromStream(Stream stream, out InfoFile infoFile)
        {
            try
            {
                infoFile = InfoFile.FromJsonStream(stream);
                return(infoFile.IsValid);
            }
            catch (Exception ex)
            {
                App.Instance.WriteExceptionLog(ex);

                infoFile = null;
                return(false);
            }
        }