FromArchive() private method

private FromArchive ( ZipArchive zip ) : LocalePackageManifest
zip System.IO.Compression.ZipArchive
return LocalePackageManifest
Esempio n. 1
0
        protected override async Task <bool> CheckAndUpdateIfNeededInner()
        {
            if (InstalledVersion == null)
            {
                return(false);
            }

            var installedVersion = File.Exists(GetPackageFilename(SettingsHolder.Locale.LocaleName)) ? InstalledVersion : @"0";
            var data             = await CmApiProvider.GetDataAsync($"locales/update/{SettingsHolder.Locale.LocaleName}/{installedVersion}");

            if (data == null)
            {
                LatestError = ToolsStrings.BaseUpdater_CannotDownloadInformation;
                Logging.Warning("Cannot get locales/update");
                return(false);
            }

            if (data.Length == 0)
            {
                return(false);
            }

            try {
                LocalePackageManifest manifest;
                using (var memory = new MemoryStream(data))
                    using (var updateZip = new ZipArchive(memory)) {
                        manifest = LocalePackageManifest.FromArchive(updateZip);
                        if (manifest == null)
                        {
                            throw new Exception("Manifest is missing");
                        }
                    }

                var package = GetPackageFilename(manifest.Id);
                await FileUtils.WriteAllBytesAsync(package, data);

                Logging.Write("Locale updated");

                InstalledVersion = manifest.Version;
                return(true);
            } catch (Exception e) {
                Logging.Warning("Cannot update locale: " + e);
                return(false);
            }
        }