コード例 #1
0
 private static void OnReloadConfigFileClick(object sender, EventArgs e)
 {
     JsonConfig.ReloadConfig();
 }
コード例 #2
0
 public static bool IsTheme4Segment(ThemeConfig theme)
 {
     return(!JsonConfig.IsNullOrEmpty(theme.sunriseImageList) &&
            !JsonConfig.IsNullOrEmpty(theme.sunsetImageList));
 }
コード例 #3
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);
            }
        }