checks matches of regex search before accessing it

This commit is contained in:
Nils Goetje 2021-04-29 15:21:24 +02:00
parent 65ccc6876a
commit 0b8117d39b

View File

@ -588,6 +588,8 @@ namespace DisplayMagician.GameLibraries
{
// Lookup the GameId within the registry key
mc = Regex.Matches(uplayEntryLines[i], @"Installs\\(\d+)\\InstallDir");
if (mc.Count > 0)
{
gameId = mc[0].Groups[1].ToString();
gotGameId = true;
mc = Regex.Matches(uplayEntryLines[i], @"HKEY_LOCAL_MACHINE\\(.*?)\\InstallDir");
@ -596,6 +598,11 @@ namespace DisplayMagician.GameLibraries
gotGameRegistryKey = true;
logger.Trace($"UplayLibrary/LoadInstalledGames: Found gameId = {gameId} and gameRegistryKey = {gameRegistryKey}");
}
else
{
logger.Trace($"UplayLibrary/LoadInstalledGames: Game with uplayEntryLines[{i}]: '{uplayEntryLines[i]}' not found");
}
}
}
logger.Trace($"UplayLibrary/LoadInstalledGames: gameId = {gameId}");