Add platform check for Wine, report Wine version

This commit is contained in:
ghorsington committed 2022-08-14 17:18:59 +03:00
1 parent d42f342d15
commit 60147c73dc
2 files changed
+42 -27

No files matched your search

@@ -10,6 +10,29 @@ namespace BepInEx.Preloader.Core.Logging;
public static class ChainloaderLogHelper
{
private static Dictionary<string, string> MacOSVersions { get; } = new()
{
// https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history
["16.0.0"] = "10.12",
["16.5.0"] = "10.12.4",
["16.6.0"] = "10.12.6",
["17.5.0"] = "10.13.4",
["17.6.0"] = "10.13.5",
["17.7.0"] = "10.13.6",
["18.2.0"] = "10.14.1",
["19.2.0"] = "10.15.2",
["19.3.0"] = "10.15.3",
["19.5.0"] = "10.15.5.1",
["20.1.0"] = "11.0",
["20.2.0"] = "11.1",
["20.3.0"] = "11.2",
["20.4.0"] = "11.3",
["20.5.0"] = "11.4",
["21.0.1"] = "12.0",
["21.1.0"] = "12.0.1",
["21.2.0"] = "12.1",
};
public static void PrintLogInfo(ManualLogSource log)
{
var consoleTitle = $"BepInEx {Paths.BepInExVersion} - {Paths.ProcessName}";
@@ -20,7 +43,7 @@ public static class ChainloaderLogHelper
//See BuildInfoAttribute for more information about this section.
var attributes = typeof(BuildInfoAttribute).Assembly.GetCustomAttributes(typeof(BuildInfoAttribute), false);
if (attributes.Length > 0)
{
var attribute = (BuildInfoAttribute) attributes[0];
@@ -28,7 +51,8 @@ public static class ChainloaderLogHelper
}
Logger.Log(LogLevel.Info, $"System platform: {GetPlatformString()}");
Logger.Log(LogLevel.Info, $"Process bitness: {(PlatformUtils.ProcessIs64Bit ? "64-bit (x64)" : "32-bit (x86)")}");
Logger.Log(LogLevel.Info,
$"Process bitness: {(PlatformUtils.ProcessIs64Bit ? "64-bit (x64)" : "32-bit (x86)")}");
}
private static string GetPlatformString()
@@ -73,6 +97,9 @@ public static class ChainloaderLogHelper
builder.Append("Vista");
else if (osVersion.Major <= 5)
builder.Append("XP");
if (PlatformHelper.Is(Platform.Wine))
builder.AppendFormat(" (Wine {0})", PlatformUtils.WineVersion);
}
else if (PlatformHelper.Is(Platform.MacOS))
{
@@ -118,29 +145,6 @@ public static class ChainloaderLogHelper
return builder.ToString();
}
private static Dictionary<string, string> MacOSVersions { get; } = new()
{
// https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history
["16.0.0"] = "10.12",
["16.5.0"] = "10.12.4",
["16.6.0"] = "10.12.6",
["17.5.0"] = "10.13.4",
["17.6.0"] = "10.13.5",
["17.7.0"] = "10.13.6",
["18.2.0"] = "10.14.1",
["19.2.0"] = "10.15.2",
["19.3.0"] = "10.15.3",
["19.5.0"] = "10.15.5.1",
["20.1.0"] = "11.0",
["20.2.0"] = "11.1",
["20.3.0"] = "11.2",
["20.4.0"] = "11.3",
["20.5.0"] = "11.4",
["21.0.1"] = "12.0",
["21.1.0"] = "12.0.1",
["21.2.0"] = "12.1",
};
public static void RewritePreloaderLogs()
{
if (PreloaderConsoleListener.LogEvents == null || PreloaderConsoleListener.LogEvents.Count == 0)
+13 -2
View File
@@ -10,6 +10,7 @@ internal static class PlatformUtils
{
public static readonly bool ProcessIs64Bit = IntPtr.Size >= 8;
public static Version WindowsVersion { get; set; }
public static Version WineVersion { get; set; }
public static string LinuxArchitecture { get; set; }
public static string LinuxKernelVersion { get; set; }
@@ -25,10 +26,8 @@ internal static class PlatformUtils
[DllImport("ntdll.dll", SetLastError = true)]
private static extern bool RtlGetVersion(ref WindowsOSVersionInfoExW versionInfo);
private static bool Is(this Platform current, Platform expected) => (current & expected) == expected;
/// <summary>
/// Recreation of MonoMod's PlatformHelper.DeterminePlatform method, but with libc calls instead of creating processes.
/// </summary>
@@ -67,6 +66,14 @@ internal static class PlatformUtils
WindowsVersion = new Version((int) windowsVersionInfo.dwMajorVersion,
(int) windowsVersionInfo.dwMinorVersion, 0,
(int) windowsVersionInfo.dwBuildNumber);
if (DynDll.TryOpenLibrary("ntdll.dll", out var ntdll) &&
ntdll.TryGetFunction("wine_get_version", out var wineGetVersion))
{
current |= Platform.Wine;
var getVersion = wineGetVersion.AsDelegate<GetWineVersionDelegate>();
WineVersion = new Version(getVersion());
}
}
// Is64BitOperatingSystem has been added in .NET Framework 4.0
@@ -113,6 +120,10 @@ internal static class PlatformUtils
PlatformHelper.Current = current;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.LPStr)]
private delegate string GetWineVersionDelegate();
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct WindowsOSVersionInfoExW
{