mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-23 08:17:47 +01:00
Add XL_PLATFORM env var, Util.GetHostPlatform()
- New env var XL_PLATFORM allows launcher to inform Dalamud of the current platform (one of Windows, macOS, or Linux). - New method Util.GetHostPlatform() provides a best guess for the current platform. This method will respect XL_PLATFORM if set, but will otherwise resort to heuristic checks.
This commit is contained in:
parent
0fca2c80c3
commit
a7aacb15e4
1 changed files with 58 additions and 10 deletions
|
|
@ -1,10 +1,8 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
@ -16,11 +14,10 @@ using Dalamud.Data;
|
||||||
using Dalamud.Game;
|
using Dalamud.Game;
|
||||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Dalamud.Interface;
|
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Utility;
|
using Dalamud.Interface.Utility;
|
||||||
using Dalamud.Logging.Internal;
|
using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Networking.Http;
|
using Dalamud.Memory;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -498,6 +495,7 @@ public static class Util
|
||||||
public static bool IsWine()
|
public static bool IsWine()
|
||||||
{
|
{
|
||||||
if (EnvironmentConfiguration.XlWineOnLinux) return true;
|
if (EnvironmentConfiguration.XlWineOnLinux) return true;
|
||||||
|
if (Environment.GetEnvironmentVariable("XL_PLATFORM") is not null and not "Windows") return true;
|
||||||
|
|
||||||
var ntdll = NativeFunctions.GetModuleHandleW("ntdll.dll");
|
var ntdll = NativeFunctions.GetModuleHandleW("ntdll.dll");
|
||||||
|
|
||||||
|
|
@ -517,6 +515,35 @@ public static class Util
|
||||||
procs.Any(p => NativeFunctions.GetProcAddress(handle, p) != nint.Zero);
|
procs.Any(p => NativeFunctions.GetProcAddress(handle, p) != nint.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the best guess for the current host's platform based on the <c>XL_PLATFORM</c> environment variable or
|
||||||
|
/// heuristics.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method is not perfectly reliable if <c>XL_PLATFORM</c> is unset. For example, macOS users running with
|
||||||
|
/// exports hidden will be marked as Linux users. Better heuristic checks for macOS are needed in order to fix this.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns>Returns the <see cref="OSPlatform"/> that Dalamud is currently running on.</returns>
|
||||||
|
public static OSPlatform GetHostPlatform()
|
||||||
|
{
|
||||||
|
switch (Environment.GetEnvironmentVariable("XL_PLATFORM"))
|
||||||
|
{
|
||||||
|
case "Windows": return OSPlatform.Windows;
|
||||||
|
case "MacOS": return OSPlatform.OSX;
|
||||||
|
case "Linux": return OSPlatform.Linux;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsWine())
|
||||||
|
{
|
||||||
|
GetWineHostVersion(out var platform, out _);
|
||||||
|
if (platform == "Darwin") return OSPlatform.OSX; // only happens on macOS without export hides (mac license)
|
||||||
|
|
||||||
|
return OSPlatform.Linux;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OSPlatform.Windows;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Heuristically determine if the Windows version is higher than Windows 11's first build.
|
/// Heuristically determine if the Windows version is higher than Windows 11's first build.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -738,4 +765,25 @@ public static class Util
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static unsafe bool GetWineHostVersion(out string? platform, out string? version)
|
||||||
|
{
|
||||||
|
platform = null;
|
||||||
|
version = null;
|
||||||
|
|
||||||
|
var ntdll = NativeFunctions.GetModuleHandleW("ntdll.dll");
|
||||||
|
var methodPtr = NativeFunctions.GetProcAddress(ntdll, "wine_get_host_version");
|
||||||
|
|
||||||
|
if (methodPtr == nint.Zero) return false;
|
||||||
|
|
||||||
|
var methodDelegate = (delegate* unmanaged[Fastcall]<out char*, out char*, void>)methodPtr;
|
||||||
|
methodDelegate(out var platformPtr, out var versionPtr);
|
||||||
|
|
||||||
|
if (platformPtr == null) return false;
|
||||||
|
|
||||||
|
platform = MemoryHelper.ReadStringNullTerminated((nint)platformPtr);
|
||||||
|
if (versionPtr != null) version = MemoryHelper.ReadStringNullTerminated((nint)versionPtr);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue