From 04c93e283aa83e64a2039e11a08cb8b918205c78 Mon Sep 17 00:00:00 2001 From: temacdonald Date: Tue, 28 Apr 2020 22:38:43 +1200 Subject: [PATCH] Fixed commandline so shortcuts would work Had to adjust both the order and structure of the command line so that the shortcuts would work, and wouldn't make people crazy! And adjusted the shortcut creator to make sure it generated correct shortcuts. Still a lot of edge cases sitting in there so need some good testing. Also disabled the CreateShortcut option, as it doesn't really work with the future combined list of multiple game library families. So the main command line options now are: - SwitchProfile permanent ... = swaps to a new display profile - SwitchProfile exe ... = temp swaps to profile and runs an exe - SwitchProfile steam ... = temp swaps to profile and runs a steam game - SwitchProfile uplay ... = temp swaps to profile and runs a uplay game - EditProfile ... = goes straight to the edit display profile screen - = starts up the graphical UI. --- HeliosDisplayManagement/Program.cs | 176 ++++++++++-------- .../UIForms/ShortcutForm.Designer.cs | 66 +++---- .../UIForms/ShortcutForm.cs | 112 ++++++----- 3 files changed, 185 insertions(+), 169 deletions(-) diff --git a/HeliosDisplayManagement/Program.cs b/HeliosDisplayManagement/Program.cs index 5e02c27..6d22f8b 100644 --- a/HeliosDisplayManagement/Program.cs +++ b/HeliosDisplayManagement/Program.cs @@ -156,6 +156,16 @@ namespace HeliosPlus { private static int Main(string[] args) { + // Write the Application Name + Console.WriteLine($"{Application.ProductName} v{Application.ProductVersion}"); + for (int i = 0; i <= Application.ProductName.Length + Application.ProductVersion .Length; i++) + { + Console.Write("="); + } + Console.WriteLine("="); + Console.WriteLine(@"Copyright © Terry MacDonald 2020-{DateTime.Today.Year}"); + Console.WriteLine(@"Based on Helios Display Management - Copyright © Soroush Falahati 2017-2020"); + // Figure out where the shortcut's will go ShortcutIconCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Assembly.GetExecutingAssembly().GetName().Name, @"ShortcutIconCache"); @@ -181,53 +191,57 @@ namespace HeliosPlus { app.GetFullNameAndVersion(); app.MakeSuggestionsInErrorMessage = true; - app.HelpOption("-?|-h|--help"); + app.HelpOption("-?|-h|--help", inherited:true); app.VersionOption("-v|--version", () => { return string.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version); }); - var optionProfile = app.Option("-p|--profile ", "The Profile Name or Profile ID of the profile to you want to use.", CommandOptionType.SingleValue); - optionProfile.Validators.Add(new ProfileMustExistValidator()); - // This is the SwitchProfile command - app.Command("SwitchProfile", (command) => + app.Command("SwitchProfile", (switchProfileCmd) => { //description and help text of the command. - command.Description = "Use this command to temporarily change profiles, and load your favourite game or application."; - command.ExtendedHelpText = "Use this command to create a new shortcut to your favourite game."; - command.HelpOption("-?|-h|--help"); + switchProfileCmd.Description = "Use this command to temporarily change profiles, and load your favourite game or application."; - command.OnExecute(() => + switchProfileCmd.OnExecute(() => { - - command.ShowHelp(); - - Console.WriteLine("Specify a subcommand"); - SwitchToProfile( - GetProfile(optionProfile.Value()) - ); - - - //command.ShowHelp(); + switchProfileCmd.ShowHelp(); return 1; }); - command.Command("execute", (subcommand) => + switchProfileCmd.Command("permanent", (switchProfilePermanentSubCmd) => { - subcommand.Description = "Change to a display profile and run an application or game executable."; - var argumentExecutable = subcommand.Argument("executabletorun", "The game exectuable file to run.").IsRequired(); - argumentExecutable.Validators.Add(new FileArgumentMustExistValidator()); - var optionWaitFor = subcommand.Option("-w|--waitfor ", "(optional) The application/game to start when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut. Cannot be used with --steam or --uplay options.", CommandOptionType.SingleValue); - optionWaitFor.Validators.Add(new FileOptionMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + switchProfilePermanentSubCmd.Description = "Change to a different display profile permanently (until you manually switch back)."; + var optionProfile = switchProfilePermanentSubCmd.Option("-p|--profile ", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + switchProfilePermanentSubCmd.OnExecute(() => { - Console.WriteLine($"Starting executable {argumentExecutable.Value}"); + Console.WriteLine($"Changing to display profile {optionProfile.Value()}."); + + SwitchToProfile(GetProfile(optionProfile.Value())); + return 0; + }); + }); + + + switchProfileCmd.Command("exe", (switchProfileExecuteSubCmd) => + { + switchProfileExecuteSubCmd.Description = "Temporarily change to a different display profile, run an application or game executable, then change back."; + var argumentExecutable = switchProfileExecuteSubCmd.Argument("PATH_TO_EXE", "(required) The game exectuable file to run.").IsRequired(); + argumentExecutable.Validators.Add(new FileArgumentMustExistValidator()); + var optionProfile = switchProfileExecuteSubCmd.Option("-p|--profile ", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + var optionWaitFor = switchProfileExecuteSubCmd.Option("-w|--waitfor ", "(optional) The application/game to start when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut. Cannot be used with --steam or --uplay options.", CommandOptionType.SingleValue); + optionWaitFor.Validators.Add(new FileOptionMustExistValidator()); + var optionTimeout = switchProfileExecuteSubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game.", CommandOptionType.SingleValue); + var optionArguments = switchProfileExecuteSubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game.", CommandOptionType.SingleValue); + switchProfileExecuteSubCmd.OnExecute(() => + { + Console.WriteLine($"Changing to display profile {optionProfile.Value()}, running executable {argumentExecutable.Value} then reverting back to this display profile when finished."); SwitchToExecutable( GetProfile(optionProfile.Value()), + //GetProfile(argProfile.Value), argumentExecutable.Value, optionWaitFor.Value(), Convert.ToUInt32(optionTimeout.Value()), @@ -238,19 +252,22 @@ namespace HeliosPlus { }); }); - command.Command("steam", (subcommand) => + switchProfileCmd.Command("steam", (switchProfileSteamSubCmd) => { - subcommand.Description = "Change to a display profile and run a Steam game."; - var argumentSteam = subcommand.Argument("steamgameid", "The Steam Game ID.").IsRequired(); + switchProfileSteamSubCmd.Description = "Change to a display profile and run a Steam game, then swap back."; + var argumentSteam = switchProfileSteamSubCmd.Argument("STEAM_GAME_ID", "(required) The Steam Game ID.").IsRequired(); argumentSteam.Validators.Add(new SteamArgumentMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + var optionProfile = switchProfileSteamSubCmd.Option("-p|--profile ", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + var optionTimeout = switchProfileSteamSubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. ", CommandOptionType.SingleValue); + var optionArguments = switchProfileSteamSubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game.", CommandOptionType.SingleValue); + switchProfileSteamSubCmd.OnExecute(() => { - Console.WriteLine($"Starting Steam Game {argumentSteam.Value}"); + Console.WriteLine($"Changing to display profile {optionProfile.Value()}, running Steam Game ID:{argumentSteam.Value} then reverting back to this display profile when finished."); SwitchToSteamGame( GetProfile(optionProfile.Value()), + //GetProfile(argProfile.Value), argumentSteam.Value, Convert.ToUInt32(optionTimeout.Value()), optionArguments.Value() @@ -260,19 +277,22 @@ namespace HeliosPlus { }); }); - command.Command("uplay", (subcommand) => + switchProfileCmd.Command("uplay", (switchProfileUplaySubCmd) => { - subcommand.Description = "Change to a display profile and run a Uplay game."; - var argumentUplay = subcommand.Argument("uplaygameid", "The Uplay Game ID to run for when we're temporarily switching profile and running the Uplay application/game.").IsRequired(); - argumentUplay.Validators.Add(new UplayArgumentMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + switchProfileUplaySubCmd.Description = "Change to a display profile and run a Uplay game."; + var argumentUplay = switchProfileUplaySubCmd.Argument("UPLAY_GAME_ID", "(required) The Uplay Game ID to run for when we're temporarily switching profile and running the Uplay application/game.").IsRequired(); + argumentUplay.Validators.Add(new UplayArgumentMustExistValidator()); + var optionProfile = switchProfileUplaySubCmd.Option("-p|--profile ", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + var optionTimeout = switchProfileUplaySubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game.", CommandOptionType.SingleValue); + var optionArguments = switchProfileUplaySubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game.", CommandOptionType.SingleValue); + switchProfileUplaySubCmd.OnExecute(() => { - Console.WriteLine($"Starting Uplay Game {argumentUplay.Value}"); + Console.WriteLine($"Changing to display profile {optionProfile.Value()}, running Uplay Game ID:{argumentUplay.Value} then reverting back to this display profile when finished."); SwitchToUplayGame( GetProfile(optionProfile.Value()), + //GetProfile(argProfile.Value), argumentUplay.Value, Convert.ToUInt32(optionTimeout.Value()), optionArguments.Value() @@ -285,31 +305,32 @@ namespace HeliosPlus { }); - // This is the CreateShortcut command - app.Command("CreateShortcut", (command) => + /*// This is the CreateShortcut command + app.Command("CreateShortcut", (createShortcutCmd) => { //description and help text of the command. - command.Description = "Use this command to create a new shortcut to your favourite game."; - command.ExtendedHelpText = "Use this command to create a new shortcut to your favourite game."; - command.HelpOption("-?|-h|--help"); + createShortcutCmd.Description = "Use this command to create a new shortcut to your favourite game."; + //createShortcutCmd.ExtendedHelpText = "Use this command to create a new shortcut to your favourite game."; - command.OnExecute(() => + var optionProfile = createShortcutCmd.Option("-p|--profile", "The Profile Name or Profile ID of the profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + + createShortcutCmd.OnExecute(() => { - Console.WriteLine("Specify a subcommand"); - command.ShowHelp(); + createShortcutCmd.ShowHelp(); return 1; }); - command.Command("execute", (subcommand) => + createShortcutCmd.Command("exe", (createShortcutExecutableSubCmd) => { - subcommand.Description = "Create a shortcut to run a Game executable."; - var argumentExecutable = subcommand.Argument("executabletorun", "The game exectuable file to run.").IsRequired(); + createShortcutExecutableSubCmd.Description = "Create a shortcut to run a Game executable."; + var argumentExecutable = createShortcutExecutableSubCmd.Argument("executabletorun", "The game exectuable file to run.").IsRequired(); argumentExecutable.Validators.Add(new FileArgumentMustExistValidator()); - var optionWaitFor = subcommand.Option("-w|--waitfor ", "(optional) The application/game to start when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut. Cannot be used with --steam or --uplay options.", CommandOptionType.SingleValue); + var optionWaitFor = createShortcutExecutableSubCmd.Option("-w|--waitfor ", "(optional) The application/game to start when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut. Cannot be used with --steam or --uplay options.", CommandOptionType.SingleValue); optionWaitFor.Validators.Add(new FileOptionMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + var optionTimeout = createShortcutExecutableSubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + var optionArguments = createShortcutExecutableSubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + createShortcutExecutableSubCmd.OnExecute(() => { Console.WriteLine($"Creating a Desktop Shortcut to the application or game {argumentExecutable.Value}"); @@ -325,14 +346,14 @@ namespace HeliosPlus { }); }); - command.Command("steam", (subcommand) => + createShortcutCmd.Command("steam", (createShortcutSteamSubCmd) => { - subcommand.Description = "Create a Steam Game shortcut."; - var argumentSteam = subcommand.Argument("steamgameid", "The Steam Game ID.").IsRequired(); + createShortcutSteamSubCmd.Description = "Create a Steam Game shortcut."; + var argumentSteam = createShortcutSteamSubCmd.Argument("steamgameid", "The Steam Game ID.").IsRequired(); argumentSteam.Validators.Add(new SteamArgumentMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + var optionTimeout = createShortcutSteamSubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + var optionArguments = createShortcutSteamSubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + createShortcutSteamSubCmd.OnExecute(() => { Console.WriteLine($"Creating a Desktop Shortcut to the Steam Game {argumentSteam.Value}"); @@ -347,14 +368,14 @@ namespace HeliosPlus { }); }); - command.Command("uplay", (subcommand) => + createShortcutCmd.Command("uplay", (createShortcutUplaySubCmd) => { - subcommand.Description = "Create a Uplay Game shortcut."; - var argumentUplay = subcommand.Argument("uplaygameid", "The Uplay Game ID to run for when we're temporarily switching profile and running the Uplay application/game.").IsRequired(); + createShortcutUplaySubCmd.Description = "Create a Uplay Game shortcut."; + var argumentUplay = createShortcutUplaySubCmd.Argument("uplaygameid", "The Uplay Game ID to run for when we're temporarily switching profile and running the Uplay application/game.").IsRequired(); argumentUplay.Validators.Add(new UplayArgumentMustExistValidator()); - var optionTimeout = subcommand.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - var optionArguments = subcommand.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); - subcommand.OnExecute(() => + var optionTimeout = createShortcutUplaySubCmd.Option("-t|--timeout", "(optional) The time in seconds we should delay starting the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + var optionArguments = createShortcutUplaySubCmd.Option("-a|--arguments", "(optional) Extra arguments to pass to the application/game when we're temporarily switching profile and running the application/game. Also can be used when creating a shortcut.", CommandOptionType.SingleValue); + createShortcutUplaySubCmd.OnExecute(() => { Console.WriteLine($"Creating a Desktop Shortcut to the Uplay Game {argumentUplay.Value}"); @@ -369,17 +390,18 @@ namespace HeliosPlus { }); }); - }); + });*/ // This is the EditProfile command - app.Command("EditProfile", (command) => + app.Command("EditProfile", (editProfileCmd) => { //description and help text of the command. - command.Description = "Use this command to edit a HeliosDMPlus profile."; - command.ExtendedHelpText = "Use this command to edit a HeliosDMPlus profile."; - command.HelpOption("-?|-h|--help"); + editProfileCmd.Description = "Use this command to edit a HeliosDMPlus profile."; - command.OnExecute(() => + var optionProfile = editProfileCmd.Option("-p|--profile", "The Profile Name or Profile ID of the profile to you want to use.", CommandOptionType.SingleValue).IsRequired(); + optionProfile.Validators.Add(new ProfileMustExistValidator()); + + editProfileCmd.OnExecute(() => { Console.WriteLine($"Editing profile {optionProfile.Value()}"); diff --git a/HeliosDisplayManagement/UIForms/ShortcutForm.Designer.cs b/HeliosDisplayManagement/UIForms/ShortcutForm.Designer.cs index 3c1f99a..208dcd5 100644 --- a/HeliosDisplayManagement/UIForms/ShortcutForm.Designer.cs +++ b/HeliosDisplayManagement/UIForms/ShortcutForm.Designer.cs @@ -38,15 +38,12 @@ namespace HeliosPlus.UIForms this.g_temporary = new System.Windows.Forms.GroupBox(); this.p_game = new System.Windows.Forms.Panel(); this.txt_game_name = new System.Windows.Forms.TextBox(); - this.nud_game_appid = new System.Windows.Forms.NumericUpDown(); - this.cmb_game_launcher = new System.Windows.Forms.ComboBox(); this.label6 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.btn_choose_game = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.txt_args_game = new System.Windows.Forms.TextBox(); this.cb_args_game = new System.Windows.Forms.CheckBox(); - this.nud_steamapps = new System.Windows.Forms.Button(); this.label5 = new System.Windows.Forms.Label(); this.nud_timeout_game = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); @@ -76,9 +73,10 @@ namespace HeliosPlus.UIForms this.rb_switch_temp = new System.Windows.Forms.RadioButton(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.lbl_profile = new System.Windows.Forms.Label(); + this.txt_game_launcher = new System.Windows.Forms.TextBox(); + this.txt_game_id = new System.Windows.Forms.TextBox(); this.g_temporary.SuspendLayout(); this.p_game.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud_game_appid)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).BeginInit(); this.p_standalone.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_executable)).BeginInit(); @@ -119,16 +117,15 @@ namespace HeliosPlus.UIForms // // p_game // + this.p_game.Controls.Add(this.txt_game_id); + this.p_game.Controls.Add(this.txt_game_launcher); this.p_game.Controls.Add(this.txt_game_name); - this.p_game.Controls.Add(this.nud_game_appid); - this.p_game.Controls.Add(this.cmb_game_launcher); this.p_game.Controls.Add(this.label6); this.p_game.Controls.Add(this.label4); this.p_game.Controls.Add(this.btn_choose_game); this.p_game.Controls.Add(this.label1); this.p_game.Controls.Add(this.txt_args_game); this.p_game.Controls.Add(this.cb_args_game); - this.p_game.Controls.Add(this.nud_steamapps); this.p_game.Controls.Add(this.label5); this.p_game.Controls.Add(this.nud_timeout_game); this.p_game.Controls.Add(this.label3); @@ -146,29 +143,6 @@ namespace HeliosPlus.UIForms this.txt_game_name.Size = new System.Drawing.Size(302, 20); this.txt_game_name.TabIndex = 21; // - // nud_game_appid - // - this.nud_game_appid.Enabled = false; - this.nud_game_appid.Location = new System.Drawing.Point(408, 105); - this.nud_game_appid.Maximum = new decimal(new int[] { - 1410065407, - 2, - 0, - 0}); - this.nud_game_appid.Name = "nud_game_appid"; - this.nud_game_appid.ReadOnly = true; - this.nud_game_appid.Size = new System.Drawing.Size(89, 20); - this.nud_game_appid.TabIndex = 1; - this.nud_game_appid.ValueChanged += new System.EventHandler(this.nud_game_appid_ValueChanged); - // - // cmb_game_launcher - // - this.cmb_game_launcher.FormattingEnabled = true; - this.cmb_game_launcher.Location = new System.Drawing.Point(408, 78); - this.cmb_game_launcher.Name = "cmb_game_launcher"; - this.cmb_game_launcher.Size = new System.Drawing.Size(163, 21); - this.cmb_game_launcher.TabIndex = 20; - // // label6 // this.label6.AutoSize = true; @@ -196,6 +170,7 @@ namespace HeliosPlus.UIForms this.btn_choose_game.TabIndex = 16; this.btn_choose_game.Text = ">>"; this.btn_choose_game.UseVisualStyleBackColor = true; + this.btn_choose_game.Click += new System.EventHandler(this.btn_choose_game_Click); // // label1 // @@ -228,15 +203,6 @@ namespace HeliosPlus.UIForms this.cb_args_game.UseVisualStyleBackColor = true; this.cb_args_game.CheckedChanged += new System.EventHandler(this.cb_args_game_CheckedChanged); // - // nud_steamapps - // - this.nud_steamapps.Location = new System.Drawing.Point(505, 105); - this.nud_steamapps.Name = "nud_steamapps"; - this.nud_steamapps.Size = new System.Drawing.Size(24, 20); - this.nud_steamapps.TabIndex = 2; - this.nud_steamapps.Text = "..."; - this.nud_steamapps.UseVisualStyleBackColor = true; - // // label5 // this.label5.AutoSize = true; @@ -544,6 +510,22 @@ namespace HeliosPlus.UIForms this.lbl_profile.Text = "[None]"; this.lbl_profile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // + // txt_game_launcher + // + this.txt_game_launcher.Location = new System.Drawing.Point(408, 78); + this.txt_game_launcher.Name = "txt_game_launcher"; + this.txt_game_launcher.ReadOnly = true; + this.txt_game_launcher.Size = new System.Drawing.Size(175, 20); + this.txt_game_launcher.TabIndex = 23; + // + // txt_game_id + // + this.txt_game_id.Location = new System.Drawing.Point(408, 104); + this.txt_game_id.Name = "txt_game_id"; + this.txt_game_id.ReadOnly = true; + this.txt_game_id.Size = new System.Drawing.Size(75, 20); + this.txt_game_id.TabIndex = 24; + // // ShortcutForm // this.AcceptButton = this.btn_save; @@ -572,7 +554,6 @@ namespace HeliosPlus.UIForms this.g_temporary.PerformLayout(); this.p_game.ResumeLayout(false); this.p_game.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud_game_appid)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).EndInit(); this.p_standalone.ResumeLayout(false); this.p_standalone.PerformLayout(); @@ -599,10 +580,8 @@ namespace HeliosPlus.UIForms private System.Windows.Forms.RadioButton rb_launcher; private System.Windows.Forms.Panel p_game; private System.Windows.Forms.Label label3; - private System.Windows.Forms.NumericUpDown nud_game_appid; private System.Windows.Forms.Label label5; private System.Windows.Forms.NumericUpDown nud_timeout_game; - private System.Windows.Forms.Button nud_steamapps; private System.Windows.Forms.OpenFileDialog dialog_open; private System.Windows.Forms.SaveFileDialog dialog_save; private System.Windows.Forms.RadioButton rb_switch_perm; @@ -617,7 +596,6 @@ namespace HeliosPlus.UIForms private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label4; private System.Windows.Forms.Button btn_choose_game; - private System.Windows.Forms.ComboBox cmb_game_launcher; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txt_game_name; private System.Windows.Forms.OpenFileDialog openFileDialog1; @@ -627,5 +605,7 @@ namespace HeliosPlus.UIForms private System.Windows.Forms.ImageList il_games; private System.Windows.Forms.ColumnHeader clm_images; private System.Windows.Forms.ColumnHeader clm_name; + private System.Windows.Forms.TextBox txt_game_id; + private System.Windows.Forms.TextBox txt_game_launcher; } } \ No newline at end of file diff --git a/HeliosDisplayManagement/UIForms/ShortcutForm.cs b/HeliosDisplayManagement/UIForms/ShortcutForm.cs index 29cb47a..f64b339 100644 --- a/HeliosDisplayManagement/UIForms/ShortcutForm.cs +++ b/HeliosDisplayManagement/UIForms/ShortcutForm.cs @@ -16,7 +16,9 @@ namespace HeliosPlus.UIForms { public partial class ShortcutForm : Form { - + + List _allSteamGames; + public ShortcutForm() { InitializeComponent(); @@ -122,12 +124,12 @@ namespace HeliosPlus.UIForms public uint GameAppId { - get => rb_switch_temp.Checked && rb_launcher.Checked ? (uint) nud_game_appid.Value : 0; + get => rb_switch_temp.Checked && rb_launcher.Checked ? (uint) Convert.ToInt32(txt_game_id.Text) : 0; set { rb_switch_temp.Checked = true; rb_launcher.Checked = true; - nud_game_appid.Value = value; + txt_game_id.Text = value.ToString(); } } @@ -144,7 +146,22 @@ namespace HeliosPlus.UIForms public SupportedGameLibrary GameLibrary { - get => rb_switch_temp.Checked && rb_launcher.Checked ? (SupportedGameLibrary) nud_game_appid.Value : SupportedGameLibrary.Unknown; + get + { + if (rb_switch_temp.Checked && rb_launcher.Checked) + { + if (txt_game_launcher.Text.Contains("Steam")) + { + return SupportedGameLibrary.Steam; + } + else if (txt_game_launcher.Text.Contains("Uplay")) + { + return SupportedGameLibrary.Uplay; + } + + } + return SupportedGameLibrary.Unknown; + } set { rb_switch_temp.Checked = true; @@ -152,9 +169,11 @@ namespace HeliosPlus.UIForms switch (value) { case SupportedGameLibrary.Steam: + txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibrary), SupportedGameLibrary.Steam); break; case SupportedGameLibrary.Uplay: + txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibrary), SupportedGameLibrary.Uplay); break; } @@ -217,6 +236,8 @@ namespace HeliosPlus.UIForms try { + // Set the Shortcut save folder to the Desktop as that's where people will want it most likely + dialog_save.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Try to set up some sensible suggestions for the Shortcut name if (rb_switch_perm.Checked) { @@ -226,11 +247,11 @@ namespace HeliosPlus.UIForms { if (rb_standalone.Checked) { - dialog_save.FileName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath); + dialog_save.FileName = String.Concat(Path.GetFileNameWithoutExtension(ExecutableNameAndPath),@" (", Profile.Name, @")"); } else { - dialog_save.FileName = GameName; + dialog_save.FileName = String.Concat(GameName, @" (", Profile.Name, @")"); } } @@ -276,9 +297,7 @@ namespace HeliosPlus.UIForms var args = new List { // Add the SwitchProfile command as the first argument to start to switch to another profile - $"{HeliosStartupAction.SwitchProfile}", - // Add the Profile Name as the second argument (use that rather than ID - though ID still will work!) - $"--profile \"{Profile.Name}\"" + $"{HeliosStartupAction.SwitchProfile}" }; // Only add the rest of the options if the temporary switch radio button is set @@ -302,6 +321,9 @@ namespace HeliosPlus.UIForms // Add the executable command and the executable name to the shortcut arguments args.Add($"execute \"{ExecutableNameAndPath}\""); + // Add the Profile Name as the first option (use that rather than ID - though ID still will work!) + args.Add($"--profile \"{Profile.Name}\""); + // Check that the wait for executable radiobutton is on if (rb_wait_executable.Checked) { @@ -325,7 +347,7 @@ namespace HeliosPlus.UIForms shortcutDescription = string.Format(Language.Executing_application_with_profile, programName, Profile.Name); // Work out the name of the shortcut we'll save. - shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(Path.GetFileNameWithoutExtension(ExecutableNameAndPath), @".ico")); + shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(@"executable-", Path.GetFileNameWithoutExtension(ExecutableNameAndPath), @".ico")); // Grab an icon for the selected executable try @@ -368,7 +390,7 @@ namespace HeliosPlus.UIForms shortcutIcon = steamGameToRun.GameIcon; // Work out the name of the shortcut we'll save. - shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, @"Uplay", String.Concat(GameAppId.ToString(), @".ico")); + shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(@"steam-", GameAppId.ToString(), @".ico")); args.Add($"--steam {GameAppId}"); @@ -397,12 +419,15 @@ namespace HeliosPlus.UIForms shortcutIcon = uplayGameToRun.GameIcon; // Work out the name of the shortcut we'll save. - shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, @"Uplay", String.Concat(GameAppId.ToString(), @".ico")); + shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(@"uplay-", GameAppId.ToString(), @".ico")); args.Add($"--uplay {GameAppId}"); } + // Add the Profile Name as the first option (use that rather than ID - though ID still will work!) + args.Add($"--profile \"{Profile.Name}\""); + // Add the game timeout argument and the timeout duration in seconds to the shortcut arguments args.Add($"--timeout {GameTimeout}"); @@ -420,11 +445,17 @@ namespace HeliosPlus.UIForms // Only add the rest of the options if the permanent switch radio button is set else { + // Add the action switch to make the permanent switch to a different profile + args.Add($"permanent"); + + // Add the Profile Name as the first option (use that rather than ID - though ID still will work!) + args.Add($"--profile \"{Profile.Name}\""); + // Prepare text for the shortcut description field shortcutDescription = string.Format(Language.Switching_display_profile_to_profile, Profile.Name); // Work out the name of the shortcut we'll save. - shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(Profile.Name, @".ico")); + shortcutIconFileName = Path.Combine(Program.ShortcutIconCachePath, String.Concat(@"permanent-", Profile.Name, @".ico")); // Grab an icon for the selected profile try @@ -505,31 +536,6 @@ namespace HeliosPlus.UIForms return fileName != null && File.Exists(fileName); } - private void nud_game_appid_ValueChanged(object sender, EventArgs e) - { - //lbl_steamname.Text = new SteamGame((uint) nud_game_appid.Value).ToString(); - } - - /*private void nud_steamapps_Click(object sender, EventArgs e) - { - var steamGamesForm = new SteamGamesForm(); - - if (steamGamesForm.ShowDialog(this) == DialogResult.OK && steamGamesForm.SteamGame != null) - { - nud_game_appid.Value = steamGamesForm.SteamGame.AppId; - } - }*/ - -/* private void rb_wait_process_CheckedChanged(object sender, EventArgs e) - { - if (rb_wait_process.Checked) - { - // Enable the Process Name Text field - txt_process_name.Enabled = true; - } - } -*/ - private void txt_executable_TextChanged(object sender, EventArgs e) { try @@ -614,22 +620,12 @@ namespace HeliosPlus.UIForms private async void ShortcutForm_Load(object sender, EventArgs e) { - // Make the game launcher selector read only. - cmb_game_launcher.DropDownStyle = ComboBoxStyle.DropDownList; - // Fill the list of supported game libraries - foreach (var gameLibrary in Enum.GetNames(typeof(SupportedGameLibrary))) { - if (gameLibrary != "Unknown") - { - cmb_game_launcher.Items.Add(gameLibrary); - } - } - - // Set the Profile name lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}"; // Start finding the games and loading the Games ListView List allSteamGames = SteamGame.GetAllInstalledGames(); + _allSteamGames = allSteamGames; foreach (var game in allSteamGames.OrderBy(game => game.GameName)) { //var iconAddress = await game.GetIcon(); @@ -705,5 +701,23 @@ namespace HeliosPlus.UIForms txt_args_game.Enabled = false; } } + + private void btn_choose_game_Click(object sender, EventArgs e) + { + if (lv_games.SelectedItems.Count > 0) + { + + txt_game_name.Text = lv_games.SelectedItems[0].Text; + foreach (SteamGame game in _allSteamGames) + { + if (game.GameName == txt_game_name.Text) + { + txt_game_launcher.Text = game.GameLibrary.ToString(); + txt_game_id.Text = game.GameId.ToString(); + } + } + } + + } } } \ No newline at end of file