public static void SetDefaultTheme(ThemeManifest theme)
 {
     DefaultTheme = theme;
 }
        /*
         * public static void ApplyFullscreenButtonPrompts(Application app, FullscreenButtonPrompts prompts)
         * {
         *  if (prompts == FullscreenSettings.DefaultButtonPrompts)
         *  {
         *      var defaultXaml = $"{FullscreenSettings.DefaultButtonPrompts.ToString()}.xaml";
         *      foreach (var dir in PlayniteApplication.CurrentNative.Resources.MergedDictionaries.ToList())
         *      {
         *          if (dir.Source == null)
         *          {
         *              continue;
         *          }
         *
         *          if (dir.Source.OriginalString.Contains("ButtonPrompts") &&
         *              !dir.Source.OriginalString.EndsWith(defaultXaml))
         *          {
         *              PlayniteApplication.CurrentNative.Resources.MergedDictionaries.Remove(dir);
         *          }
         *      }
         *  }
         *  else
         *  {
         *      var promptsPath = Path.Combine(ThemeManager.DefaultTheme.DirectoryPath, "Images", "ButtonPrompts");
         *      foreach (var dir in Directory.GetDirectories(promptsPath))
         *      {
         *          var dirInfo = new DirectoryInfo(dir);
         *          var promptXaml = Path.Combine(dir, $"{dirInfo.Name}.xaml");
         *          if (File.Exists(promptXaml) && dirInfo.Name == prompts.ToString())
         *          {
         *              var xaml = Xaml.FromFile(promptXaml);
         *              if (xaml is ResourceDictionary xamlDir)
         *              {
         *                  xamlDir.Source = new Uri(promptXaml, UriKind.Absolute);
         *                  PlayniteApplication.CurrentNative.Resources.MergedDictionaries.Add(xamlDir);
         *              }
         *          }
         *      }
         *  }
         * }
         */

        public static bool ApplyTheme(Application app, ThemeManifest theme, ApplicationMode mode)
        {
            var apiVesion = mode == ApplicationMode.Desktop ? DesktopApiVersion : FullscreenApiVersion;

            if (!theme.ThemeApiVersion.IsNullOrEmpty())
            {
                var themeVersion = new Version(theme.ThemeApiVersion);
                if (themeVersion.Major != apiVesion.Major || themeVersion > apiVesion)
                {
                    logger.Error($"Failed to apply {theme.Name} theme, unsupported API version {theme.ThemeApiVersion}.");
                    return(false);
                }
            }

            var allLoaded       = true;
            var loadedXamls     = new List <ResourceDictionary>();
            var acceptableXamls = new List <string>();
            var defaultRoot     = $"Themes/{mode.GetDescription()}/{DefaultTheme.DirectoryName}/";

            foreach (var dict in app.Resources.MergedDictionaries)
            {
                if (dict.Source.OriginalString.StartsWith("Themes") && dict.Source.OriginalString.EndsWith("xaml"))
                {
                    acceptableXamls.Add(dict.Source.OriginalString.Replace(defaultRoot, "").Replace('/', '\\'));
                }
            }

            foreach (var accXaml in acceptableXamls)
            {
                var xamlPath = Path.Combine(theme.DirectoryPath, accXaml);
                if (!File.Exists(xamlPath))
                {
                    continue;
                }

                try
                {
                    var xaml = Xaml.FromFile(xamlPath);
                    if (xaml is ResourceDictionary xamlDir)
                    {
                        xamlDir.Source = new Uri(xamlPath, UriKind.Absolute);
                        loadedXamls.Add(xamlDir as ResourceDictionary);
                    }
                    else
                    {
                        logger.Error($"Skipping theme file {xamlPath}, it's not resource dictionary.");
                    }
                }
                catch (Exception e) //when (!PlayniteEnvironment.ThrowAllErrors)
                {
                    logger.Error(e, $"Failed to load xaml {xamlPath}");
                    allLoaded = false;
                    break;
                }
            }

            if (allLoaded)
            {
                loadedXamls.ForEach(a => app.Resources.MergedDictionaries.Add(a));
                return(true);
            }

            return(false);
        }
 public static void SetCurrentTheme(ThemeManifest theme)
 {
     CurrentTheme = theme;
 }