Exemplo n.º 1
0
        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);
            }));
        }
Exemplo n.º 2
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);
            }));
        }
Exemplo n.º 3
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();
            }
        }