Пример #1
0
        public static ThemeDescription InstallFromPackedFile(string path)
        {
            logger.Info($"Installing theme extenstion {path}");
            var desc = GetDescriptionFromPackedFile(path);

            if (desc == null)
            {
                throw new FileNotFoundException("Theme manifest not found.");
            }

            var installDir = Paths.GetSafeFilename(desc.Name).Replace(" ", string.Empty) + "_" + (desc.Name + desc.Author).MD5();
            var targetDir  = PlayniteSettings.IsPortable ? PlaynitePaths.ThemesProgramPath : PlaynitePaths.ThemesUserDataPath;

            targetDir = Path.Combine(targetDir, desc.Mode.GetDescription(), installDir);
            var oldBackPath = targetDir + "_old";

            if (Directory.Exists(targetDir))
            {
                logger.Debug($"Replacing existing theme installation: {targetDir}.");
                Directory.Move(targetDir, oldBackPath);
            }

            FileSystem.CreateDirectory(targetDir, true);
            ZipFile.ExtractToDirectory(path, targetDir);

            if (Directory.Exists(oldBackPath))
            {
                Directory.Delete(oldBackPath, true);
            }

            return(ThemeDescription.FromFile(Path.Combine(targetDir, PlaynitePaths.ThemeManifestFileName)));
        }
Пример #2
0
        public static List <ThemeDescription> GetAvailableThemes(ApplicationMode mode)
        {
            var modeDir = GetThemeRootDir(mode);
            var added   = new List <string>();
            var themes  = new List <ThemeDescription>();

            var userPath = Path.Combine(PlaynitePaths.ThemesUserDataPath, modeDir);

            if (!PlayniteSettings.IsPortable && Directory.Exists(userPath))
            {
                foreach (var dir in Directory.GetDirectories(userPath))
                {
                    try
                    {
                        var descriptorPath = Path.Combine(dir, PlaynitePaths.ThemeManifestFileName);
                        if (File.Exists(descriptorPath))
                        {
                            var info = new FileInfo(descriptorPath);
                            added.Add(info.Directory.Name);
                            themes.Add(ThemeDescription.FromFile(descriptorPath));
                        }
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, $"Failed to load theme info {dir}");
                    }
                }
            }

            var programPath = Path.Combine(PlaynitePaths.ThemesProgramPath, modeDir);

            if (Directory.Exists(programPath))
            {
                foreach (var dir in Directory.GetDirectories(programPath))
                {
                    try
                    {
                        var descriptorPath = Path.Combine(dir, PlaynitePaths.ThemeManifestFileName);
                        if (File.Exists(descriptorPath))
                        {
                            var info = new FileInfo(descriptorPath);
                            if (!added.Contains(info.Directory.Name))
                            {
                                themes.Add(ThemeDescription.FromFile(descriptorPath));
                            }
                        }
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, $"Failed to load theme info {dir}");
                    }
                }
            }

            return(themes);
        }
Пример #3
0
        public static List <ThemeDescription> GetAvailableThemes(ApplicationMode mode)
        {
            var modeDir = GetThemeRootDir(mode);
            var added   = new List <string>();
            var themes  = new List <ThemeDescription>();

            var userPath = Path.Combine(PlaynitePaths.ThemesUserDataPath, modeDir);

            if (!PlayniteSettings.IsPortable && Directory.Exists(userPath))
            {
                foreach (var dir in Directory.GetDirectories(userPath))
                {
                    var descriptorPath = Path.Combine(dir, ThemeManifestFileName);
                    if (File.Exists(descriptorPath))
                    {
                        var info = new FileInfo(descriptorPath);
                        added.Add(info.Directory.Name);
                        themes.Add(ThemeDescription.FromFile(descriptorPath));
                    }
                }
            }

            var programPath = Path.Combine(PlaynitePaths.ThemesProgramPath, modeDir);

            if (Directory.Exists(programPath))
            {
                foreach (var dir in Directory.GetDirectories(programPath))
                {
                    var descriptorPath = Path.Combine(dir, ThemeManifestFileName);
                    if (File.Exists(descriptorPath))
                    {
                        var info = new FileInfo(descriptorPath);
                        if (!added.Contains(info.Directory.Name))
                        {
                            themes.Add(ThemeDescription.FromFile(descriptorPath));
                        }
                    }
                }
            }

            return(themes);
        }