Fixed game refresh

This commit is contained in:
Terry MacDonald 2021-11-09 09:26:04 +13:00
parent 6724a4d2ae
commit 2b653999dd
5 changed files with 96 additions and 18 deletions

View File

@ -35,6 +35,8 @@ namespace DisplayMagician.GameLibraries
public static List<Game> AllInstalledGamesInAllLibraries { get; set; } public static List<Game> AllInstalledGamesInAllLibraries { get; set; }
public static bool GamesLoaded { get; set; } = false; public static bool GamesLoaded { get; set; } = false;
public static bool GamesImagesLoaded { get; set; } = false;
public virtual List<Game> AllInstalledGames { get; set; } public virtual List<Game> AllInstalledGames { get; set; }
public virtual int InstalledGameCount { get; set; } public virtual int InstalledGameCount { get; set; }
@ -260,6 +262,12 @@ namespace DisplayMagician.GameLibraries
} }
} }
// Clear the game libraries in case this is a refresh
SteamLibrary.GetLibrary().AllInstalledGames.Clear();
UplayLibrary.GetLibrary().AllInstalledGames.Clear();
OriginLibrary.GetLibrary().AllInstalledGames.Clear();
EpicLibrary.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 = SteamLibrary.GetLibrary().AllInstalledGames;
GameLibrary.AllInstalledGamesInAllLibraries.AddRange(UplayLibrary.GetLibrary().AllInstalledGames); GameLibrary.AllInstalledGamesInAllLibraries.AddRange(UplayLibrary.GetLibrary().AllInstalledGames);
@ -344,6 +352,7 @@ namespace DisplayMagician.GameLibraries
game.AvailableGameBitmaps = bmList; game.AvailableGameBitmaps = bmList;
game.GameBitmap = ImageUtils.GetMeLargestAvailableBitmap(bmList); game.GameBitmap = ImageUtils.GetMeLargestAvailableBitmap(bmList);
} }
GamesImagesLoaded = true;
} }

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.0.202")] [assembly: AssemblyVersion("2.1.0.214")]
[assembly: AssemblyFileVersion("2.1.0.202")] [assembly: AssemblyFileVersion("2.1.0.214")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -132,6 +132,7 @@ namespace DisplayMagician.UIForms
this.cb_autosuggest = new System.Windows.Forms.CheckBox(); this.cb_autosuggest = new System.Windows.Forms.CheckBox();
this.btn_hotkey = new System.Windows.Forms.Button(); this.btn_hotkey = new System.Windows.Forms.Button();
this.lbl_hotkey_assigned = new System.Windows.Forms.Label(); this.lbl_hotkey_assigned = new System.Windows.Forms.Label();
this.btn_refresh_games_list = new System.Windows.Forms.Button();
this.tabc_shortcut.SuspendLayout(); this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout(); this.tabp_display.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbLogo)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbLogo)).BeginInit();
@ -326,7 +327,7 @@ namespace DisplayMagician.UIForms
this.tabp_audio.Location = new System.Drawing.Point(4, 32); this.tabp_audio.Location = new System.Drawing.Point(4, 32);
this.tabp_audio.Name = "tabp_audio"; this.tabp_audio.Name = "tabp_audio";
this.tabp_audio.Padding = new System.Windows.Forms.Padding(3); this.tabp_audio.Padding = new System.Windows.Forms.Padding(3);
this.tabp_audio.Size = new System.Drawing.Size(1082, 713); this.tabp_audio.Size = new System.Drawing.Size(1082, 731);
this.tabp_audio.TabIndex = 4; this.tabp_audio.TabIndex = 4;
this.tabp_audio.Text = "2. Choose Audio"; this.tabp_audio.Text = "2. Choose Audio";
// //
@ -973,6 +974,7 @@ namespace DisplayMagician.UIForms
// //
// p_game // p_game
// //
this.p_game.Controls.Add(this.btn_refresh_games_list);
this.p_game.Controls.Add(this.btn_choose_game_icon); this.p_game.Controls.Add(this.btn_choose_game_icon);
this.p_game.Controls.Add(this.pb_game_icon); this.p_game.Controls.Add(this.pb_game_icon);
this.p_game.Controls.Add(this.lbl_no_game_libraries); this.p_game.Controls.Add(this.lbl_no_game_libraries);
@ -1489,6 +1491,22 @@ namespace DisplayMagician.UIForms
this.lbl_hotkey_assigned.Visible = false; this.lbl_hotkey_assigned.Visible = false;
this.lbl_hotkey_assigned.Click += new System.EventHandler(this.lbl_hotkey_assigned_Click); this.lbl_hotkey_assigned.Click += new System.EventHandler(this.lbl_hotkey_assigned_Click);
// //
// btn_refresh_games_list
//
this.btn_refresh_games_list.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_refresh_games_list.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_refresh_games_list.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_refresh_games_list.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_refresh_games_list.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_refresh_games_list.ForeColor = System.Drawing.Color.White;
this.btn_refresh_games_list.Location = new System.Drawing.Point(950, 162);
this.btn_refresh_games_list.Name = "btn_refresh_games_list";
this.btn_refresh_games_list.Size = new System.Drawing.Size(117, 25);
this.btn_refresh_games_list.TabIndex = 42;
this.btn_refresh_games_list.Text = "Refresh Games List";
this.btn_refresh_games_list.UseVisualStyleBackColor = true;
this.btn_refresh_games_list.Click += new System.EventHandler(this.btn_refresh_games_list_Click);
//
// ShortcutForm // ShortcutForm
// //
this.AcceptButton = this.btn_save; this.AcceptButton = this.btn_save;
@ -1658,5 +1676,6 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.CheckBox cb_run_cmd_afterwards; private System.Windows.Forms.CheckBox cb_run_cmd_afterwards;
private System.Windows.Forms.TextBox txt_run_cmd_afterwards_args; private System.Windows.Forms.TextBox txt_run_cmd_afterwards_args;
private System.Windows.Forms.CheckBox cb_run_cmd_afterwards_args; private System.Windows.Forms.CheckBox cb_run_cmd_afterwards_args;
private System.Windows.Forms.Button btn_refresh_games_list;
} }
} }

View File

@ -110,7 +110,11 @@ namespace DisplayMagician.UIForms
try try
{ {
audioController = new CoreAudioController(); if (audioController == null)
{
audioController = new CoreAudioController();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -775,7 +779,7 @@ namespace DisplayMagician.UIForms
// Save everything is golden and close the form. // Save everything is golden and close the form.
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
this.Close(); this.Hide();
} }
private void txt_alternative_executable_TextChanged(object sender, EventArgs e) private void txt_alternative_executable_TextChanged(object sender, EventArgs e)
@ -941,9 +945,12 @@ namespace DisplayMagician.UIForms
Game shortcutGame = null; Game shortcutGame = null;
// Parse the game bitmaps now as we need them // Parse the game bitmaps now the first time as we need them
GameLibraries.GameLibrary.RefreshGameBitmaps(); // We need to add a refresh button to the shortcut page now!
if (!GameLibraries.GameLibrary.GamesImagesLoaded)
{
GameLibraries.GameLibrary.RefreshGameBitmaps();
}
// Load all the profiles to prepare things // Load all the profiles to prepare things
bool foundChosenProfileInLoadedProfiles = false; bool foundChosenProfileInLoadedProfiles = false;
@ -1903,7 +1910,7 @@ namespace DisplayMagician.UIForms
private void btn_back_Click(object sender, EventArgs e) private void btn_back_Click(object sender, EventArgs e)
{ {
this.Close(); this.Hide();
} }
private void radiobutton_Paint(object sender, PaintEventArgs e) private void radiobutton_Paint(object sender, PaintEventArgs e)
@ -2824,6 +2831,45 @@ namespace DisplayMagician.UIForms
{ {
txt_run_cmd_afterwards.Text = getExeFile(); txt_run_cmd_afterwards.Text = getExeFile();
} }
private void btn_refresh_games_list_Click(object sender, EventArgs e)
{
// Change the mouse crusor so the user knows something is happening
this.Cursor = Cursors.WaitCursor;
// Empty the games list
GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Clear();
// Load all the new games
GameLibraries.GameLibrary.LoadGamesInBackground();
// Parse the libraries
GameLibraries.GameLibrary.RefreshGameBitmaps();
// Load all the Games into the Games ListView
ilv_games.Items.Clear();
foreach (var game in DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.OrderBy(game => game.Name))
{
// Add the game to the game array
ImageListViewItem newItem = new ImageListViewItem(game, game.Name);
if (_editingExistingShortcut && game.Name.Equals(_shortcutToEdit.GameName))
{
newItem.Selected = true;
}
ilv_games.Items.Add(newItem, _gameAdaptor);
}
// Make sure that if the item is selected that it's visible
if (ilv_games.SelectedItems.Count > 0)
{
int selectedIndex = ilv_games.SelectedItems[0].Index;
ilv_games.EnsureVisible(selectedIndex);
}
// Change the user cursor back
this.Cursor = Cursors.Default;
// Show we're done
MessageBox.Show(
@"The list of available games has been updated.",
@"Games List Updated",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
} }
// Class used to populate combo boxes // Class used to populate combo boxes

View File

@ -19,6 +19,7 @@ namespace DisplayMagician.UIForms
private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor(); private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor();
private ShortcutItem _selectedShortcut = null; private ShortcutItem _selectedShortcut = null;
private ShortcutForm _shortcutForm = null;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public ShortcutLibraryForm() public ShortcutLibraryForm()
@ -264,13 +265,16 @@ namespace DisplayMagician.UIForms
private void btn_new_Click(object sender, EventArgs e) private void btn_new_Click(object sender, EventArgs e)
{ {
this.Cursor = Cursors.WaitCursor; this.Cursor = Cursors.WaitCursor;
var shortcutForm = new ShortcutForm(new ShortcutItem(),false); if (_shortcutForm == null)
//ShortcutRepository.IsValidRefresh();
shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK)
{ {
ShortcutRepository.AddShortcut(shortcutForm.Shortcut); _shortcutForm = new ShortcutForm(new ShortcutItem(), false);
_selectedShortcut = shortcutForm.Shortcut; }
//ShortcutRepository.IsValidRefresh();
_shortcutForm.ShowDialog(this);
if (_shortcutForm.DialogResult == DialogResult.OK)
{
ShortcutRepository.AddShortcut(_shortcutForm.Shortcut);
_selectedShortcut = _shortcutForm.Shortcut;
//ShortcutRepository.IsValidRefresh(); //ShortcutRepository.IsValidRefresh();
RefreshShortcutLibraryUI(); RefreshShortcutLibraryUI();
} }
@ -313,10 +317,10 @@ namespace DisplayMagician.UIForms
this.Cursor = Cursors.WaitCursor; this.Cursor = Cursors.WaitCursor;
var shortcutForm = new ShortcutForm(_selectedShortcut,true); _shortcutForm = new ShortcutForm(_selectedShortcut,true);
//ilv_saved_shortcuts.SuspendLayout(); //ilv_saved_shortcuts.SuspendLayout();
shortcutForm.ShowDialog(this); _shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK) if (_shortcutForm.DialogResult == DialogResult.OK)
{ {
RefreshShortcutLibraryUI(); RefreshShortcutLibraryUI();
// As this is an edit, we need to manually force saving the shortcut library // As this is an edit, we need to manually force saving the shortcut library