-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
48 lines (39 loc) · 1.22 KB
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace ResourcefulShared {
public static class Utilities {
#region Properties
#if NET45
public static bool IsWindows {
get {
var windir = Environment.GetEnvironmentVariable("windir");
return (!string.IsNullOrEmpty(windir) && windir.Contains(@"\") && Directory.Exists(windir));
}
}
public static bool IsLinux {
get {
if (!File.Exists(@"/proc/sys/kernel/ostype")) return false;
var osType = File.ReadAllText(@"/proc/sys/kernel/ostype");
return osType.StartsWith("Linux", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsMacOS => File.Exists(@"/System/Library/CoreServices/SystemVersion.plist");
#else
public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
public static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public static bool IsMacOS => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
public static bool IsConsoleApp {
get {
try {
return Console.WindowHeight > 0;
}
catch {
return false;
}
}
}
#endregion
}
}