diff --git a/mist/mist.cpp b/mist/mist.cpp index 998b3cf..ac6b972 100644 --- a/mist/mist.cpp +++ b/mist/mist.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #pragma comment(lib, "miniupnpc.lib") #pragma comment(lib, "libnatpmp.lib") @@ -14,6 +15,7 @@ #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "wininet.lib") #pragma comment(lib, "wtsapi32.lib") +#pragma comment(lib, "powrprof.lib") #define MINIUPNP_STATICLIB #include @@ -298,6 +300,28 @@ bool IsConsoleSessionActive() return ret; } +bool IsSleepEnabled() +{ + SYSTEM_POWER_POLICY powerPolicy; + + if (CallNtPowerInformation(SystemPowerPolicyAc, NULL, 0, &powerPolicy, sizeof(powerPolicy)) < 0) { + return false; + } + + return powerPolicy.IdleTimeout != 0 && powerPolicy.Idle.Action == PowerActionSleep; +} + +bool IsHibernationEnabled() +{ + SYSTEM_POWER_POLICY powerPolicy; + + if (CallNtPowerInformation(SystemPowerPolicyAc, NULL, 0, &powerPolicy, sizeof(powerPolicy)) < 0) { + return false; + } + + return powerPolicy.DozeS4Timeout != 0 || (powerPolicy.IdleTimeout != 0 && powerPolicy.Idle.Action == PowerActionHibernate); +} + bool IsZeroTierInstalled() { DWORD error; @@ -1030,6 +1054,20 @@ int main(int argc, char* argv[]) return -1; } + fprintf(CONSOLE_OUT, "Checking power settings...\n"); + + if (IsSleepEnabled()) { + DisplayMessage("This computer has sleep mode enabled. Sleep mode may prevent this PC from being available for streaming.\n\n" + "Please ensure sleep is disabled in Power Options so this PC is always ready for streaming.", + "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting", MpWarn, false); + } + + if (IsHibernationEnabled()) { + DisplayMessage("This computer has hibernation enabled. Hibernation may prevent this PC from being available for streaming.\n\n" + "Please ensure hibernation is disabled in Power Options so this PC is always ready for streaming.", + "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting", MpWarn, false); + } + fprintf(CONSOLE_OUT, "Checking for anti-virus and firewall software...\n"); char wmicBuf[8192];