mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Implementing RestartProgram and Reboot methods for windows
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#if !SIMPLSHARP
|
#if !SIMPLSHARP
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.IO;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
@@ -125,7 +127,12 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void RestartProgram()
|
public static void RestartProgram()
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
string filename = Process.GetCurrentProcess().MainModule?.FileName;
|
||||||
|
if (string.IsNullOrEmpty(filename) || !IcdFile.Exists(filename))
|
||||||
|
throw new InvalidOperationException("Failed to find program filename");
|
||||||
|
|
||||||
|
Process.Start(filename);
|
||||||
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -134,7 +141,15 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Reboot()
|
public static void Reboot()
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
// TODO - Linux
|
||||||
|
ProcessStartInfo psi =
|
||||||
|
new ProcessStartInfo("shutdown", "/r /t 0")
|
||||||
|
{
|
||||||
|
CreateNoWindow = true,
|
||||||
|
UseShellExecute = false
|
||||||
|
};
|
||||||
|
|
||||||
|
Process.Start(psi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user