Skip to content

Commit 2b2dd41

Browse files
committed
add option to search Windows GameConfigStore for the game executable
1 parent 916cee9 commit 2b2dd41

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

GameLib.Core/LauncherOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
public class LauncherOptions
44
{
55
/// <summary>
6-
/// Define if Launcher plugin should use local catalog data to get more detailed information about specific games
6+
/// Define if Launcher plugin should use local catalog data (if present)
7+
/// to get more detailed information about specific games
78
/// Note: Can in increase load time for the plugin
89
/// </summary>
910
public bool LoadLocalCatalogData { get; init; } = true;
1011

12+
/// <summary>
13+
/// If executable cannot be found via the "regular" way try searching Windows GameConfigStore
14+
/// </summary>
15+
public bool SearchGameConfigStore { get; init; } = true;
16+
1117
/// <summary>
1218
/// Define if Launcher plugin should use online query's to get more detailed information about specific games
1319
/// Note: Can in increase load time for the plugin

GameLib.Core/Util/RegistryUtil.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,43 @@ public static class RegistryUtil
2424
return executablePath;
2525
}
2626

27+
/// <summary>
28+
/// Search the Windows GameConfigStore for the game executable
29+
/// NOTE: this detection mode does not work for all games, also
30+
/// the game must have started at least once to appear in GameConfigStore
31+
/// </summary>
32+
/// <param name="installDir">Installation directory of the game</param>
33+
/// <returns>The path of the executable; <see langword="null"/> if not found</returns>
34+
public static string? SearchGameConfigStore(string installDir)
35+
{
36+
const string RegistryPath = @"System\GameConfigStore\Children";
37+
38+
using var regKey = GetKey(RegistryHive.CurrentUser, RegistryPath, true);
39+
40+
if (regKey is null)
41+
{
42+
return null;
43+
}
44+
45+
foreach (var subKey in regKey.GetSubKeyNames())
46+
{
47+
var executablePath = PathUtil.Sanitize(GetValue(RegistryHive.CurrentUser, $@"{RegistryPath}\{subKey}", "MatchedExeFullPath", string.Empty));
48+
if (string.IsNullOrEmpty(executablePath))
49+
{
50+
continue;
51+
}
52+
53+
if (executablePath.StartsWith(installDir, StringComparison.OrdinalIgnoreCase) &&
54+
File.Exists(executablePath) &&
55+
PathUtil.IsExecutable(executablePath))
56+
{
57+
return executablePath;
58+
}
59+
}
60+
61+
return null;
62+
}
63+
2764
/// <summary>
2865
/// Gets the registry key for the passed Hive and KeyName
2966
/// Firstly it checks in the 32bit environment, if no key found in the 64bit environment

0 commit comments

Comments
 (0)