From df232e6184430988b766a56674e802844e395233 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 18 May 2019 20:25:33 +1000 Subject: [PATCH] Add additional CurrentOS checks --- BizHawk.Client.Common/config/Config.cs | 9 ++++++-- BizHawk.Client.EmuHawk/MainForm.Events.cs | 10 ++++++++- BizHawk.Client.EmuHawk/MainForm.cs | 21 +++++++++++++++++-- BizHawk.Client.EmuHawk/Program.cs | 11 ++++++++-- .../config/DisplayConfigLite.cs | 11 ++++++++++ .../config/FirmwaresConfig.cs | 2 ++ BizHawk.Client.EmuHawk/tools/CDL.cs | 12 ++++++++++- BizHawk.Client.EmuHawk/tools/ToolBox.cs | 3 +++ BizHawk.Common/BizInvoke/MemoryBlock.cs | 3 +++ 9 files changed, 74 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 37221da1d1..c0bf196702 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -342,8 +342,13 @@ namespace BizHawk.Client.Common public int DispPrescale = 1; - // warning: we dont even want to deal with changing this at runtime. but we want it changed here for config purposes. so dont check this variable. check in GlobalWin or something like that. - public EDispMethod DispMethod = EDispMethod.SlimDX9; + /// + /// warning: we dont even want to deal with changing this at runtime. but we want it changed here for config purposes. so dont check this variable. check in GlobalWin or something like that. + /// force DX for Windows and GDI+ for Unix when a new config is generated + /// + public EDispMethod DispMethod = OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows + ? EDispMethod.SlimDX9 + : EDispMethod.GdiPlus; public int DispChrome_FrameWindowed = 2; public bool DispChrome_StatusBarWindowed = true; diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 65878e36e2..4ece99a72f 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -25,6 +25,7 @@ using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Emulation.Cores.Computers.AppleII; using BizHawk.Client.ApiHawk; +using BizHawk.Common; using BizHawk.Emulation.Cores.Computers.Commodore64; using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Computers.SinclairSpectrum; @@ -1469,7 +1470,14 @@ namespace BizHawk.Client.EmuHawk private void RamSearchMenuItem_Click(object sender, EventArgs e) { - GlobalWin.Tools.Load(); + var ramSearch = GlobalWin.Tools.Load(); + if (OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows) + { + // this is apparently needed for weird mono-forms-on-different-thread issues + // dont do .Show() within Load() for RamSearch - instead put an instance of it here on MainForm, then show here + // the mono winforms implementation is.... weird and buggy + ramSearch.Show(); + } } private void LuaConsoleMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 283cb22aa5..4623b15806 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -161,7 +161,9 @@ namespace BizHawk.Client.EmuHawk Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt")); // TODO GL - a lot of disorganized wiring-up here - CGC.CGCBinPath = Path.Combine(PathManager.GetDllDirectory(), "cgc.exe"); + CGC.CGCBinPath = OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows + ? Path.Combine(PathManager.GetDllDirectory(), "cgc.exe") + : "cgc"; // installed separately (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH PresentationPanel = new PresentationPanel(); PresentationPanel.GraphicsControl.MainWindow = true; GlobalWin.DisplayManager = new DisplayManager(PresentationPanel); @@ -2069,7 +2071,22 @@ namespace BizHawk.Client.EmuHawk // sends an alt+mnemonic combination private void SendAltKeyChar(char c) { - typeof(ToolStrip).InvokeMember("ProcessMnemonicInternal", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Instance, null, MainformMenu, new object[] { c }); + switch (OSTailoredCode.CurrentOS) + { + case OSTailoredCode.DistinctOS.Linux: + case OSTailoredCode.DistinctOS.macOS: + // no mnemonics for you + break; + case OSTailoredCode.DistinctOS.Windows: + //HACK + var _ = typeof(ToolStrip).InvokeMember( + "ProcessMnemonicInternal", + System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Instance, + null, + MainformMenu, + new object[] { c }); + break; + } } public static string FormatFilter(params string[] args) diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs index 96e98ff548..2b0f14d079 100644 --- a/BizHawk.Client.EmuHawk/Program.cs +++ b/BizHawk.Client.EmuHawk/Program.cs @@ -80,7 +80,13 @@ namespace BizHawk.Client.EmuHawk [STAThread] private static int Main(string[] args) { - return SubMain(args); + var exitCode = SubMain(args); + if (EXE_PROJECT.OSTailoredCode.CurrentOS == EXE_PROJECT.OSTailoredCode.DistinctOS.Linux) + { + Console.WriteLine("BizHawk has completed its shutdown routines, killing process..."); + Process.GetCurrentProcess().Kill(); + } + return exitCode; } //NoInlining should keep this code from getting jammed into Main() which would create dependencies on types which havent been setup by the resolver yet... or something like that @@ -309,7 +315,8 @@ REDO_DISPMETHOD: //so.. we're going to resort to something really bad. //avert your eyes. var configPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.ini"); - if (File.Exists(configPath) + if (EXE_PROJECT.OSTailoredCode.CurrentOS == EXE_PROJECT.OSTailoredCode.DistinctOS.Windows // LuaInterface is not currently working on Mono + && File.Exists(configPath) && (Array.Find(File.ReadAllLines(configPath), line => line.Contains(" \"UseNLua\": ")) ?? string.Empty) .Contains("false")) { diff --git a/BizHawk.Client.EmuHawk/config/DisplayConfigLite.cs b/BizHawk.Client.EmuHawk/config/DisplayConfigLite.cs index a094247ef3..cb4f4f7515 100644 --- a/BizHawk.Client.EmuHawk/config/DisplayConfigLite.cs +++ b/BizHawk.Client.EmuHawk/config/DisplayConfigLite.cs @@ -3,6 +3,7 @@ using System.IO; using System.Windows.Forms; using BizHawk.Emulation.Common; using BizHawk.Client.Common; +using BizHawk.Common; namespace BizHawk.Client.EmuHawk { @@ -91,6 +92,16 @@ namespace BizHawk.Client.EmuHawk txtCropBottom.Text = Global.Config.DispCropBottom.ToString(); RefreshAspectRatioOptions(); + + if (OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows) + { + // Disable SlimDX on Unix + rbD3D9.Enabled = false; + rbD3D9.AutoCheck = false; + cbAlternateVsync.Enabled = false; + label13.Enabled = false; + label8.Enabled = false; + } } private void btnOk_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 826df7d025..69a302c097 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -358,6 +358,8 @@ namespace BizHawk.Client.EmuHawk private void tbbOpenFolder_Click(object sender, EventArgs e) { var frmWares = PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null); + if (OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows && !Directory.Exists(frmWares)) + Directory.CreateDirectory(frmWares); System.Diagnostics.Process.Start(frmWares); } diff --git a/BizHawk.Client.EmuHawk/tools/CDL.cs b/BizHawk.Client.EmuHawk/tools/CDL.cs index 0571d4e4ac..92fee7a5c5 100644 --- a/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -7,6 +7,7 @@ using BizHawk.Emulation.Common; using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.ToolExtensions; +using BizHawk.Common; //TODO - select which memorydomains go out to the CDL file. will this cause a problem when re-importing it? //perhaps missing domains shouldnt fail a check @@ -98,7 +99,16 @@ namespace BizHawk.Client.EmuHawk if (_cdl == null) { lvCDL.BeginUpdate(); - lvCDL.Items.Clear(); + if (OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows) + { + lvCDL.Items.Clear(); + } + else + { + // this is a winforms implementation problem for mono + // see https://github.com/mono/mono/issues/11070 + // until this is resolved in mono we should just skip this call + } lvCDL.EndUpdate(); return; } diff --git a/BizHawk.Client.EmuHawk/tools/ToolBox.cs b/BizHawk.Client.EmuHawk/tools/ToolBox.cs index 67aefdfd0f..23c3a8df8c 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolBox.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolBox.cs @@ -7,6 +7,7 @@ using System.Windows.Forms; using BizHawk.Emulation.Common; using BizHawk.Client.ApiHawk; +using BizHawk.Common; namespace BizHawk.Client.EmuHawk { @@ -68,6 +69,8 @@ namespace BizHawk.Client.EmuHawk continue; // if (!ApiInjector.IsAvailable(, t)) // continue; + if (t == typeof(HexView) && OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows) + continue; // Skip this tool on Unix. It isn't finished and only causes exceptions var instance = Activator.CreateInstance(t); diff --git a/BizHawk.Common/BizInvoke/MemoryBlock.cs b/BizHawk.Common/BizInvoke/MemoryBlock.cs index ae3c867adf..7bbdf04f36 100644 --- a/BizHawk.Common/BizInvoke/MemoryBlock.cs +++ b/BizHawk.Common/BizInvoke/MemoryBlock.cs @@ -79,6 +79,9 @@ namespace BizHawk.Common.BizInvoke /// public MemoryBlock(ulong start, ulong size) { + if (OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows) + throw new InvalidOperationException("MemoryBlock ctor called on Unix"); + if (!WaterboxUtils.Aligned(start)) throw new ArgumentOutOfRangeException(); if (size == 0)