Major improvement for ShortcutForm loading speed

Also fixes the most recent bug highlighted by erbkaiser in #49.
This commit is contained in:
Terry MacDonald 2021-11-15 21:45:43 +13:00
parent 058060ed60
commit ea38f25e28
5 changed files with 123 additions and 52 deletions

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.228")] [assembly: AssemblyVersion("2.1.0.239")]
[assembly: AssemblyFileVersion("2.1.0.228")] [assembly: AssemblyFileVersion("2.1.0.239")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -93,6 +93,7 @@ namespace DisplayMagician.UIForms
this.rb_standalone = new System.Windows.Forms.RadioButton(); this.rb_standalone = new System.Windows.Forms.RadioButton();
this.rb_no_game = new System.Windows.Forms.RadioButton(); this.rb_no_game = new System.Windows.Forms.RadioButton();
this.p_game = new System.Windows.Forms.Panel(); this.p_game = new System.Windows.Forms.Panel();
this.btn_refresh_games_list = new System.Windows.Forms.Button();
this.btn_choose_game_icon = new System.Windows.Forms.Button(); this.btn_choose_game_icon = new System.Windows.Forms.Button();
this.pb_game_icon = new System.Windows.Forms.PictureBox(); this.pb_game_icon = new System.Windows.Forms.PictureBox();
this.lbl_no_game_libraries = new System.Windows.Forms.Label(); this.lbl_no_game_libraries = new System.Windows.Forms.Label();
@ -132,7 +133,6 @@ 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();
@ -996,6 +996,22 @@ namespace DisplayMagician.UIForms
this.p_game.Size = new System.Drawing.Size(1076, 389); this.p_game.Size = new System.Drawing.Size(1076, 389);
this.p_game.TabIndex = 7; this.p_game.TabIndex = 7;
// //
// 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);
//
// btn_choose_game_icon // btn_choose_game_icon
// //
this.btn_choose_game_icon.Enabled = false; this.btn_choose_game_icon.Enabled = false;
@ -1491,22 +1507,6 @@ 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;

View File

@ -61,15 +61,16 @@ namespace DisplayMagician.UIForms
//private string _userExeIconPath = ""; //private string _userExeIconPath = "";
private List<ShortcutBitmap> _availableImages = new List<ShortcutBitmap>(); private List<ShortcutBitmap> _availableImages = new List<ShortcutBitmap>();
private ShortcutBitmap _selectedImage = new ShortcutBitmap(); private ShortcutBitmap _selectedImage = new ShortcutBitmap();
private bool _firstShow = true;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public ShortcutForm(ShortcutItem shortcutToEdit, bool editingExistingShortcut = false) public ShortcutForm()
{ {
InitializeComponent(); InitializeComponent();
Program.AppSplashScreen = new LoadingForm(); Program.AppSplashScreen = new LoadingForm();
Program.AppSplashScreen.Title = "Preparing images..."; Program.AppSplashScreen.Title = "Preparing images...";
Program.AppSplashScreen.Description = "Preparing images before showing you the Shortcut information. You will be able to swap your shortcut icon to any image you want, or choose one from a list."; Program.AppSplashScreen.Description = "Preparing images before showing you the Shortcut information. You will be able to swap your shortcut icon to any image you want, or choose one from a list.";
var splashThread = new Thread(new ThreadStart( var splashThread = new Thread(new ThreadStart(
() => Application.Run(Program.AppSplashScreen))); () => Application.Run(Program.AppSplashScreen)));
splashThread.SetApartmentState(ApartmentState.STA); splashThread.SetApartmentState(ApartmentState.STA);
@ -82,9 +83,6 @@ namespace DisplayMagician.UIForms
_profileAdaptor = new ProfileAdaptor(); _profileAdaptor = new ProfileAdaptor();
_gameAdaptor = new GameAdaptor(); _gameAdaptor = new GameAdaptor();
_editingExistingShortcut = editingExistingShortcut;
_shortcutToEdit = shortcutToEdit;
// Style the Saved Profiles list // Style the Saved Profiles list
ilv_saved_profiles.MultiSelect = false; ilv_saved_profiles.MultiSelect = false;
ilv_saved_profiles.ThumbnailSize = new Size(100, 100); ilv_saved_profiles.ThumbnailSize = new Size(100, 100);
@ -126,6 +124,7 @@ namespace DisplayMagician.UIForms
public ShortcutItem Shortcut public ShortcutItem Shortcut
{ {
get => _shortcutToEdit; get => _shortcutToEdit;
set => _shortcutToEdit = value;
} }
public bool EditingExistingShortcut public bool EditingExistingShortcut
@ -940,22 +939,63 @@ namespace DisplayMagician.UIForms
} }
} }
private void ShortcutForm_Load(object sender, EventArgs e) private void ClearForm()
{
// Clear the textboxes
txt_alternative_executable.Text = "";
txt_alternative_game.Text = "";
txt_args_executable.Text = "";
txt_args_game.Text = "";
txt_executable.Text = "";
txt_game_name.Text = "Please select a game from the list below...";
txt_run_cmd_afterwards.Text = "";
txt_run_cmd_afterwards_args.Text = "";
txt_shortcut_save_name.Text = "";
// Set the radio buttons to default
rb_no_change_audio.Checked = true;
rb_change_audio.Checked = false;
rb_keep_audio_volume.Checked = true;
rb_set_audio_volume.Checked = false;
rb_change_capture.Checked = false;
rb_keep_capture_volume.Checked = false;
rb_no_change_capture.Checked = true;
rb_set_capture_volume.Checked = false;
// Set the game mode on load
rb_launcher.Checked = true;
rb_no_game.Checked = false;
rb_standalone.Checked = false;
// Set the checkboxes
cb_args_executable.Checked = false;
cb_args_game.Checked = false;
cb_autosuggest.Checked = true;
cb_run_cmd_afterwards.Checked = false;
cb_run_cmd_afterwards_args.Checked = false;
cb_wait_alternative_game.Checked = false;
// Wipe the pictureboxes if they're in use
if (pb_exe_icon.Image != null)
{
pb_exe_icon.Image = null;
}
if (pb_game_icon.Image != null)
{
pb_game_icon.Image = null;
}
}
private void LoadShortcut()
{ {
Game shortcutGame = null; Game shortcutGame = null;
// Parse the game bitmaps now the first time as we need them
// 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;
ProfileItem chosenProfile = null; ProfileItem chosenProfile = null;
ClearForm();
// Prepare the Game process priority combo box // Prepare the Game process priority combo box
cbx_game_priority.DataSource = new ComboItem[] { cbx_game_priority.DataSource = new ComboItem[] {
new ComboItem{ Value = ProcessPriority.High, Text = "High" }, new ComboItem{ Value = ProcessPriority.High, Text = "High" },
@ -982,6 +1022,9 @@ namespace DisplayMagician.UIForms
cbx_exe_priority.SelectedIndex = 2; //Normal cbx_exe_priority.SelectedIndex = 2; //Normal
cbx_exe_priority.Enabled = true; cbx_exe_priority.Enabled = true;
// Empty the selected game in case this is a reload
txt_alternative_executable.Text = "";
// Populate all the Audio devices in the audio devices list. // Populate all the Audio devices in the audio devices list.
// Set the Audio device to the shortcut audio device only if // Set the Audio device to the shortcut audio device only if
// the Change Audio radiobutton is set // the Change Audio radiobutton is set
@ -1400,11 +1443,11 @@ namespace DisplayMagician.UIForms
{ {
txt_shortcut_save_name.Text = _shortcutToEdit.Name; txt_shortcut_save_name.Text = _shortcutToEdit.Name;
} }
// Set the selected image and available images (originalBitmap is set during shortcut update) // Set the selected image and available images (originalBitmap is set during shortcut update)
if (_editingExistingShortcut) if (_editingExistingShortcut)
{ {
ShortcutBitmap defaultBitmap = new ShortcutBitmap(); ShortcutBitmap defaultBitmap = new ShortcutBitmap();
@ -1436,12 +1479,12 @@ namespace DisplayMagician.UIForms
// If the game is selected, then grab images from the game // If the game is selected, then grab images from the game
if (shortcutGame != null) if (shortcutGame != null)
{ {
_availableImages.AddRange(ImageUtils.GetMeAllBitmapsFromFile(shortcutGame.IconPath)); _availableImages.AddRange(ImageUtils.GetMeAllBitmapsFromFile(shortcutGame.IconPath));
if (shortcutGame.ExePath != shortcutGame.IconPath) if (shortcutGame.ExePath != shortcutGame.IconPath)
{ {
_availableImages.AddRange(ImageUtils.GetMeAllBitmapsFromFile(shortcutGame.ExePath)); _availableImages.AddRange(ImageUtils.GetMeAllBitmapsFromFile(shortcutGame.ExePath));
} }
} }
// If the different exe to monitor is set, then grab the icons from there too! // If the different exe to monitor is set, then grab the icons from there too!
if (!String.IsNullOrWhiteSpace(_shortcutToEdit.DifferentGameExeToMonitor) && File.Exists(_shortcutToEdit.DifferentGameExeToMonitor)) if (!String.IsNullOrWhiteSpace(_shortcutToEdit.DifferentGameExeToMonitor) && File.Exists(_shortcutToEdit.DifferentGameExeToMonitor))
@ -1567,8 +1610,8 @@ namespace DisplayMagician.UIForms
btn_choose_exe_icon.Enabled = true; btn_choose_exe_icon.Enabled = true;
} }
} }
} }
} }
else else
{ {
// We're editing a new shortcut, so no game or anything selected // We're editing a new shortcut, so no game or anything selected
@ -1578,7 +1621,7 @@ namespace DisplayMagician.UIForms
if (_shortcutToEdit.StartPrograms is List<StartProgram> && _shortcutToEdit.StartPrograms.Count > 0) if (_shortcutToEdit.StartPrograms is List<StartProgram> && _shortcutToEdit.StartPrograms.Count > 0)
{ {
flp_start_programs.Controls.Clear(); flp_start_programs.Controls.Clear();
Padding firstStartProgramMargin = new Padding(10) { }; Padding firstStartProgramMargin = new Padding(10) { };
Padding otherStartProgramMargin = new Padding(10, 0, 10, 10) { }; Padding otherStartProgramMargin = new Padding(10, 0, 10, 10) { };
@ -1592,7 +1635,7 @@ namespace DisplayMagician.UIForms
continue; continue;
} }
StartProgramControl startProgramControl = new StartProgramControl(myStartProgram,spOrder); StartProgramControl startProgramControl = new StartProgramControl(myStartProgram, spOrder);
startProgramControl.Dock = DockStyle.None; startProgramControl.Dock = DockStyle.None;
if (spOrder == 1) if (spOrder == 1)
{ {
@ -1601,7 +1644,7 @@ namespace DisplayMagician.UIForms
else else
{ {
startProgramControl.Margin = otherStartProgramMargin; startProgramControl.Margin = otherStartProgramMargin;
} }
startProgramControl.Width = flp_start_programs.Width - 40; startProgramControl.Width = flp_start_programs.Width - 40;
startProgramControl.MouseDown += new MouseEventHandler(StartProgramControl_MouseDown); startProgramControl.MouseDown += new MouseEventHandler(StartProgramControl_MouseDown);
startProgramControl.DragOver += new DragEventHandler(StartProgramControl_DragOver); startProgramControl.DragOver += new DragEventHandler(StartProgramControl_DragOver);
@ -1615,13 +1658,13 @@ namespace DisplayMagician.UIForms
// Setup the single stop program we're beginning with // Setup the single stop program we're beginning with
if (_shortcutToEdit.StopPrograms is List<StopProgram> && _shortcutToEdit.StopPrograms.Count > 0) if (_shortcutToEdit.StopPrograms is List<StopProgram> && _shortcutToEdit.StopPrograms.Count > 0)
{ {
cb_run_cmd_afterwards.Checked = true; cb_run_cmd_afterwards.Checked = true;
txt_run_cmd_afterwards.Text = _shortcutToEdit.StopPrograms[0].Executable; txt_run_cmd_afterwards.Text = _shortcutToEdit.StopPrograms[0].Executable;
if (_shortcutToEdit.StopPrograms[0].ExecutableArgumentsRequired) if (_shortcutToEdit.StopPrograms[0].ExecutableArgumentsRequired)
{ {
cb_run_cmd_afterwards_args.Checked = true; cb_run_cmd_afterwards_args.Checked = true;
txt_run_cmd_afterwards_args.Text = _shortcutToEdit.StopPrograms[0].Arguments; txt_run_cmd_afterwards_args.Text = _shortcutToEdit.StopPrograms[0].Arguments;
} }
} }
else else
{ {
@ -1639,8 +1682,26 @@ namespace DisplayMagician.UIForms
// Finally enable the save button if it's still valid // Finally enable the save button if it's still valid
EnableSaveButtonIfValid(); EnableSaveButtonIfValid();
// Close the splash screen }
CloseTheSplashScreen();
private void ShortcutForm_Load(object sender, EventArgs e)
{
if (_firstShow)
{
// Parse the game bitmaps now the first time as we need them
// We need to add a refresh button to the shortcut page now!
if (!GameLibraries.GameLibrary.GamesImagesLoaded)
{
GameLibraries.GameLibrary.RefreshGameBitmaps();
}
// Close the splash screen
CloseTheSplashScreen();
_firstShow = false;
}
// Load the shortcut info
LoadShortcut();
} }
@ -2870,6 +2931,7 @@ namespace DisplayMagician.UIForms
MessageBoxButtons.OK, MessageBoxButtons.OK,
MessageBoxIcon.Exclamation); MessageBoxIcon.Exclamation);
} }
} }
// Class used to populate combo boxes // Class used to populate combo boxes

View File

@ -219,7 +219,7 @@
this.tsmi_copy, this.tsmi_copy,
this.tsmi_delete}); this.tsmi_delete});
this.cms_shortcuts.Name = "cms_shortcuts"; this.cms_shortcuts.Name = "cms_shortcuts";
this.cms_shortcuts.Size = new System.Drawing.Size(216, 136); this.cms_shortcuts.Size = new System.Drawing.Size(216, 114);
// //
// tsmi_edit // tsmi_edit
// //

View File

@ -265,11 +265,15 @@ 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;
ShortcutItem si = new ShortcutItem();
if (_shortcutForm == null) if (_shortcutForm == null)
{ {
_shortcutForm = new ShortcutForm(new ShortcutItem(), false); _shortcutForm = new ShortcutForm();
} }
//ShortcutRepository.IsValidRefresh(); //ShortcutRepository.IsValidRefresh()
// Set the Shortcut to as a new shortcut
_shortcutForm.Shortcut = si;
_shortcutForm.EditingExistingShortcut = false;
_shortcutForm.ShowDialog(this); _shortcutForm.ShowDialog(this);
if (_shortcutForm.DialogResult == DialogResult.OK) if (_shortcutForm.DialogResult == DialogResult.OK)
{ {
@ -317,7 +321,12 @@ namespace DisplayMagician.UIForms
this.Cursor = Cursors.WaitCursor; this.Cursor = Cursors.WaitCursor;
_shortcutForm = new ShortcutForm(_selectedShortcut,true); if (_shortcutForm == null)
{
_shortcutForm = new ShortcutForm();
}
_shortcutForm.Shortcut = _selectedShortcut;
_shortcutForm.EditingExistingShortcut = 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)