Finish moving Win32 imports to BizHawk.Common, organise, and cleanup
This commit is contained in:
parent
784c800ca2
commit
7cd29c0f54
|
@ -288,7 +288,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public int width, height;
|
||||
public int pitch; //in bytes
|
||||
public int pitch_add;
|
||||
public void PopulateBITMAPINFOHEADER24(ref Win32.BITMAPINFOHEADER bmih)
|
||||
public void PopulateBITMAPINFOHEADER24(ref AVIWriterImports.BITMAPINFOHEADER bmih)
|
||||
{
|
||||
bmih.Init();
|
||||
bmih.biPlanes = 1;
|
||||
|
@ -303,7 +303,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
bmih.biSizeImage = (uint)(pitch * height);
|
||||
}
|
||||
|
||||
public void PopulateBITMAPINFOHEADER32(ref Win32.BITMAPINFOHEADER bmih)
|
||||
public void PopulateBITMAPINFOHEADER32(ref AVIWriterImports.BITMAPINFOHEADER bmih)
|
||||
{
|
||||
bmih.Init();
|
||||
bmih.biPlanes = 1;
|
||||
|
@ -316,8 +316,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public bool has_audio;
|
||||
public int a_samplerate, a_channels, a_bits;
|
||||
public void PopulateWAVEFORMATEX(ref Win32.WAVEFORMATEX wfex)
|
||||
public void PopulateWAVEFORMATEX(ref AVIWriterImports.WAVEFORMATEX wfex)
|
||||
{
|
||||
const int WAVE_FORMAT_PCM = 1;
|
||||
int bytes = 0;
|
||||
if (a_bits == 16) bytes = 2;
|
||||
else if (a_bits == 8) bytes = 1;
|
||||
|
@ -329,7 +330,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
wfex.nBlockAlign = (ushort)(bytes * a_channels);
|
||||
wfex.nChannels = (ushort)a_channels;
|
||||
wfex.wBitsPerSample = (ushort)a_bits;
|
||||
wfex.wFormatTag = Win32.WAVE_FORMAT_PCM;
|
||||
wfex.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfex.nSamplesPerSec = (uint)a_samplerate;
|
||||
wfex.nAvgBytesPerSec = (uint)(wfex.nBlockAlign * a_samplerate);
|
||||
}
|
||||
|
@ -407,17 +408,30 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public void Dispose() { }
|
||||
private CodecToken() { }
|
||||
private Win32.AVICOMPRESSOPTIONS comprOptions;
|
||||
private AVIWriterImports.AVICOMPRESSOPTIONS comprOptions;
|
||||
public string codec;
|
||||
public byte[] Format = new byte[0];
|
||||
public byte[] Parms = new byte[0];
|
||||
|
||||
public static CodecToken CreateFromAVICOMPRESSOPTIONS(ref Win32.AVICOMPRESSOPTIONS opts)
|
||||
private static string decode_mmioFOURCC(int code)
|
||||
{
|
||||
char[] chs = new char[4];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
chs[i] = (char)(byte)((code >> (i << 3)) & 0xFF);
|
||||
if (!char.IsLetterOrDigit(chs[i]))
|
||||
chs[i] = ' ';
|
||||
}
|
||||
return new string(chs);
|
||||
}
|
||||
|
||||
public static CodecToken CreateFromAVICOMPRESSOPTIONS(ref AVIWriterImports.AVICOMPRESSOPTIONS opts)
|
||||
{
|
||||
var ret = new CodecToken
|
||||
{
|
||||
comprOptions = opts,
|
||||
codec = Win32.decode_mmioFOURCC(opts.fccHandler),
|
||||
codec = decode_mmioFOURCC(opts.fccHandler),
|
||||
Format = new byte[opts.cbFormat],
|
||||
Parms = new byte[opts.cbParms]
|
||||
};
|
||||
|
@ -435,7 +449,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static void DeallocateAVICOMPRESSOPTIONS(ref Win32.AVICOMPRESSOPTIONS opts)
|
||||
public static void DeallocateAVICOMPRESSOPTIONS(ref AVIWriterImports.AVICOMPRESSOPTIONS opts)
|
||||
{
|
||||
#if false // test: increase stability by never freeing anything, ever
|
||||
if (opts.lpParms != IntPtr.Zero) Win32Imports.HeapFree(Win32Imports.GetProcessHeap(), 0, opts.lpParms);
|
||||
|
@ -445,7 +459,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
opts.lpFormat = IntPtr.Zero;
|
||||
}
|
||||
|
||||
public void AllocateToAVICOMPRESSOPTIONS(ref Win32.AVICOMPRESSOPTIONS opts)
|
||||
public void AllocateToAVICOMPRESSOPTIONS(ref AVIWriterImports.AVICOMPRESSOPTIONS opts)
|
||||
{
|
||||
opts = comprOptions;
|
||||
if (opts.cbParms != 0)
|
||||
|
@ -487,7 +501,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var m = new MemoryStream(data, false);
|
||||
var b = new BinaryReader(m);
|
||||
|
||||
Win32.AVICOMPRESSOPTIONS comprOptions = new Win32.AVICOMPRESSOPTIONS();
|
||||
AVIWriterImports.AVICOMPRESSOPTIONS comprOptions = new AVIWriterImports.AVICOMPRESSOPTIONS();
|
||||
|
||||
byte[] Format;
|
||||
byte[] Parms;
|
||||
|
@ -525,7 +539,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
comprOptions = comprOptions,
|
||||
Format = Format,
|
||||
Parms = Parms,
|
||||
codec = Win32.decode_mmioFOURCC(comprOptions.fccHandler)
|
||||
codec = decode_mmioFOURCC(comprOptions.fccHandler)
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
@ -553,7 +567,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
static AviWriterSegment()
|
||||
{
|
||||
Win32.AVIFileInit();
|
||||
AVIWriterImports.AVIFileInit();
|
||||
}
|
||||
|
||||
public AviWriterSegment()
|
||||
|
@ -612,20 +626,29 @@ namespace BizHawk.Client.EmuHawk
|
|||
return outStatus.video_bytes + outStatus.audio_bytes;
|
||||
}
|
||||
|
||||
static unsafe int AVISaveOptions(IntPtr stream, ref Win32.AVICOMPRESSOPTIONS opts, IntPtr owner)
|
||||
private static bool FAILED(int hr) => hr < 0;
|
||||
|
||||
static unsafe int AVISaveOptions(IntPtr stream, ref AVIWriterImports.AVICOMPRESSOPTIONS opts, IntPtr owner)
|
||||
{
|
||||
fixed (Win32.AVICOMPRESSOPTIONS* _popts = &opts)
|
||||
fixed (AVIWriterImports.AVICOMPRESSOPTIONS* _popts = &opts)
|
||||
{
|
||||
IntPtr* pStream = &stream;
|
||||
Win32.AVICOMPRESSOPTIONS* popts = _popts;
|
||||
Win32.AVICOMPRESSOPTIONS** ppopts = &popts;
|
||||
return Win32.AVISaveOptions(owner, 0, 1, (void*)pStream, (void*)ppopts);
|
||||
AVIWriterImports.AVICOMPRESSOPTIONS* popts = _popts;
|
||||
AVIWriterImports.AVICOMPRESSOPTIONS** ppopts = &popts;
|
||||
return AVIWriterImports.AVISaveOptions(owner, 0, 1, (void*)pStream, (void*)ppopts);
|
||||
}
|
||||
}
|
||||
|
||||
Parameters parameters;
|
||||
public void OpenFile(string destPath, Parameters parameters, CodecToken videoCodecToken)
|
||||
{
|
||||
static int mmioFOURCC(string str) => (
|
||||
((int)(byte)(str[0]))
|
||||
| ((int)(byte)(str[1]) << 8)
|
||||
| ((int)(byte)(str[2]) << 16)
|
||||
| ((int)(byte)(str[3]) << 24)
|
||||
);
|
||||
|
||||
this.parameters = parameters;
|
||||
this.currVideoCodecToken = videoCodecToken;
|
||||
|
||||
|
@ -637,36 +660,36 @@ namespace BizHawk.Client.EmuHawk
|
|||
File.Delete(destPath);
|
||||
}
|
||||
|
||||
if (Win32.FAILED(Win32.AVIFileOpenW(ref pAviFile, destPath, Win32.OpenFileStyle.OF_CREATE | Win32.OpenFileStyle.OF_WRITE, 0)))
|
||||
if (FAILED(AVIWriterImports.AVIFileOpenW(ref pAviFile, destPath, AVIWriterImports.OpenFileStyle.OF_CREATE | AVIWriterImports.OpenFileStyle.OF_WRITE, 0)))
|
||||
{
|
||||
throw new InvalidOperationException($"Couldnt open dest path for avi file: {destPath}");
|
||||
}
|
||||
|
||||
// initialize the video stream
|
||||
Win32.AVISTREAMINFOW vidstream_header = new Win32.AVISTREAMINFOW();
|
||||
Win32.BITMAPINFOHEADER bmih = new Win32.BITMAPINFOHEADER();
|
||||
AVIWriterImports.AVISTREAMINFOW vidstream_header = new AVIWriterImports.AVISTREAMINFOW();
|
||||
AVIWriterImports.BITMAPINFOHEADER bmih = new AVIWriterImports.BITMAPINFOHEADER();
|
||||
parameters.PopulateBITMAPINFOHEADER24(ref bmih);
|
||||
vidstream_header.fccType = Win32.mmioFOURCC("vids");
|
||||
vidstream_header.fccType = mmioFOURCC("vids");
|
||||
vidstream_header.dwRate = parameters.fps;
|
||||
vidstream_header.dwScale = parameters.fps_scale;
|
||||
vidstream_header.dwSuggestedBufferSize = (int)bmih.biSizeImage;
|
||||
if (Win32.FAILED(Win32.AVIFileCreateStreamW(pAviFile, out pAviRawVideoStream, ref vidstream_header)))
|
||||
if (FAILED(AVIWriterImports.AVIFileCreateStreamW(pAviFile, out pAviRawVideoStream, ref vidstream_header)))
|
||||
{
|
||||
CloseFile();
|
||||
throw new InvalidOperationException("Failed opening raw video stream. Not sure how this could happen");
|
||||
}
|
||||
|
||||
// initialize audio stream
|
||||
Win32.AVISTREAMINFOW audstream_header = new Win32.AVISTREAMINFOW();
|
||||
Win32.WAVEFORMATEX wfex = new Win32.WAVEFORMATEX();
|
||||
AVIWriterImports.AVISTREAMINFOW audstream_header = new AVIWriterImports.AVISTREAMINFOW();
|
||||
AVIWriterImports.WAVEFORMATEX wfex = new AVIWriterImports.WAVEFORMATEX();
|
||||
parameters.PopulateWAVEFORMATEX(ref wfex);
|
||||
audstream_header.fccType = Win32.mmioFOURCC("auds");
|
||||
audstream_header.fccType = mmioFOURCC("auds");
|
||||
audstream_header.dwQuality = -1;
|
||||
audstream_header.dwScale = wfex.nBlockAlign;
|
||||
audstream_header.dwRate = (int)wfex.nAvgBytesPerSec;
|
||||
audstream_header.dwSampleSize = wfex.nBlockAlign;
|
||||
audstream_header.dwInitialFrames = 1; // ??? optimal value?
|
||||
if (Win32.FAILED(Win32.AVIFileCreateStreamW(pAviFile, out pAviRawAudioStream, ref audstream_header)))
|
||||
if (FAILED(AVIWriterImports.AVIFileCreateStreamW(pAviFile, out pAviRawAudioStream, ref audstream_header)))
|
||||
{
|
||||
CloseFile();
|
||||
throw new InvalidOperationException("Failed opening raw audio stream. Not sure how this could happen");
|
||||
|
@ -693,7 +716,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// encoder params
|
||||
Win32.AVICOMPRESSOPTIONS comprOptions = new Win32.AVICOMPRESSOPTIONS();
|
||||
AVIWriterImports.AVICOMPRESSOPTIONS comprOptions = new AVIWriterImports.AVICOMPRESSOPTIONS();
|
||||
currVideoCodecToken?.AllocateToAVICOMPRESSOPTIONS(ref comprOptions);
|
||||
|
||||
bool result = AVISaveOptions(pAviRawVideoStream, ref comprOptions, hwnd) != 0;
|
||||
|
@ -729,9 +752,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// open compressed video stream
|
||||
Win32.AVICOMPRESSOPTIONS opts = new Win32.AVICOMPRESSOPTIONS();
|
||||
AVIWriterImports.AVICOMPRESSOPTIONS opts = new AVIWriterImports.AVICOMPRESSOPTIONS();
|
||||
currVideoCodecToken.AllocateToAVICOMPRESSOPTIONS(ref opts);
|
||||
bool failed = Win32.FAILED(Win32.AVIMakeCompressedStream(out pAviCompressedVideoStream, pAviRawVideoStream, ref opts, IntPtr.Zero));
|
||||
bool failed = FAILED(AVIWriterImports.AVIMakeCompressedStream(out pAviCompressedVideoStream, pAviRawVideoStream, ref opts, IntPtr.Zero));
|
||||
CodecToken.DeallocateAVICOMPRESSOPTIONS(ref opts);
|
||||
|
||||
if (failed)
|
||||
|
@ -741,7 +764,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// set the compressed video stream input format
|
||||
Win32.BITMAPINFOHEADER bmih = new Win32.BITMAPINFOHEADER();
|
||||
AVIWriterImports.BITMAPINFOHEADER bmih = new AVIWriterImports.BITMAPINFOHEADER();
|
||||
if (bit32)
|
||||
{
|
||||
parameters.PopulateBITMAPINFOHEADER32(ref bmih);
|
||||
|
@ -751,7 +774,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
parameters.PopulateBITMAPINFOHEADER24(ref bmih);
|
||||
}
|
||||
|
||||
if (Win32.FAILED(Win32.AVIStreamSetFormat(pAviCompressedVideoStream, 0, ref bmih, Marshal.SizeOf(bmih))))
|
||||
if (FAILED(AVIWriterImports.AVIStreamSetFormat(pAviCompressedVideoStream, 0, ref bmih, Marshal.SizeOf(bmih))))
|
||||
{
|
||||
bit32 = true; // we'll try again
|
||||
CloseStreams();
|
||||
|
@ -759,9 +782,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// set audio stream input format
|
||||
Win32.WAVEFORMATEX wfex = new Win32.WAVEFORMATEX();
|
||||
AVIWriterImports.WAVEFORMATEX wfex = new AVIWriterImports.WAVEFORMATEX();
|
||||
parameters.PopulateWAVEFORMATEX(ref wfex);
|
||||
if (Win32.FAILED(Win32.AVIStreamSetFormat(pAviRawAudioStream, 0, ref wfex, Marshal.SizeOf(wfex))))
|
||||
if (FAILED(AVIWriterImports.AVIStreamSetFormat(pAviRawAudioStream, 0, ref wfex, Marshal.SizeOf(wfex))))
|
||||
{
|
||||
CloseStreams();
|
||||
throw new InvalidOperationException("Failed setting raw audio stream input format");
|
||||
|
@ -776,19 +799,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
CloseStreams();
|
||||
if (pAviRawAudioStream != IntPtr.Zero)
|
||||
{
|
||||
Win32.AVIStreamRelease(pAviRawAudioStream);
|
||||
AVIWriterImports.AVIStreamRelease(pAviRawAudioStream);
|
||||
pAviRawAudioStream = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (pAviRawVideoStream != IntPtr.Zero)
|
||||
{
|
||||
Win32.AVIStreamRelease(pAviRawVideoStream);
|
||||
AVIWriterImports.AVIStreamRelease(pAviRawVideoStream);
|
||||
pAviRawVideoStream = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (pAviFile != IntPtr.Zero)
|
||||
{
|
||||
Win32.AVIFileRelease(pAviFile);
|
||||
AVIWriterImports.AVIFileRelease(pAviFile);
|
||||
pAviFile = IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
@ -812,7 +835,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (pAviCompressedVideoStream != IntPtr.Zero)
|
||||
{
|
||||
Win32.AVIStreamRelease(pAviCompressedVideoStream);
|
||||
AVIWriterImports.AVIStreamRelease(pAviCompressedVideoStream);
|
||||
pAviCompressedVideoStream = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
@ -853,7 +876,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// (TODO - inefficient- build directly in a buffer)
|
||||
int bytes_written;
|
||||
Win32.AVIStreamWrite(pAviRawAudioStream, outStatus.audio_samples, todo_realsamples, buf, todo_realsamples * 4, 0, IntPtr.Zero, out bytes_written);
|
||||
AVIWriterImports.AVIStreamWrite(pAviRawAudioStream, outStatus.audio_samples, todo_realsamples, buf, todo_realsamples * 4, 0, IntPtr.Zero, out bytes_written);
|
||||
outStatus.audio_samples += todo_realsamples;
|
||||
outStatus.audio_bytes += bytes_written;
|
||||
outStatus.audio_buffered_shorts = 0;
|
||||
|
@ -861,6 +884,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public unsafe void AddFrame(IVideoProvider source)
|
||||
{
|
||||
const int AVIIF_KEYFRAME = 0x00000010;
|
||||
|
||||
if (parameters.width != source.BufferWidth
|
||||
|| parameters.height != source.BufferHeight)
|
||||
throw new InvalidOperationException("video buffer changed between start and now");
|
||||
|
@ -899,7 +924,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
int bytes_written;
|
||||
int ret = Win32.AVIStreamWrite(pAviCompressedVideoStream, outStatus.video_frames, 1, new IntPtr(bytes_ptr), todo, Win32.AVIIF_KEYFRAME, IntPtr.Zero, out bytes_written);
|
||||
int ret = AVIWriterImports.AVIStreamWrite(pAviCompressedVideoStream, outStatus.video_frames, 1, new IntPtr(bytes_ptr), todo, AVIIF_KEYFRAME, IntPtr.Zero, out bytes_written);
|
||||
outStatus.video_bytes += bytes_written;
|
||||
outStatus.video_frames++;
|
||||
}
|
||||
|
@ -931,7 +956,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
int bytes_written;
|
||||
int ret = Win32.AVIStreamWrite(pAviCompressedVideoStream, outStatus.video_frames, 1, new IntPtr(bytes_ptr), todo * 3, Win32.AVIIF_KEYFRAME, IntPtr.Zero, out bytes_written);
|
||||
int ret = AVIWriterImports.AVIStreamWrite(pAviCompressedVideoStream, outStatus.video_frames, 1, new IntPtr(bytes_ptr), todo * 3, AVIIF_KEYFRAME, IntPtr.Zero, out bytes_written);
|
||||
outStatus.video_bytes += bytes_written;
|
||||
outStatus.video_frames++;
|
||||
}
|
||||
|
|
|
@ -620,7 +620,6 @@
|
|||
<Compile Include="CustomControls\ViewportPanel.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CustomControls\Win32.cs" />
|
||||
<Compile Include="DisplayManager\DisplayManager.cs" />
|
||||
<Compile Include="DisplayManager\DisplaySurface.cs" />
|
||||
<Compile Include="DisplayManager\FilterManager.cs" />
|
||||
|
|
|
@ -1,248 +1,85 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
//I believe this code is from http://support.microsoft.com/kb/306285
|
||||
//The license is assumed to be effectively public domain.
|
||||
//I saw a version of it with at least one bug fixed at https://github.com/slavat/MailSystem.NET/blob/master/Queuing%20System/ActiveQLibrary/CustomControl/FolderBrowser.cs
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Component wrapping access to the Browse For Folder common dialog box.
|
||||
/// Call the ShowDialog() method to bring the dialog box up.
|
||||
/// </summary>
|
||||
public sealed class FolderBrowserEx : Component //TODO inherit CommonDialog
|
||||
/// <remarks>
|
||||
/// I believe this code is from http://support.microsoft.com/kb/306285<br/>
|
||||
/// The license is assumed to be effectively public domain.<br/>
|
||||
/// I saw a version of it with at least one bug fixed at https://github.com/slavat/MailSystem.NET/blob/master/Queuing%20System/ActiveQLibrary/CustomControl/FolderBrowser.cs<br/>
|
||||
/// --zeromus
|
||||
/// </remarks>
|
||||
public sealed class FolderBrowserEx : Component
|
||||
{
|
||||
private const int MAX_PATH = 260;
|
||||
/// <remarks>is this supposed to be public? we're obviously not using it at callsites at the moment --yoshi</remarks>
|
||||
private Win32Imports.BROWSEINFO.FLAGS publicOptions = Win32Imports.BROWSEINFO.FLAGS.RestrictToFilesystem | Win32Imports.BROWSEINFO.FLAGS.RestrictToDomain;
|
||||
|
||||
// Root node of the tree view.
|
||||
private FolderID startLocation = FolderID.Desktop;
|
||||
|
||||
// Browse info options.
|
||||
private int publicOptions = (int) Win32API.Shell32.BffStyles.RestrictToFilesystem |
|
||||
(int) Win32API.Shell32.BffStyles.RestrictToDomain;
|
||||
|
||||
private const int privateOptions = (int) (Win32API.Shell32.BffStyles.NewDialogStyle | Win32API.Shell32.BffStyles.ShowTextBox);
|
||||
|
||||
// Description text to show.
|
||||
public string Description = "Please select a folder below:";
|
||||
|
||||
/// <summary>
|
||||
/// Enum of CSIDLs identifying standard shell folders.
|
||||
/// </summary>
|
||||
public enum FolderID
|
||||
{
|
||||
Desktop = 0x0000,
|
||||
Printers = 0x0004,
|
||||
MyDocuments = 0x0005,
|
||||
Favorites = 0x0006,
|
||||
Recent = 0x0008,
|
||||
SendTo = 0x0009,
|
||||
StartMenu = 0x000b,
|
||||
MyComputer = 0x0011,
|
||||
NetworkNeighborhood = 0x0012,
|
||||
Templates = 0x0015,
|
||||
MyPictures = 0x0027,
|
||||
NetAndDialUpConnections = 0x0031,
|
||||
}
|
||||
public string SelectedPath;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function that returns the IMalloc interface used by the shell.
|
||||
/// </summary>
|
||||
private static Win32API.IMalloc GetShMalloc()
|
||||
/// <summary>Shows the folder browser dialog box with the specified owner window.</summary>
|
||||
public DialogResult ShowDialog(IWin32Window owner = null)
|
||||
{
|
||||
Win32API.Shell32.SHGetMalloc(out var malloc);
|
||||
return malloc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the folder browser dialog box.
|
||||
/// </summary>
|
||||
public DialogResult ShowDialog()
|
||||
{
|
||||
return ShowDialog(null);
|
||||
}
|
||||
|
||||
private int Callback(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData)
|
||||
{
|
||||
switch (uMsg)
|
||||
const Win32Imports.BROWSEINFO.FLAGS privateOptions = Win32Imports.BROWSEINFO.FLAGS.NewDialogStyle | Win32Imports.BROWSEINFO.FLAGS.ShowTextBox;
|
||||
const int startLocation = 0; // = Desktop CSIDL
|
||||
int Callback(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData)
|
||||
{
|
||||
case 1:
|
||||
IntPtr str = Marshal.StringToHGlobalUni(SelectedPath);
|
||||
Win32.SendMessage(hwnd, 0x400 + 103, (IntPtr)1, str);
|
||||
Marshal.FreeHGlobal(str);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Shows the folder browser dialog box with the specified owner window.
|
||||
/// </summary>
|
||||
public DialogResult ShowDialog(IWin32Window owner)
|
||||
{
|
||||
IntPtr pidlRoot = IntPtr.Zero;
|
||||
|
||||
// Get/find an owner HWND for this dialog.
|
||||
|
||||
var hWndOwner = owner?.Handle ?? Win32API.GetActiveWindow();
|
||||
|
||||
// Get the IDL for the specific startLocation.
|
||||
Win32API.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int) startLocation, out pidlRoot);
|
||||
|
||||
if (pidlRoot == IntPtr.Zero)
|
||||
{
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
|
||||
int mergedOptions = publicOptions | privateOptions;
|
||||
|
||||
if ((mergedOptions & (int) Win32API.Shell32.BffStyles.NewDialogStyle) != 0)
|
||||
{
|
||||
if (System.Threading.ApartmentState.MTA == Application.OleRequired())
|
||||
if (uMsg == 1)
|
||||
{
|
||||
mergedOptions = mergedOptions & (~(int) Win32API.Shell32.BffStyles.NewDialogStyle);
|
||||
var str = Marshal.StringToHGlobalUni(SelectedPath);
|
||||
Win32Imports.SendMessage(hwnd, 0x400 + 103, (IntPtr) 1, str);
|
||||
Marshal.FreeHGlobal(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
IntPtr pidlRet = IntPtr.Zero;
|
||||
var hWndOwner = owner?.Handle ?? Win32Imports.GetActiveWindow();
|
||||
Win32Imports.SHGetSpecialFolderLocation(hWndOwner, startLocation, out var pidlRoot);
|
||||
if (pidlRoot == IntPtr.Zero) return DialogResult.Cancel;
|
||||
var mergedOptions = publicOptions | privateOptions;
|
||||
if ((mergedOptions & Win32Imports.BROWSEINFO.FLAGS.NewDialogStyle) != 0 && ApartmentState.MTA == Application.OleRequired())
|
||||
{
|
||||
mergedOptions &= ~Win32Imports.BROWSEINFO.FLAGS.NewDialogStyle;
|
||||
}
|
||||
|
||||
IntPtr pidlRet = default;
|
||||
try
|
||||
{
|
||||
// Construct a BROWSEINFO.
|
||||
Win32API.Shell32.BROWSEINFO bi = new Win32API.Shell32.BROWSEINFO();
|
||||
IntPtr buffer = Marshal.AllocHGlobal(MAX_PATH);
|
||||
|
||||
bi.pidlRoot = pidlRoot;
|
||||
bi.hwndOwner = hWndOwner;
|
||||
bi.pszDisplayName = buffer;
|
||||
bi.lpszTitle = Description;
|
||||
bi.ulFlags = mergedOptions;
|
||||
bi.lpfn = Callback;
|
||||
// The rest of the fields are initialized to zero by the constructor.
|
||||
// bi.lParam = IntPtr.Zero; bi.iImage = 0;
|
||||
|
||||
// Show the dialog.
|
||||
pidlRet = Win32API.Shell32.SHBrowseForFolder(ref bi);
|
||||
|
||||
// Free the buffer you've allocated on the global heap.
|
||||
var buffer = Marshal.AllocHGlobal(Win32Imports.MAX_PATH);
|
||||
var bi = new Win32Imports.BROWSEINFO
|
||||
{
|
||||
hwndOwner = hWndOwner,
|
||||
pidlRoot = pidlRoot,
|
||||
pszDisplayName = buffer,
|
||||
lpszTitle = Description,
|
||||
ulFlags = mergedOptions,
|
||||
lpfn = Callback
|
||||
};
|
||||
pidlRet = Win32Imports.SHBrowseForFolder(ref bi);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
|
||||
if (pidlRet == IntPtr.Zero)
|
||||
{
|
||||
// User clicked Cancel.
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
|
||||
// Then retrieve the path from the IDList.
|
||||
var sb = new StringBuilder(MAX_PATH);
|
||||
if (0 == Win32API.Shell32.SHGetPathFromIDList(pidlRet, sb))
|
||||
{
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
|
||||
// Convert to a string.
|
||||
if (pidlRet == IntPtr.Zero) return DialogResult.Cancel; // user clicked Cancel
|
||||
var sb = new StringBuilder(Win32Imports.MAX_PATH);
|
||||
if (Win32Imports.SHGetPathFromIDList(pidlRet, sb) == 0) return DialogResult.Cancel;
|
||||
SelectedPath = sb.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Win32API.IMalloc malloc = GetShMalloc();
|
||||
Win32Imports.SHGetMalloc(out var malloc);
|
||||
malloc.Free(pidlRoot);
|
||||
|
||||
if (pidlRet != IntPtr.Zero)
|
||||
{
|
||||
malloc.Free(pidlRet);
|
||||
}
|
||||
if (pidlRet != IntPtr.Zero) malloc.Free(pidlRet);
|
||||
}
|
||||
|
||||
return DialogResult.OK;
|
||||
}
|
||||
|
||||
public string SelectedPath;
|
||||
}
|
||||
|
||||
internal class Win32API
|
||||
{
|
||||
// C# representation of the IMalloc interface.
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
|
||||
Guid("00000002-0000-0000-C000-000000000046")]
|
||||
public interface IMalloc
|
||||
{
|
||||
[PreserveSig]
|
||||
IntPtr Alloc([In] int cb);
|
||||
|
||||
[PreserveSig]
|
||||
IntPtr Realloc([In] IntPtr pv, [In] int cb);
|
||||
|
||||
[PreserveSig]
|
||||
void Free([In] IntPtr pv);
|
||||
|
||||
[PreserveSig]
|
||||
int GetSize([In] IntPtr pv);
|
||||
|
||||
[PreserveSig]
|
||||
int DidAlloc(IntPtr pv);
|
||||
|
||||
[PreserveSig]
|
||||
void HeapMinimize();
|
||||
}
|
||||
|
||||
[DllImport("User32.DLL")]
|
||||
public static extern IntPtr GetActiveWindow();
|
||||
|
||||
public class Shell32
|
||||
{
|
||||
// Styles used in the BROWSEINFO.ulFlags field.
|
||||
[Flags]
|
||||
public enum BffStyles
|
||||
{
|
||||
RestrictToFilesystem = 0x0001, // BIF_RETURNONLYFSDIRS
|
||||
RestrictToDomain = 0x0002, // BIF_DONTGOBELOWDOMAIN
|
||||
RestrictToSubfolders = 0x0008, // BIF_RETURNFSANCESTORS
|
||||
ShowTextBox = 0x0010, // BIF_EDITBOX
|
||||
ValidateSelection = 0x0020, // BIF_VALIDATE
|
||||
NewDialogStyle = 0x0040, // BIF_NEWDIALOGSTYLE
|
||||
BrowseForComputer = 0x1000, // BIF_BROWSEFORCOMPUTER
|
||||
BrowseForPrinter = 0x2000, // BIF_BROWSEFORPRINTER
|
||||
BrowseForEverything = 0x4000, // BIF_BROWSEINCLUDEFILES
|
||||
}
|
||||
|
||||
// Delegate type used in BROWSEINFO.lpfn field.
|
||||
public delegate int BFFCALLBACK(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8)]
|
||||
public struct BROWSEINFO
|
||||
{
|
||||
public IntPtr hwndOwner;
|
||||
public IntPtr pidlRoot;
|
||||
public IntPtr pszDisplayName;
|
||||
[MarshalAs(UnmanagedType.LPTStr)] public string lpszTitle;
|
||||
public int ulFlags;
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] public BFFCALLBACK lpfn;
|
||||
public IntPtr lParam;
|
||||
public int iImage;
|
||||
}
|
||||
|
||||
[DllImport("Shell32.DLL")]
|
||||
public static extern int SHGetMalloc(out IMalloc ppMalloc);
|
||||
|
||||
[DllImport("Shell32.DLL")]
|
||||
public static extern int SHGetSpecialFolderLocation(
|
||||
IntPtr hwndOwner, int nFolder, out IntPtr ppidl);
|
||||
|
||||
[DllImport("Shell32.DLL")]
|
||||
public static extern int SHGetPathFromIDList(
|
||||
IntPtr pidl, StringBuilder Path);
|
||||
|
||||
[DllImport("Shell32.DLL", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO bi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,532 +0,0 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public static unsafe class Win32
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct RECT
|
||||
{
|
||||
private int _Left;
|
||||
private int _Top;
|
||||
private int _Right;
|
||||
private int _Bottom;
|
||||
|
||||
public RECT(RECT Rectangle)
|
||||
: this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
|
||||
{
|
||||
}
|
||||
public RECT(int Left, int Top, int Right, int Bottom)
|
||||
{
|
||||
_Left = Left;
|
||||
_Top = Top;
|
||||
_Right = Right;
|
||||
_Bottom = Bottom;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get { return _Left; }
|
||||
set { _Left = value; }
|
||||
}
|
||||
public int Y
|
||||
{
|
||||
get { return _Top; }
|
||||
set { _Top = value; }
|
||||
}
|
||||
public int Left
|
||||
{
|
||||
get { return _Left; }
|
||||
set { _Left = value; }
|
||||
}
|
||||
public int Top
|
||||
{
|
||||
get { return _Top; }
|
||||
set { _Top = value; }
|
||||
}
|
||||
public int Right
|
||||
{
|
||||
get { return _Right; }
|
||||
set { _Right = value; }
|
||||
}
|
||||
public int Bottom
|
||||
{
|
||||
get { return _Bottom; }
|
||||
set { _Bottom = value; }
|
||||
}
|
||||
public int Height
|
||||
{
|
||||
get { return _Bottom - _Top; }
|
||||
set { _Bottom = value - _Top; }
|
||||
}
|
||||
public int Width
|
||||
{
|
||||
get { return _Right - _Left; }
|
||||
set { _Right = value + _Left; }
|
||||
}
|
||||
public Point Location
|
||||
{
|
||||
get { return new Point(Left, Top); }
|
||||
set
|
||||
{
|
||||
_Left = value.X;
|
||||
_Top = value.Y;
|
||||
}
|
||||
}
|
||||
public Size Size
|
||||
{
|
||||
get { return new Size(Width, Height); }
|
||||
set
|
||||
{
|
||||
_Right = value.Width + _Left;
|
||||
_Bottom = value.Height + _Top;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator Rectangle(RECT Rectangle)
|
||||
{
|
||||
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
|
||||
}
|
||||
public static implicit operator RECT(Rectangle Rectangle)
|
||||
{
|
||||
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
|
||||
}
|
||||
public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
|
||||
{
|
||||
return Rectangle1.Equals(Rectangle2);
|
||||
}
|
||||
public static bool operator !=(RECT Rectangle1, RECT Rectangle2)
|
||||
{
|
||||
return !Rectangle1.Equals(Rectangle2);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{Left: {_Left}; Top: {_Top}; Right: {_Right}; Bottom: {_Bottom}}}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ToString().GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(RECT Rectangle)
|
||||
{
|
||||
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
|
||||
}
|
||||
|
||||
public override bool Equals(object Object)
|
||||
{
|
||||
if (Object is RECT)
|
||||
{
|
||||
return Equals((RECT)Object);
|
||||
}
|
||||
else if (Object is Rectangle)
|
||||
{
|
||||
return Equals(new RECT((Rectangle)Object));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct AVISTREAMINFOW
|
||||
{
|
||||
public Int32 fccType;
|
||||
public Int32 fccHandler;
|
||||
public Int32 dwFlags;
|
||||
public Int32 dwCaps;
|
||||
public Int16 wPriority;
|
||||
public Int16 wLanguage;
|
||||
public Int32 dwScale;
|
||||
public Int32 dwRate;
|
||||
public Int32 dwStart;
|
||||
public Int32 dwLength;
|
||||
public Int32 dwInitialFrames;
|
||||
public Int32 dwSuggestedBufferSize;
|
||||
public Int32 dwQuality;
|
||||
public Int32 dwSampleSize;
|
||||
public RECT rcFrame;
|
||||
public Int32 dwEditCount;
|
||||
public Int32 dwFormatChangeCount;
|
||||
[MarshalAs(UnmanagedType.LPWStr, SizeConst=64)]
|
||||
public string szName;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct BITMAPINFOHEADER
|
||||
{
|
||||
public uint biSize;
|
||||
public int biWidth;
|
||||
public int biHeight;
|
||||
public ushort biPlanes;
|
||||
public ushort biBitCount;
|
||||
public uint biCompression;
|
||||
public uint biSizeImage;
|
||||
public int biXPelsPerMeter;
|
||||
public int biYPelsPerMeter;
|
||||
public uint biClrUsed;
|
||||
public uint biClrImportant;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
biSize = (uint)Marshal.SizeOf(this);
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct WAVEFORMATEX
|
||||
{
|
||||
public ushort wFormatTag;
|
||||
public ushort nChannels;
|
||||
public uint nSamplesPerSec;
|
||||
public uint nAvgBytesPerSec;
|
||||
public ushort nBlockAlign;
|
||||
public ushort wBitsPerSample;
|
||||
public ushort cbSize;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
cbSize = (ushort)Marshal.SizeOf(this);
|
||||
}
|
||||
}
|
||||
|
||||
public const int WAVE_FORMAT_PCM = 1;
|
||||
public const int AVIIF_KEYFRAME = 0x00000010;
|
||||
|
||||
[Flags]
|
||||
public enum OpenFileStyle : uint
|
||||
{
|
||||
OF_CANCEL = 0x00000800, // Ignored. For a dialog box with a Cancel button, use OF_PROMPT.
|
||||
OF_CREATE = 0x00001000, // Creates a new file. If file exists, it is truncated to zero (0) length.
|
||||
OF_DELETE = 0x00000200, // Deletes a file.
|
||||
OF_EXIST = 0x00004000, // Opens a file and then closes it. Used to test that a file exists
|
||||
OF_PARSE = 0x00000100, // Fills the OFSTRUCT structure, but does not do anything else.
|
||||
OF_PROMPT = 0x00002000, // Displays a dialog box if a requested file does not exist
|
||||
OF_READ = 0x00000000, // Opens a file for reading only.
|
||||
OF_READWRITE = 0x00000002, // Opens a file with read/write permissions.
|
||||
OF_REOPEN = 0x00008000, // Opens a file by using information in the reopen buffer.
|
||||
|
||||
// For MS-DOS–based file systems, opens a file with compatibility mode, allows any process on a
|
||||
// specified computer to open the file any number of times.
|
||||
// Other efforts to open a file with other sharing modes fail. This flag is mapped to the
|
||||
// FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.
|
||||
OF_SHARE_COMPAT = 0x00000000,
|
||||
|
||||
// Opens a file without denying read or write access to other processes.
|
||||
// On MS-DOS-based file systems, if the file has been opened in compatibility mode
|
||||
// by any other process, the function fails.
|
||||
// This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.
|
||||
OF_SHARE_DENY_NONE = 0x00000040,
|
||||
|
||||
// Opens a file and denies read access to other processes.
|
||||
// On MS-DOS-based file systems, if the file has been opened in compatibility mode,
|
||||
// or for read access by any other process, the function fails.
|
||||
// This flag is mapped to the FILE_SHARE_WRITE flag of the CreateFile function.
|
||||
OF_SHARE_DENY_READ = 0x00000030,
|
||||
|
||||
// Opens a file and denies write access to other processes.
|
||||
// On MS-DOS-based file systems, if a file has been opened in compatibility mode,
|
||||
// or for write access by any other process, the function fails.
|
||||
// This flag is mapped to the FILE_SHARE_READ flag of the CreateFile function.
|
||||
OF_SHARE_DENY_WRITE = 0x00000020,
|
||||
|
||||
// Opens a file with exclusive mode, and denies both read/write access to other processes.
|
||||
// If a file has been opened in any other mode for read/write access, even by the current process,
|
||||
// the function fails.
|
||||
OF_SHARE_EXCLUSIVE = 0x00000010,
|
||||
|
||||
// Verifies that the date and time of a file are the same as when it was opened previously.
|
||||
// This is useful as an extra check for read-only files.
|
||||
OF_VERIFY = 0x00000400,
|
||||
|
||||
// Opens a file for write access only.
|
||||
OF_WRITE = 0x00000001
|
||||
}
|
||||
|
||||
[DllImport("avifil32.dll", SetLastError = true)]
|
||||
public static extern int AVIFileOpenW(ref IntPtr pAviFile, [MarshalAs(UnmanagedType.LPWStr)] string szFile, OpenFileStyle uMode, int lpHandler);
|
||||
|
||||
[DllImport("avifil32.dll", SetLastError = true)]
|
||||
public static extern void AVIFileInit();
|
||||
|
||||
// Create a new stream in an existing file and creates an interface to the new stream
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIFileCreateStreamW(
|
||||
IntPtr pfile,
|
||||
out IntPtr ppavi,
|
||||
ref AVISTREAMINFOW psi);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct AVICOMPRESSOPTIONS
|
||||
{
|
||||
public int fccType;
|
||||
public int fccHandler;
|
||||
public int dwKeyFrameEvery;
|
||||
public int dwQuality;
|
||||
public int dwBytesPerSecond;
|
||||
public int dwFlags;
|
||||
public IntPtr lpFormat;
|
||||
public int cbFormat;
|
||||
public IntPtr lpParms;
|
||||
public int cbParms;
|
||||
public int dwInterleaveEvery;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
public static extern SafeFileHandle CreateFile(
|
||||
string lpFileName,
|
||||
uint dwDesiredAccess,
|
||||
uint dwShareMode,
|
||||
IntPtr SecurityAttributes,
|
||||
uint dwCreationDisposition,
|
||||
uint dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile
|
||||
);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern FileType GetFileType(IntPtr hFile);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetCommandLine();
|
||||
|
||||
public enum FileType : uint
|
||||
{
|
||||
FileTypeChar = 0x0002,
|
||||
FileTypeDisk = 0x0001,
|
||||
FileTypePipe = 0x0003,
|
||||
FileTypeRemote = 0x8000,
|
||||
FileTypeUnknown = 0x0000,
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetConsoleWindow();
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool AttachConsole(int dwProcessId);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool AllocConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = false)]
|
||||
public static extern bool FreeConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool SetStdHandle(int nStdHandle, IntPtr hConsoleOutput);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CreateFile(
|
||||
string fileName,
|
||||
int desiredAccess,
|
||||
int shareMode,
|
||||
IntPtr securityAttributes,
|
||||
int creationDisposition,
|
||||
int flagsAndAttributes,
|
||||
IntPtr templateFile);
|
||||
|
||||
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
|
||||
public static extern bool CloseHandle(IntPtr handle);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = false)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
// Retrieve the save options for a file and returns them in a buffer
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVISaveOptions(IntPtr hwnd, int flags, int streams, void* ppAvi, void* plpOptions);
|
||||
|
||||
// Free the resources allocated by the AVISaveOptions function
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVISaveOptionsFree(
|
||||
int streams,
|
||||
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] plpOptions);
|
||||
|
||||
// Create a compressed stream from an uncompressed stream and a
|
||||
// compression filter, and returns the address of a pointer to
|
||||
// the compressed stream
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIMakeCompressedStream(
|
||||
out IntPtr ppsCompressed,
|
||||
IntPtr psSource,
|
||||
ref AVICOMPRESSOPTIONS lpOptions,
|
||||
IntPtr pclsidHandler);
|
||||
|
||||
// Set the format of a stream at the specified position
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamSetFormat(
|
||||
IntPtr pavi,
|
||||
int lPos,
|
||||
ref BITMAPINFOHEADER lpFormat,
|
||||
int cbFormat);
|
||||
|
||||
// Set the format of a stream at the specified position
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamSetFormat(
|
||||
IntPtr pavi,
|
||||
int lPos,
|
||||
ref WAVEFORMATEX lpFormat,
|
||||
int cbFormat);
|
||||
|
||||
// Write data to a stream
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamWrite(
|
||||
IntPtr pavi,
|
||||
int lStart,
|
||||
int lSamples,
|
||||
IntPtr lpBuffer,
|
||||
int cbBuffer,
|
||||
int dwFlags,
|
||||
IntPtr plSampWritten,
|
||||
out int plBytesWritten);
|
||||
|
||||
// Release an open AVI stream
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamRelease(IntPtr pavi);
|
||||
|
||||
// Release an open AVI stream
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIFileRelease(IntPtr pfile);
|
||||
|
||||
|
||||
// Replacement of mmioFOURCC macros
|
||||
public static int mmioFOURCC(string str)
|
||||
{
|
||||
return (
|
||||
((int)(byte)(str[0])) |
|
||||
((int)(byte)(str[1]) << 8) |
|
||||
((int)(byte)(str[2]) << 16) |
|
||||
((int)(byte)(str[3]) << 24));
|
||||
}
|
||||
|
||||
public static bool FAILED(int hr) { return hr < 0; }
|
||||
|
||||
|
||||
|
||||
// Inverse of mmioFOURCC
|
||||
public static string decode_mmioFOURCC(int code)
|
||||
{
|
||||
char[] chs = new char[4];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
chs[i] = (char)(byte)((code >> (i << 3)) & 0xFF);
|
||||
if (!char.IsLetterOrDigit(chs[i]))
|
||||
chs[i] = ' ';
|
||||
}
|
||||
return new string(chs);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("Kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false)]
|
||||
public static extern void ZeroMemory(IntPtr dest, uint size);
|
||||
|
||||
[DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||
public static extern IntPtr MemSet(IntPtr dest, int c, uint count);
|
||||
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool PathRelativePathTo(
|
||||
[Out] System.Text.StringBuilder pszPath,
|
||||
[In] string pszFrom,
|
||||
[In] FileAttributes dwAttrFrom,
|
||||
[In] string pszTo,
|
||||
[In] FileAttributes dwAttrTo
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// File attributes are metadata values stored by the file system on disk and are used by the system and are available to developers via various file I/O APIs.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
//[CLSCompliant(false)]
|
||||
public enum FileAttributes : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// A file that is read-only. Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories. For more information, see "You cannot view or change the Read-only or the System attributes of folders in Windows Server 2003, in Windows XP, or in Windows Vista".
|
||||
/// </summary>
|
||||
Readonly = 0x00000001,
|
||||
|
||||
/// <summary>
|
||||
/// The file or directory is hidden. It is not included in an ordinary directory listing.
|
||||
/// </summary>
|
||||
Hidden = 0x00000002,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that the operating system uses a part of, or uses exclusively.
|
||||
/// </summary>
|
||||
System = 0x00000004,
|
||||
|
||||
/// <summary>
|
||||
/// The handle that identifies a directory.
|
||||
/// </summary>
|
||||
Directory = 0x00000010,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that is an archive file or directory. Applications typically use this attribute to mark files for backup or removal.
|
||||
/// </summary>
|
||||
Archive = 0x00000020,
|
||||
|
||||
/// <summary>
|
||||
/// This value is reserved for system use.
|
||||
/// </summary>
|
||||
Device = 0x00000040,
|
||||
|
||||
/// <summary>
|
||||
/// A file that does not have other attributes set. This attribute is valid only when used alone.
|
||||
/// </summary>
|
||||
Normal = 0x00000080,
|
||||
|
||||
/// <summary>
|
||||
/// A file that is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is available, because typically, an application deletes a temporary file after the handle is closed. In that scenario, the system can entirely avoid writing the data. Otherwise, the data is written after the handle is closed.
|
||||
/// </summary>
|
||||
Temporary = 0x00000100,
|
||||
|
||||
/// <summary>
|
||||
/// A file that is a sparse file.
|
||||
/// </summary>
|
||||
SparseFile = 0x00000200,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that has an associated reparse point, or a file that is a symbolic link.
|
||||
/// </summary>
|
||||
ReparsePoint = 0x00000400,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.
|
||||
/// </summary>
|
||||
Compressed = 0x00000800,
|
||||
|
||||
/// <summary>
|
||||
/// The data of a file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is the hierarchical storage management software. Applications should not arbitrarily change this attribute.
|
||||
/// </summary>
|
||||
Offline = 0x00001000,
|
||||
|
||||
/// <summary>
|
||||
/// The file or directory is not to be indexed by the content indexing service.
|
||||
/// </summary>
|
||||
NotContentIndexed = 0x00002000,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.
|
||||
/// </summary>
|
||||
Encrypted = 0x00004000,
|
||||
|
||||
/// <summary>
|
||||
/// This value is reserved for system use.
|
||||
/// </summary>
|
||||
Virtual = 0x00010000
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,10 +3,10 @@ using System.Collections.Generic;
|
|||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.ReflectionExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk.WinFormExtensions
|
||||
|
@ -140,53 +140,6 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
|
|||
|
||||
public static class ListViewExtensions
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct HDITEM
|
||||
{
|
||||
public Mask mask;
|
||||
public int cxy;
|
||||
[MarshalAs(UnmanagedType.LPTStr)]
|
||||
public string pszText;
|
||||
public IntPtr hbm;
|
||||
public int cchTextMax;
|
||||
public Format fmt;
|
||||
public IntPtr lParam;
|
||||
// _WIN32_IE >= 0x0300
|
||||
public int iImage;
|
||||
public int iOrder;
|
||||
// _WIN32_IE >= 0x0500
|
||||
public uint type;
|
||||
public IntPtr pvFilter;
|
||||
// _WIN32_WINNT >= 0x0600
|
||||
public uint state;
|
||||
|
||||
[Flags]
|
||||
public enum Mask
|
||||
{
|
||||
Format = 0x4, // HDI_FORMAT
|
||||
};
|
||||
|
||||
[Flags]
|
||||
public enum Format
|
||||
{
|
||||
SortDown = 0x200, // HDF_SORTDOWN
|
||||
SortUp = 0x400, // HDF_SORTUP
|
||||
};
|
||||
};
|
||||
|
||||
public const int LVM_FIRST = 0x1000;
|
||||
public const int LVM_GETHEADER = LVM_FIRST + 31;
|
||||
|
||||
public const int HDM_FIRST = 0x1200;
|
||||
public const int HDM_GETITEM = HDM_FIRST + 11;
|
||||
public const int HDM_SETITEM = HDM_FIRST + 12;
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
|
||||
|
||||
/// <summary>
|
||||
/// Dumps the contents of the ListView into a tab separated list of lines
|
||||
/// </summary>
|
||||
|
@ -226,43 +179,30 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
|
|||
|
||||
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
|
||||
{
|
||||
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
|
||||
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
|
||||
const int LVM_GETHEADER = 4127;
|
||||
const int HDM_GETITEM = 4619;
|
||||
const int HDM_SETITEM = 4620;
|
||||
var columnHeader = Win32Imports.SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
|
||||
for (int columnNumber = 0, l = listViewControl.Columns.Count; columnNumber < l; columnNumber++)
|
||||
{
|
||||
var columnPtr = new IntPtr(columnNumber);
|
||||
var item = new HDITEM
|
||||
var item = new Win32Imports.HDITEM { mask = Win32Imports.HDITEM.Mask.Format };
|
||||
if (Win32Imports.SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero) throw new Win32Exception();
|
||||
if (columnNumber != columnIndex || order == SortOrder.None)
|
||||
{
|
||||
mask = HDITEM.Mask.Format
|
||||
};
|
||||
|
||||
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
|
||||
{
|
||||
throw new Win32Exception();
|
||||
item.fmt &= ~Win32Imports.HDITEM.Format.SortDown & ~Win32Imports.HDITEM.Format.SortUp;
|
||||
}
|
||||
|
||||
if (order != SortOrder.None && columnNumber == columnIndex)
|
||||
else if (order == SortOrder.Ascending)
|
||||
{
|
||||
switch (order)
|
||||
{
|
||||
case SortOrder.Ascending:
|
||||
item.fmt &= ~HDITEM.Format.SortDown;
|
||||
item.fmt |= HDITEM.Format.SortUp;
|
||||
break;
|
||||
case SortOrder.Descending:
|
||||
item.fmt &= ~HDITEM.Format.SortUp;
|
||||
item.fmt |= HDITEM.Format.SortDown;
|
||||
break;
|
||||
}
|
||||
item.fmt &= ~Win32Imports.HDITEM.Format.SortDown;
|
||||
item.fmt |= Win32Imports.HDITEM.Format.SortUp;
|
||||
}
|
||||
else
|
||||
else if (order == SortOrder.Descending)
|
||||
{
|
||||
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
|
||||
}
|
||||
|
||||
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
|
||||
{
|
||||
throw new Win32Exception();
|
||||
item.fmt &= ~Win32Imports.HDITEM.Format.SortUp;
|
||||
item.fmt |= Win32Imports.HDITEM.Format.SortDown;
|
||||
}
|
||||
if (Win32Imports.SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero) throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,12 +133,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
|
||||
if (oldOut == IntPtr.Zero)
|
||||
oldOut = Win32.GetStdHandle( -11 ); //STD_OUTPUT_HANDLE
|
||||
oldOut = ConsoleImports.GetStdHandle( -11 ); //STD_OUTPUT_HANDLE
|
||||
|
||||
Win32.FileType fileType = Win32.GetFileType(oldOut);
|
||||
ConsoleImports.FileType fileType = ConsoleImports.GetFileType(oldOut);
|
||||
|
||||
//stdout is already connected to something. keep using it and dont let the console interfere
|
||||
shouldRedirectStdout = (fileType == Win32.FileType.FileTypeUnknown || fileType == Win32.FileType.FileTypePipe);
|
||||
shouldRedirectStdout = (fileType == ConsoleImports.FileType.FileTypeUnknown || fileType == ConsoleImports.FileType.FileTypePipe);
|
||||
|
||||
//attach to an existing console
|
||||
attachedConsole = false;
|
||||
|
@ -146,7 +146,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
//ever since a recent KB, XP-based systems glitch out when attachconsole is called and theres no console to attach to.
|
||||
if (Environment.OSVersion.Version.Major != 5)
|
||||
{
|
||||
if (Win32.AttachConsole(-1))
|
||||
if (ConsoleImports.AttachConsole(-1))
|
||||
{
|
||||
hasConsole = true;
|
||||
attachedConsole = true;
|
||||
|
@ -155,12 +155,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (!attachedConsole)
|
||||
{
|
||||
Win32.FreeConsole();
|
||||
if (Win32.AllocConsole())
|
||||
ConsoleImports.FreeConsole();
|
||||
if (ConsoleImports.AllocConsole())
|
||||
{
|
||||
//set icons for the console so we can tell them apart from the main window
|
||||
Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)0/*ICON_SMALL*/, Properties.Resources.console16x16.GetHicon());
|
||||
Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)1/*ICON_LARGE*/, Properties.Resources.console32x32.GetHicon());
|
||||
Win32Imports.SendMessage(ConsoleImports.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)0/*ICON_SMALL*/, Properties.Resources.console16x16.GetHicon());
|
||||
Win32Imports.SendMessage(ConsoleImports.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)1/*ICON_LARGE*/, Properties.Resources.console32x32.GetHicon());
|
||||
hasConsole = true;
|
||||
}
|
||||
else
|
||||
|
@ -169,17 +169,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if(hasConsole)
|
||||
{
|
||||
IntPtr ptr = Win32.GetCommandLine();
|
||||
IntPtr ptr = ConsoleImports.GetCommandLine();
|
||||
string commandLine = Marshal.PtrToStringAuto(ptr);
|
||||
Console.Title = SkipEverythingButProgramInCommandLine(commandLine);
|
||||
}
|
||||
|
||||
if (shouldRedirectStdout)
|
||||
{
|
||||
conOut = Win32.CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, 3, 0, IntPtr.Zero);
|
||||
conOut = ConsoleImports.CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, 3, 0, IntPtr.Zero);
|
||||
|
||||
if (!Win32.SetStdHandle(-11, conOut))
|
||||
throw new Exception($"{nameof(Win32.SetStdHandle)}() failed");
|
||||
if (!ConsoleImports.SetStdHandle(-11, conOut))
|
||||
throw new Exception($"{nameof(ConsoleImports.SetStdHandle)}() failed");
|
||||
}
|
||||
|
||||
//DotNetRewireConout();
|
||||
|
@ -197,9 +197,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!hasConsole)
|
||||
return;
|
||||
|
||||
if(shouldRedirectStdout) Win32.CloseHandle(conOut);
|
||||
if(!attachedConsole) Win32.FreeConsole();
|
||||
Win32.SetStdHandle(-11, oldOut);
|
||||
if(shouldRedirectStdout) ConsoleImports.CloseHandle(conOut);
|
||||
if(!attachedConsole) ConsoleImports.FreeConsole();
|
||||
ConsoleImports.SetStdHandle(-11, oldOut);
|
||||
|
||||
conOut = IntPtr.Zero;
|
||||
hasConsole = false;
|
||||
|
@ -216,8 +216,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (ConsoleVisible == false) return;
|
||||
if (Global.Config.WIN32_CONSOLE)
|
||||
{
|
||||
IntPtr x = Win32.GetConsoleWindow();
|
||||
Win32.SetForegroundWindow(x);
|
||||
IntPtr x = ConsoleImports.GetConsoleWindow();
|
||||
ConsoleImports.SetForegroundWindow(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Windows.Forms;
|
|||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -84,7 +85,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public void Clear()
|
||||
{
|
||||
var lockBits = BMP.LockBits(new Rectangle(0, 0, BMP.Width, BMP.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
Win32.MemSet(lockBits.Scan0, 0xff, (uint)(lockBits.Height * lockBits.Stride));
|
||||
Win32Imports.MemSet(lockBits.Scan0, 0xff, (uint)(lockBits.Height * lockBits.Stride));
|
||||
BMP.UnlockBits(lockBits);
|
||||
Refresh();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ using BizHawk.Client.Common;
|
|||
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
||||
using BizHawk.Emulation.Cores.Nintendo.GBA;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -409,7 +411,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
Bitmap bmp = mbv.BmpView.BMP;
|
||||
var lockdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
// Clear()
|
||||
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride));
|
||||
Win32Imports.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride));
|
||||
|
||||
int* pixels = (int*)lockdata.Scan0;
|
||||
int pitch = lockdata.Stride / sizeof(int);
|
||||
|
@ -501,7 +503,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (tophalfonly)
|
||||
{
|
||||
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(128 * lockdata.Stride));
|
||||
Win32Imports.MemSet(lockdata.Scan0, 0xff, (uint)(128 * lockdata.Stride));
|
||||
pixels += 128 * pitch;
|
||||
tiles += 16384;
|
||||
}
|
||||
|
|
|
@ -289,30 +289,28 @@ namespace BizHawk.Client.EmuHawk
|
|||
#endif
|
||||
}
|
||||
|
||||
static FileAttributes GetPathAttribute(string path1)
|
||||
{
|
||||
var di = new DirectoryInfo(path1.Split('|').First());
|
||||
if (di.Exists)
|
||||
{
|
||||
return FileAttributes.Directory;
|
||||
}
|
||||
|
||||
var fi = new FileInfo(path1.Split('|').First());
|
||||
if (fi.Exists)
|
||||
{
|
||||
return FileAttributes.Normal;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
var path = new StringBuilder(260 /* = MAX_PATH */);
|
||||
return Win32.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath))
|
||||
return Win32Imports.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath))
|
||||
? path.ToString()
|
||||
: throw new ArgumentException("Paths must have a common prefix");
|
||||
}
|
||||
|
||||
/// <seealso cref="GetRelativePath"/>
|
||||
private static Win32.FileAttributes GetPathAttribute(string path)
|
||||
{
|
||||
var di = new DirectoryInfo(path.Split('|').First());
|
||||
if (di.Exists)
|
||||
{
|
||||
return Win32.FileAttributes.Directory;
|
||||
}
|
||||
|
||||
var fi = new FileInfo(path.Split('|').First());
|
||||
if (fi.Exists)
|
||||
{
|
||||
return Win32.FileAttributes.Normal;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
private void SystemDropDown_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Recalculate();
|
||||
|
|
|
@ -896,7 +896,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
groupFreeze.SuspendLayout();
|
||||
|
||||
Win32.SendMessage(groupFreeze.Handle, 11, (IntPtr)0, IntPtr.Zero); //WM_SETREDRAW false
|
||||
Win32Imports.SendMessage(groupFreeze.Handle, 11, (IntPtr)0, IntPtr.Zero); //WM_SETREDRAW false
|
||||
|
||||
var tp = tabctrlDetails.SelectedTab;
|
||||
|
||||
|
@ -916,7 +916,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
groupFreeze.ResumeLayout();
|
||||
|
||||
Win32.SendMessage(groupFreeze.Handle, 11, (IntPtr)1, IntPtr.Zero); //WM_SETREDRAW true
|
||||
Win32Imports.SendMessage(groupFreeze.Handle, 11, (IntPtr)1, IntPtr.Zero); //WM_SETREDRAW true
|
||||
groupFreeze.Refresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,8 @@
|
|||
<Compile Include="Win32/ShellLinkImports.cs" />
|
||||
<Compile Include="Win32/ThreadHacks.cs" />
|
||||
<Compile Include="Win32/Win32Imports.cs" />
|
||||
<Compile Include="Win32\AVIWriterImports.cs" />
|
||||
<Compile Include="Win32\ConsoleImports.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public static class AVIWriterImports
|
||||
{
|
||||
[Flags]
|
||||
public enum OpenFileStyle : uint
|
||||
{
|
||||
OF_WRITE = 0x00000001,
|
||||
OF_CREATE = 0x00001000
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct AVISTREAMINFOW
|
||||
{
|
||||
public int fccType;
|
||||
public int fccHandler;
|
||||
public int dwFlags;
|
||||
public int dwCaps;
|
||||
public short wPriority;
|
||||
public short wLanguage;
|
||||
public int dwScale;
|
||||
public int dwRate;
|
||||
public int dwStart;
|
||||
public int dwLength;
|
||||
public int dwInitialFrames;
|
||||
public int dwSuggestedBufferSize;
|
||||
public int dwQuality;
|
||||
public int dwSampleSize;
|
||||
public RECT rcFrame;
|
||||
public int dwEditCount;
|
||||
public int dwFormatChangeCount;
|
||||
[MarshalAs(UnmanagedType.LPWStr, SizeConst=64)] public string szName;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct RECT
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct BITMAPINFOHEADER
|
||||
{
|
||||
public uint biSize;
|
||||
public int biWidth;
|
||||
public int biHeight;
|
||||
public ushort biPlanes;
|
||||
public ushort biBitCount;
|
||||
public uint biCompression;
|
||||
public uint biSizeImage;
|
||||
public int biXPelsPerMeter;
|
||||
public int biYPelsPerMeter;
|
||||
public uint biClrUsed;
|
||||
public uint biClrImportant;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
biSize = (uint)Marshal.SizeOf(this);
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct AVICOMPRESSOPTIONS
|
||||
{
|
||||
public int fccType;
|
||||
public int fccHandler;
|
||||
public int dwKeyFrameEvery;
|
||||
public int dwQuality;
|
||||
public int dwBytesPerSecond;
|
||||
public int dwFlags;
|
||||
public IntPtr lpFormat;
|
||||
public int cbFormat;
|
||||
public IntPtr lpParms;
|
||||
public int cbParms;
|
||||
public int dwInterleaveEvery;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct WAVEFORMATEX
|
||||
{
|
||||
public ushort wFormatTag;
|
||||
public ushort nChannels;
|
||||
public uint nSamplesPerSec;
|
||||
public uint nAvgBytesPerSec;
|
||||
public ushort nBlockAlign;
|
||||
public ushort wBitsPerSample;
|
||||
public ushort cbSize;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
cbSize = (ushort)Marshal.SizeOf(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Create a new stream in an existing file and creates an interface to the new stream</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIFileCreateStreamW(IntPtr pfile, out IntPtr ppavi, ref AVISTREAMINFOW psi);
|
||||
|
||||
[DllImport("avifil32.dll", SetLastError = true)]
|
||||
public static extern void AVIFileInit();
|
||||
|
||||
[DllImport("avifil32.dll", SetLastError = true)]
|
||||
public static extern int AVIFileOpenW(ref IntPtr pAviFile, [MarshalAs(UnmanagedType.LPWStr)] string szFile, OpenFileStyle uMode, int lpHandler);
|
||||
|
||||
/// <summary>Release an open AVI stream</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIFileRelease(IntPtr pfile);
|
||||
|
||||
/// <summary>Create a compressed stream from an uncompressed stream and a compression filter, and returns the address of a pointer to the compressed stream</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIMakeCompressedStream(out IntPtr ppsCompressed, IntPtr psSource, ref AVICOMPRESSOPTIONS lpOptions, IntPtr pclsidHandler);
|
||||
|
||||
/// <summary>Retrieve the save options for a file and returns them in a buffer</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern unsafe int AVISaveOptions(IntPtr hwnd, int flags, int streams, void* ppAvi, void* plpOptions);
|
||||
|
||||
/// <inheritdoc cref="AVIFileRelease"/>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamRelease(IntPtr pavi);
|
||||
|
||||
/// <summary>Set the format of a stream at the specified position</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamSetFormat(IntPtr pavi, int lPos, ref BITMAPINFOHEADER lpFormat, int cbFormat);
|
||||
|
||||
/// <inheritdoc cref="AVIStreamSetFormat(System.IntPtr,int,ref BizHawk.Common.AVIWriterImports.BITMAPINFOHEADER,int)"/>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamSetFormat(IntPtr pavi, int lPos, ref WAVEFORMATEX lpFormat, int cbFormat);
|
||||
|
||||
/// <summary>Write data to a stream</summary>
|
||||
[DllImport("avifil32.dll")]
|
||||
public static extern int AVIStreamWrite(IntPtr pavi, int lStart, int lSamples, IntPtr lpBuffer, int cbBuffer, int dwFlags, IntPtr plSampWritten, out int plBytesWritten);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public static class ConsoleImports
|
||||
{
|
||||
public enum FileType : uint
|
||||
{
|
||||
FileTypeUnknown = 0,
|
||||
FileTypeDisk = 1,
|
||||
FileTypeChar = 2,
|
||||
FileTypePipe = 3,
|
||||
FileTypeRemote = 0x8000
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern FileType GetFileType(IntPtr hFile);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetCommandLine();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetConsoleWindow();
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool AttachConsole(int dwProcessId);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool AllocConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = false)]
|
||||
public static extern bool FreeConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool SetStdHandle(int nStdHandle, IntPtr hConsoleOutput);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CreateFile(string fileName, int desiredAccess, int shareMode, IntPtr securityAttributes, int creationDisposition, int flagsAndAttributes, IntPtr templateFile);
|
||||
|
||||
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
|
||||
public static extern bool CloseHandle(IntPtr handle);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
|
@ -7,9 +9,100 @@ namespace BizHawk.Common
|
|||
{
|
||||
public const int MAX_PATH = 260;
|
||||
|
||||
public delegate int BFFCALLBACK(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8)]
|
||||
public struct BROWSEINFO
|
||||
{
|
||||
public IntPtr hwndOwner;
|
||||
public IntPtr pidlRoot;
|
||||
public IntPtr pszDisplayName;
|
||||
[MarshalAs(UnmanagedType.LPTStr)] public string lpszTitle;
|
||||
public FLAGS ulFlags;
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] public BFFCALLBACK lpfn;
|
||||
public IntPtr lParam;
|
||||
public int iImage;
|
||||
|
||||
[Flags]
|
||||
public enum FLAGS
|
||||
{
|
||||
/// <remarks>BIF_RETURNONLYFSDIRS</remarks>
|
||||
RestrictToFilesystem = 0x0001,
|
||||
/// <remarks>BIF_DONTGOBELOWDOMAIN</remarks>
|
||||
RestrictToDomain = 0x0002,
|
||||
/// <remarks>BIF_RETURNFSANCESTORS</remarks>
|
||||
RestrictToSubfolders = 0x0008,
|
||||
/// <remarks>BIF_EDITBOX</remarks>
|
||||
ShowTextBox = 0x0010,
|
||||
/// <remarks>BIF_VALIDATE</remarks>
|
||||
ValidateSelection = 0x0020,
|
||||
/// <remarks>BIF_NEWDIALOGSTYLE</remarks>
|
||||
NewDialogStyle = 0x0040,
|
||||
/// <remarks>BIF_BROWSEFORCOMPUTER</remarks>
|
||||
BrowseForComputer = 0x1000,
|
||||
/// <remarks>BIF_BROWSEFORPRINTER</remarks>
|
||||
BrowseForPrinter = 0x2000,
|
||||
/// <remarks>BIF_BROWSEINCLUDEFILES</remarks>
|
||||
BrowseForEverything = 0x4000
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct HDITEM
|
||||
{
|
||||
public Mask mask;
|
||||
public int cxy;
|
||||
[MarshalAs(UnmanagedType.LPTStr)] public string pszText;
|
||||
public IntPtr hbm;
|
||||
public int cchTextMax;
|
||||
public Format fmt;
|
||||
public IntPtr lParam;
|
||||
|
||||
// _WIN32_IE >= 0x0300
|
||||
public int iImage;
|
||||
public int iOrder;
|
||||
|
||||
// _WIN32_IE >= 0x0500
|
||||
public uint type;
|
||||
public IntPtr pvFilter;
|
||||
|
||||
// _WIN32_WINNT >= 0x0600
|
||||
public uint state;
|
||||
|
||||
[Flags]
|
||||
public enum Mask
|
||||
{
|
||||
Format = 0x4
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum Format
|
||||
{
|
||||
SortDown = 0x200,
|
||||
SortUp = 0x400
|
||||
}
|
||||
}
|
||||
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000002-0000-0000-C000-000000000046")]
|
||||
public interface IMalloc
|
||||
{
|
||||
[PreserveSig] IntPtr Alloc([In] int cb);
|
||||
[PreserveSig] IntPtr Realloc([In] IntPtr pv, [In] int cb);
|
||||
[PreserveSig] void Free([In] IntPtr pv);
|
||||
[PreserveSig] int GetSize([In] IntPtr pv);
|
||||
[PreserveSig] int DidAlloc(IntPtr pv);
|
||||
[PreserveSig] void HeapMinimize();
|
||||
}
|
||||
|
||||
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint _control87(uint @new, uint mask);
|
||||
|
||||
[DllImport("kernel32.dll", EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
public static extern bool DeleteFileW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetActiveWindow();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError=true)]
|
||||
public static extern unsafe uint GetCurrentDirectoryW(uint nBufferLength, byte* pBuffer);
|
||||
|
||||
|
@ -35,9 +128,33 @@ namespace BizHawk.Common
|
|||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern uint MapVirtualKey(uint uCode, uint uMapType);
|
||||
|
||||
[DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||
public static extern IntPtr MemSet(IntPtr dest, int c, uint count);
|
||||
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool PathRelativePathTo([Out] StringBuilder pszPath, [In] string pszFrom, [In] FileAttributes dwAttrFrom, [In] string pszTo, [In] FileAttributes dwAttrTo);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, ref HDITEM lParam);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern unsafe bool SetCurrentDirectoryW(byte* lpPathName);
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO bi);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern int SHGetMalloc(out IMalloc ppMalloc);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern int SHGetPathFromIDList(IntPtr pidl, StringBuilder Path);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
public static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, int nFolder, out IntPtr ppidl);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -90,40 +91,31 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
|
|||
IDisposable Save();
|
||||
}
|
||||
|
||||
|
||||
private class Win32_FPCtrl : IFPCtrl
|
||||
{
|
||||
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint _control87(uint @new, uint mask);
|
||||
[Conditional("DEBUG")]
|
||||
public static void PrintCurrentFP() => Console.WriteLine($"Current FP word: 0x{Win32Imports._control87(0, 0):X8}");
|
||||
|
||||
public static void PrintCurrentFP()
|
||||
{
|
||||
uint curr = _control87(0, 0);
|
||||
Console.WriteLine("Current FP word: 0x{0:x8}", curr);
|
||||
}
|
||||
|
||||
uint cw;
|
||||
private uint cw;
|
||||
|
||||
public IDisposable Save()
|
||||
{
|
||||
cw = _control87(0, 0);
|
||||
_control87(0x00000, 0x30000);
|
||||
cw = Win32Imports._control87(0, 0);
|
||||
Win32Imports._control87(0x00000, 0x30000);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_control87(cw, 0x30000);
|
||||
Win32Imports._control87(cw, 0x30000);
|
||||
}
|
||||
}
|
||||
|
||||
private class Unix_FPCtrl : IFPCtrl
|
||||
{
|
||||
public IDisposable Save()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public void Dispose()
|
||||
{ }
|
||||
public IDisposable Save() => this;
|
||||
|
||||
public void Dispose() {}
|
||||
}
|
||||
|
||||
IFPCtrl FP;
|
||||
|
|
|
@ -23,9 +23,6 @@ namespace BizHawk.Emulation.Cores.Libretro
|
|||
//YUCK
|
||||
public LibretroCore core;
|
||||
|
||||
[DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||
public static unsafe extern void* CopyMemory(void* dest, void* src, ulong count);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate IntPtr DllInit(IntPtr dllModule);
|
||||
|
||||
|
|
Loading…
Reference in New Issue