Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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()));
            }
        }
Ejemplo n.º 3
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);
            }));
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }
Ejemplo n.º 5
0
        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()));
            }
        }
Ejemplo n.º 6
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;
                    }
                }
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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();
            }
        }