mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add remote desktop start/stop commands and process with server support
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using RemSox.Processes;
|
||||
using RemSox.Processing;
|
||||
|
||||
namespace RemSox.UI.CLI.Commands;
|
||||
|
||||
public class StartRemoteDesktopCommand : ICommand
|
||||
{
|
||||
public string Name => "rdp-start";
|
||||
public string Description => "Starts the remote desktop server on the specified port (rdp-start <port>)";
|
||||
|
||||
public Task ExecuteAsync(string? arguments, Action<string> printLine)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(arguments) || !int.TryParse(arguments.Trim(), out int port) || port <= 0 || port > 65535)
|
||||
{
|
||||
printLine("Usage: rdp-start <port> (1-65535)");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (ProcessManager.IsProcessRunning<RemoteDesktopProcess>())
|
||||
{
|
||||
printLine("Remote desktop server is already running.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_ = ProcessManager.SpawnProcess<RemoteDesktopProcess>([port.ToString()]);
|
||||
printLine($"Remote desktop server started on port {port}.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using RemSox.Processes;
|
||||
using RemSox.Processing;
|
||||
|
||||
namespace RemSox.UI.CLI.Commands;
|
||||
|
||||
public class StopRemoteDesktopCommand : ICommand
|
||||
{
|
||||
public string Name => "rdp-stop";
|
||||
public string Description => "Stops the remote desktop server";
|
||||
|
||||
public async Task ExecuteAsync(string? arguments, Action<string> printLine)
|
||||
{
|
||||
if (!ProcessManager.IsProcessRunning<RemoteDesktopProcess>())
|
||||
{
|
||||
printLine("Remote desktop server is not running.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (RemoteDesktopProcess process in ProcessManager.GetProcessesOfType<RemoteDesktopProcess>())
|
||||
{
|
||||
await ProcessManager.StopProcessAndWaitAsync(process.Id);
|
||||
}
|
||||
|
||||
printLine("Remote desktop server stopped.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user