Add support for starting apps with arguments and custom file names to UpToolLib and UpToolCLI (the UpToolCLI impl is limited due to System.Commandline: values starting with dashes need to share a string with the option switch)

This commit is contained in:
JFronny 2020-08-31 22:11:40 +02:00
parent 0976297348
commit 042b126634
3 changed files with 12 additions and 5 deletions

View File

@ -36,6 +36,7 @@ uptool:
$app.appendChild($xml.CreateElement("ID")).InnerText = "0e35d154-d0d3-45e0-b080-62f521263a44"
$app.appendChild($xml.CreateElement("File")).InnerText = $CI_PROJECT_URL + "/-/jobs/" + $CI_JOB_ID + "/artifacts/raw/Tools.zip"
$app.appendChild($xml.CreateElement("Hash")).InnerText = $(Get-FileHash .\Tools.zip).Hash
$app.appendChild($xml.CreateElement("MainFile")).InnerText = "pkgtool.exe"
$app.appendChild($xml.CreateElement("Icon")).InnerText = "https://gitlab.com/JFronny/UpTool2/-/raw/master/UpTool2.ico"
echo NULL > tools.xml
$xml.save($(gi .\tools.xml).Fullname)

View File

@ -28,9 +28,11 @@ namespace UpToolCLI
Command start = new Command("start", "Starts an app")
{
new Argument<string>("identifier", "Something to identify the app"),
new Option<string>(new[] {"--arguments", "--args", "-a"}, () => "", "The arguments to run the file with"),
new Option<string>(new[] {"--file", "-f"}, () => null, "The file to run instead of the MainFile"),
new Option<bool>(new[] {"--waitForExit", "-wait"}, "Waits until the program quits")
};
start.Handler = CommandHandler.Create<string, bool>(Start);
start.Handler = CommandHandler.Create<string, string, string, bool>(Start);
rootCommand.AddCommand(start);
}
@ -78,7 +80,7 @@ Online: {UpdateCheck.InstallerHash}");
#endif
}
private static void Start(string identifier, bool waitForExit)
private static void Start(string identifier, string arguments, string file, bool waitForExit)
{
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
@ -90,7 +92,7 @@ Online: {UpdateCheck.InstallerHash}");
if (tmp.Runnable)
{
Console.WriteLine($"Starting {tmp.Name}");
Process tmp1 = AppExtras.RunApp(tmp);
Process tmp1 = AppExtras.RunApp(tmp, file ?? tmp.MainFile, arguments);
if (waitForExit)
tmp1.WaitForExit();
}

View File

@ -4,17 +4,21 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Mime;
using UpToolLib.DataStructures;
namespace UpToolLib.Tool
{
public static class AppExtras
{
public static Process RunApp(App app) =>
public static Process RunApp(App app) => RunApp(app, app.MainFile, "");
public static Process RunApp(App app, string arguments) => RunApp(app, app.MainFile, arguments);
public static Process RunApp(App app, string file, string arguments) =>
Process.Start(
new ProcessStartInfo
{
FileName = Path.Combine(app.DataPath, app.MainFile),
FileName = Path.Combine(app.DataPath, file),
Arguments = arguments,
WorkingDirectory = app.DataPath
});