Modified Game Library installation checks

UplayLibrary was erroring when run without
Uplay installed. Needed to tweak it so that
DisplayMagician will work without Uplay
library or Steam library installed.
This commit is contained in:
Terry MacDonald 2021-01-06 16:00:52 +13:00
parent 65e78a0b29
commit f1c484637c
3 changed files with 58 additions and 19 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@
bld/
[Bb]in/
[Oo]bj/
*.editorconfig
# Visual Studio 2015 cache/options directory
.vs/

View File

@ -24,6 +24,8 @@ namespace DisplayMagician.GameLibraries
private static string _steamConfigVdfFile;
private static string _registrySteamKey = @"SOFTWARE\\Valve\\Steam";
private static string _registryAppsKey = $@"{_registrySteamKey}\\Apps";
private static bool _isSteamInstalled = false;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
// Other constants that are useful
#endregion
@ -39,15 +41,34 @@ namespace DisplayMagician.GameLibraries
#region Class Constructors
static SteamLibrary()
{
// Find the SteamExe location, and the SteamPath for later
using (var key = Registry.CurrentUser.OpenSubKey(SteamLibrary.SteamRegistryKey, RegistryKeyPermissionCheck.ReadSubTree))
try
{
_steamExe = (string)key?.GetValue(@"SteamExe", string.Empty) ?? string.Empty;
_steamExe = _steamExe.Replace('/', '\\');
_steamPath = (string)key?.GetValue(@"SteamPath", string.Empty) ?? string.Empty;
_steamPath = _steamPath.Replace('/', '\\');
// Find the SteamExe location, and the SteamPath for later
using (var key = Registry.CurrentUser.OpenSubKey(SteamLibrary.SteamRegistryKey, RegistryKeyPermissionCheck.ReadSubTree))
{
_steamExe = (string)key?.GetValue(@"SteamExe", string.Empty) ?? string.Empty;
_steamExe = _steamExe.Replace('/', '\\');
_steamPath = (string)key?.GetValue(@"SteamPath", string.Empty) ?? string.Empty;
_steamPath = _steamPath.Replace('/', '\\');
}
_isSteamInstalled = true;
}
catch (SecurityException ex)
{
logger.Warn("The user does not have the permissions required to read the Steam registry key.");
}
catch (ObjectDisposedException ex)
{
logger.Warn("The Microsoft.Win32.RegistryKey is closed when trying to access theSteam registry key (closed keys cannot be accessed).");
}
catch (IOException ex)
{
logger.Warn("The Steam registry key has been marked for deletion so we cannot access the value during the SteamLibrary check.");
}
catch (UnauthorizedAccessException ex)
{
logger.Warn("The user does not have the necessary registry rights to check whether Steam is installed.");
}
}
#endregion
@ -108,10 +129,7 @@ namespace DisplayMagician.GameLibraries
{
get
{
if (!string.IsNullOrWhiteSpace(SteamExe) && File.Exists(SteamExe))
return true;
return false;
return _isSteamInstalled;
}
}

View File

@ -21,12 +21,15 @@ namespace DisplayMagician.GameLibraries
// Common items to the class
private static List<Game> _allUplayGames = new List<Game>();
private static string uplayAppIdRegex = @"/^[0-9A-F]{1,10}$";
private static bool _isUplayInstalled = false;
private static string _uplayExe;
private static string _uplayPath;
private static string _uplayConfigVdfFile;
internal static string registryUplayLauncherKey = @"SOFTWARE\WOW6432Node\Ubisoft\Launcher";
internal static string registryUplayInstallsKey = @"SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs";
internal static string registryUplayOpenCmdKey = @"SOFTWARE\Classes\uplay\Shell\Open\Command";
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
// Other constants that are useful
#endregion
@ -43,10 +46,30 @@ namespace DisplayMagician.GameLibraries
#region Class Constructors
static UplayLibrary()
{
// Find the UplayExe location, and the UplayPath for later
RegistryKey uplayInstallKey = Registry.LocalMachine.OpenSubKey(registryUplayLauncherKey, RegistryKeyPermissionCheck.ReadSubTree);
_uplayPath = uplayInstallKey.GetValue("InstallDir", "C:\\Program Files (x86)\\Ubisoft\\Ubisoft Game Launcher\\").ToString();
_uplayExe = $"{_uplayPath}upc.exe";
try
{
// Find the UplayExe location, and the UplayPath for later
RegistryKey uplayInstallKey = Registry.LocalMachine.OpenSubKey(registryUplayLauncherKey, RegistryKeyPermissionCheck.ReadSubTree);
_uplayPath = uplayInstallKey.GetValue("InstallDir", "C:\\Program Files (x86)\\Ubisoft\\Ubisoft Game Launcher\\").ToString();
_uplayExe = $"{_uplayPath}upc.exe";
_isUplayInstalled = true;
}
catch (SecurityException ex)
{
logger.Warn("The user does not have the permissions required to read the Uplay InstallDir registry key.");
}
catch(ObjectDisposedException ex)
{
logger.Warn("The Microsoft.Win32.RegistryKey is closed when trying to access the Uplay InstallDir registry key (closed keys cannot be accessed).");
}
catch (IOException ex)
{
logger.Warn("The Uplay InstallDir registry key has been marked for deletion so we cannot access the value dueing the UplayLibrary check.");
}
catch (UnauthorizedAccessException ex)
{
logger.Warn("The user does not have the necessary registry rights to check whether Uplay is installed.");
}
}
#endregion
@ -91,10 +114,7 @@ namespace DisplayMagician.GameLibraries
{
get
{
if (!string.IsNullOrWhiteSpace(UplayExe) && File.Exists(UplayExe))
return true;
return false;
return _isUplayInstalled;
}
}