diff --git a/DisplayMagician/ShortcutItem.cs b/DisplayMagician/ShortcutItem.cs index 884e079..e8eb0b0 100644 --- a/DisplayMagician/ShortcutItem.cs +++ b/DisplayMagician/ShortcutItem.cs @@ -61,6 +61,18 @@ namespace DisplayMagician public bool DontStartIfAlreadyRunning; } + public struct StopProgram + { + public int Priority; + public bool Disabled; + public ProcessPriority ProcessPriority; + public string Executable; + public string Arguments; + public bool ExecutableArgumentsRequired; + public bool CloseOnFinish; + public bool DontStartIfAlreadyRunning; + } + public struct Executable { public string DifferentExecutableToMonitor; @@ -139,6 +151,7 @@ namespace DisplayMagician private ShortcutValidity _isValid; private List _shortcutErrors = new List(); private List _startPrograms; + private List _stopPrograms; private Bitmap _shortcutBitmap, _originalBitmap; [JsonIgnore] #pragma warning disable CS3008 // Identifier is not CLS-compliant @@ -641,6 +654,20 @@ namespace DisplayMagician } } + public List StopPrograms + { + get + { + return _stopPrograms; + } + + set + { + _stopPrograms = value; + } + } + + public string OriginalIconPath { get { @@ -788,6 +815,7 @@ namespace DisplayMagician bool setCaptureVolume = false, decimal captureVolume = -1, List startPrograms = null, + List stopPrograms = null, bool autoName = true, Keys hotkey = Keys.None, string uuid = "" @@ -843,7 +871,8 @@ namespace DisplayMagician string captureDevice = "", bool setCaptureVolume = false, decimal captureVolume = -1, - List startPrograms = null, + List startPrograms = null, + List stopPrograms = null, bool autoName = true, string uuid = "", Keys hotkey = Keys.None @@ -877,6 +906,7 @@ namespace DisplayMagician _capturePermanence = capturePermanence; _autoName = autoName; _startPrograms = startPrograms; + _stopPrograms = stopPrograms; _originalIconPath = originalIconPath; _userChoseOwnIcon = userChoseOwnIcon; _availableImages = availableImages; @@ -912,7 +942,8 @@ namespace DisplayMagician string captureDevice = "", bool setCaptureVolume = false, decimal captureVolume = -1, - List startPrograms = null, + List startPrograms = null, + List stopPrograms = null, bool autoName = true, Keys hotkey = Keys.None, string uuid = "" @@ -943,6 +974,7 @@ namespace DisplayMagician _capturePermanence = capturePermanence; _autoName = autoName; _startPrograms = startPrograms; + _stopPrograms = stopPrograms; _originalIconPath = originalIconPath; _userChoseOwnIcon = userChoseOwnIcon; _availableImages = availableImages; @@ -995,6 +1027,7 @@ namespace DisplayMagician shortcut.IsValid = IsValid; shortcut.Errors.AddRange(Errors); shortcut.StartPrograms = StartPrograms; + shortcut.StopPrograms = StopPrograms; shortcut.ChangeAudioDevice = ChangeAudioDevice; shortcut.AudioDevice = AudioDevice; shortcut.SetAudioVolume = SetAudioVolume; diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index e89fbc6..a09a9b8 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -36,6 +36,7 @@ namespace DisplayMagician.UIForms private ShortcutPermanence _audioPermanence = ShortcutPermanence.Temporary; private ShortcutPermanence _capturePermanence = ShortcutPermanence.Temporary; List _startPrograms = new List(); + List _stopPrograms = new List(); private string _audioDevice = ""; private bool _changeAudioDevice = false; private bool _setAudioVolume = false; @@ -496,7 +497,23 @@ namespace DisplayMagician.UIForms // Replace the old start programs with the ones we've created now _startPrograms = newStartPrograms; - + + // Store the single stop program if it's set (but wth lots of defaults) + if (!String.IsNullOrWhiteSpace(txt_run_cmd_afterwards.Text) && File.Exists(txt_run_cmd_afterwards.Text)) + { + _stopPrograms = new List(); + StopProgram stopProgram = new StopProgram(); + stopProgram.Executable = txt_run_cmd_afterwards.Text; + stopProgram.Priority = 0; + stopProgram.DontStartIfAlreadyRunning = false; + stopProgram.Arguments = ""; + stopProgram.Disabled = false; + stopProgram.ExecutableArgumentsRequired = false; + stopProgram.ProcessPriority = ProcessPriority.Normal; + _stopPrograms.Add(stopProgram); + } + + // Now we create the Shortcut Object ready to save // If we're launching a game if (rb_launcher.Checked) @@ -580,6 +597,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _uuid, _hotkey @@ -606,6 +624,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _uuid, _hotkey @@ -657,6 +676,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _hotkey ); @@ -682,6 +702,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _hotkey ); @@ -709,6 +730,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _hotkey ); @@ -731,6 +753,7 @@ namespace DisplayMagician.UIForms _setCaptureVolume, _captureVolume, _startPrograms, + _stopPrograms, _autoName, _hotkey ); @@ -1429,6 +1452,12 @@ namespace DisplayMagician.UIForms } } + // Setup the single stop program we're beginning with + if (_shortcutToEdit.StopPrograms is List && _shortcutToEdit.StopPrograms.Count > 0) + { + txt_run_cmd_afterwards.Text = _shortcutToEdit.StopPrograms[0].Executable; + } + // Refresh the Shortcut UI RefreshShortcutUI(); ChangeSelectedProfile(chosenProfile);