From 686119c7dd4f6f6341bdcbfa0eda1ce20a9ee9e4 Mon Sep 17 00:00:00 2001
From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com>
Date: Sat, 28 Oct 2023 05:04:41 -0700
Subject: [PATCH] organize and cleanup a ton of win32 imports, do cleanup
elsewhere with that
---
.../KeyInput/RawKeyInput.cs | 6 +-
.../SDL2/SDL2InputAdapter.cs | 6 +-
src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs | 409 +++++++++---------
.../CustomControls/FolderBrowserDialogEx.cs | 70 ++-
.../CustomControls/InputWidget.cs | 11 +-
.../Extensions/ControlExtensions.cs | 43 +-
.../tools/SNES/SNESGraphicsDebugger.cs | 4 +-
.../Extensions/PathExtensions.cs | 2 +-
.../MemoryBlock/MemoryBlockWindowsPal.cs | 2 +-
src/BizHawk.Common/Win32/AVIWriterImports.cs | 13 +-
src/BizHawk.Common/Win32/CWDHacks.cs | 68 ++-
src/BizHawk.Common/Win32/CommctrlImports.cs | 57 +++
src/BizHawk.Common/Win32/HeapApiImports.cs | 22 +
...Kernel32Imports.cs => MemoryApiImports.cs} | 3 +-
src/BizHawk.Common/Win32/MotWHack.cs | 3 +-
src/BizHawk.Common/Win32/ShellLinkImports.cs | 20 +-
src/BizHawk.Common/Win32/ShlobjImports.cs | 93 ++++
src/BizHawk.Common/Win32/ThreadHacks.cs | 26 +-
src/BizHawk.Common/Win32/Win32Imports.cs | 208 +--------
.../Win32/Win32ShellContextMenu.cs | 5 +
src/BizHawk.Common/Win32/WmImports.cs | 90 ++++
.../N64/NativeApi/mupen64plusCoreApi.cs | 10 +-
22 files changed, 654 insertions(+), 517 deletions(-)
create mode 100644 src/BizHawk.Common/Win32/CommctrlImports.cs
create mode 100644 src/BizHawk.Common/Win32/HeapApiImports.cs
rename src/BizHawk.Common/Win32/{Kernel32Imports.cs => MemoryApiImports.cs} (91%)
create mode 100644 src/BizHawk.Common/Win32/ShlobjImports.cs
create mode 100644 src/BizHawk.Common/Win32/WmImports.cs
diff --git a/src/BizHawk.Bizware.Input/KeyInput/RawKeyInput.cs b/src/BizHawk.Bizware.Input/KeyInput/RawKeyInput.cs
index adcf38a00a..6e8e543e4d 100644
--- a/src/BizHawk.Bizware.Input/KeyInput/RawKeyInput.cs
+++ b/src/BizHawk.Bizware.Input/KeyInput/RawKeyInput.cs
@@ -9,7 +9,7 @@ using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using static BizHawk.Common.RawInputImports;
-using static BizHawk.Common.Win32Imports;
+using static BizHawk.Common.WmImports;
using RawKey = Vortice.DirectInput.Key;
@@ -35,7 +35,7 @@ namespace BizHawk.Bizware.Input
{
var wc = default(WNDCLASS);
wc.lpfnWndProc = _wndProc;
- wc.hInstance = GetModuleHandle(null);
+ wc.hInstance = Win32Imports.GetModuleHandle(null);
wc.lpszClassName = "RawKeyInputClass";
var atom = RegisterClass(ref wc);
@@ -125,7 +125,7 @@ namespace BizHawk.Bizware.Input
nHeight: 1,
hWndParent: HWND_MESSAGE,
hMenu: IntPtr.Zero,
- hInstance: GetModuleHandle(null),
+ hInstance: Win32Imports.GetModuleHandle(null),
lpParam: IntPtr.Zero);
if (window == IntPtr.Zero)
diff --git a/src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs b/src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs
index bad8f912eb..dcdb9dbae2 100644
--- a/src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs
+++ b/src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs
@@ -46,10 +46,10 @@ namespace BizHawk.Bizware.Input
// similar code shouldn't be needed on other platforms (which have global message queues and not thread local message queues)
if (!OSTailoredCode.IsUnixHost)
{
- while (Win32Imports.PeekMessage(out var msg, IntPtr.Zero, 0, 0, Win32Imports.PM_REMOVE))
+ while (WmImports.PeekMessage(out var msg, IntPtr.Zero, 0, 0, WmImports.PM_REMOVE))
{
- Win32Imports.TranslateMessage(ref msg);
- Win32Imports.DispatchMessage(ref msg);
+ WmImports.TranslateMessage(ref msg);
+ WmImports.DispatchMessage(ref msg);
}
}
diff --git a/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs
index 326d52405d..fec7b679ae 100644
--- a/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs
+++ b/src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs
@@ -12,6 +12,8 @@ using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common;
+using static BizHawk.Common.HeapApiImports;
+
// some helpful p/invoke from http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx?msg=1142967
namespace BizHawk.Client.EmuHawk
{
@@ -19,7 +21,7 @@ namespace BizHawk.Client.EmuHawk
"Uses the Microsoft AVIFIL32 system to write .avi files. Audio is uncompressed; Video can be compressed with any installed VCM codec. Splits on 2G and resolution change.")]
internal class AviWriter : IVideoWriter
{
- private CodecToken _currVideoCodecToken = null;
+ private CodecToken _currVideoCodecToken;
private AviWriterSegment _currSegment;
private readonly IDialogParent _dialogParent;
@@ -35,9 +37,7 @@ namespace BizHawk.Client.EmuHawk
private bool IsOpen => _nameProvider != null;
public void Dispose()
- {
- _currSegment?.Dispose();
- }
+ => _currSegment?.Dispose();
/// sets the codec token to be used for video compression
/// does not inherit
@@ -57,12 +57,16 @@ namespace BizHawk.Client.EmuHawk
{
var (dir, baseName, ext) = template.SplitPathToDirFileAndExt();
yield return template;
- int counter = 1;
- for (;;)
+ var counter = 1;
+ while (counter < int.MaxValue)
{
yield return Path.Combine(dir, $"{baseName}_{counter}{ext}");
counter++;
}
+
+ yield return Path.Combine(dir, $"{baseName}_{counter}{ext}");
+
+ throw new InvalidOperationException("Reached maximum names");
}
///
@@ -70,9 +74,7 @@ namespace BizHawk.Client.EmuHawk
/// set a video codec token first.
///
public void OpenFile(string baseName)
- {
- OpenFile(CreateBasicNameProvider(baseName));
- }
+ => OpenFile(CreateBasicNameProvider(baseName));
// thread communication
// synchronized queue with custom messages
@@ -86,19 +88,18 @@ namespace BizHawk.Client.EmuHawk
{
while (true)
{
- object o = _threadQ.Take();
- if (o is IVideoProvider provider)
+ var o = _threadQ.Take();
+ switch (o)
{
- AddFrameEx(provider);
- }
- else if (o is short[] arr)
- {
- AddSamplesEx(arr);
- }
- else
- {
- // anything else is assumed to be quit time
- return;
+ case IVideoProvider provider:
+ AddFrameEx(provider);
+ break;
+ case short[] arr:
+ AddSamplesEx(arr);
+ break;
+ default:
+ // anything else is assumed to be quit time
+ return;
}
}
}
@@ -121,6 +122,7 @@ namespace BizHawk.Client.EmuHawk
public int BackgroundColor { get; }
public int VsyncNumerator { get; }
public int VsyncDenominator { get; }
+
public VideoCopy(IVideoProvider c)
{
_vb = (int[])c.GetVideoBuffer().Clone();
@@ -134,9 +136,7 @@ namespace BizHawk.Client.EmuHawk
}
public int[] GetVideoBuffer()
- {
- return _vb;
- }
+ => _vb;
}
/// opens an avi file for recording, with being used to name files
@@ -149,14 +149,14 @@ namespace BizHawk.Client.EmuHawk
throw new InvalidOperationException("Tried to start recording an AVI with no video codec token set");
}
- _threadQ = new System.Collections.Concurrent.BlockingCollection