-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Environment.cs
32 lines (27 loc) · 1.01 KB
/
Environment.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
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace Reloaded.Mod.Shared
{
public static class Environment
{
/// <summary>
/// True if executing under Wine, else false.
/// </summary>
public static bool IsWine { get; private set; }
/// <summary>
/// Gets the full path to the current process.
/// </summary>
public static Lazy<string> CurrentProcessLocation { get; private set; } = new Lazy<string>(() => Path.GetFullPath(Process.GetCurrentProcess().MainModule.FileName));
static Environment()
{
var ntdll = GetModuleHandle("ntdll.dll");
IsWine = GetProcAddress(ntdll, "wine_get_version") != IntPtr.Zero;
}
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("kernel32.dll")]
private static extern IntPtr GetModuleHandle(string lpModuleName);
}
}