Refactor PlatformLinkedLibSingleton and replace RunningOnUnix with CurrentOS
This commit is contained in:
parent
436b6452fb
commit
d76e1a8a8b
|
@ -123,24 +123,24 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
if (PlatformLinkedLibSingleton.RunningOnUnix)
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
|
||||||
OTK_Keyboard.Initialize();
|
|
||||||
// OTK_Gamepad.Initialize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
KeyInput.Initialize();
|
KeyInput.Initialize();
|
||||||
IPCKeyInput.Initialize();
|
IPCKeyInput.Initialize();
|
||||||
GamePad.Initialize();
|
GamePad.Initialize();
|
||||||
GamePad360.Initialize();
|
GamePad360.Initialize();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OTK_Keyboard.Initialize();
|
||||||
|
// OTK_Gamepad.Initialize();
|
||||||
|
}
|
||||||
Instance = new Input();
|
Instance = new Input();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Cleanup()
|
public static void Cleanup()
|
||||||
{
|
{
|
||||||
if (!PlatformLinkedLibSingleton.RunningOnUnix)
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
{
|
||||||
KeyInput.Cleanup();
|
KeyInput.Cleanup();
|
||||||
GamePad.Cleanup();
|
GamePad.Cleanup();
|
||||||
|
@ -331,18 +331,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var keyEvents = PlatformLinkedLibSingleton.RunningOnUnix
|
var keyEvents = PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows
|
||||||
? OTK_Keyboard.Update()
|
? KeyInput.Update().Concat(IPCKeyInput.Update())
|
||||||
: KeyInput.Update().Concat(IPCKeyInput.Update());
|
: OTK_Keyboard.Update();
|
||||||
if (PlatformLinkedLibSingleton.RunningOnUnix)
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
GamePad.UpdateAll();
|
GamePad.UpdateAll();
|
||||||
GamePad360.UpdateAll();
|
GamePad360.UpdateAll();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
//this block is going to massively modify data structures that the binding method uses, so we have to lock it all
|
//this block is going to massively modify data structures that the binding method uses, so we have to lock it all
|
||||||
lock (this)
|
lock (this)
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
if (!EXE_PROJECT.PlatformLinkedLibSingleton.RunningOnUnix)
|
if (EXE_PROJECT.PlatformLinkedLibSingleton.CurrentOS == EXE_PROJECT.PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
{
|
||||||
var libLoader = EXE_PROJECT.PlatformLinkedLibSingleton.LinkedLibManager;
|
var libLoader = EXE_PROJECT.PlatformLinkedLibSingleton.LinkedLibManager;
|
||||||
|
|
||||||
|
@ -141,7 +141,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
GlobalWin.GLManager = GLManager.Instance;
|
GlobalWin.GLManager = GLManager.Instance;
|
||||||
|
|
||||||
//now create the "GL" context for the display method. we can reuse the IGL_TK context if opengl display method is chosen
|
//now create the "GL" context for the display method. we can reuse the IGL_TK context if opengl display method is chosen
|
||||||
if (EXE_PROJECT.PlatformLinkedLibSingleton.RunningOnUnix) Global.Config.DispMethod = Config.EDispMethod.GdiPlus;
|
if (EXE_PROJECT.PlatformLinkedLibSingleton.CurrentOS != EXE_PROJECT.PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
|
Global.Config.DispMethod = Config.EDispMethod.GdiPlus;
|
||||||
|
|
||||||
REDO_DISPMETHOD:
|
REDO_DISPMETHOD:
|
||||||
if (Global.Config.DispMethod == Config.EDispMethod.GdiPlus)
|
if (Global.Config.DispMethod == Config.EDispMethod.GdiPlus)
|
||||||
GlobalWin.GL = new Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus();
|
GlobalWin.GL = new Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus();
|
||||||
|
@ -187,7 +189,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
goto REDO_DISPMETHOD;
|
goto REDO_DISPMETHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EXE_PROJECT.PlatformLinkedLibSingleton.RunningOnUnix)
|
if (EXE_PROJECT.PlatformLinkedLibSingleton.CurrentOS == EXE_PROJECT.PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
{
|
||||||
//WHY do we have to do this? some intel graphics drivers (ig7icd64.dll 10.18.10.3304 on an unknown chip on win8.1) are calling SetDllDirectory() for the process, which ruins stuff.
|
//WHY do we have to do this? some intel graphics drivers (ig7icd64.dll 10.18.10.3304 on an unknown chip on win8.1) are calling SetDllDirectory() for the process, which ruins stuff.
|
||||||
//The relevant initialization happened just before in "create IGL context".
|
//The relevant initialization happened just before in "create IGL context".
|
||||||
|
|
|
@ -41,9 +41,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
//TODO implement
|
//TODO implement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static PlatformSpecificScreenBlankInterface screenBlankInterface = PlatformLinkedLibSingleton.RunningOnUnix
|
private static PlatformSpecificScreenBlankInterface screenBlankInterface = PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows
|
||||||
? (PlatformSpecificScreenBlankInterface) new MiscUnixScreenBlankInterface()
|
? (PlatformSpecificScreenBlankInterface) new WinScreenBlankInterface()
|
||||||
: (PlatformSpecificScreenBlankInterface) new WinScreenBlankInterface();
|
: (PlatformSpecificScreenBlankInterface) new MiscUnixScreenBlankInterface();
|
||||||
|
|
||||||
private const int SPI_GETSCREENSAVERTIMEOUT = 14;
|
private const int SPI_GETSCREENSAVERTIMEOUT = 14;
|
||||||
private const int SPI_SETSCREENSAVERTIMEOUT = 15;
|
private const int SPI_SETSCREENSAVERTIMEOUT = 15;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.OpenAL)
|
if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.OpenAL)
|
||||||
_outputDevice = new OpenALSoundOutput(this);
|
_outputDevice = new OpenALSoundOutput(this);
|
||||||
if (!PlatformLinkedLibSingleton.RunningOnUnix)
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows)
|
||||||
{
|
{
|
||||||
if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound)
|
if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound)
|
||||||
_outputDevice = new DirectSoundSoundOutput(this, mainWindowHandle);
|
_outputDevice = new DirectSoundSoundOutput(this, mainWindowHandle);
|
||||||
|
|
|
@ -160,7 +160,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return timeBeginPeriod(ms);
|
return timeBeginPeriod(ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static PlatformSpecificSysTimer sysTimer = PlatformLinkedLibSingleton.RunningOnUnix ? (PlatformSpecificSysTimer) new UnixMonoSysTimer() : (PlatformSpecificSysTimer) new WinSysTimer();
|
static PlatformSpecificSysTimer sysTimer = PlatformLinkedLibSingleton.CurrentOS != PlatformLinkedLibSingleton.DistinctOS.Windows ? (PlatformSpecificSysTimer) new UnixMonoSysTimer() : (PlatformSpecificSysTimer) new WinSysTimer();
|
||||||
static uint TimeBeginPeriod(uint ms)
|
static uint TimeBeginPeriod(uint ms)
|
||||||
{
|
{
|
||||||
return sysTimer.TimeBeginPeriod(ms);
|
return sysTimer.TimeBeginPeriod(ms);
|
||||||
|
|
|
@ -71,7 +71,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
protected override void OnMouseClick(MouseEventArgs e)
|
protected override void OnMouseClick(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (!PlatformLinkedLibSingleton.RunningOnUnix) HideCaret(Handle);
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows) HideCaret(Handle);
|
||||||
base.OnMouseClick(e);
|
base.OnMouseClick(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
protected override void OnGotFocus(EventArgs e)
|
protected override void OnGotFocus(EventArgs e)
|
||||||
{
|
{
|
||||||
if (!PlatformLinkedLibSingleton.RunningOnUnix) HideCaret(Handle);
|
if (PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows) HideCaret(Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||||
|
|
|
@ -186,9 +186,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
||||||
LuaImp = PlatformLinkedLibSingleton.RunningOnUnix
|
LuaImp = PlatformLinkedLibSingleton.CurrentOS == PlatformLinkedLibSingleton.DistinctOS.Windows
|
||||||
? (PlatformEmuLuaLibrary) new NotReallyLuaLibrary()
|
? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider)
|
||||||
: (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider);
|
: (PlatformEmuLuaLibrary) new NotReallyLuaLibrary();
|
||||||
if (currentScripts != null)
|
if (currentScripts != null)
|
||||||
{
|
{
|
||||||
LuaImp.ScriptList.AddRange(currentScripts);
|
LuaImp.ScriptList.AddRange(currentScripts);
|
||||||
|
|
|
@ -740,7 +740,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.RunningOnUnix) return false;
|
if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.CurrentOS != PlatformLinkedLibSingleton.DistinctOS.Windows) return false;
|
||||||
|
|
||||||
var tool = Assembly
|
var tool = Assembly
|
||||||
.GetExecutingAssembly()
|
.GetExecutingAssembly()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
//put in a different namespace for EXE so we can have an instance of this type (by linking to this file rather than copying it) built-in to the exe
|
//put in a different namespace for EXE so we can have an instance of this type (by linking to this file rather than copying it) built-in to the exe
|
||||||
|
@ -9,16 +10,44 @@ namespace EXE_PROJECT
|
||||||
namespace BizHawk.Common
|
namespace BizHawk.Common
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
public sealed class PlatformLinkedLibSingleton
|
public sealed class PlatformLinkedLibSingleton
|
||||||
{
|
{
|
||||||
public static readonly bool RunningOnUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
|
/// <remarks>macOS doesn't use PlatformID.MacOSX</remarks>
|
||||||
|
public static readonly DistinctOS CurrentOS = Environment.OSVersion.Platform == PlatformID.Unix
|
||||||
|
? currentIsMacOS() ? DistinctOS.macOS : DistinctOS.Linux
|
||||||
|
: DistinctOS.Windows;
|
||||||
|
|
||||||
private static readonly Lazy<PlatformLinkedLibManager> lazy = new Lazy<PlatformLinkedLibManager>(() => RunningOnUnix
|
private static readonly Lazy<PlatformLinkedLibManager> lazy = new Lazy<PlatformLinkedLibManager>(() =>
|
||||||
? (PlatformLinkedLibManager) new UnixMonoLinkedLibManager()
|
{
|
||||||
: (PlatformLinkedLibManager) new Win32LinkedLibManager());
|
switch (CurrentOS)
|
||||||
|
{
|
||||||
|
case DistinctOS.Linux:
|
||||||
|
case DistinctOS.macOS:
|
||||||
|
return new UnixMonoLinkedLibManager();
|
||||||
|
case DistinctOS.Windows:
|
||||||
|
return new Win32LinkedLibManager();
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
public static PlatformLinkedLibManager LinkedLibManager { get { return lazy.Value; } }
|
public static PlatformLinkedLibManager LinkedLibManager => lazy.Value;
|
||||||
|
|
||||||
|
private static bool currentIsMacOS()
|
||||||
|
{
|
||||||
|
var proc = new Process {
|
||||||
|
StartInfo = new ProcessStartInfo {
|
||||||
|
Arguments = "-s",
|
||||||
|
CreateNoWindow = true,
|
||||||
|
FileName = "uname",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
UseShellExecute = false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
proc.Start();
|
||||||
|
if (proc.StandardOutput.EndOfStream) throw new Exception("Can't determine OS (uname wrote nothing to stdout)!");
|
||||||
|
return proc.StandardOutput.ReadLine() == "Darwin";
|
||||||
|
}
|
||||||
|
|
||||||
private PlatformLinkedLibSingleton() {}
|
private PlatformLinkedLibSingleton() {}
|
||||||
|
|
||||||
|
@ -29,16 +58,16 @@ public sealed class PlatformLinkedLibSingleton
|
||||||
int FreePlatformSpecific(IntPtr hModule);
|
int FreePlatformSpecific(IntPtr hModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UnixMonoLinkedLibManager : PlatformLinkedLibManager
|
private class UnixMonoLinkedLibManager : PlatformLinkedLibManager
|
||||||
{
|
{
|
||||||
// This class is copied from a tutorial, so don't git blame and then email me expecting insight.
|
// This class is copied from a tutorial, so don't git blame and then email me expecting insight.
|
||||||
const int RTLD_NOW = 2;
|
const int RTLD_NOW = 2;
|
||||||
[DllImport("libdl.so.2")]
|
[DllImport("libdl.so.2")]
|
||||||
private static extern IntPtr dlopen(String fileName, int flags);
|
private static extern IntPtr dlopen(string fileName, int flags);
|
||||||
[DllImport("libdl.so.2")]
|
[DllImport("libdl.so.2")]
|
||||||
private static extern IntPtr dlerror();
|
private static extern IntPtr dlerror();
|
||||||
[DllImport("libdl.so.2")]
|
[DllImport("libdl.so.2")]
|
||||||
private static extern IntPtr dlsym(IntPtr handle, String symbol);
|
private static extern IntPtr dlsym(IntPtr handle, string symbol);
|
||||||
[DllImport("libdl.so.2")]
|
[DllImport("libdl.so.2")]
|
||||||
private static extern int dlclose(IntPtr handle);
|
private static extern int dlclose(IntPtr handle);
|
||||||
public IntPtr LoadPlatformSpecific(string dllToLoad)
|
public IntPtr LoadPlatformSpecific(string dllToLoad)
|
||||||
|
@ -59,7 +88,7 @@ public sealed class PlatformLinkedLibSingleton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Win32LinkedLibManager : PlatformLinkedLibManager
|
private class Win32LinkedLibManager : PlatformLinkedLibManager
|
||||||
{
|
{
|
||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
private static extern UInt32 GetLastError();
|
private static extern UInt32 GetLastError();
|
||||||
|
@ -89,5 +118,12 @@ public sealed class PlatformLinkedLibSingleton
|
||||||
return FreeLibrary(hModule) ? 1 : 0;
|
return FreeLibrary(hModule) ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DistinctOS : byte
|
||||||
|
{
|
||||||
|
Linux = 0,
|
||||||
|
macOS = 1,
|
||||||
|
Windows = 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue