コード例 #1
0
        private static Installation?FindSteamInstallation(ModData modData, IGeneration generation)
        {
            foreach (var steamDirectory in InstallationFinder.SteamDirectory())
            {
                var manifestPath = Path.Combine(steamDirectory, "steamapps", $"appmanifest_{generation.SteamAppId}.acf");

                if (!File.Exists(manifestPath))
                {
                    continue;
                }

                var data = InstallationFinder.ParseKeyValuesManifest(manifestPath);

                if (!data.TryGetValue("StateFlags", out var stateFlags) || stateFlags != "4")
                {
                    continue;
                }

                if (!data.TryGetValue("installdir", out var installDir))
                {
                    continue;
                }

                installDir = Path.Combine(steamDirectory, "steamapps", "common", installDir);

                Log.Write("debug", $"Steam version candidate: {installDir}");

                var game = InstallationUtils.TryRegister(modData, installDir, generation);

                if (game != null)
                {
                    return(game);
                }
            }

            Log.Write("debug", "Steam version not found");

            return(null);
        }
コード例 #2
0
 public static Installation?RegisterInstallation(ModData modData, IGeneration generation)
 {
     return(InstallationFinder.FindSteamInstallation(modData, generation)
            ?? InstallationFinder.FindGoGInstallation(modData, generation) ?? InstallationFinder.FindCdVersion(modData, generation));
 }
コード例 #3
0
        private static IEnumerable <string> SteamDirectory()
        {
            var candidatePaths = new List <string>();

            switch (Platform.CurrentPlatform)
            {
            case PlatformType.Windows:
            {
                var prefixes = new[] { "HKEY_LOCAL_MACHINE\\Software\\", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\" };

                foreach (var prefix in prefixes)
                {
                    if (Registry.GetValue($"{prefix}Valve\\Steam", "InstallPath", null) is string path)
                    {
                        candidatePaths.Add(path);
                    }
                }

                break;
            }

            case PlatformType.OSX:
                candidatePaths.Add(
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Steam")
                    );

                break;

            case PlatformType.Linux:
                candidatePaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".steam", "root"));

                break;

            case PlatformType.Unknown:
                break;

            default:
                throw new ArgumentOutOfRangeException(Enum.GetName(Platform.CurrentPlatform));
            }

            foreach (var libraryPath in candidatePaths.Where(Directory.Exists))
            {
                yield return(libraryPath);

                var libraryFoldersPath = Path.Combine(libraryPath, "steamapps", "libraryfolders.vdf");

                if (!File.Exists(libraryFoldersPath))
                {
                    continue;
                }

                var data = InstallationFinder.ParseKeyValuesManifest(libraryFoldersPath);

                for (var i = 1;; i++)
                {
                    if (!data.TryGetValue(i.ToString(), out var path))
                    {
                        break;
                    }

                    yield return(path);
                }
            }
        }