Пример #1
0
        public List <string> GetThemes()
        {
            List <string> themes = new List <string>();

            themes.Add(THEME_DEFAULT);

            foreach (string subStr in Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, THEME_FOLDER)).Where(s => Path.GetExtension(s).Contains(THEME_EXT)))
            {
                themes.Add(Path.GetFileNameWithoutExtension(subStr));
            }

            // Because RetroBar is published as a single-file app, it gets extracted to a temp directory, so custom themes won't be there.
            // Get the executable path to find the custom themes directory when not a debug build.
            string customThemeDir = Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), THEME_FOLDER);

            if (Directory.Exists(customThemeDir))
            {
                foreach (string subStr in Directory.GetFiles(customThemeDir)
                         .Where(s => Path.GetExtension(s).Contains(THEME_EXT) && !themes.Contains(Path.GetFileNameWithoutExtension(s))))
                {
                    themes.Add(Path.GetFileNameWithoutExtension(subStr));
                }
            }

            return(themes);
        }
Пример #2
0
        private List <string> GetDictionaries(string dictDefault, string dictFolder, string dictExtension)
        {
            List <string> dictionaries = new List <string> {
                dictDefault
            };

            foreach (string subStr in Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dictFolder))
                     .Where(s => Path.GetExtension(s).Contains(dictExtension)))
            {
                dictionaries.Add(Path.GetFileNameWithoutExtension(subStr));
            }

            // Because RetroBar is published as a single-file app, it gets extracted to a temp directory, so custom dictionaries won't be there.
            // Get the executable path to find the custom dictionaries directory when not a debug build.
            string customDictDir = Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), dictFolder);

            if (Directory.Exists(customDictDir))
            {
                foreach (string subStr in Directory.GetFiles(customDictDir)
                         .Where(s => Path.GetExtension(s).Contains(dictExtension) && !dictionaries.Contains(Path.GetFileNameWithoutExtension(s))))
                {
                    dictionaries.Add(Path.GetFileNameWithoutExtension(subStr));
                }
            }

            return(dictionaries);
        }
Пример #3
0
        public void SetTheme(string theme)
        {
            string themeFilePath;

            if (theme == THEME_DEFAULT)
            {
                Application.Current.Resources.MergedDictionaries.Clear();
                themeFilePath = Path.ChangeExtension(Path.Combine(THEME_FOLDER, THEME_DEFAULT), THEME_EXT);
            }
            else
            {
                themeFilePath = Path.ChangeExtension(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, THEME_FOLDER, theme), THEME_EXT);

                if (!File.Exists(themeFilePath))
                {
                    // custom theme in app directory
                    themeFilePath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), THEME_FOLDER, theme), THEME_EXT);

                    if (!File.Exists(themeFilePath))
                    {
                        return;
                    }
                }
            }

            ResourceDictionary newRes = new ResourceDictionary()
            {
                Source = new Uri(themeFilePath, UriKind.RelativeOrAbsolute)
            };

            Application.Current.Resources.MergedDictionaries.Add(newRes);
        }
Пример #4
0
        private void SetDictionary(string dictionary, string dictFolder, string dictDefault, string dictExtension, int dictType)
        {
            string dictFilePath;

            if (dictionary == dictDefault)
            {
                if (dictType == 0)
                {
                    ClearPreviousThemes();
                }
                dictFilePath = Path.ChangeExtension(Path.Combine(dictFolder, dictDefault), dictExtension);
            }
            else
            {
                dictFilePath = Path.ChangeExtension(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dictFolder, dictionary),
                                                    dictExtension);

                if (!File.Exists(dictFilePath))
                {
                    dictFilePath = // Custom dictionary in app directory
                                   Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ExePath.GetExecutablePath()), dictFolder, dictionary),
                                                        dictExtension);

                    if (!File.Exists(dictFilePath))
                    {
                        return;
                    }
                }
            }

            GetMergedDictionaries().Add(new ResourceDictionary()
            {
                Source = new Uri(dictFilePath, UriKind.RelativeOrAbsolute)
            });
        }