From a56e68d94e901534965de63ca537de9f09a155ed Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 15 Nov 2020 21:06:38 +1300 Subject: [PATCH] Added Uplay to RunShortcut HeliosPlus now runs Uplay Games and correctly waits until they have exited before changing back. It won't wait for Uplay updates however, as I really don't know how Uplay marks things as being updated. So I don't know how to look for the updates occurring! --- HeliosPlus/GameLibraries/UplayGame.cs | 8 ++-- HeliosPlus/GameLibraries/UplayLibrary.cs | 54 ++++++++++++++++++------ HeliosPlus/ShortcutRepository.cs | 6 +-- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/HeliosPlus/GameLibraries/UplayGame.cs b/HeliosPlus/GameLibraries/UplayGame.cs index 3fef5e1..cd8b0e1 100644 --- a/HeliosPlus/GameLibraries/UplayGame.cs +++ b/HeliosPlus/GameLibraries/UplayGame.cs @@ -151,7 +151,7 @@ namespace HeliosPlus.GameLibraries } } - public override bool IsUpdating + /*public override bool IsUpdating { get { @@ -184,7 +184,7 @@ namespace HeliosPlus.GameLibraries throw; } } - } + }*/ public bool CopyTo(UplayGame uplayGame) { @@ -213,10 +213,10 @@ namespace HeliosPlus.GameLibraries return name + " " + Language.Running; } - if (IsUpdating) + /*if (IsUpdating) { return name + " " + Language.Updating; - } + }*/ return name; } diff --git a/HeliosPlus/GameLibraries/UplayLibrary.cs b/HeliosPlus/GameLibraries/UplayLibrary.cs index 44905a9..7297c42 100644 --- a/HeliosPlus/GameLibraries/UplayLibrary.cs +++ b/HeliosPlus/GameLibraries/UplayLibrary.cs @@ -321,7 +321,7 @@ namespace HeliosPlus.GameLibraries // Yay us :). // First we want to know the index of the start_game entry to use later - int startGameIndex = uplayEntryLines.FindIndex(a => a.StartsWith(" start_game:")); + //int startGameIndex = uplayEntryLines.FindIndex(a => a.StartsWith(" start_game:")); MatchCollection mc; // First we check if there are any localization CONSTANTS that we will need to map later. @@ -346,7 +346,7 @@ namespace HeliosPlus.GameLibraries // for each game record grab: UplayAppInfo uplayGameAppInfo = new UplayAppInfo(); - // name: (lookup the id in lookup table to find the name if needed) +/* // name: (lookup the id in lookup table to find the name if needed) if (uplayEntryLines.Exists(a => a.StartsWith(" name:", StringComparison.InvariantCultureIgnoreCase))) { mc = Regex.Matches(uplayEntry, @" name\: (.*)"); @@ -359,11 +359,11 @@ namespace HeliosPlus.GameLibraries } else continue; - +*/ // icon_image: (lookup the id in lookup table to find the ICON) - if (uplayEntryLines.Exists(a => a.StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase))) + /*if (uplayEntryLines.Exists(a => a.StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase))) { - mc = Regex.Matches(uplayEntry, @" icon_image: (.*)"); + mc = Regex.Matches(uplayEntry, @"icon_image: (.*)"); string iconImageFileName = mc[0].Groups[1].ToString(); // if the icon_image contains a localization reference, then dereference it if (localizations.ContainsKey(iconImageFileName)) @@ -376,7 +376,7 @@ namespace HeliosPlus.GameLibraries { uplayGameAppInfo.GameUplayIconPath = uplayGameIconPath; } - } + }*/ // find the exe name looking at root: -> start_game: -> online: -> executables: -> path: -> relative: (get ACU.exe) // Lookup the Game registry key from looking at root: -> start_game: -> online: -> executables: -> working_directory: -> register: (get HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Launcher\Installs\720\InstallDir) @@ -386,25 +386,55 @@ namespace HeliosPlus.GameLibraries //if (uplayEntryLines.Find (a => a.StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase))) + bool gotGameIconPath = false; + bool gotGameName = false; string gameFileName = ""; bool gotGameFileName = false; string gameId = ""; bool gotGameId = false; - for (int i = startGameIndex; i<= (startGameIndex+30); i++) + for (int i = 0; i <= 50; i++) { // Stop this loop once we have both filname and gameid - if (gotGameFileName && gotGameId) + if (gotGameFileName && gotGameId && gotGameIconPath && gotGameName) break; - + // This line contains the Game Name + if (uplayEntryLines[i].StartsWith(" name:", StringComparison.InvariantCultureIgnoreCase) && !gotGameName) + { + mc = Regex.Matches(uplayEntryLines[i], @" name\: (.*)"); + uplayGameAppInfo.GameName = mc[0].Groups[1].ToString(); + // if the name contains a localization reference, then dereference it + if (localizations.ContainsKey(uplayGameAppInfo.GameName)) + { + uplayGameAppInfo.GameName = localizations[uplayGameAppInfo.GameName]; + } + gotGameName = true; + } + else if (uplayEntryLines[i].StartsWith(" icon_image:", StringComparison.InvariantCultureIgnoreCase) && !gotGameIconPath) + { + mc = Regex.Matches(uplayEntryLines[i], @"icon_image: (.*)"); + string iconImageFileName = mc[0].Groups[1].ToString(); + // if the icon_image contains a localization reference, then dereference it + if (localizations.ContainsKey(iconImageFileName)) + { + iconImageFileName = localizations[iconImageFileName]; + } + //61fdd16f06ae08158d0a6d476f1c6bd5.ico + string uplayGameIconPath = _uplayPath + @"data\games\" + iconImageFileName; + if (File.Exists(uplayGameIconPath) && uplayGameIconPath.EndsWith(".ico")) + { + uplayGameAppInfo.GameUplayIconPath = uplayGameIconPath; + } + gotGameIconPath = true; + } // This line contains the filename - if (uplayEntryLines[i].StartsWith(" relative:") && !gotGameFileName) + else if (uplayEntryLines[i].StartsWith(" relative:") && !gotGameFileName) { mc = Regex.Matches(uplayEntryLines[i], @"relative: (.*)"); gameFileName = mc[0].Groups[1].ToString(); gotGameFileName = true; } // This line contains the registryKey - if (uplayEntryLines[i].StartsWith(" register: HKEY_LOCAL_MACHINE") && !gotGameId) + else if (uplayEntryLines[i].StartsWith(" register: HKEY_LOCAL_MACHINE") && !gotGameId) { // Lookup the GameId within the registry key mc = Regex.Matches(uplayEntryLines[i], @"Installs\\(\d+)\\InstallDir"); @@ -419,7 +449,7 @@ namespace HeliosPlus.GameLibraries // From that we lookup the actual game path uplayGameAppInfo.GameInstallDir = Path.GetFullPath(uplayGameInstallKey.GetValue("InstallDir", "").ToString()).TrimEnd('\\'); - uplayGameAppInfo.GameExe = uplayGameAppInfo.GameInstallDir + gameFileName; + uplayGameAppInfo.GameExe = Path.Combine(uplayGameAppInfo.GameInstallDir,gameFileName); uplayGameAppInfo.GameID = uint.Parse(gameId); // Then we have the gameID, the thumbimage, the icon, the name, the exe path diff --git a/HeliosPlus/ShortcutRepository.cs b/HeliosPlus/ShortcutRepository.cs index b0be982..54d4b4d 100644 --- a/HeliosPlus/ShortcutRepository.cs +++ b/HeliosPlus/ShortcutRepository.cs @@ -731,7 +731,7 @@ namespace HeliosPlus } // Start the URI Handler to run Uplay - Console.WriteLine($"Starting Steam Game: {uplayGameToRun.Name}"); + Console.WriteLine($"Starting Uplay Game: {uplayGameToRun.Name}"); var uplayProcess = Process.Start(address); // Wait for Steam game to update if needed @@ -745,10 +745,10 @@ namespace HeliosPlus Thread.Sleep(300); - if (!uplayGameToRun.IsUpdating) + /*if (!uplayGameToRun.IsUpdating) { ticks += 300; - } + }*/ } // Store the Steam Process ID for later