Added: open command-line support
This commit is contained in:
parent
90253076a3
commit
974bedaca7
55
MainForm.cs
55
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(() =>
|
||||
|
@ -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'">
|
||||
|
Loading…
Reference in New Issue
Block a user