private static void LoadInstalledThemes(List <string> themeIds)
        {
            foreach (string themeId in themeIds)
            {
                ThemeLoader.TryLoad(themeId).Match(ThemeLoader.HandleError, theme =>
                {
                    themeSettings.Add(theme);

                    if (theme.themeId == JsonConfig.settings.themeName)
                    {
                        currentTheme = theme;
                    }
                });
            }

            foreach (string themeId in defaultThemes)
            {
                if (!themeIds.Contains(themeId))
                {
                    themeSettings.Add(new ThemeConfig {
                        themeId = themeId
                    });
                }
            }
        }
        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 ThemeResult ImportTheme(string importPath)
        {
            string      themeId    = Path.GetFileNameWithoutExtension(importPath);
            int         themeIndex = themeSettings.FindIndex(t => t.themeId == 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);
            }));
        }
        private void ImportNext()
        {
            if (ThemeManager.importPaths.Count > 0)
            {
                foreach (string themePath in ThemeManager.importPaths)
                {
                    importQueue.Enqueue(themePath);
                }

                numJobs += ThemeManager.importPaths.Count;
                ThemeManager.importPaths.Clear();
            }

            this.Invoke(new Action(() => UpdateTotalPercentage(0)));

            if (importQueue.Count > 0)
            {
                string themePath = importQueue.Peek();
                this.Invoke(new Action(() =>
                                       label1.Text = string.Format(_("Importing theme from {0}..."),
                                                                   Path.GetFileName(themePath))));

                ThemeResult result = ThemeManager.ImportTheme(themePath);
                result.Match(e => this.Invoke(new Action(() => ThemeLoader.HandleError(e))),
                             theme => ThemeManager.importedThemes.Add(theme));

                importQueue.Dequeue();
                ImportNext();
            }
            else
            {
                ThemeManager.importMode = false;
                this.Invoke(new Action(() => this.Close()));
            }
        }
示例#5
0
        private void LoadThemes(List <ThemeConfig> themes, string activeTheme = null)
        {
            Size         thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            ListViewItem focusedItem   = null;

            foreach (ThemeConfig theme in themes.ToList())
            {
                try
                {
                    using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true))
                    {
                        this.Invoke(new Action(() =>
                        {
                            listView1.LargeImageList.Images.Add(thumbnailImage);
                            string itemText = ThemeManager.GetThemeName(theme);
                            if (JsonConfig.settings.favoriteThemes != null &&
                                JsonConfig.settings.favoriteThemes.Contains(theme.themeId))
                            {
                                itemText = "★ " + itemText;
                            }
                            ListViewItem newItem = listView1.Items.Add(itemText, listView1.LargeImageList.Images.Count - 1);
                            newItem.Tag          = theme.themeId;

                            if (activeTheme == null || activeTheme == theme.themeId)
                            {
                                focusedItem = newItem;
                            }
                        }));
                    }
                }
                catch (OutOfMemoryException)
                {
                    ThemeLoader.HandleError(new FailedToCreateThumbnail(theme.themeId));
                }
            }

            this.Invoke(new Action(() =>
            {
                listView1.Sort();

                if (focusedItem == null)
                {
                    focusedItem = listView1.Items[0];
                }

                focusedItem.Selected = true;
                listView1.EnsureVisible(focusedItem.Index);

                ThemeThumbLoader.CacheThumbnails(listView1);
            }));
        }
示例#6
0
        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();
                }
            }
        }
        private void ImportNext()
        {
            if (ThemeManager.importPaths.Count > 0)
            {
                foreach (string themePath in ThemeManager.importPaths)
                {
                    importQueue.Enqueue(themePath);
                }

                numJobs += ThemeManager.importPaths.Count;
                ThemeManager.importPaths.Clear();
            }

            this.Invoke(new Action(() => UpdateTotalPercentage(0)));

            if (importQueue.Count > 0)
            {
                string themePath = importQueue.Peek();
                this.Invoke(new Action(() => UpdateImportStatus(themePath)));
                ThemeConfig theme = ThemeManager.ImportTheme(themePath);
                this.Invoke(new Action(() => ThemeLoader.HandleError(
                                           Path.GetFileNameWithoutExtension(themePath))));

                if (theme != null)
                {
                    if (Path.GetExtension(themePath) == ".json")
                    {
                        downloadQueue = new Queue <ThemeConfig>(
                            new List <ThemeConfig>()
                        {
                            theme
                        });
                        DownloadNext();  // TODO Test this
                    }

                    ThemeManager.importedThemes.Add(theme);
                }

                importQueue.Dequeue();
                ImportNext();
            }
            else
            {
                ThemeManager.importMode = false;
                this.Invoke(new Action(() => this.Close()));
            }
        }
示例#9
0
        private static void LoadInstalledThemes(List <string> themeIds)
        {
            foreach (string themeId in themeIds)
            {
                ThemeConfig theme = ThemeLoader.TryLoad(themeId);
                ThemeLoader.HandleError(themeId);

                if (theme != null)
                {
                    themeSettings.Add(theme);

                    if (theme.themeId == JsonConfig.settings.themeName)
                    {
                        currentTheme = theme;
                    }
                }
            }
        }
示例#10
0
        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);
            }));
        }
示例#11
0
        private static void DownloadMissingImages()
        {
            List <ThemeConfig> missingThemes = new List <ThemeConfig>();

            foreach (ThemeConfig theme in themeSettings)
            {
                string themePath = Path.Combine("themes", theme.themeId);

                if (!Directory.Exists(themePath) ||
                    (Directory.GetFiles(themePath, theme.imageFilename).Length == 0))
                {
                    missingThemes.Add(theme);
                }
            }

            if (missingThemes.Count == 0)
            {
                filesVerified = true;
                LaunchSequence.NextStep();
                return;
            }

            foreach (ThemeConfig theme in
                     missingThemes.Where(theme => string.IsNullOrEmpty(theme.imagesZipUri)))
            {
                missingThemes.Remove(theme);
                ThemeLoader.HandleError(theme.themeId,
                                        string.Format(_("Failed to find images for the '{0}' theme"), theme.themeId));
            }

            downloadDialog             = new ProgressDialog();
            downloadDialog.FormClosed += OnDownloadDialogClosed;
            downloadDialog.Show();

            MainMenu.themeItem.Enabled = false;
            downloadDialog.InitDownload(missingThemes);
        }
示例#12
0
        private void DownloadNext()
        {
            if (downloadQueue.Count > 0)
            {
                ThemeConfig theme = downloadQueue.Peek();
                this.Invoke(new Action(() => UpdateDownloadStatus(theme)));

                if (theme.imagesZipUri.StartsWith("file://"))
                {
                    string themePath = (new Uri(theme.imagesZipUri)).LocalPath;

                    Task.Run(() => {
                        bool success = ThemeLoader.CopyLocalTheme(theme, themePath,
                                                                  this.UpdateTotalPercentage);

                        if (!success)
                        {
                            this.Invoke(new Action(() => ThemeLoader.HandleError(theme.themeId)));
                        }

                        downloadQueue.Dequeue();
                        this.Invoke(new Action(() => DownloadNext()));
                    });
                }
                else if (!string.IsNullOrEmpty(theme.imagesZipUri))
                {
                    List <string> imagesZipUris = theme.imagesZipUri.Split('|').ToList();
                    wc.DownloadFileAsync(new Uri(imagesZipUris.First()),
                                         theme.themeId + "_images.zip", imagesZipUris.Skip(1).ToList());
                }
            }
            else if (!ThemeManager.importMode)
            {
                this.Close();
            }
        }