|
|
@ -35,6 +35,14 @@ namespace IPA.Utilities |
|
|
|
Win32.SetConsoleCtrlHandler(registeredHandler, false); |
|
|
|
Win32.SetConsoleCtrlHandler(registeredHandler, true); |
|
|
|
WinHttp.SetPeekMessageHook(PeekMessageHook); |
|
|
|
|
|
|
|
AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; |
|
|
|
AppDomain.CurrentDomain.ProcessExit += OnProcessExit; |
|
|
|
} |
|
|
|
|
|
|
|
private static void OnProcessExit(object sender, EventArgs args) |
|
|
|
{ |
|
|
|
WinHttp.SetIgnoreUnhandledExceptions(true); |
|
|
|
} |
|
|
|
|
|
|
|
private static class WinHttp |
|
|
@ -52,7 +60,11 @@ namespace IPA.Utilities |
|
|
|
[DllImport("bsipa-doorstop")] |
|
|
|
public static extern void SetPeekMessageHook( |
|
|
|
[MarshalAs(UnmanagedType.FunctionPtr)] |
|
|
|
PeekMessageHook hook); |
|
|
|
PeekMessageHook hook); |
|
|
|
|
|
|
|
[DllImport("bsipa-doorstop")] |
|
|
|
public static extern void SetIgnoreUnhandledExceptions( |
|
|
|
[MarshalAs(UnmanagedType.Bool)] bool ignore); |
|
|
|
} |
|
|
|
|
|
|
|
private static Win32.ConsoleCtrlDelegate _handler = null; |
|
|
@ -106,29 +118,29 @@ namespace IPA.Utilities |
|
|
|
|
|
|
|
private static volatile bool exitRecieved = false; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A struct that allows <c>using</c> blocks to manage an execute section.
|
|
|
|
/// <summary>
|
|
|
|
/// A struct that allows <c>using</c> blocks to manage an execute section.
|
|
|
|
/// </summary>
|
|
|
|
public struct AutoExecuteSection : IDisposable |
|
|
|
{ |
|
|
|
private readonly bool constructed; |
|
|
|
internal AutoExecuteSection(bool val) |
|
|
|
{ |
|
|
|
constructed = val && !isInExecuteSection; |
|
|
|
if (constructed) |
|
|
|
EnterExecuteSection(); |
|
|
|
} |
|
|
|
|
|
|
|
void IDisposable.Dispose() |
|
|
|
{ |
|
|
|
if (constructed) |
|
|
|
ExitExecuteSection(); |
|
|
|
} |
|
|
|
public struct AutoExecuteSection : IDisposable |
|
|
|
{ |
|
|
|
private readonly bool constructed; |
|
|
|
internal AutoExecuteSection(bool val) |
|
|
|
{ |
|
|
|
constructed = val && !isInExecuteSection; |
|
|
|
if (constructed) |
|
|
|
EnterExecuteSection(); |
|
|
|
} |
|
|
|
|
|
|
|
void IDisposable.Dispose() |
|
|
|
{ |
|
|
|
if (constructed) |
|
|
|
ExitExecuteSection(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates an <see cref="AutoExecuteSection"/> for automated management of an execute section.
|
|
|
|
/// </summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates an <see cref="AutoExecuteSection"/> for automated management of an execute section.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>the new <see cref="AutoExecuteSection"/> that manages the section</returns>
|
|
|
|
public static AutoExecuteSection ExecuteSection() => new AutoExecuteSection(true); |
|
|
|
|
|
|
|