mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Partially working uplay scanning
Updated Uplay library scanning to work properly, but it requires access to the HKEY_LOCAL_MACHINE reg key, which only works with adrministrative rights. I really don't want to need that, so I'll be trying to find an alternative way to get the information I need from the file system.
This commit is contained in:
parent
b83478a031
commit
8c132a79f5
@ -411,16 +411,18 @@ namespace DisplayMagician.GameLibraries
|
|||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: Uplay Config File Path = {uplayConfigFilePath }");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: Uplay Config File Path = {uplayConfigFilePath }");
|
||||||
string uplayConfigFileString = File.ReadAllText(uplayConfigFilePath);
|
string uplayConfigFileString = File.ReadAllText(uplayConfigFilePath);
|
||||||
uplayConfigFileString = uplayConfigFileString.Remove(0, 12);
|
uplayConfigFileString = uplayConfigFileString.Remove(0, 12);
|
||||||
|
string[] dividingText = { "version: 2.0" };
|
||||||
|
List<string> uplayConfigFile = uplayConfigFileString.Split(dividingText,StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
// Split the file into records at the SOH unicode character
|
// Split the file into records at the SOH unicode character
|
||||||
List<string> uplayConfigFile = uplayConfigFileString.Split((Char)1).ToList();
|
//List<string> uplayConfigFile = uplayConfigFileString.Split((Char)1).ToList();
|
||||||
|
|
||||||
// Go through every record and attempt to parse it
|
// Go through every record and attempt to parse it
|
||||||
foreach (string uplayEntry in uplayConfigFile) {
|
foreach (string uplayEntry in uplayConfigFile) {
|
||||||
// Skip any Uplay entry records that don't start with 'version:'
|
// Skip any Uplay entry records that don't start with 'version:'
|
||||||
if (!uplayEntry.StartsWith("version:",StringComparison.OrdinalIgnoreCase))
|
//if (!uplayEntry.StartsWith("version:",StringComparison.OrdinalIgnoreCase))
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: Uplay Entry (that don't start with version) = {uplayEntry}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: Uplay Entry that starts with 'version: 2.0') = {uplayEntry}");
|
||||||
|
|
||||||
//Split the record into entrylines
|
//Split the record into entrylines
|
||||||
string[] delimeters = { "\r\n" };
|
string[] delimeters = { "\r\n" };
|
||||||
@ -479,10 +481,12 @@ namespace DisplayMagician.GameLibraries
|
|||||||
bool gotGameFileName = false;
|
bool gotGameFileName = false;
|
||||||
string gameId = "";
|
string gameId = "";
|
||||||
bool gotGameId = false;
|
bool gotGameId = false;
|
||||||
|
string gameRegistryKey = "";
|
||||||
|
bool gotGameRegistryKey = false;
|
||||||
for (int i = 0; i <= 50; i++)
|
for (int i = 0; i <= 50; i++)
|
||||||
{
|
{
|
||||||
// Stop this loop once we have both filname and gameid
|
// Stop this loop once we have both filname and gameid
|
||||||
if (gotGameFileName && gotGameId && gotGameIconPath && gotGameName)
|
if (gotGameFileName && gotGameId && gotGameIconPath && gotGameName && gotGameRegistryKey)
|
||||||
{
|
{
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: We got all the entries: gameFileName = {gameFileName } && gameId = {gameId } && gameIconPath = {uplayGameAppInfo.GameUplayIconPath} && gameName = {uplayGameAppInfo.GameName}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: We got all the entries: gameFileName = {gameFileName } && gameId = {gameId } && gameIconPath = {uplayGameAppInfo.GameUplayIconPath} && gameName = {uplayGameAppInfo.GameName}");
|
||||||
break;
|
break;
|
||||||
@ -535,18 +539,40 @@ namespace DisplayMagician.GameLibraries
|
|||||||
mc = Regex.Matches(uplayEntryLines[i], @"Installs\\(\d+)\\InstallDir");
|
mc = Regex.Matches(uplayEntryLines[i], @"Installs\\(\d+)\\InstallDir");
|
||||||
gameId = mc[0].Groups[1].ToString();
|
gameId = mc[0].Groups[1].ToString();
|
||||||
gotGameId = true;
|
gotGameId = true;
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: Found gameId = {gameId}");
|
//mc = Regex.Matches(uplayEntryLines[i], @"(HKEY_LOCAL_MACHINE.*?\\InstallDir)");
|
||||||
|
mc = Regex.Matches(uplayEntryLines[i], @"(HKEY_LOCAL_MACHINE.*?)\\InstallDir");
|
||||||
|
gameRegistryKey = mc[0].Groups[1].ToString();
|
||||||
|
gotGameRegistryKey = true;
|
||||||
|
logger.Trace($"UplayLibrary/LoadInstalledGames: Found gameId = {gameId} and gameRegistryKey = {gameRegistryKey}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: gameId = {gameId}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: gameId = {gameId}");
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: gameFileName = {gameFileName}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: gameFileName = {gameFileName}");
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: gameGameIconPath = {uplayGameAppInfo.GameUplayIconPath}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: gameGameIconPath = {uplayGameAppInfo.GameUplayIconPath}");
|
||||||
|
logger.Trace($"UplayLibrary/LoadInstalledGames: gameRegistryKey = {gameRegistryKey}");
|
||||||
|
|
||||||
|
if (gotGameRegistryKey)
|
||||||
|
{
|
||||||
// Now we need to lookup the game install path in registry using the gameId
|
// Now we need to lookup the game install path in registry using the gameId
|
||||||
string registryUplayGameInstallsKey = registryUplayInstallsKey + "\\" + gameId;
|
using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: registryUplayGameInstallsKey = {registryUplayGameInstallsKey}");
|
using (RegistryKey uplayGameInstallKey = hklm.OpenSubKey(gameRegistryKey, RegistryKeyPermissionCheck.ReadSubTree))
|
||||||
RegistryKey uplayGameInstallKey = Registry.LocalMachine.OpenSubKey(registryUplayGameInstallsKey, RegistryKeyPermissionCheck.ReadSubTree);
|
{
|
||||||
|
if (uplayGameInstallKey == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// check if null (means the game isn't installed any more!)
|
||||||
|
// if it's null then skip!
|
||||||
|
/* if (uplayGameInstallKey == null)
|
||||||
|
{
|
||||||
|
// if we can't find it in the default location, then we try within WOW6432Node instead
|
||||||
|
gameRegistryKey = gameRegistryKey.Replace(@"Ubisoft", @"WOW6432Node\Ubisoft");
|
||||||
|
uplayGameInstallKey = Registry.LocalMachine.OpenSubKey(gameRegistryKey, RegistryKeyPermissionCheck.ReadSubTree);
|
||||||
|
if (uplayGameInstallKey == null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
foreach (string regKeyName in uplayGameInstallKey.GetValueNames())
|
foreach (string regKeyName in uplayGameInstallKey.GetValueNames())
|
||||||
{
|
{
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: uplayGameInstallKey[{regKeyName}] = {uplayGameInstallKey.GetValue(regKeyName)}");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: uplayGameInstallKey[{regKeyName}] = {uplayGameInstallKey.GetValue(regKeyName)}");
|
||||||
@ -564,7 +590,8 @@ namespace DisplayMagician.GameLibraries
|
|||||||
uplayGameAppInfo.GameID = int.Parse(gameId);
|
uplayGameAppInfo.GameID = int.Parse(gameId);
|
||||||
logger.Trace($"UplayLibrary/LoadInstalledGames: uplayGameAppInfo.GameID = {uplayGameAppInfo.GameID }");
|
logger.Trace($"UplayLibrary/LoadInstalledGames: uplayGameAppInfo.GameID = {uplayGameAppInfo.GameID }");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
logger.Warn($"UplayLibrary/LoadInstalledGames: gameInstallDir is null or all whitespace!");
|
logger.Warn($"UplayLibrary/LoadInstalledGames: gameInstallDir is null or all whitespace!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,6 +600,9 @@ namespace DisplayMagician.GameLibraries
|
|||||||
_allUplayGames.Add(new UplayGame(uplayGameAppInfo.GameID, uplayGameAppInfo.GameName, uplayGameAppInfo.GameExe, uplayGameAppInfo.GameUplayIconPath));
|
_allUplayGames.Add(new UplayGame(uplayGameAppInfo.GameID, uplayGameAppInfo.GameName, uplayGameAppInfo.GameExe, uplayGameAppInfo.GameUplayIconPath));
|
||||||
logger.Debug($"UplayLibrary/LoadInstalledGames: Adding Uplay Game with game id {uplayGameAppInfo.GameID}, name {uplayGameAppInfo.GameName}, game exe {uplayGameAppInfo.GameExe} and icon path {uplayGameAppInfo.GameUplayIconPath}");
|
logger.Debug($"UplayLibrary/LoadInstalledGames: Adding Uplay Game with game id {uplayGameAppInfo.GameID}, name {uplayGameAppInfo.GameName}, game exe {uplayGameAppInfo.GameExe} and icon path {uplayGameAppInfo.GameUplayIconPath}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
logger.Info($"UplayLibrary/LoadInstalledGames: Found {_allUplayGames.Count} installed Uplay games");
|
logger.Info($"UplayLibrary/LoadInstalledGames: Found {_allUplayGames.Count} installed Uplay games");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user