Пример #1
0
        public static void Initialize()
        {
            Directory.CreateDirectory("images");
            Directory.CreateDirectory("themes");

            List <string> themeNames = defaultThemes.ToList();

            foreach (string filePath in Directory.EnumerateFiles("themes", "*.json"))
            {
                themeNames.Add(Path.GetFileNameWithoutExtension(filePath));
            }
            themeNames.Sort();

            foreach (string name in themeNames)
            {
                ThemeConfig theme = JsonConfig.LoadTheme(name);
                themeSettings.Add(theme);

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

            DownloadMissingImages(FindMissingThemes());
        }
Пример #2
0
        public static ThemeConfig ImportTheme(string themeJson)
        {
            string themeName   = Path.GetFileNameWithoutExtension(themeJson);
            bool   isInstalled = false;

            foreach (ThemeConfig theme in themeSettings)
            {
                if (theme.themeName == themeName)
                {
                    isInstalled = true;
                    break;
                }
            }

            if (isInstalled)
            {
                DialogResult result = MessageBox.Show("The '" + themeName.Replace('_', ' ') +
                                                      "' theme is already installed. Do you want to overwrite it?", "Question",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result != DialogResult.Yes)
                {
                    return(null);
                }
            }

            File.Copy(themeJson, Path.Combine("themes", themeName + ".json"), true);
            return(JsonConfig.LoadTheme(themeName));
        }
Пример #3
0
        public static void Initialize()
        {
            Directory.CreateDirectory("themes");

            // TODO Remove after everyone has new file structure
            if (Directory.Exists("images"))
            {
                UpdateThemeFileStructure();
            }

            List <string> themeNames = defaultThemes.ToList();

            foreach (string filePath in Directory.EnumerateFiles("themes", "*.json",
                                                                 SearchOption.AllDirectories))
            {
                themeNames.Add(Path.GetFileName(Path.GetDirectoryName(filePath)));
            }
            themeNames.Sort();

            foreach (string name in themeNames)
            {
                ThemeConfig theme = JsonConfig.LoadTheme(name);
                themeSettings.Add(theme);

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

            DownloadMissingImages(FindMissingThemes());
        }
Пример #4
0
        private static void UpdateThemeFileStructure()
        {
            List <string> filePaths = Directory.GetFiles("themes", "*.json").ToList();

            filePaths.AddRange(defaultThemes.Select(
                                   themeName => Path.Combine("themes", themeName + ".json")));

            foreach (string filePath in filePaths)
            {
                string themeName = Path.GetFileNameWithoutExtension(filePath);
                Directory.CreateDirectory(Path.Combine("themes", themeName));

                if (File.Exists(filePath))
                {
                    File.Move(filePath, Path.Combine("themes", themeName, "theme.json"));
                }

                ThemeConfig theme = JsonConfig.LoadTheme(themeName);
                foreach (string imagePath in Directory.GetFiles("images", theme.imageFilename))
                {
                    File.Move(imagePath,
                              Path.Combine("themes", themeName, Path.GetFileName(imagePath)));
                }
            }

            if (Directory.GetFiles("images").Length == 0 &&
                Directory.GetDirectories("images").Length == 0)
            {
                Directory.Delete("images", false);
            }
        }
Пример #5
0
        public static void Initialize()
        {
            Directory.CreateDirectory("images");
            Directory.CreateDirectory("themes");

            List <string> themeNames = new List <string>()
            {
                "Mojave_Desert", "Solar_Gradients"
            };

            foreach (string filePath in Directory.EnumerateFiles("themes", "*.json"))
            {
                themeNames.Add(Path.GetFileNameWithoutExtension(filePath));
            }
            themeNames.Sort();

            foreach (string name in themeNames)
            {
                ThemeConfig theme = JsonConfig.LoadTheme(name);
                themeSettings.Add(theme);

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

            // TODO Test not setting themename here, and test location on Windows 7 and async on Windows 10
        }
Пример #6
0
 public static ThemeResult TryLoad(string themeId)
 {
     if (!File.Exists(Path.Combine("themes", themeId, "theme.json")))
     {
         return(new ThemeResult(new NoThemeJSON(themeId)));
     }
     else
     {
         return(ValidateThemeJSON(JsonConfig.LoadTheme(themeId)));
     }
 }
Пример #7
0
        public static ThemeConfig ImportTheme(string themePath)
        {
            string themeId     = Path.GetFileNameWithoutExtension(themePath);
            bool   isInstalled = themeSettings.FindIndex(t => t.themeId == themeId) != -1;

            if (isInstalled)
            {
                DialogResult result = MessageBox.Show("The '" + themeId + "' theme is already " +
                                                      "installed. Do you want to overwrite it?", "Question", MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Warning);

                if (result != DialogResult.Yes)
                {
                    return(null);
                }
            }

            try
            {
                Directory.CreateDirectory(Path.Combine("themes", themeId));

                if (Path.GetExtension(themePath) != ".json")
                {
                    using (ZipArchive archive = ZipFile.OpenRead(themePath))
                    {
                        ZipArchiveEntry themeJson = archive.Entries.Single(
                            entry => Path.GetExtension(entry.Name) == ".json");
                        themeJson.ExtractToFile(Path.Combine("themes", themeId, "theme.json"),
                                                true);
                    }

                    ExtractTheme(themePath, themeId);
                }
                else
                {
                    File.Copy(themePath, Path.Combine("themes", themeId, "theme.json"), true);
                }

                ThemeConfig theme = JsonConfig.LoadTheme(themeId);
                themeSettings.Add(theme);
                themeSettings.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId));

                return(theme);
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to import theme from " + themePath + "\n\n" + e.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return(null);
            }
        }
Пример #8
0
        public static ThemeConfig TryLoad(string themeId)
        {
            errorMsg = null;
            ThemeConfig theme = null;

            if (!ThemeManager.defaultThemes.Contains(themeId) &&
                !File.Exists(Path.Combine("themes", themeId, "theme.json")))
            {
                errorMsg = _("Theme JSON file could not be found.");
            }
            else
            {
                theme = JsonConfig.LoadTheme(themeId);
                ValidateThemeJSON(theme);
            }

            return((errorMsg == null) ? theme : null);
        }
Пример #9
0
        public static ThemeConfig ImportTheme(string themePath)
        {
            string themeName   = Path.GetFileNameWithoutExtension(themePath);
            bool   isInstalled = themeSettings.FindIndex(
                theme => theme.themeName == themeName) != -1;

            if (isInstalled)
            {
                DialogResult result = DarkMessageBox.ShowWarning("The '" +
                                                                 themeName.Replace('_', ' ') + "' theme is already installed. Do you want to " +
                                                                 "overwrite it?", "Question", DarkDialogButton.YesNo);

                if (result != DialogResult.Yes)
                {
                    return(null);
                }
            }

            try
            {
                if (Path.GetExtension(themePath) == ".zip")
                {
                    using (ZipArchive archive = ZipFile.OpenRead(themePath))
                    {
                        ZipArchiveEntry themeJson = archive.Entries.Single(
                            entry => Path.GetExtension(entry.Name) == ".json");
                        themeJson.ExtractToFile(Path.Combine("themes", themeName + ".json"), true);
                    }

                    ExtractTheme(themePath);
                }
                else
                {
                    File.Copy(themePath, Path.Combine("themes", themeName + ".json"), true);
                }

                return(JsonConfig.LoadTheme(themeName));
            }
            catch (Exception e)
            {
                DarkMessageBox.ShowWarning("Failed to import theme:\n" + e.Message, "Error");
                return(null);
            }
        }
Пример #10
0
        public static void Initialize()
        {
            Directory.CreateDirectory("themes");
            Compatibility.CompatibilizeThemes();

            List <string> themeIds = defaultThemes.ToList();

            foreach (string filePath in Directory.EnumerateFiles("themes", "*.json",
                                                                 SearchOption.AllDirectories))
            {
                string themeId = Path.GetFileName(Path.GetDirectoryName(filePath));

                if (!themeId.StartsWith("."))
                {
                    themeIds.Add(themeId);
                }
            }

            themeIds.Sort();

            foreach (string themeId in themeIds)
            {
                try
                {
                    ThemeConfig theme = JsonConfig.LoadTheme(themeId);

                    themeSettings.Add(theme);

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

            DownloadMissingImages(FindMissingThemes());
        }
Пример #11
0
        public static ThemeConfig ImportTheme(string themePath, IntPtr dialogHandle)
        {
            string themeId    = Path.GetFileNameWithoutExtension(themePath);
            int    themeIndex = themeSettings.FindIndex(t => t.themeId == themeId);

            if (themeIndex != -1)
            {
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Paused);
                DialogResult result = MessageBox.Show(string.Format(_("The '{0}' theme is " +
                                                                      "already installed. Do you want to overwrite it?"), themeId), _("Question"),
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Normal);

                if (result != DialogResult.Yes)
                {
                    return(null);
                }
            }

            try
            {
                Directory.CreateDirectory(Path.Combine("themes", themeId));

                if (Path.GetExtension(themePath) != ".json")
                {
                    using (ZipArchive archive = ZipFile.OpenRead(themePath))
                    {
                        ZipArchiveEntry themeJson = archive.Entries.Single(
                            entry => Path.GetExtension(entry.Name) == ".json");
                        themeJson.ExtractToFile(Path.Combine("themes", themeId, "theme.json"),
                                                true);
                    }

                    ExtractTheme(themePath, themeId);
                }
                else
                {
                    File.Copy(themePath, Path.Combine("themes", themeId, "theme.json"), true);
                }

                ThemeConfig theme = JsonConfig.LoadTheme(themeId);

                if (themeIndex == -1)
                {
                    themeSettings.Add(theme);
                    themeSettings.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId));
                }
                else
                {
                    themeSettings[themeIndex] = theme;
                }

                return(theme);
            }
            catch (Exception e)
            {
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Error);
                MessageBox.Show(string.Format(_("Failed to import theme from {0}\n\n{1}"),
                                              themePath, e.Message), _("Error"), MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                TaskbarProgress.SetState(dialogHandle, TaskbarProgress.TaskbarStates.Normal);

                return(null);
            }
        }