diff --git a/DisplayMagician/ShortcutItem.cs b/DisplayMagician/ShortcutItem.cs index f434c05..ecb933a 100644 --- a/DisplayMagician/ShortcutItem.cs +++ b/DisplayMagician/ShortcutItem.cs @@ -739,6 +739,7 @@ namespace DisplayMagician get => new Version(1, 0); } + public string UUID { get diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index 4da386c..f6dfc30 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -5,6 +5,7 @@ using DisplayMagician.InterProcess; using DisplayMagicianShared; using Microsoft.Toolkit.Uwp.Notifications; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; @@ -396,7 +397,7 @@ namespace DisplayMagician { string json = ""; try - { + { json = File.ReadAllText(_shortcutStorageJsonFileName, Encoding.Unicode); } catch (Exception ex) @@ -406,6 +407,29 @@ namespace DisplayMagician if (!string.IsNullOrWhiteSpace(json)) { + + // "Disabled": false, + + + + // Firstly perform any modifications we need to do to update the JSON structure + // to handle old versions of the file that need updating. Done with a simple regex replace + try + { + + // Replace any "Enabled": true with "Disabled": false + json = Regex.Replace(json, @" ""Enabled"": true,", @" ""Disabled"": false,"); + // Replace any "Enabled": false with "Disabled": true + json = Regex.Replace(json, @" ""Enabled"": false,", @" ""Disabled"": true,"); + } + catch(Exception ex) + { + // problem updating JSON + logger.Error(ex, $"ShortcutRepository/LoadShortcuts: Tried to update the JSON in the {_shortcutStorageJsonFileName} but the Regex Replace threw an exception."); + } + + + #pragma warning disable IDE0059 // Unnecessary assignment of a value List shortcuts = new List(); #pragma warning restore IDE0059 // Unnecessary assignment of a value @@ -773,7 +797,7 @@ namespace DisplayMagician // Now run the pre-start applications List startProgramsToStop = new List(); - List startProgramsToStart = shortcutToUse.StartPrograms.Where(program => program.Disabled == true).OrderBy(program => program.Priority).ToList(); + List startProgramsToStart = shortcutToUse.StartPrograms.Where(program => program.Disabled == false).Where(program => !String.IsNullOrWhiteSpace(program.Executable)).OrderBy(program => program.Priority).ToList(); if (startProgramsToStart.Count > 0) { logger.Info($"ShortcutRepository/RunShortcut: Starting {startProgramsToStart.Count} programs before the main game or executable"); diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 1c4f0c9..785661f 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -1172,6 +1172,12 @@ namespace DisplayMagician.UIForms int spOrder = 1; foreach (StartProgram myStartProgram in _shortcutToEdit.StartPrograms.OrderBy(sp => sp.Priority)) { + if (String.IsNullOrWhiteSpace(myStartProgram.Executable)) + { + logger.Warn($"ShortcutForm/ShortcutForm_Load: Start program #{myStartProgram.Priority} is empty, so skipping."); + continue; + } + StartProgramControl startProgramControl = new StartProgramControl(myStartProgram,spOrder); startProgramControl.Dock = DockStyle.None; if (spOrder == 1) diff --git a/DisplayMagician/UIForms/StartProgramControl.Designer.cs b/DisplayMagician/UIForms/StartProgramControl.Designer.cs index c77d39c..b0fe93e 100644 --- a/DisplayMagician/UIForms/StartProgramControl.Designer.cs +++ b/DisplayMagician/UIForms/StartProgramControl.Designer.cs @@ -57,6 +57,7 @@ namespace DisplayMagician.UIForms this.cb_dont_start_if_running.Text = "Don\'t start if program already running"; this.cb_dont_start_if_running.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.cb_dont_start_if_running.UseVisualStyleBackColor = true; + this.cb_dont_start_if_running.CheckedChanged += new System.EventHandler(this.cb_dont_start_if_running_CheckedChanged); // // txt_start_program // @@ -67,6 +68,7 @@ namespace DisplayMagician.UIForms this.txt_start_program.Name = "txt_start_program"; this.txt_start_program.Size = new System.Drawing.Size(538, 26); this.txt_start_program.TabIndex = 25; + this.txt_start_program.TextChanged += new System.EventHandler(this.txt_start_program_TextChanged); // // cb_start_program_close // @@ -80,6 +82,7 @@ namespace DisplayMagician.UIForms this.cb_start_program_close.Text = "Close started program when you finish playing Game"; this.cb_start_program_close.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.cb_start_program_close.UseVisualStyleBackColor = true; + this.cb_start_program_close.CheckedChanged += new System.EventHandler(this.cb_start_program_close_CheckedChanged); // // btn_start_program // @@ -104,6 +107,7 @@ namespace DisplayMagician.UIForms this.txt_start_program_args.Name = "txt_start_program_args"; this.txt_start_program_args.Size = new System.Drawing.Size(506, 26); this.txt_start_program_args.TabIndex = 22; + this.txt_start_program_args.TextChanged += new System.EventHandler(this.txt_start_program_args_TextChanged); // // cb_start_program_pass_args // diff --git a/DisplayMagician/UIForms/StartProgramControl.cs b/DisplayMagician/UIForms/StartProgramControl.cs index 572c194..769d521 100644 --- a/DisplayMagician/UIForms/StartProgramControl.cs +++ b/DisplayMagician/UIForms/StartProgramControl.cs @@ -82,26 +82,28 @@ namespace DisplayMagician.UIForms private void cb_start_program_CheckedChanged(object sender, EventArgs e) { // Disable the start program fields - if (!cb_disable_start_program.Checked) + if (cb_disable_start_program.Checked) { - // Enable the Executable Arguments Text field - txt_start_program.Visible = true; - btn_start_program.Visible = true; - txt_start_program_args.Visible = true; - cb_start_program_pass_args.Visible = true; - cb_start_program_close.Visible = true; - cb_dont_start_if_running.Visible = true; + myStartProgram.Disabled = true; + // Disable the Executable Arguments Text field + txt_start_program.Enabled = false; + btn_start_program.Enabled = false; + txt_start_program_args.Enabled = false; + cb_start_program_pass_args.Enabled = false; + cb_start_program_close.Enabled = false; + cb_dont_start_if_running.Enabled = false; } else { - // Disable the Executable Arguments Text field - txt_start_program.Visible = false; - btn_start_program.Visible = false; - txt_start_program_args.Visible = false; - cb_start_program_pass_args.Visible = false; - cb_start_program_close.Visible = false; - cb_dont_start_if_running.Visible = false; - } + myStartProgram.Disabled = false; + // Enable the Executable Arguments Text field + txt_start_program.Enabled = true; + btn_start_program.Enabled = true; + txt_start_program_args.Enabled = true; + cb_start_program_pass_args.Enabled = true; + cb_start_program_close.Enabled = true; + cb_dont_start_if_running.Enabled = true; + } } private void cb_start_program_pass_args_CheckedChanged(object sender, EventArgs e) @@ -110,12 +112,12 @@ namespace DisplayMagician.UIForms if (cb_start_program_pass_args.Checked) { // Enable the Executable Arguments Text field - txt_start_program_args.Visible = true; + txt_start_program_args.Enabled = true; } else { // Disable the Executable Arguments Text field - txt_start_program_args.Visible = false; + txt_start_program_args.Enabled = false; } } @@ -177,5 +179,39 @@ namespace DisplayMagician.UIForms { ((ShortcutForm)this.Parent.Parent.Parent.Parent).StartProgramEarlier(this); } + + private void cb_dont_start_if_running_CheckedChanged(object sender, EventArgs e) + { + if (cb_dont_start_if_running.Checked) + { + myStartProgram.DontStartIfAlreadyRunning = true; + } + else + { + myStartProgram.DontStartIfAlreadyRunning = false; + } + } + + private void cb_start_program_close_CheckedChanged(object sender, EventArgs e) + { + if (cb_start_program_close.Checked) + { + myStartProgram.CloseOnFinish = true; + } + else + { + myStartProgram.CloseOnFinish = false; + } + } + + private void txt_start_program_TextChanged(object sender, EventArgs e) + { + myStartProgram.Executable = txt_start_program.Text; + } + + private void txt_start_program_args_TextChanged(object sender, EventArgs e) + { + myStartProgram.Arguments = txt_start_program_args.Text; + } } }