Skip to content

SteamVR Runtime Selector doesn't work with multiple library folders #2

@aondw

Description

@aondw

Hi, I came across an issue where it doesn't correctly select the steamvr openxr runtime if you have multiple library folders and steamvr is installed in the second folder.

here's a fixed version:

internal class SteamVRRuntimeJson : IOpenXRRuntimeJson
    {
        private const string SteamPathKey = @"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam";
        private const string SteamPathValue = "SteamPath";
        private const string LibraryFoldersVdf = "steamapps/libraryfolders.vdf";
        private const string LibraryFoldersKey = "\"libraryfolders\"";
        private const string JsonName = @"common/SteamVR/steamxr_win64.json";
        private static readonly Regex RxLibraryPath = new Regex(@"^\s*""path""\s*""([^""]+)""", RegexOptions.Compiled);

        public OpenXRRuntimeType Name => OpenXRRuntimeType.SteamVR;

        public bool TryGetJsonPath(out string jsonPath)
        {
            jsonPath = default;

            var steamPathValue = Registry.GetValue(SteamPathKey, SteamPathValue, string.Empty);
            if (!(steamPathValue is string steamPath) || string.IsNullOrWhiteSpace(steamPath))
                return false;

            var libraryFolders = Path.Combine(steamPath, LibraryFoldersVdf);
            if (!File.Exists(libraryFolders))
                return false;

            var folders = new List<string> { Path.Combine(steamPath, "steamapps") };

            foreach (var line in File.ReadLines(libraryFolders))
            {
                var match = RxLibraryPath.Match(line.Trim());
                if (match.Success)
                {
                    var path = match.Groups[1].Value.Replace(@"\\", @"\");
                    folders.Add(Path.Combine(path, "steamapps"));
                }
            }

            foreach (var folder in folders)
            {
                var path = Path.Combine(folder, JsonName);
                if (File.Exists(path))
                {
                    jsonPath = Path.GetFullPath(path);
                    return true;
                }
            }

            return false;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions