public async void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { stopwatch.Stop(); ThemeConfig theme = (ThemeConfig)e.UserState; if ((e.Error == null) && EnsureZipNotHtml()) { cancelButton.Enabled = false; ThemeResult result = await Task.Run( () => ThemeLoader.ExtractTheme(imagesZipDest, theme.themeId, theme)); result.DoLeft(ThemeLoader.HandleError); this.Close(); } else if (themeUriIndex >= themeUris.Count) { bool shouldRetry = ThemeLoader.PromptDialog(string.Format(_("Failed to " + "download images for the '{0}' theme. Do you want to try again?"), theme.themeId)); if (shouldRetry) { InitDownload(theme); } else { ThemeLoader.HandleError(new FailedToDownloadImages(theme.themeId)); } } else { themeUriIndex++; DownloadNext(theme); } }
public static ThemeConfig ImportTheme(string importPath) { string themeId = Path.GetFileNameWithoutExtension(importPath); int themeIndex = themeSettings.FindIndex(t => t.themeId == themeId); if (themeIndex != -1) { bool shouldOverwrite = ThemeLoader.PromptDialog(string.Format(_("The '{0}' " + "theme is already installed. Do you want to overwrite it?"), themeId)); if (!shouldOverwrite) { return(null); } } Directory.CreateDirectory(Path.Combine("themes", themeId)); bool shouldContinue = true; ThemeConfig theme = null; if (Path.GetExtension(importPath) != ".json") { shouldContinue = ThemeLoader.ExtractTheme(importPath, themeId); } else { File.Copy(importPath, Path.Combine("themes", themeId, "theme.json"), true); } if (shouldContinue) { theme = ThemeLoader.TryLoad(themeId); } if (theme == null) { return(null); } if (themeIndex == -1) { themeSettings.Add(theme); themeSettings.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId)); } else { themeSettings[themeIndex] = theme; } return(theme); }
public async void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { stopwatch.Stop(); if (e.Error == null) { ThemeConfig theme = downloadQueue.Dequeue(); await Task.Run(() => ThemeLoader.ExtractTheme(theme.themeId + "_images.zip", theme.themeId, true)); ThemeLoader.HandleError(theme.themeId); DownloadNext(); } else { List <string> imagesZipUris = (List <string>)e.UserState; ThemeConfig theme = downloadQueue.Peek(); if (imagesZipUris.Count == 0) { bool shouldRetry = ThemeLoader.PromptDialog(string.Format(_("Failed to " + "download images for the '{0}' theme. Do you want to try again?"), theme.themeId)); if (shouldRetry) { imagesZipUris = theme.imagesZipUri.Split('|').ToList(); } else { ThemeLoader.HandleError(theme.themeId, string.Format( _("Failed to download images for the '{0}' theme"), theme.themeId)); } } if (imagesZipUris.Count > 0) { wc.DownloadFileAsync(new Uri(imagesZipUris.First()), theme.themeId + "_images.zip", imagesZipUris.Skip(1).ToList()); } else { downloadQueue.Dequeue(); DownloadNext(); } } }
public static ThemeResult ImportTheme(string importPath) { string themeId = Path.GetFileNameWithoutExtension(importPath); int themeIndex = themeSettings.FindIndex(t => t.themeId == themeId); if (themeIndex != -1) { bool shouldOverwrite = ThemeLoader.PromptDialog(string.Format(_("The '{0}' " + "theme is already installed. Do you want to overwrite it?"), themeId)); if (!shouldOverwrite) { return(null); // TODO Update when nullable reference types are supported } } Directory.CreateDirectory(Path.Combine("themes", themeId)); ThemeResult result; if (Path.GetExtension(importPath) != ".json") { result = ThemeLoader.ExtractTheme(importPath, themeId); } else { result = ThemeLoader.CopyLocalTheme(importPath, themeId); } return(result.Match(e => new ThemeResult(e), theme => { if (themeIndex == -1) { themeSettings.Add(theme); themeSettings.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId)); } else { themeSettings[themeIndex] = theme; } return new ThemeResult(theme); })); }