From 4c6e9113d29a8a101061547f1597f5a4cac4f5c3 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 5 Mar 2017 17:41:57 +0100 Subject: [PATCH] Closes #489 --- ArchiSteamFarm/OS.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ArchiSteamFarm/OS.cs b/ArchiSteamFarm/OS.cs index ddd73f477..3d49565c6 100644 --- a/ArchiSteamFarm/OS.cs +++ b/ArchiSteamFarm/OS.cs @@ -37,6 +37,7 @@ namespace ArchiSteamFarm { case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: + DisableQuickEditMode(); KeepWindowsSystemActive(); break; } @@ -44,6 +45,23 @@ namespace ArchiSteamFarm { SystemEvents.TimeChanged += OnTimeChanged; } + private static void DisableQuickEditMode() { + // http://stackoverflow.com/questions/30418886/how-and-why-does-quickedit-mode-in-command-prompt-freeze-applications + IntPtr consoleHandle = NativeMethods.GetStdHandle(NativeMethods.StandardInputHandle); + + uint consoleMode; + if (!NativeMethods.GetConsoleMode(consoleHandle, out consoleMode)) { + ASF.ArchiLogger.LogGenericError(Strings.WarningFailed); + return; + } + + consoleMode &= ~NativeMethods.EnableQuickEditMode; + + if (!NativeMethods.SetConsoleMode(consoleHandle, consoleMode)) { + ASF.ArchiLogger.LogGenericError(Strings.WarningFailed); + } + } + private static void KeepWindowsSystemActive() { // This function calls unmanaged API in order to tell Windows OS that it should not enter sleep state while the program is running // If user wishes to enter sleep mode, then he should use ShutdownOnFarmingFinished or manage ASF process with third-party tool or script @@ -59,6 +77,18 @@ namespace ArchiSteamFarm { private static async void OnTimeChanged(object sender, EventArgs e) => await MobileAuthenticator.OnTimeChanged().ConfigureAwait(false); private static class NativeMethods { + internal const uint EnableQuickEditMode = 0x0040; + internal const int StandardInputHandle = -10; + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr GetStdHandle(int nStdHandle); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState);