mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-06 04:52:21 -07:00
Use OperatingSystem
class to get OS information
(cherry picked from commit 135b5c2ddd8f0a274b0d59eb07f75aaf1446b9da)
This commit is contained in:
parent
ca5379f817
commit
54a758a1b8
1 changed files with 19 additions and 70 deletions
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -25,22 +24,25 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
|
||||||
static OsInfo()
|
static OsInfo()
|
||||||
{
|
{
|
||||||
var platform = Environment.OSVersion.Platform;
|
if (OperatingSystem.IsWindows())
|
||||||
|
|
||||||
switch (platform)
|
|
||||||
{
|
{
|
||||||
case PlatformID.Win32NT:
|
Os = Os.Windows;
|
||||||
{
|
}
|
||||||
Os = Os.Windows;
|
else if (OperatingSystem.IsMacOS())
|
||||||
break;
|
{
|
||||||
}
|
Os = Os.Osx;
|
||||||
|
}
|
||||||
case PlatformID.MacOSX:
|
else if (OperatingSystem.IsFreeBSD())
|
||||||
case PlatformID.Unix:
|
{
|
||||||
{
|
Os = Os.Bsd;
|
||||||
Os = GetPosixFlavour();
|
}
|
||||||
break;
|
else
|
||||||
}
|
{
|
||||||
|
#if ISMUSL
|
||||||
|
Os = Os.LinuxMusl;
|
||||||
|
#else
|
||||||
|
Os = Os.Linux;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,59 +86,6 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||||
IsDocker = true;
|
IsDocker = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Os GetPosixFlavour()
|
|
||||||
{
|
|
||||||
var output = RunAndCapture("uname", "-s");
|
|
||||||
|
|
||||||
if (output.StartsWith("Darwin"))
|
|
||||||
{
|
|
||||||
return Os.Osx;
|
|
||||||
}
|
|
||||||
else if (output.Contains("BSD"))
|
|
||||||
{
|
|
||||||
return Os.Bsd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if ISMUSL
|
|
||||||
return Os.LinuxMusl;
|
|
||||||
#else
|
|
||||||
return Os.Linux;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string RunAndCapture(string filename, string args)
|
|
||||||
{
|
|
||||||
var processStartInfo = new ProcessStartInfo
|
|
||||||
{
|
|
||||||
FileName = filename,
|
|
||||||
Arguments = args,
|
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true,
|
|
||||||
RedirectStandardOutput = true
|
|
||||||
};
|
|
||||||
|
|
||||||
var output = string.Empty;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var p = Process.Start(processStartInfo))
|
|
||||||
{
|
|
||||||
// To avoid deadlocks, always read the output stream first and then wait.
|
|
||||||
output = p.StandardOutput.ReadToEnd();
|
|
||||||
|
|
||||||
p.WaitForExit(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
output = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IOsInfo
|
public interface IOsInfo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue