diff --git a/MainForm.cs b/MainForm.cs index 2749cb4..611ac3b 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -50,6 +50,22 @@ namespace RandomFileRunner randy = new Random(); } + protected async override void OnShown(EventArgs e) + { + base.OnShown(e); + + string[] commandLineArgs = Environment.GetCommandLineArgs(); + + string jsonfigFilename = null; + if (string.IsNullOrWhiteSpace(jsonfigFilename)) jsonfigFilename = ParseOpenFile_FromCMD(commandLineArgs); + if (string.IsNullOrWhiteSpace(jsonfigFilename)) jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig"); + + if (!string.IsNullOrWhiteSpace(jsonfigFilename) && File.Exists(jsonfigFilename)) + { + await LoadSessionFile(jsonfigFilename); + } + } + protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); @@ -217,7 +233,7 @@ namespace RandomFileRunner { System.Diagnostics.Process.Start(new ProcessStartInfo() { - FileName = "https://www.hiimray.co.uk", + FileName = "https://www.hiimray.co.uk/software-random-file-runner", UseShellExecute = true }); } @@ -567,6 +583,43 @@ namespace RandomFileRunner }); } + protected string ParseOpenFile_FromCMD(string[] args) + { + if (args.Length <= 1) + { + return null; + } + + int i = 1; + while (true) + { + if (i > (args.Length - 1)) + { + break; + } + + switch (args[i].Trim().ToLower()) + { + case "-o": + case "-open": + if ((i + 1) > (args.Length - 1)) break; + + string openFilename = args[(i + 1)]; + if (string.IsNullOrWhiteSpace(openFilename)) break; + if (!File.Exists(openFilename)) break; + + return openFilename; + + i++; + break; + } + + i++; + } + + return null; + } + protected async Task SaveSessionFile(string filename) { await Task.Run(() => diff --git a/RandomFileRunner.csproj b/RandomFileRunner.csproj index 38b0b0c..0f438f3 100644 --- a/RandomFileRunner.csproj +++ b/RandomFileRunner.csproj @@ -11,7 +11,7 @@ Ray Lam favicon.ico true - 0.1.0.017 + 0.1.0.019