mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Prerequisites - Added optional arguments to PowerShell actions
This commit is contained in:
1 parent
a6f52ce4a0
commit
42fdf44df9
2 files changed
+26
-4
No files matched your search
+13
-2
@@ -15,10 +15,15 @@ namespace Artemis.Core
|
|||||||
/// <param name="name">The name of the action</param>
|
/// <param name="name">The name of the action</param>
|
||||||
/// <param name="code">The inline code to run</param>
|
/// <param name="code">The inline code to run</param>
|
||||||
/// <param name="elevate">A boolean indicating whether the file should run with administrator privileges</param>
|
/// <param name="elevate">A boolean indicating whether the file should run with administrator privileges</param>
|
||||||
public RunInlinePowerShellAction(string name, string code, bool elevate = false) : base(name)
|
/// <param name="arguments">
|
||||||
|
/// Optional arguments to pass to your script, you are responsible for proper quoting etc.
|
||||||
|
/// <para>Arguments are available in PowerShell as <c>$args[0], $args[1]</c> etc.</para>
|
||||||
|
/// </param>
|
||||||
|
public RunInlinePowerShellAction(string name, string code, bool elevate = false, string? arguments = null) : base(name)
|
||||||
{
|
{
|
||||||
Code = code;
|
Code = code;
|
||||||
Elevate = elevate;
|
Elevate = elevate;
|
||||||
|
Arguments = arguments;
|
||||||
ProgressIndeterminate = true;
|
ProgressIndeterminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +37,12 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Elevate { get; }
|
public bool Elevate { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets optional arguments to pass to your script, you are responsible for proper quoting etc.
|
||||||
|
/// <para>Arguments are available in PowerShell as <c>$args[0], $args[1]</c> etc.</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? Arguments { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Execute(CancellationToken cancellationToken)
|
public override async Task Execute(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@@ -57,7 +68,7 @@ namespace Artemis.Core
|
|||||||
ShowProgressBar = true;
|
ShowProgressBar = true;
|
||||||
ProgressIndeterminate = true;
|
ProgressIndeterminate = true;
|
||||||
|
|
||||||
int result = await ExecuteFileAction.RunProcessAsync("powershell.exe", $"-File {file}", Elevate);
|
int result = await ExecuteFileAction.RunProcessAsync("powershell.exe", $"-File {file} {Arguments}", Elevate);
|
||||||
|
|
||||||
Status = $"PowerShell exited with code {result}";
|
Status = $"PowerShell exited with code {result}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,15 @@ namespace Artemis.Core
|
|||||||
/// <param name="name">The name of the action</param>
|
/// <param name="name">The name of the action</param>
|
||||||
/// <param name="scriptPath">The full path of the script to run</param>
|
/// <param name="scriptPath">The full path of the script to run</param>
|
||||||
/// <param name="elevate">A boolean indicating whether the file should run with administrator privileges</param>
|
/// <param name="elevate">A boolean indicating whether the file should run with administrator privileges</param>
|
||||||
public RunPowerShellAction(string name, string scriptPath, bool elevate = false) : base(name)
|
/// <param name="arguments">
|
||||||
|
/// Optional arguments to pass to your script, you are responsible for proper quoting etc.
|
||||||
|
/// <para>Arguments are available in PowerShell as <c>$args[0], $args[1]</c> etc.</para>
|
||||||
|
/// </param>
|
||||||
|
public RunPowerShellAction(string name, string scriptPath, bool elevate = false, string? arguments = null) : base(name)
|
||||||
{
|
{
|
||||||
ScriptPath = scriptPath;
|
ScriptPath = scriptPath;
|
||||||
Elevate = elevate;
|
Elevate = elevate;
|
||||||
|
Arguments = arguments;
|
||||||
ProgressIndeterminate = true;
|
ProgressIndeterminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +38,12 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Elevate { get; }
|
public bool Elevate { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets optional arguments to pass to your script, you are responsible for proper quoting etc.
|
||||||
|
/// <para>Arguments are available in PowerShell as <c>$args[0], $args[1]</c> etc.</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? Arguments { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Execute(CancellationToken cancellationToken)
|
public override async Task Execute(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@@ -45,7 +56,7 @@ namespace Artemis.Core
|
|||||||
ShowProgressBar = true;
|
ShowProgressBar = true;
|
||||||
ProgressIndeterminate = true;
|
ProgressIndeterminate = true;
|
||||||
|
|
||||||
int result = await ExecuteFileAction.RunProcessAsync("powershell.exe", $"-File {ScriptPath}", Elevate);
|
int result = await ExecuteFileAction.RunProcessAsync("powershell.exe", $"-File {ScriptPath} {Arguments}", Elevate);
|
||||||
|
|
||||||
Status = $"PowerShell exited with code {result}";
|
Status = $"PowerShell exited with code {result}";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user