From 5b99c3ac7af57fed9d561ef81f3e6f682763eb04 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 18 May 2021 22:03:02 +1200 Subject: [PATCH] Working Game selection window Also correctly extracts icons from icon files and game exes as best it can. --- DisplayMagician/ImageUtils.cs | 79 ++++++++++--------- DisplayMagician/Program.cs | 11 +-- .../UIForms/ShortcutForm.Designer.cs | 2 +- DisplayMagician/UIForms/ShortcutForm.cs | 64 +-------------- 4 files changed, 51 insertions(+), 105 deletions(-) diff --git a/DisplayMagician/ImageUtils.cs b/DisplayMagician/ImageUtils.cs index 71178cf..8f437ff 100644 --- a/DisplayMagician/ImageUtils.cs +++ b/DisplayMagician/ImageUtils.cs @@ -152,43 +152,7 @@ namespace DisplayMagician Icon myIcon = null; Bitmap bm = null; - Bitmap bmToReturn = new Bitmap(1, 1); - - try { - - List myExtractedIcons = MintPlayer.IconUtils.IconExtractor.Split(fileNameAndPath); - Size largeSize = new Size(256, 256); - foreach (Icon myExtractedIcon in myExtractedIcons) - { - - try - { - myIcon = (Icon)IconUtil.TryGetIcon(myExtractedIcon, largeSize, 32, true, true); - } - catch (ArgumentNullException nullex) - { - logger.Debug(nullex, $"ShortcutItem/GetMeABitmapFromFile: There was a faulty icon image within this icon that we couldn't test, so skipping it."); - continue; - } - - if (myIcon != null) - { - bm = myIcon.ToBitmap(); - - if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height) - { - bmToReturn = bm; - logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead."); - } - } - } - - } - catch (Exception ex) - { - logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to Split the icon using MintPlayer IconExtractor! "); - } - + Bitmap bmToReturn = new Bitmap(1, 1); if (fileNameAndPath.EndsWith(".ico")) { @@ -244,7 +208,7 @@ namespace DisplayMagician else { - try + /*try { List myIcons = ImageUtils.ExtractIconsFromExe(fileNameAndPath, true); if (myIcons != null && myIcons.Count > 0) @@ -264,7 +228,7 @@ namespace DisplayMagician catch (Exception ex) { logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from an *.exe or *.dll using ImageUtils.ExtractIconsFromExe."); - } + }*/ try { @@ -288,6 +252,43 @@ namespace DisplayMagician } + try + { + + List myExtractedIcons = MintPlayer.IconUtils.IconExtractor.Split(fileNameAndPath); + Size largeSize = new Size(256, 256); + foreach (Icon myExtractedIcon in myExtractedIcons) + { + + try + { + myIcon = (Icon)IconUtil.TryGetIcon(myExtractedIcon, largeSize, 32, true, true); + } + catch (ArgumentNullException nullex) + { + logger.Debug(nullex, $"ShortcutItem/GetMeABitmapFromFile: There was a faulty icon image within this icon that we couldn't test, so skipping it."); + continue; + } + + if (myIcon != null) + { + bm = myIcon.ToBitmap(); + + if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height) + { + bmToReturn = bm; + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead."); + } + } + } + + } + catch (Exception ex) + { + logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to Split the icon using MintPlayer IconExtractor! "); + } + + if (bmToReturn == null) { // If we couldn't get any bitmaps at all diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index b561d5a..643baa5 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -881,16 +881,17 @@ namespace DisplayMagician { Bitmap bm = null; try { - ArrayList filesToSearchForIcon = new ArrayList(); + /*ArrayList filesToSearchForIcon = new ArrayList(); filesToSearchForIcon.Add(game.ExePath); if (game.IconPath != game.ExePath) filesToSearchForIcon.Add(game.IconPath); - bm = ImageUtils.GetMeABitmapFromFile(filesToSearchForIcon); - - - //bm = ImageUtils.GetMeABitmapFromFile(game.IconPath); + bm = ImageUtils.GetMeABitmapFromFile(filesToSearchForIcon);*/ + // We only want the icon location that the GameLibrary told us to use + // Note: This may be an icon file, or an exe file. + // This function tries to get a 256x256 Vista sized bitmap from the file + bm = ImageUtils.GetMeABitmapFromFile(game.IconPath); } catch (Exception ex) diff --git a/DisplayMagician/UIForms/ShortcutForm.Designer.cs b/DisplayMagician/UIForms/ShortcutForm.Designer.cs index 79423ce..5bc948a 100644 --- a/DisplayMagician/UIForms/ShortcutForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutForm.Designer.cs @@ -205,7 +205,7 @@ namespace DisplayMagician.UIForms this.tabc_shortcut.ShowToolTips = true; this.tabc_shortcut.Size = new System.Drawing.Size(1090, 654); this.tabc_shortcut.TabIndex = 28; - //this.tabc_shortcut.VisibleChanged += new System.EventHandler(this.tabc_shortcut_VisibleChanged); + this.tabc_shortcut.Click += new System.EventHandler(this.tabc_shortcut_VisibleChanged); // // tabp_display // diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index dde6eca..c7b82c2 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -702,7 +702,7 @@ namespace DisplayMagician.UIForms itemToSelect.Focused = true; itemToSelect.Enabled = true; ilv_games.EnsureVisible(itemToSelect.Index); - ilv_games.Refresh(); + //ilv_games.Refresh(); } } @@ -931,8 +931,6 @@ namespace DisplayMagician.UIForms ilv_games.Items.Add(newItem, _gameAdaptor); } - SelectGameInImageListView(); - if (_shortcutToEdit != null) { if (ProfileRepository.ContainsProfile(_shortcutToEdit.ProfileUUID)) @@ -1070,17 +1068,7 @@ namespace DisplayMagician.UIForms { cb_args_game.Checked = true; } - //select the loaded Game item if it is there - /*foreach (ImageListViewItem gameItem in ilv_games.Items) - { - if (gameItem.Text.Equals(_shortcutToEdit.GameName)) - { - gameItem.Selected = true; - ilv_games.EnsureVisible(gameItem.Index); - break; - } - } -*/ } + } cb_autosuggest.Checked = _shortcutToEdit.AutoName; @@ -1375,44 +1363,6 @@ namespace DisplayMagician.UIForms ilv_saved_profiles.ResumeLayout(); } - /*if (DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count > 0) - { - - // Temporarily stop updating the saved_profiles listview - ilv_games.SuspendLayout(); - - ImageListViewItem ilvItem = null; - foreach (Game loadedGame in DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries) - { - bool thisLoadedProfileIsAlreadyHere = (from item in ilv_games.Items where item.Text == loadedGame.Name orderby item.Text select item.Text).Any(); - if (!thisLoadedProfileIsAlreadyHere) - { - ilvItem = new ImageListViewItem(loadedGame, loadedGame.Name); - //ilv_saved_profiles.Items.Add(newItem); - ilv_games.Items.Add(ilvItem, _gameAdaptor); - } - - } - - // If a game has been selected - if (!String.IsNullOrEmpty(_shortcutToEdit.GameName)) - { - foreach (ImageListViewItem gameItem in ilv_games.Items) - { - if (gameItem.Text == _shortcutToEdit.GameName) - { - gameItem.Selected = true; - ilv_games.EnsureVisible(gameItem.Index); - } - - } - - } - - // Restart updating the saved_profiles listview - ilv_games.ResumeLayout(); - } -*/ UpdateHotkeyLabel(_shortcutToEdit.Hotkey); EnableSaveButtonIfValid(); } @@ -2199,16 +2149,10 @@ namespace DisplayMagician.UIForms EnableSaveButtonIfValid(); } - /*private void tabc_shortcut_VisibleChanged(object sender, EventArgs e) + private void tabc_shortcut_VisibleChanged(object sender, EventArgs e) { if (tabc_shortcut.Visible == true) SelectGameInImageListView(); - }*/ - - /*private void ilv_games_VisibleChanged(object sender, EventArgs e) - { - if (ilv_games.SelectedItems.Count > 0) - ilv_games.EnsureVisible(ilv_games.SelectedItems[0].Index); - }*/ + } } } \ No newline at end of file