Added: open command-line support

This commit is contained in:
Ray 2021-10-31 03:23:25 +00:00
parent 90253076a3
commit 974bedaca7
2 changed files with 55 additions and 2 deletions

View File

@ -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(() =>

View File

@ -11,7 +11,7 @@
<Copyright>Ray Lam</Copyright>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<NoWin32Manifest>true</NoWin32Manifest>
<Version>0.1.0.017</Version>
<Version>0.1.0.019</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">