Multi-Platform Package Manager for Stable Diffusion
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

using System.Diagnostics;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;
namespace StabilityMatrix.Avalonia.Helpers;
[SupportedOSPlatform("windows")]
public static class WindowsElevated
{
/// <summary>
/// Move a file from source to target using elevated privileges.
/// </summary>
public static async Task<int> MoveFiles(params (string sourcePath, string targetPath)[] moves)
{
// Combine into single command
var args = string.Join(" & ", moves.Select(
x => $"move \"{x.sourcePath}\" \"{x.targetPath}\""));
using var process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = $"/c {args}";
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Verb = "runas";
process.Start();
await process.WaitForExitAsync().ConfigureAwait(false);
return process.ExitCode;
}
}