mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Closes #489
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user