Fixed non-Steam Games in Steam Game list

Fixes #68. The reason DisplayMagician was crashing was that it was hitting a Uplay Game in the Steam Library. This was not a valid thing to see. The reason DisplayMagician was doing that was because of a bug in the way that the list of installed games was combined. This bug has been in all 2.x versions of DisplayMagician, and would have affected anyone with Steam and any one more GameLibrary (e.g. GOG, Epic, Uplay etc).

I also managed to find a potential issue with editing shortcuts that I've hopefully now averted.
Properly clear out the form and all it's storage variables when the form loads (done)
Add in some protection logic to avoid a crash even if this situation occurs again (partly done)

Additionally, I found a recursive logic flaw that meant that DisplayMagician used WAAAAAAAAAAAAAY more memory than it needed to. I'm talking 5GB of memory rather than the 129MB it was supposed to do. So I'm so thankful that you logged this issue so I could find that one :).
This commit is contained in:
Terry MacDonald 2021-12-23 18:45:04 +13:00
parent c87f55c4a9
commit de1f6654c3
8 changed files with 188 additions and 70 deletions

View File

@ -269,7 +269,8 @@ namespace DisplayMagician.GameLibraries
EpicLibrary.GetLibrary().AllInstalledGames.Clear(); EpicLibrary.GetLibrary().AllInstalledGames.Clear();
GogLibrary.GetLibrary().AllInstalledGames.Clear(); GogLibrary.GetLibrary().AllInstalledGames.Clear();
// Produce a single array of Games we can reference later // Produce a single array of Games we can reference later
GameLibrary.AllInstalledGamesInAllLibraries = SteamLibrary.GetLibrary().AllInstalledGames; GameLibrary.AllInstalledGamesInAllLibraries = new List<Game>();
GameLibrary.AllInstalledGamesInAllLibraries.AddRange(SteamLibrary.GetLibrary().AllInstalledGames);
GameLibrary.AllInstalledGamesInAllLibraries.AddRange(UplayLibrary.GetLibrary().AllInstalledGames); GameLibrary.AllInstalledGamesInAllLibraries.AddRange(UplayLibrary.GetLibrary().AllInstalledGames);
GameLibrary.AllInstalledGamesInAllLibraries.AddRange(OriginLibrary.GetLibrary().AllInstalledGames); GameLibrary.AllInstalledGamesInAllLibraries.AddRange(OriginLibrary.GetLibrary().AllInstalledGames);
GameLibrary.AllInstalledGamesInAllLibraries.AddRange(EpicLibrary.GetLibrary().AllInstalledGames); GameLibrary.AllInstalledGamesInAllLibraries.AddRange(EpicLibrary.GetLibrary().AllInstalledGames);

View File

@ -482,7 +482,7 @@ namespace DisplayMagician.GameLibraries
if (uplayInstallKey != null) if (uplayInstallKey != null)
{ {
int uplayGamesInstalledCount = 0; int uplayGamesInstalledCount = 0;
// Loop through the subKeys as they are the Steam Game IDs // Loop through the subKeys as they are the Uplay Game IDs
foreach (string uplayGameKeyName in uplayInstallKey.GetSubKeyNames()) foreach (string uplayGameKeyName in uplayInstallKey.GetSubKeyNames())
{ {
logger.Trace($"UplayLibrary/LoadInstalledGames: Found uplayGameKeyName = {uplayGameKeyName}"); logger.Trace($"UplayLibrary/LoadInstalledGames: Found uplayGameKeyName = {uplayGameKeyName}");
@ -497,7 +497,7 @@ namespace DisplayMagician.GameLibraries
if (!uplayGameKey.GetValue(@"InstallDir", "").ToString().Equals("")) if (!uplayGameKey.GetValue(@"InstallDir", "").ToString().Equals(""))
{ {
logger.Trace($"UplayLibrary/LoadInstalledGames: {uplayGameKey} contains an 'InstallDir' value so is an installed Uplay Game."); logger.Trace($"UplayLibrary/LoadInstalledGames: {uplayGameKey} contains an 'InstallDir' value so is an installed Uplay Game.");
// Add this Steam App ID to the list we're keeping for later // Add this Uplay App ID to the list we're keeping for later
uplayGamesInstalledCount++; uplayGamesInstalledCount++;
} }
else else

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information // Version information
[assembly: AssemblyVersion("2.1.3.1")] [assembly: AssemblyVersion("2.1.3.10")]
[assembly: AssemblyFileVersion("2.1.3.1")] [assembly: AssemblyFileVersion("2.1.3.10")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -1159,6 +1159,7 @@ namespace DisplayMagician
// Is the main application still installed? // Is the main application still installed?
if (Category.Equals(ShortcutCategory.Application)) if (Category.Equals(ShortcutCategory.Application))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: This shortcut is an Application");
// We need to check if the Application still exists // We need to check if the Application still exists
if (!System.IO.File.Exists(ExecutableNameAndPath)) if (!System.IO.File.Exists(ExecutableNameAndPath))
{ {
@ -1180,41 +1181,76 @@ namespace DisplayMagician
else if (Category.Equals(ShortcutCategory.Game)) else if (Category.Equals(ShortcutCategory.Game))
{ {
GameLibrary gameLibraryToUse = null; GameLibrary gameLibraryToUse = null;
logger.Trace($"ShortcutItem/RefreshValidity: This shortcut is a Game");
// If the game is a Steam Game we check for that // If the game is a Steam Game we check for that
if (GameLibrary.Equals(SupportedGameLibraryType.Steam)) if (GameLibrary.Equals(SupportedGameLibraryType.Steam))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: The game library is Steam"); logger.Trace($"ShortcutItem/RefreshValidity: The game library is Steam");
// We now need to get the SteamGame info // We now need to get the SteamGame info
gameLibraryToUse = SteamLibrary.GetLibrary(); try
{
gameLibraryToUse = SteamLibrary.GetLibrary();
}
catch(Exception ex)
{
logger.Error(ex,$"ShortcutItem/RefreshValidity: Exception while trying to get a handle to the Steam library");
}
} }
// If the game is a Uplay Uplay Game we check for that // If the game is a Uplay Uplay Game we check for that
else if (GameLibrary.Equals(SupportedGameLibraryType.Uplay)) else if (GameLibrary.Equals(SupportedGameLibraryType.Uplay))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: The game library is Uplay"); logger.Trace($"ShortcutItem/RefreshValidity: The game library is Uplay");
// We now need to get the Uplay Game info // We now need to get the Uplay Game info
gameLibraryToUse = UplayLibrary.GetLibrary(); try
{
gameLibraryToUse = UplayLibrary.GetLibrary();
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutItem/RefreshValidity: Exception while trying to get a handle to the Uplay library");
}
} }
// If the game is an Origin Game we check for that // If the game is an Origin Game we check for that
else if (GameLibrary.Equals(SupportedGameLibraryType.Origin)) else if (GameLibrary.Equals(SupportedGameLibraryType.Origin))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: The game library is Origin"); logger.Trace($"ShortcutItem/RefreshValidity: The game library is Origin");
// We now need to get the Uplay Game info // We now need to get the Uplay Game info
gameLibraryToUse = OriginLibrary.GetLibrary(); try
{
gameLibraryToUse = OriginLibrary.GetLibrary();
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutItem/RefreshValidity: Exception while trying to get a handle to the Origin library");
}
} }
// If the game is an Epic Game we check for that // If the game is an Epic Game we check for that
else if (GameLibrary.Equals(SupportedGameLibraryType.Epic)) else if (GameLibrary.Equals(SupportedGameLibraryType.Epic))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: The game library is Epic"); logger.Trace($"ShortcutItem/RefreshValidity: The game library is Epic");
// We now need to get the Epic Game info // We now need to get the Epic Game info
gameLibraryToUse = EpicLibrary.GetLibrary(); try
{
gameLibraryToUse = EpicLibrary.GetLibrary();
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutItem/RefreshValidity: Exception while trying to get a handle to the Epic library");
}
} }
// If the game is an GOG Game we check for that // If the game is an GOG Game we check for that
else if (GameLibrary.Equals(SupportedGameLibraryType.GOG)) else if (GameLibrary.Equals(SupportedGameLibraryType.GOG))
{ {
logger.Trace($"ShortcutItem/RefreshValidity: The game library is GOG"); logger.Trace($"ShortcutItem/RefreshValidity: The game library is GOG");
// We now need to get the GOG Game info // We now need to get the GOG Game info
gameLibraryToUse = GogLibrary.GetLibrary(); try
{
gameLibraryToUse = GogLibrary.GetLibrary();
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutItem/RefreshValidity: Exception while trying to get a handle to the GOG library");
}
} }
else else
{ {
@ -1256,7 +1292,18 @@ namespace DisplayMagician
if (worstError != ShortcutValidity.Error) if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error; worstError = ShortcutValidity.Error;
} }
} }
else
{
logger.Trace($"ShortcutItem/RefreshValidity: The GameLibrary was not created properly during the validity check!");
ShortcutError error = new ShortcutError();
error.Name = "GameLibraryToUseNotCreated";
error.Validity = ShortcutValidity.Error;
error.Message = $"The GameLibrary was not created properly during the validity check.";
_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;
@ -1268,22 +1315,26 @@ namespace DisplayMagician
try try
{ {
audioDevices = audioController.GetPlaybackDevices(); audioDevices = audioController.GetPlaybackDevices();
logger.Trace($"ShortcutItem/RefreshValidity: Audio Controller successfully detected");
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Warn(ex, $"ShortcutRepository/RefreshValidity: Exception trying to get all playback devices!"); logger.Warn(ex, $"ShortcutItem/RefreshValidity: Exception trying to get all playback devices!");
} }
if (audioDevices != null) if (audioDevices != null)
{ {
bool audioFound = false;
logger.Trace($"ShortcutItem/RefreshValidity: Audio Controller successfully returned a list of audio playback devices");
foreach (CoreAudioDevice audioDevice in audioDevices) foreach (CoreAudioDevice audioDevice in audioDevices)
{ {
logger.Trace($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName}"); logger.Trace($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName}");
if (audioDevice.FullName.Equals(AudioDevice)) if (audioDevice.FullName.Equals(AudioDevice))
{ {
audioFound = true;
logger.Trace($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want!"); logger.Trace($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want!");
if (audioDevice.State == DeviceState.Disabled) if (audioDevice.State == DeviceState.Disabled)
{ {
logger.Warn($"ShortcutRepository/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is disabled!"); logger.Warn($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is disabled!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "AudioDeviceDisabled"; error.Name = "AudioDeviceDisabled";
error.Validity = ShortcutValidity.Warning; error.Validity = ShortcutValidity.Warning;
@ -1294,36 +1345,39 @@ namespace DisplayMagician
} }
if (audioDevice.State == DeviceState.NotPresent) if (audioDevice.State == DeviceState.NotPresent)
{ {
logger.Warn($"ShortcutRepository/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is not present!"); logger.Warn($"ShortcutItem/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is not present!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "AudioDeviceNotPresent"; error.Name = "AudioDeviceNotPresent";
error.Validity = ShortcutValidity.Error; error.Validity = ShortcutValidity.Warning;
error.Message = $"The Audio Device {AudioDevice} is not present, so the shortcut '{Name}' cannot be used."; error.Message = $"The Audio Device {AudioDevice} is not present, so the shortcut '{Name}' cannot be used.";
_shortcutErrors.Add(error); _shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error;
}
// As per Issue #39, this causes issues on HDMI audio devices and others that *could* work if the screen was enabled.
// Disabling this code as it is too much error checking for audio devices. The user can plug these in after the chagne and they will work.
/*if (audioDevice.State == DeviceState.Unplugged)
{
logger.Warn($"ShortcutRepository/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is unplugged!");
ShortcutError error = new ShortcutError();
error.Name = "AudioDeviceUnplugged";
error.Validity = ShortcutValidity.Warning;
error.Message = $"The Audio Device {AudioDevice} is unplugged, so the shortcut '{Name}' cannot be used. You need to plug in the audio device to use this shortcut, or edit the shortcut to change the audio device.";
_shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error) if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Warning; worstError = ShortcutValidity.Warning;
}*/ }
break; break;
} }
} }
if (!audioFound)
{
logger.Warn($"ShortcutItem/RefreshValidity: The audio device {AudioDevice} was not found in the list of audio devices currently available!");
ShortcutError error = new ShortcutError();
error.Name = "AudioDeviceNotFound";
error.Validity = ShortcutValidity.Warning;
error.Message = $"The audio device {AudioDevice} was not found in the list of audio devices currently available!";
_shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Warning;
}
} }
else
{
logger.Warn($"ShortcutItem/RefreshValidity: No audio devices detected by Capture Audio. That's fine though, so not logging as an error.");
}
} }
else else
{ {
logger.Error($"ShortcutRepository/RefreshValidity: The audio device chipset is not supported by DisplayMagician!"); logger.Error($"ShortcutItem/RefreshValidity: The audio device chipset is not supported by DisplayMagician!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "AudioChipsetNotSupported"; error.Name = "AudioChipsetNotSupported";
error.Validity = ShortcutValidity.Warning; error.Validity = ShortcutValidity.Warning;
@ -1345,20 +1399,22 @@ namespace DisplayMagician
} }
catch(Exception ex) catch(Exception ex)
{ {
logger.Warn(ex, $"ShortcutRepository/RefreshValidity: Exception trying to get all capture devices!"); logger.Warn(ex, $"ShortcutItem/RefreshValidity: Exception trying to get all capture devices!");
} }
if (captureDevices != null) if (captureDevices != null)
{ {
bool captureFound = false;
foreach (CoreAudioDevice captureDevice in captureDevices) foreach (CoreAudioDevice captureDevice in captureDevices)
{ {
logger.Trace($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName}"); logger.Trace($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName}");
if (captureDevice.FullName.Equals(CaptureDevice)) if (captureDevice.FullName.Equals(CaptureDevice))
{ {
captureFound = true;
logger.Trace($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want!"); logger.Trace($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want!");
if (captureDevice.State == DeviceState.Disabled) if (captureDevice.State == DeviceState.Disabled)
{ {
logger.Warn($"ShortcutRepository/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is disabled!"); logger.Warn($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is disabled!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "CaptureDeviceDisabled"; error.Name = "CaptureDeviceDisabled";
error.Validity = ShortcutValidity.Warning; error.Validity = ShortcutValidity.Warning;
@ -1369,40 +1425,43 @@ namespace DisplayMagician
} }
if (captureDevice.State == DeviceState.NotPresent) if (captureDevice.State == DeviceState.NotPresent)
{ {
logger.Warn($"ShortcutRepository/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is not present!"); logger.Warn($"ShortcutItem/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is not present!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "CaptureDeviceNotPresent"; error.Name = "CaptureDeviceNotPresent";
error.Validity = ShortcutValidity.Error; error.Validity = ShortcutValidity.Warning;
error.Message = $"The Capture Device {CaptureDevice} is not present, so the shortcut '{Name}' cannot be used."; error.Message = $"The Capture Device {CaptureDevice} is not present, so the shortcut '{Name}' cannot be used.";
_shortcutErrors.Add(error); _shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Error;
}
// As per Issue #39, this causes issues on HDMI audiodevices and others that *could* work if the screen was enabled.
// Disabling this code as it is too much error checking for capture devices. The user can plug these in after the chagne and they will work.
/*if (captureDevice.State == DeviceState.Unplugged)
{
logger.Warn($"ShortcutRepository/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is unplugged!");
ShortcutError error = new ShortcutError();
error.Name = "CaptureDeviceUnplugged";
error.Validity = ShortcutValidity.Warning;
error.Message = $"The Capture Device {CaptureDevice} is unplugged, so the shortcut '{Name}' cannot be used. You need to plug in the capture device to use this shortcut, or edit the shortcut to change the capture device.";
_shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error) if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Warning; worstError = ShortcutValidity.Warning;
}*/ }
break; break;
} }
} }
}
if (!captureFound)
{
logger.Warn($"ShortcutItem/RefreshValidity: The capture device {CaptureDevice} was not found in the list of capture devices currently available!");
ShortcutError error = new ShortcutError();
error.Name = "CaptureDeviceNotFound";
error.Validity = ShortcutValidity.Warning;
error.Message = $"The capture device {CaptureDevice} was not found in the list of capture devices currently available!";
_shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Warning;
}
}
else
{
logger.Warn($"ShortcutItem/RefreshValidity: No capture devices detected by Capture Audio. That's fine though, so not logging as an error.");
}
} }
else else
{ {
logger.Error($"ShortcutRepository/RefreshValidity: The capture device chipset is not supported by DisplayMagician!"); logger.Error($"ShortcutItem/RefreshValidity: The capture device chipset is not supported by DisplayMagician!");
ShortcutError error = new ShortcutError(); ShortcutError error = new ShortcutError();
error.Name = "AudioChipsetNotSupported"; error.Name = "CaptureChipsetNotSupported";
error.Validity = ShortcutValidity.Warning; error.Validity = ShortcutValidity.Warning;
error.Message = $"The Audio chipset isn't supported by DisplayMagician. You need to edit the shortcut to not change the microphone input settings."; error.Message = $"The Capture chipset isn't supported by DisplayMagician. You need to edit the shortcut to not change the microphone input settings.";
_shortcutErrors.Add(error); _shortcutErrors.Add(error);
if (worstError != ShortcutValidity.Error) if (worstError != ShortcutValidity.Error)
worstError = ShortcutValidity.Warning; worstError = ShortcutValidity.Warning;

View File

@ -482,11 +482,13 @@ namespace DisplayMagician
{ {
foreach (string jsonError in jsonErrors) foreach (string jsonError in jsonErrors)
{ {
logger.Error($"ShortcutRepository/LoadShortcuts: {jsonErrors}"); logger.Error($"ShortcutRepository/LoadShortcuts: JSON.Net Error found while loading {_shortcutStorageJsonFileName}: {jsonErrors}");
} }
} }
logger.Trace($"ShortcutRepository/LoadShortcuts: Loaded {_allShortcuts.Count} shortcuts from {_shortcutStorageJsonFileName} Shortcut JSON file");
// Lookup all the Profile Names in the Saved Profiles // Lookup all the Profile Names in the Saved Profiles
// and link the profiles to the Shortcuts as we only // and link the profiles to the Shortcuts as we only
// store the profile names to allow users to uodate profiles // store the profile names to allow users to uodate profiles
@ -494,7 +496,7 @@ namespace DisplayMagician
logger.Debug($"ShortcutRepository/LoadShortcuts: Connecting Shortcut profile names to the real profile objects"); logger.Debug($"ShortcutRepository/LoadShortcuts: Connecting Shortcut profile names to the real profile objects");
foreach (ShortcutItem updatedShortcut in _allShortcuts) foreach (ShortcutItem updatedShortcut in _allShortcuts)
{ {
if (!String.IsNullOrWhiteSpace(updatedShortcut.ProfileUUID)) if (String.IsNullOrWhiteSpace(updatedShortcut.ProfileUUID))
{ {
logger.Error($"ShortcutRepository/LoadShortcuts: Shortcut '{updatedShortcut.Name}' profile UUID is null or whitespace! Skipping this processing this entry, and setting ProfileToUse to null."); logger.Error($"ShortcutRepository/LoadShortcuts: Shortcut '{updatedShortcut.Name}' profile UUID is null or whitespace! Skipping this processing this entry, and setting ProfileToUse to null.");
updatedShortcut.ProfileToUse = null; updatedShortcut.ProfileToUse = null;
@ -528,10 +530,10 @@ namespace DisplayMagician
updatedShortcut.ProfileToUse = null; updatedShortcut.ProfileToUse = null;
} }
} }
// Sort the shortcuts alphabetically // Sort the shortcuts alphabetically
logger.Trace($"ShortcutRepository/LoadShortcuts: Sorting the Shortcuts alphabetically.");
_allShortcuts.Sort(); _allShortcuts.Sort();
} }
else else
@ -543,10 +545,17 @@ namespace DisplayMagician
{ {
logger.Debug($"ShortcutRepository/LoadShortcuts: Couldn't find the {_shortcutStorageJsonFileName} shortcut JSON file that contains the Shortcuts"); logger.Debug($"ShortcutRepository/LoadShortcuts: Couldn't find the {_shortcutStorageJsonFileName} shortcut JSON file that contains the Shortcuts");
} }
_shortcutsLoaded = true; logger.Trace($"ShortcutRepository/LoadShortcuts: Checking validity of the loaded shortcuts to make sure they're ok to use now");
try
IsValidRefresh(); {
return true; _shortcutsLoaded = true;
return true;
}
catch (Exception ex)
{
logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Exception while checking the validity of the loaded shortcuts to make sure they're ok to use");
return false;
}
} }
public static bool SaveShortcuts() public static bool SaveShortcuts()
@ -632,11 +641,13 @@ namespace DisplayMagician
{ {
// We need to refresh the cached answer // We need to refresh the cached answer
// Get the list of connected devices // Get the list of connected devices
logger.Trace($"ShortcutRepository/IsValidRefresh: IsValidRefresh starting.");
foreach (ShortcutItem loadedShortcut in AllShortcuts) foreach (ShortcutItem loadedShortcut in AllShortcuts)
{ {
logger.Trace($"ShortcutRepository/IsValidRefresh: Running RefreshValidity on Shortcut {loadedShortcut.Name}");
loadedShortcut.RefreshValidity(); loadedShortcut.RefreshValidity();
} }
logger.Trace($"ShortcutRepository/IsValidRefresh: IsValidRefresh completed.");
} }
private static ProcessPriorityClass TranslatePriorityClassToClass(ProcessPriority processPriority) private static ProcessPriorityClass TranslatePriorityClassToClass(ProcessPriority processPriority)

View File

@ -272,6 +272,7 @@ namespace DisplayMagician.UIForms
private void btn_setup_display_profiles_Click(object sender, EventArgs e) private void btn_setup_display_profiles_Click(object sender, EventArgs e)
{ {
logger.Trace($"MainForm/btn_setup_display_profiles_Click: User pressed the Display Profiles button (or selected the menu item)");
DisplayProfileForm displayProfileForm = null; DisplayProfileForm displayProfileForm = null;
if (Application.OpenForms.OfType<DisplayProfileForm>().Any()) if (Application.OpenForms.OfType<DisplayProfileForm>().Any())
{ {
@ -295,6 +296,7 @@ namespace DisplayMagician.UIForms
private void btn_setup_game_shortcuts_Click(object sender, EventArgs e) private void btn_setup_game_shortcuts_Click(object sender, EventArgs e)
{ {
logger.Trace($"MainForm/btn_setup_game_shortcuts_Click: User pressed the Game Shortcuts button (or selected the menu item)");
ShortcutLibraryForm shortcutLibraryForm = null; ShortcutLibraryForm shortcutLibraryForm = null;
if (Application.OpenForms.OfType<ShortcutLibraryForm>().Any()) if (Application.OpenForms.OfType<ShortcutLibraryForm>().Any())
{ {

View File

@ -919,6 +919,39 @@ namespace DisplayMagician.UIForms
private void ClearForm() private void ClearForm()
{ {
// Reset all the tracking variables back to default
_editingExistingShortcut = false;
//_loadedProfiles = new List<ProfileItem>();
_profileToUse = null;
_gameLauncher = "";
//_gameToUse;
// _executableToUse;
_displayPermanence = ShortcutPermanence.Temporary;
_audioPermanence = ShortcutPermanence.Temporary;
_capturePermanence = ShortcutPermanence.Temporary;
_startPrograms = new List<StartProgram>();
_stopPrograms = new List<StopProgram>();
_audioDevice = "";
_changeAudioDevice = false;
_setAudioVolume = false;
_audioVolume = -1;
_captureDevice = "";
_changeCaptureDevice = false;
_setCaptureVolume = false;
_captureVolume = -1;
_shortcutToEdit = null;
_selectedGame = null;
_isUnsaved = true;
_loadedShortcut = false;
_autoName = true;
_gameId = "0";
_uuid = "";
audioDevices = null;
selectedAudioDevice = null;
captureDevices = null;
selectedCaptureDevice = null;
_hotkey = Keys.None;
// Clear the textboxes // Clear the textboxes
txt_alternative_executable.Text = ""; txt_alternative_executable.Text = "";
txt_alternative_game.Text = ""; txt_alternative_game.Text = "";
@ -1376,10 +1409,10 @@ namespace DisplayMagician.UIForms
cb_wait_alternative_game.Checked = false; cb_wait_alternative_game.Checked = false;
} }
// Set the launcher items if we have them // Show an error message if there isn't a game launcher selected
if (_shortcutToEdit.GameLibrary.Equals(SupportedGameLibraryType.Unknown)) if (_shortcutToEdit.GameLibrary.Equals(SupportedGameLibraryType.Unknown))
{ {
if (DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count <= 0) if (GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count <= 0)
{ {
// Fill in the game library information to highlight there isn't one detected. // Fill in the game library information to highlight there isn't one detected.
_gameLauncher = "None detected"; _gameLauncher = "None detected";
@ -1398,6 +1431,7 @@ namespace DisplayMagician.UIForms
} }
else else
{ {
// Set the launcher items if we have them
_gameLauncher = _shortcutToEdit.GameLibrary.ToString("G"); _gameLauncher = _shortcutToEdit.GameLibrary.ToString("G");
txt_game_name.Text = _shortcutToEdit.GameName; txt_game_name.Text = _shortcutToEdit.GameName;
_gameId = _shortcutToEdit.GameAppId; _gameId = _shortcutToEdit.GameAppId;

View File

@ -43,13 +43,14 @@ namespace DisplayMagician.UIForms
// Refresh the profiles and the shortcut validity to start // Refresh the profiles and the shortcut validity to start
// The rest of the refreshing happens as the shortcuts are added // The rest of the refreshing happens as the shortcuts are added
// and deleted. // and deleted.
logger.Trace($"ShortcutLibraryForm/ShortcutLibraryForm_Load: Refreshing Possibilty.");
ProfileRepository.IsPossibleRefresh(); ProfileRepository.IsPossibleRefresh();
logger.Trace($"ShortcutLibraryForm/ShortcutLibraryForm_Load: Refreshing Validity.");
ShortcutRepository.IsValidRefresh(); ShortcutRepository.IsValidRefresh();
logger.Trace($"ShortcutLibraryForm/ShortcutLibraryForm_Load: Refreshing SHortutLibraryUI.");
// Refresh the Shortcut Library UI // Refresh the Shortcut Library UI
RefreshShortcutLibraryUI(); RefreshShortcutLibraryUI();
logger.Trace($"ShortcutLibraryForm/ShortcutLibraryForm_Load: Remove the UI warning if we do have some shortcuts to show the user.");
RemoveWarningIfShortcuts(); RemoveWarningIfShortcuts();
} }
@ -61,13 +62,18 @@ namespace DisplayMagician.UIForms
return; return;
// Temporarily stop updating the saved_profiles listview // Temporarily stop updating the saved_profiles listview
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: Suspending the imagelistview layout");
ilv_saved_shortcuts.SuspendLayout(); ilv_saved_shortcuts.SuspendLayout();
ImageListViewItem newItem = null; ImageListViewItem newItem = null;
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: Emptying shortcut list");
ilv_saved_shortcuts.Items.Clear(); ilv_saved_shortcuts.Items.Clear();
foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name)) foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name))
{ {
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: Adding shortcut {loadedShortcut.Name} into the list of shortcuts shown to the user ");
// Ignore any shortcuts with incompatible game libraries // Ignore any shortcuts with incompatible game libraries
if (loadedShortcut.Category == ShortcutCategory.Game && (!Enum.IsDefined(typeof(SupportedGameLibraryType), loadedShortcut.GameLibrary) || loadedShortcut.GameLibrary == SupportedGameLibraryType.Unknown)) if (loadedShortcut.Category == ShortcutCategory.Game && (!Enum.IsDefined(typeof(SupportedGameLibraryType), loadedShortcut.GameLibrary) || loadedShortcut.GameLibrary == SupportedGameLibraryType.Unknown))
{ {
@ -81,26 +87,31 @@ namespace DisplayMagician.UIForms
// Select it if its the selectedProfile // Select it if its the selectedProfile
if (_selectedShortcut is ShortcutItem && _selectedShortcut.Equals(loadedShortcut)) if (_selectedShortcut is ShortcutItem && _selectedShortcut.Equals(loadedShortcut))
{ {
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: This shortcut {loadedShortcut.Name} is the selected one so selecting it in the UI");
newItem.Selected = true; newItem.Selected = true;
// Hide the run button if the shortcut isn't valid // Hide the run button if the shortcut isn't valid
if (_selectedShortcut.IsValid == ShortcutValidity.Warning || _selectedShortcut.IsValid == ShortcutValidity.Error) if (_selectedShortcut.IsValid == ShortcutValidity.Warning || _selectedShortcut.IsValid == ShortcutValidity.Error)
{ {
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: This shortcut {loadedShortcut.Name} is the selected one and is invalid ({_selectedShortcut.IsValid.ToString("G")}), so highlighting that in the UI");
btn_run.Visible = false; btn_run.Visible = false;
cms_shortcuts.Items[1].Enabled = false; cms_shortcuts.Items[1].Enabled = false;
} }
else else
{ {
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: This shortcut {loadedShortcut.Name} is the selected one and is valid, so highlighting that in the UI");
btn_run.Visible = true; btn_run.Visible = true;
cms_shortcuts.Items[1].Enabled = true; cms_shortcuts.Items[1].Enabled = true;
} }
} }
//ilv_saved_profiles.Items.Add(newItem); //ilv_saved_profiles.Items.Add(newItem);
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: Adding this shortcut {loadedShortcut.Name} to the imagelistview");
ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor); ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor);
} }
logger.Trace($"ShortcutLibraryForm/RefreshShortcutLibraryUI: Resuming the imagelistview layout");
// Restart updating the saved_profiles listview // Restart updating the saved_profiles listview
ilv_saved_shortcuts.ResumeLayout(); ilv_saved_shortcuts.ResumeLayout();