From 9b365eed2f74958cd783dfc3c7b838a5fa90d286 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Thu, 28 Oct 2021 04:38:08 +0200
Subject: [PATCH] feat: add Linux check to util, for reference
---
Dalamud/Utility/Util.cs | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs
index cded71473..2c58a7710 100644
--- a/Dalamud/Utility/Util.cs
+++ b/Dalamud/Utility/Util.cs
@@ -5,12 +5,13 @@ using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
-
+using Dalamud.Configuration.Internal;
using Dalamud.Game;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Logging.Internal;
using ImGuiNET;
+using Microsoft.Win32;
using Serilog;
namespace Dalamud.Utility
@@ -263,5 +264,34 @@ namespace Dalamud.Utility
// TODO: Someone implement GetUTF8String with some IntPtr overloads.
// while(Marshal.ReadByte(0, sz) != 0) { sz++; }
+
+ ///
+ /// Heuristically determine if Dalamud is running on Linux/WINE.
+ ///
+ /// Whether or not Dalamud is running on Linux/WINE.
+ public static bool IsLinux()
+ {
+ bool Check1()
+ {
+ return EnvironmentConfiguration.XlWineOnLinux;
+ }
+
+ bool Check2()
+ {
+ var hModule = NativeFunctions.GetModuleHandleW("ntdll.dll");
+ var proc1 = NativeFunctions.GetProcAddress(hModule, "wine_get_version");
+ var proc2 = NativeFunctions.GetProcAddress(hModule, "wine_get_build_id");
+
+ return proc1 != IntPtr.Zero || proc2 != IntPtr.Zero;
+ }
+
+ bool Check3()
+ {
+ return Registry.CurrentUser.OpenSubKey(@"Software\Wine") != null ||
+ Registry.LocalMachine.OpenSubKey(@"Software\Wine") != null;
+ }
+
+ return Check1() || Check2() || Check3();
+ }
}
}