From a230a43fa078ca83c8cfa7f8b60e5934fe4353bf Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 16 Oct 2021 17:28:35 +1300 Subject: [PATCH] Avoiding missing uplay_id game ids Some Uplay Games have the uplay_id set to zero, when they shouldn't be. Havign to take the Game ID from the Reg key path to compensate. --- DisplayMagician/GameLibraries/UplayLibrary.cs | 43 +++++++++++++++++-- DisplayMagician/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/DisplayMagician/GameLibraries/UplayLibrary.cs b/DisplayMagician/GameLibraries/UplayLibrary.cs index ac0e684..c3135d8 100644 --- a/DisplayMagician/GameLibraries/UplayLibrary.cs +++ b/DisplayMagician/GameLibraries/UplayLibrary.cs @@ -545,6 +545,7 @@ namespace DisplayMagician.GameLibraries productInfo = deserializer.Deserialize(item.GameInfo); var root = productInfo.root; + string gameId = ""; string gameName = ""; string gameExePath = ""; string gameIconPath = ""; @@ -599,12 +600,19 @@ namespace DisplayMagician.GameLibraries regKeyText = regKeyText.Replace(@"\InstallDir", ""); regKeyText = regKeyText.Replace(@"Ubisoft", @"WOW6432Node\Ubisoft"); logger.Trace($"UplayLibrary/GetInstallDirFromRegKey: Accessing HKLM reg key {regKeyText}"); - if (this.GetInstallDirFromRegKey(regKeyText, out exePath)) { gameExePath = Path.Combine(exePath, executable.path.relative); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses local machine registry key: {executable.working_directory.register} "); } + // Get the GameID from the reg key + string pattern = @"Installs\\(\d+)\\InstallDir"; + MatchCollection mc = Regex.Matches(executable.working_directory.register, pattern); + if (mc.Count > 0) + { + gameId = mc[0].Groups[1].Value; + } + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); } /*else if (executable.working_directory.register.StartsWith("HKEY_CURRENT_USER")) { @@ -620,6 +628,14 @@ namespace DisplayMagician.GameLibraries gameExePath = Path.Combine(exePath, executable.path.relative); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses current user registry key: {executable.working_directory.register} "); } + // Get the GameID from the reg key + string pattern = @"Installs\\(\d+)\\InstallDir"; + MatchCollection mc = Regex.Matches(executable.working_directory.register, pattern); + if (mc.Count > 0) + { + gameId = mc[0].Groups[1].Value; + } + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); }*/ else if (!String.IsNullOrEmpty(executable.working_directory.append)) { @@ -627,6 +643,8 @@ namespace DisplayMagician.GameLibraries gameExePath = Path.Combine(executable.working_directory.append, executable.path.relative); gameIconPath = Path.Combine(executable.working_directory.append, executable.icon_image); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses appended file path: {executable.working_directory.append} "); + gameId = productInfo.uplay_id.ToString(); + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); } else { @@ -674,7 +692,7 @@ namespace DisplayMagician.GameLibraries // Now we need to save the game name, cause if we're here then we're good enough to save // Then we have the gameID, the thumbimage, the icon, the name, the exe path // And we add the Game to the list of games we have! - _allGames.Add(new UplayGame(productInfo.uplay_id.ToString(), gameName, gameExePath, gameIconPath)); + _allGames.Add(new UplayGame(gameId, gameName, gameExePath, gameIconPath)); logger.Trace($"UplayLibrary/LoadInstalledGames: Adding Uplay Game with game id {productInfo.uplay_id}, name {gameName}, game exe {gameExePath} and icon path {gameIconPath}"); break; } @@ -707,6 +725,15 @@ namespace DisplayMagician.GameLibraries gameExePath = Path.Combine(exePath, executable.path.relative); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses local machine registry key: {executable.working_directory.register} "); } + // Get the GameID from the reg key + string pattern = @"Installs\\(\d+)\\InstallDir"; + MatchCollection mc = Regex.Matches(executable.working_directory.register, pattern); + if (mc.Count > 0) + { + gameId = mc[0].Groups[1].Value; + } + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); + } /*else if (executable.working_directory.register.StartsWith("HKEY_CURRENT_USER")) { @@ -722,6 +749,14 @@ namespace DisplayMagician.GameLibraries gameExePath = Path.Combine(exePath, executable.path.relative); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses current user registry key: {executable.working_directory.register} "); } + // Get the GameID from the reg key + string pattern = @"Installs\\(\d+)\\InstallDir"; + MatchCollection mc = Regex.Matches(executable.working_directory.register, pattern); + if (mc.Count > 0) + { + gameId = mc[0].Groups[1].Value; + } + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); }*/ else if (!String.IsNullOrEmpty(executable.working_directory.append)) { @@ -729,6 +764,8 @@ namespace DisplayMagician.GameLibraries gameExePath = Path.Combine(executable.working_directory.append, executable.path.relative); gameIconPath = Path.Combine(executable.working_directory.append, executable.icon_image); logger.Trace($"UplayLibrary/LoadInstalledGames: Relative executable uses appended file path: {executable.working_directory.append} "); + gameId = productInfo.uplay_id.ToString(); + logger.Trace($"UplayLibrary/LoadInstalledGames: Got uplay Game ID: {gameId} "); } else { @@ -776,7 +813,7 @@ namespace DisplayMagician.GameLibraries // Now we need to save the game name, cause if we're here then we're good enough to save // Then we have the gameID, the thumbimage, the icon, the name, the exe path // And we add the Game to the list of games we have! - _allGames.Add(new UplayGame(productInfo.uplay_id.ToString(), gameName, gameExePath, gameIconPath)); + _allGames.Add(new UplayGame(gameId, gameName, gameExePath, gameIconPath)); logger.Trace($"UplayLibrary/LoadInstalledGames: Adding Uplay Game with game id {productInfo.uplay_id}, name {gameName}, game exe {gameExePath} and icon path {gameIconPath}"); break; } diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index ad16e06..168c68a 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.0.1.149")] -[assembly: AssemblyFileVersion("2.0.1.149")] +[assembly: AssemblyVersion("2.0.1.159")] +[assembly: AssemblyFileVersion("2.0.1.159")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)]