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
- <none>   = starts up the graphical UI.
This commit is contained in:
temacdonald 2020-04-28 22:38:43 +12:00
parent 322fbcb305
commit 04c93e283a
3 changed files with 185 additions and 169 deletions

View File

@ -156,6 +156,16 @@ namespace HeliosPlus {
private static int Main(string[] args) 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 // Figure out where the shortcut's will go
ShortcutIconCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ShortcutIconCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Assembly.GetExecutingAssembly().GetName().Name, @"ShortcutIconCache"); Assembly.GetExecutingAssembly().GetName().Name, @"ShortcutIconCache");
@ -181,53 +191,57 @@ namespace HeliosPlus {
app.GetFullNameAndVersion(); app.GetFullNameAndVersion();
app.MakeSuggestionsInErrorMessage = true; app.MakeSuggestionsInErrorMessage = true;
app.HelpOption("-?|-h|--help"); app.HelpOption("-?|-h|--help", inherited:true);
app.VersionOption("-v|--version", () => { app.VersionOption("-v|--version", () => {
return string.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version); return string.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
}); });
var optionProfile = app.Option("-p|--profile <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 // This is the SwitchProfile command
app.Command("SwitchProfile", (command) => app.Command("SwitchProfile", (switchProfileCmd) =>
{ {
//description and help text of the command. //description and help text of the command.
command.Description = "Use this command to temporarily change profiles, and load your favourite game or application."; switchProfileCmd.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");
command.OnExecute(() => switchProfileCmd.OnExecute(() =>
{ {
switchProfileCmd.ShowHelp();
command.ShowHelp();
Console.WriteLine("Specify a subcommand");
SwitchToProfile(
GetProfile(optionProfile.Value())
);
//command.ShowHelp();
return 1; return 1;
}); });
command.Command("execute", (subcommand) => switchProfileCmd.Command("permanent", (switchProfilePermanentSubCmd) =>
{ {
subcommand.Description = "Change to a display profile and run an application or game executable."; switchProfilePermanentSubCmd.Description = "Change to a different display profile permanently (until you manually switch back).";
var argumentExecutable = subcommand.Argument("executabletorun", "The game exectuable file to run.").IsRequired(); var optionProfile = switchProfilePermanentSubCmd.Option("-p|--profile <PROFILENAME>", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired();
argumentExecutable.Validators.Add(new FileArgumentMustExistValidator()); optionProfile.Validators.Add(new ProfileMustExistValidator());
var optionWaitFor = subcommand.Option("-w|--waitfor <PROCESSNAME>", "(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); switchProfilePermanentSubCmd.OnExecute(() =>
optionWaitFor.Validators.Add(new FileOptionMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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(() =>
{ {
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 <PROFILENAME>", "(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 <PROCESSNAME>", "(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<uint>("-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( SwitchToExecutable(
GetProfile(optionProfile.Value()), GetProfile(optionProfile.Value()),
//GetProfile(argProfile.Value),
argumentExecutable.Value, argumentExecutable.Value,
optionWaitFor.Value(), optionWaitFor.Value(),
Convert.ToUInt32(optionTimeout.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."; switchProfileSteamSubCmd.Description = "Change to a display profile and run a Steam game, then swap back.";
var argumentSteam = subcommand.Argument("steamgameid", "The Steam Game ID.").IsRequired(); var argumentSteam = switchProfileSteamSubCmd.Argument("STEAM_GAME_ID", "(required) The Steam Game ID.").IsRequired();
argumentSteam.Validators.Add(new SteamArgumentMustExistValidator()); argumentSteam.Validators.Add(new SteamArgumentMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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 optionProfile = switchProfileSteamSubCmd.Option("-p|--profile <PROFILENAME>", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired();
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); optionProfile.Validators.Add(new ProfileMustExistValidator());
subcommand.OnExecute(() => var optionTimeout = switchProfileSteamSubCmd.Option<uint>("-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( SwitchToSteamGame(
GetProfile(optionProfile.Value()), GetProfile(optionProfile.Value()),
//GetProfile(argProfile.Value),
argumentSteam.Value, argumentSteam.Value,
Convert.ToUInt32(optionTimeout.Value()), Convert.ToUInt32(optionTimeout.Value()),
optionArguments.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."; switchProfileUplaySubCmd.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(); 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()); argumentUplay.Validators.Add(new UplayArgumentMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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 optionProfile = switchProfileUplaySubCmd.Option("-p|--profile <PROFILENAME>", "(required) The Profile Name or Profile ID of the display profile to you want to use.", CommandOptionType.SingleValue).IsRequired();
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); optionProfile.Validators.Add(new ProfileMustExistValidator());
subcommand.OnExecute(() => var optionTimeout = switchProfileUplaySubCmd.Option<uint>("-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( SwitchToUplayGame(
GetProfile(optionProfile.Value()), GetProfile(optionProfile.Value()),
//GetProfile(argProfile.Value),
argumentUplay.Value, argumentUplay.Value,
Convert.ToUInt32(optionTimeout.Value()), Convert.ToUInt32(optionTimeout.Value()),
optionArguments.Value() optionArguments.Value()
@ -285,31 +305,32 @@ namespace HeliosPlus {
}); });
// This is the CreateShortcut command /*// This is the CreateShortcut command
app.Command("CreateShortcut", (command) => app.Command("CreateShortcut", (createShortcutCmd) =>
{ {
//description and help text of the command. //description and help text of the command.
command.Description = "Use this command to create a new shortcut to your favourite game."; createShortcutCmd.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."; //createShortcutCmd.ExtendedHelpText = "Use this command to create a new shortcut to your favourite game.";
command.HelpOption("-?|-h|--help");
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"); createShortcutCmd.ShowHelp();
command.ShowHelp();
return 1; return 1;
}); });
command.Command("execute", (subcommand) => createShortcutCmd.Command("exe", (createShortcutExecutableSubCmd) =>
{ {
subcommand.Description = "Create a shortcut to run a Game executable."; createShortcutExecutableSubCmd.Description = "Create a shortcut to run a Game executable.";
var argumentExecutable = subcommand.Argument("executabletorun", "The game exectuable file to run.").IsRequired(); var argumentExecutable = createShortcutExecutableSubCmd.Argument("executabletorun", "The game exectuable file to run.").IsRequired();
argumentExecutable.Validators.Add(new FileArgumentMustExistValidator()); argumentExecutable.Validators.Add(new FileArgumentMustExistValidator());
var optionWaitFor = subcommand.Option("-w|--waitfor <PROCESSNAME>", "(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 <PROCESSNAME>", "(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()); optionWaitFor.Validators.Add(new FileOptionMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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 optionTimeout = createShortcutExecutableSubCmd.Option<uint>("-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); 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);
subcommand.OnExecute(() => createShortcutExecutableSubCmd.OnExecute(() =>
{ {
Console.WriteLine($"Creating a Desktop Shortcut to the application or game {argumentExecutable.Value}"); 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."; createShortcutSteamSubCmd.Description = "Create a Steam Game shortcut.";
var argumentSteam = subcommand.Argument("steamgameid", "The Steam Game ID.").IsRequired(); var argumentSteam = createShortcutSteamSubCmd.Argument("steamgameid", "The Steam Game ID.").IsRequired();
argumentSteam.Validators.Add(new SteamArgumentMustExistValidator()); argumentSteam.Validators.Add(new SteamArgumentMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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 optionTimeout = createShortcutSteamSubCmd.Option<uint>("-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); 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);
subcommand.OnExecute(() => createShortcutSteamSubCmd.OnExecute(() =>
{ {
Console.WriteLine($"Creating a Desktop Shortcut to the Steam Game {argumentSteam.Value}"); 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."; createShortcutUplaySubCmd.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(); 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()); argumentUplay.Validators.Add(new UplayArgumentMustExistValidator());
var optionTimeout = subcommand.Option<uint>("-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 optionTimeout = createShortcutUplaySubCmd.Option<uint>("-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); 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);
subcommand.OnExecute(() => createShortcutUplaySubCmd.OnExecute(() =>
{ {
Console.WriteLine($"Creating a Desktop Shortcut to the Uplay Game {argumentUplay.Value}"); Console.WriteLine($"Creating a Desktop Shortcut to the Uplay Game {argumentUplay.Value}");
@ -369,17 +390,18 @@ namespace HeliosPlus {
}); });
}); });
}); });*/
// This is the EditProfile command // This is the EditProfile command
app.Command("EditProfile", (command) => app.Command("EditProfile", (editProfileCmd) =>
{ {
//description and help text of the command. //description and help text of the command.
command.Description = "Use this command to edit a HeliosDMPlus profile."; editProfileCmd.Description = "Use this command to edit a HeliosDMPlus profile.";
command.ExtendedHelpText = "Use this command to edit a HeliosDMPlus profile.";
command.HelpOption("-?|-h|--help");
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()}"); Console.WriteLine($"Editing profile {optionProfile.Value()}");

View File

@ -38,15 +38,12 @@ namespace HeliosPlus.UIForms
this.g_temporary = new System.Windows.Forms.GroupBox(); this.g_temporary = new System.Windows.Forms.GroupBox();
this.p_game = new System.Windows.Forms.Panel(); this.p_game = new System.Windows.Forms.Panel();
this.txt_game_name = new System.Windows.Forms.TextBox(); 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.label6 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.btn_choose_game = new System.Windows.Forms.Button(); this.btn_choose_game = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.txt_args_game = new System.Windows.Forms.TextBox(); this.txt_args_game = new System.Windows.Forms.TextBox();
this.cb_args_game = new System.Windows.Forms.CheckBox(); 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.label5 = new System.Windows.Forms.Label();
this.nud_timeout_game = new System.Windows.Forms.NumericUpDown(); this.nud_timeout_game = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
@ -76,9 +73,10 @@ namespace HeliosPlus.UIForms
this.rb_switch_temp = new System.Windows.Forms.RadioButton(); this.rb_switch_temp = new System.Windows.Forms.RadioButton();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.lbl_profile = new System.Windows.Forms.Label(); 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.g_temporary.SuspendLayout();
this.p_game.SuspendLayout(); this.p_game.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nud_game_appid)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).BeginInit();
this.p_standalone.SuspendLayout(); this.p_standalone.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nud_timeout_executable)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_executable)).BeginInit();
@ -119,16 +117,15 @@ namespace HeliosPlus.UIForms
// //
// p_game // 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.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.label6);
this.p_game.Controls.Add(this.label4); this.p_game.Controls.Add(this.label4);
this.p_game.Controls.Add(this.btn_choose_game); this.p_game.Controls.Add(this.btn_choose_game);
this.p_game.Controls.Add(this.label1); this.p_game.Controls.Add(this.label1);
this.p_game.Controls.Add(this.txt_args_game); this.p_game.Controls.Add(this.txt_args_game);
this.p_game.Controls.Add(this.cb_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.label5);
this.p_game.Controls.Add(this.nud_timeout_game); this.p_game.Controls.Add(this.nud_timeout_game);
this.p_game.Controls.Add(this.label3); 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.Size = new System.Drawing.Size(302, 20);
this.txt_game_name.TabIndex = 21; 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 // label6
// //
this.label6.AutoSize = true; this.label6.AutoSize = true;
@ -196,6 +170,7 @@ namespace HeliosPlus.UIForms
this.btn_choose_game.TabIndex = 16; this.btn_choose_game.TabIndex = 16;
this.btn_choose_game.Text = ">>"; this.btn_choose_game.Text = ">>";
this.btn_choose_game.UseVisualStyleBackColor = true; this.btn_choose_game.UseVisualStyleBackColor = true;
this.btn_choose_game.Click += new System.EventHandler(this.btn_choose_game_Click);
// //
// label1 // label1
// //
@ -228,15 +203,6 @@ namespace HeliosPlus.UIForms
this.cb_args_game.UseVisualStyleBackColor = true; this.cb_args_game.UseVisualStyleBackColor = true;
this.cb_args_game.CheckedChanged += new System.EventHandler(this.cb_args_game_CheckedChanged); 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 // label5
// //
this.label5.AutoSize = true; this.label5.AutoSize = true;
@ -544,6 +510,22 @@ namespace HeliosPlus.UIForms
this.lbl_profile.Text = "[None]"; this.lbl_profile.Text = "[None]";
this.lbl_profile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 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 // ShortcutForm
// //
this.AcceptButton = this.btn_save; this.AcceptButton = this.btn_save;
@ -572,7 +554,6 @@ namespace HeliosPlus.UIForms
this.g_temporary.PerformLayout(); this.g_temporary.PerformLayout();
this.p_game.ResumeLayout(false); this.p_game.ResumeLayout(false);
this.p_game.PerformLayout(); this.p_game.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nud_game_appid)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).EndInit();
this.p_standalone.ResumeLayout(false); this.p_standalone.ResumeLayout(false);
this.p_standalone.PerformLayout(); this.p_standalone.PerformLayout();
@ -599,10 +580,8 @@ namespace HeliosPlus.UIForms
private System.Windows.Forms.RadioButton rb_launcher; private System.Windows.Forms.RadioButton rb_launcher;
private System.Windows.Forms.Panel p_game; private System.Windows.Forms.Panel p_game;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown nud_game_appid;
private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label5;
private System.Windows.Forms.NumericUpDown nud_timeout_game; 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.OpenFileDialog dialog_open;
private System.Windows.Forms.SaveFileDialog dialog_save; private System.Windows.Forms.SaveFileDialog dialog_save;
private System.Windows.Forms.RadioButton rb_switch_perm; 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 label6;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btn_choose_game; 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.Label label1;
private System.Windows.Forms.TextBox txt_game_name; private System.Windows.Forms.TextBox txt_game_name;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1;
@ -627,5 +605,7 @@ namespace HeliosPlus.UIForms
private System.Windows.Forms.ImageList il_games; private System.Windows.Forms.ImageList il_games;
private System.Windows.Forms.ColumnHeader clm_images; private System.Windows.Forms.ColumnHeader clm_images;
private System.Windows.Forms.ColumnHeader clm_name; private System.Windows.Forms.ColumnHeader clm_name;
private System.Windows.Forms.TextBox txt_game_id;
private System.Windows.Forms.TextBox txt_game_launcher;
} }
} }

View File

@ -17,6 +17,8 @@ namespace HeliosPlus.UIForms
public partial class ShortcutForm : Form public partial class ShortcutForm : Form
{ {
List<SteamGame> _allSteamGames;
public ShortcutForm() public ShortcutForm()
{ {
InitializeComponent(); InitializeComponent();
@ -122,12 +124,12 @@ namespace HeliosPlus.UIForms
public uint GameAppId 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 set
{ {
rb_switch_temp.Checked = true; rb_switch_temp.Checked = true;
rb_launcher.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 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 set
{ {
rb_switch_temp.Checked = true; rb_switch_temp.Checked = true;
@ -152,9 +169,11 @@ namespace HeliosPlus.UIForms
switch (value) switch (value)
{ {
case SupportedGameLibrary.Steam: case SupportedGameLibrary.Steam:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibrary), SupportedGameLibrary.Steam);
break; break;
case SupportedGameLibrary.Uplay: case SupportedGameLibrary.Uplay:
txt_game_launcher.Text = Enum.GetName(typeof(SupportedGameLibrary), SupportedGameLibrary.Uplay);
break; break;
} }
@ -217,6 +236,8 @@ namespace HeliosPlus.UIForms
try 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 // Try to set up some sensible suggestions for the Shortcut name
if (rb_switch_perm.Checked) if (rb_switch_perm.Checked)
{ {
@ -226,11 +247,11 @@ namespace HeliosPlus.UIForms
{ {
if (rb_standalone.Checked) if (rb_standalone.Checked)
{ {
dialog_save.FileName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath); dialog_save.FileName = String.Concat(Path.GetFileNameWithoutExtension(ExecutableNameAndPath),@" (", Profile.Name, @")");
} }
else else
{ {
dialog_save.FileName = GameName; dialog_save.FileName = String.Concat(GameName, @" (", Profile.Name, @")");
} }
} }
@ -276,9 +297,7 @@ namespace HeliosPlus.UIForms
var args = new List<string> var args = new List<string>
{ {
// Add the SwitchProfile command as the first argument to start to switch to another profile // Add the SwitchProfile command as the first argument to start to switch to another profile
$"{HeliosStartupAction.SwitchProfile}", $"{HeliosStartupAction.SwitchProfile}"
// Add the Profile Name as the second argument (use that rather than ID - though ID still will work!)
$"--profile \"{Profile.Name}\""
}; };
// Only add the rest of the options if the temporary switch radio button is set // 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 // Add the executable command and the executable name to the shortcut arguments
args.Add($"execute \"{ExecutableNameAndPath}\""); 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 // Check that the wait for executable radiobutton is on
if (rb_wait_executable.Checked) if (rb_wait_executable.Checked)
{ {
@ -325,7 +347,7 @@ namespace HeliosPlus.UIForms
shortcutDescription = string.Format(Language.Executing_application_with_profile, programName, Profile.Name); shortcutDescription = string.Format(Language.Executing_application_with_profile, programName, Profile.Name);
// Work out the name of the shortcut we'll save. // 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 // Grab an icon for the selected executable
try try
@ -368,7 +390,7 @@ namespace HeliosPlus.UIForms
shortcutIcon = steamGameToRun.GameIcon; shortcutIcon = steamGameToRun.GameIcon;
// Work out the name of the shortcut we'll save. // 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}"); args.Add($"--steam {GameAppId}");
@ -397,12 +419,15 @@ namespace HeliosPlus.UIForms
shortcutIcon = uplayGameToRun.GameIcon; shortcutIcon = uplayGameToRun.GameIcon;
// Work out the name of the shortcut we'll save. // 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}"); 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 // Add the game timeout argument and the timeout duration in seconds to the shortcut arguments
args.Add($"--timeout {GameTimeout}"); 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 // Only add the rest of the options if the permanent switch radio button is set
else 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 // Prepare text for the shortcut description field
shortcutDescription = string.Format(Language.Switching_display_profile_to_profile, Profile.Name); shortcutDescription = string.Format(Language.Switching_display_profile_to_profile, Profile.Name);
// Work out the name of the shortcut we'll save. // 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 // Grab an icon for the selected profile
try try
@ -505,31 +536,6 @@ namespace HeliosPlus.UIForms
return fileName != null && File.Exists(fileName); 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) private void txt_executable_TextChanged(object sender, EventArgs e)
{ {
try try
@ -614,22 +620,12 @@ namespace HeliosPlus.UIForms
private async void ShortcutForm_Load(object sender, EventArgs e) 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 // Set the Profile name
lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}"; lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}";
// Start finding the games and loading the Games ListView // Start finding the games and loading the Games ListView
List<SteamGame> allSteamGames = SteamGame.GetAllInstalledGames(); List<SteamGame> allSteamGames = SteamGame.GetAllInstalledGames();
_allSteamGames = allSteamGames;
foreach (var game in allSteamGames.OrderBy(game => game.GameName)) foreach (var game in allSteamGames.OrderBy(game => game.GameName))
{ {
//var iconAddress = await game.GetIcon(); //var iconAddress = await game.GetIcon();
@ -705,5 +701,23 @@ namespace HeliosPlus.UIForms
txt_args_game.Enabled = false; 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();
}
}
}
}
} }
} }