Fixed coping with gamelibrary removal

DisplayMagician can now handle it if a gamelibrary
is removed, or if you use a shortcut config file from
later version of DisplayMagician with an earlier version
of the DisplayMagician application. It will simply ignore
the incompatible shortcut, and it won't be able to be
edited or used.
This commit is contained in:
Terry MacDonald 2021-06-07 10:57:59 +12:00
parent 109a675f04
commit c93d2b8378
3 changed files with 55 additions and 34 deletions

View File

@ -94,7 +94,7 @@ namespace DisplayMagician
private bool _processNameToMonitorUsesExecutable = true; private bool _processNameToMonitorUsesExecutable = true;
private string _gameAppId; private string _gameAppId;
private string _gameName; private string _gameName;
private SupportedGameLibraryType _gameLibrary; private SupportedGameLibraryType _gameLibrary = SupportedGameLibraryType.Unknown;
private int _startTimeout = 20; private int _startTimeout = 20;
private string _gameArguments; private string _gameArguments;
private bool _gameArgumentsRequired; private bool _gameArgumentsRequired;
@ -1017,6 +1017,11 @@ namespace DisplayMagician
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the GOG icon as the icon instead."); logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the GOG icon as the icon instead.");
bm = ToBitmapOverlay(Properties.Resources.GOG, _profileToUse.ProfileIcon.ToBitmap(), 256, 256); bm = ToBitmapOverlay(Properties.Resources.GOG, _profileToUse.ProfileIcon.ToBitmap(), 256, 256);
} }
else
{
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Unknown Game Library, so using the DisplayMagician icon as the icon instead.");
bm = ToBitmapOverlay(Properties.Resources.DisplayMagician.ToBitmap(), _profileToUse.ProfileIcon.ToBitmap(), 256, 256);
}
si.Add(bm); si.Add(bm);
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Saving the replacement icon for Shortcut '{Name}' to {_savedShortcutIconCacheFilename}."); logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Saving the replacement icon for Shortcut '{Name}' to {_savedShortcutIconCacheFilename}.");
shortcutIcon.Save(_savedShortcutIconCacheFilename, MultiIconFormat.ICO); shortcutIcon.Save(_savedShortcutIconCacheFilename, MultiIconFormat.ICO);
@ -1042,7 +1047,7 @@ namespace DisplayMagician
{ {
if (_category == ShortcutCategory.Application) if (_category == ShortcutCategory.Application)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the executable icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the executable icon as the icon instead.");
originalBitmap = ImageUtils.GetMeABitmapFromFile(_executableNameAndPath); originalBitmap = ImageUtils.GetMeABitmapFromFile(_executableNameAndPath);
} }
else if (_category == ShortcutCategory.Game) else if (_category == ShortcutCategory.Game)
@ -1050,38 +1055,38 @@ namespace DisplayMagician
logger.Trace($"ShortcutItem/ToBitmapOverlay: OriginalBitmap is null, so we'll try to make the BitmapOverlay using GameLibrary Icon."); logger.Trace($"ShortcutItem/ToBitmapOverlay: OriginalBitmap is null, so we'll try to make the BitmapOverlay using GameLibrary Icon.");
if (_gameLibrary == SupportedGameLibraryType.Steam) if (_gameLibrary == SupportedGameLibraryType.Steam)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Steam icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the Steam icon as the icon instead.");
originalBitmap = Properties.Resources.Steam; originalBitmap = Properties.Resources.Steam;
} }
else if (_gameLibrary == SupportedGameLibraryType.Uplay) else if (_gameLibrary == SupportedGameLibraryType.Uplay)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Uplay icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the Uplay icon as the icon instead.");
originalBitmap = Properties.Resources.Uplay; originalBitmap = Properties.Resources.Uplay;
} }
else if (_gameLibrary == SupportedGameLibraryType.Origin) else if (_gameLibrary == SupportedGameLibraryType.Origin)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Origin icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the Origin icon as the icon instead.");
originalBitmap = Properties.Resources.Origin; originalBitmap = Properties.Resources.Origin;
} }
else if (_gameLibrary == SupportedGameLibraryType.Epic) else if (_gameLibrary == SupportedGameLibraryType.Epic)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Epic icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the Epic icon as the icon instead.");
originalBitmap = Properties.Resources.Epic; originalBitmap = Properties.Resources.Epic;
} }
else if (_gameLibrary == SupportedGameLibraryType.GOG) else if (_gameLibrary == SupportedGameLibraryType.GOG)
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the GOG icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the GOG icon as the icon instead.");
originalBitmap = Properties.Resources.GOG; originalBitmap = Properties.Resources.GOG;
} }
else else
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Unknown Game Library, so using the DisplayMagician icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Unknown Game Library, so using the DisplayMagician icon as the icon instead.");
originalBitmap = Properties.Resources.DisplayMagician.ToBitmap(); originalBitmap = Properties.Resources.DisplayMagician.ToBitmap();
} }
} }
else else
{ {
logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the profile icon as the icon instead."); logger.Trace($"ShortcutItem/ToBitmapOverlay: Using the profile icon as the icon instead.");
originalBitmap = _profileToUse.ProfileBitmap; originalBitmap = _profileToUse.ProfileBitmap;
} }
@ -1209,32 +1214,47 @@ namespace DisplayMagician
// We now need to get the GOG Game info // We now need to get the GOG Game info
gameLibraryToUse = GogLibrary.GetLibrary(); gameLibraryToUse = GogLibrary.GetLibrary();
} }
else
// Check if Gamelibrary is installed and error if it isn't
if (!gameLibraryToUse.IsGameLibraryInstalled)
{ {
logger.Warn($"ShortcutItem/RefreshValidity: The game library is not installed!"); gameLibraryToUse = null;
logger.Warn($"ShortcutItem/RefreshValidity: The game shortcut uses an unsupported game library! (You've probably downgraded DisplayMagician to an earlier version)");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = $"{gameLibraryToUse.GameLibraryName}NotInstalled"; error.Name = $"UnknownGameLibrary";
error.Validity = ShortcutValidity.Error; error.Validity = ShortcutValidity.Error;
error.Message = $"{gameLibraryToUse.GameLibraryName} is not installed on this computer."; error.Message = $"The game shortcut uses an unsupported game library.";
_shortcutErrors.Add(error); _shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error) if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error; worstError = ShortcutValidity.Error;
} }
// We need to look up details about the game if (gameLibraryToUse != null)
if (!gameLibraryToUse.ContainsGameById(GameAppId))
{ {
logger.Warn($"ShortcutItem/RefreshValidity: The game library does not have Game ID {GameAppId} installed!"); // Check if Gamelibrary is installed and error if it isn't
ShortcutError error = new ShortcutError(); if (!gameLibraryToUse.IsGameLibraryInstalled)
error.Name = "{gameLibraryToUse.GameLibraryName}GameNotInstalled"; {
error.Validity = ShortcutValidity.Error; logger.Warn($"ShortcutItem/RefreshValidity: The game library is not installed!");
error.Message = $"The {gameLibraryToUse.GameLibraryName} Game with AppID '{GameAppId}' is not installed on this computer."; ShortcutError error = new ShortcutError();
_shortcutErrors.Add(error); error.Name = $"{gameLibraryToUse.GameLibraryName}NotInstalled";
if (worstError != ShortcutValidity.Error) error.Validity = ShortcutValidity.Error;
worstError = ShortcutValidity.Error; error.Message = $"{gameLibraryToUse.GameLibraryName} is not installed on this computer.";
} _shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error;
}
// We need to look up details about the game
if (!gameLibraryToUse.ContainsGameById(GameAppId))
{
logger.Warn($"ShortcutItem/RefreshValidity: The game library does not have Game ID {GameAppId} installed!");
ShortcutError error = new ShortcutError();
error.Name = "{gameLibraryToUse.GameLibraryName}GameNotInstalled";
error.Validity = ShortcutValidity.Error;
error.Message = $"The {gameLibraryToUse.GameLibraryName} Game with AppID '{GameAppId}' is not installed on this computer.";
_shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error;
}
}
} }
// Check the Audio Device is still valid (if one is specified) // Check the Audio Device is still valid (if one is specified)
CoreAudioController audioController = ShortcutRepository.AudioController; CoreAudioController audioController = ShortcutRepository.AudioController;

View File

@ -380,11 +380,6 @@ namespace DisplayMagician
if (!string.IsNullOrWhiteSpace(json)) if (!string.IsNullOrWhiteSpace(json))
{ {
// "Disabled": false,
// Firstly perform any modifications we need to do to update the JSON structure // Firstly perform any modifications we need to do to update the JSON structure
// to handle old versions of the file that need updating. Done with a simple regex replace // to handle old versions of the file that need updating. Done with a simple regex replace
try try
@ -401,8 +396,6 @@ namespace DisplayMagician
logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Tried to update the JSON in the {_shortcutStorageJsonFileName} but the Regex Replace threw an exception."); logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Tried to update the JSON in the {_shortcutStorageJsonFileName} but the Regex Replace threw an exception.");
} }
#pragma warning disable IDE0059 // Unnecessary assignment of a value #pragma warning disable IDE0059 // Unnecessary assignment of a value
List<ShortcutItem> shortcuts = new List<ShortcutItem>(); List<ShortcutItem> shortcuts = new List<ShortcutItem>();
#pragma warning restore IDE0059 // Unnecessary assignment of a value #pragma warning restore IDE0059 // Unnecessary assignment of a value

View File

@ -19,7 +19,7 @@ namespace DisplayMagician.UIForms
private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor(); private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor();
private ShortcutItem _selectedShortcut = null; private ShortcutItem _selectedShortcut = null;
//public static Dictionary<string, bool> shortcutValidity = new Dictionary<string, bool>(); private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public ShortcutLibraryForm() public ShortcutLibraryForm()
{ {
@ -65,6 +65,14 @@ namespace DisplayMagician.UIForms
foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name)) foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name))
{ {
// Ignore any shortcuts with incompatible game libraries
if (!Enum.IsDefined(typeof(SupportedGameLibraryType), loadedShortcut.GameLibrary) || loadedShortcut.GameLibrary == SupportedGameLibraryType.Unknown)
{
// Skip showing unknown game library items as we have no way to deal with them
logger.Warn( $"ShortcutLibraryForm/RefreshShortcutLibraryUI: Ignoring game shortcut {loadedShortcut.Name} as it's from a Game library this version doesn't support.");
continue;
}
newItem = new ImageListViewItem(loadedShortcut, loadedShortcut.Name); newItem = new ImageListViewItem(loadedShortcut, loadedShortcut.Name);
// Select it if its the selectedProfile // Select it if its the selectedProfile