kernel32: Implement GetSystemPowerStatus on top of NtPowerInformation.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alex Henrie 2019-10-29 20:22:25 -06:00 committed by Alexandre Julliard
parent b0635c9b20
commit c58e3a5e29
1 changed files with 38 additions and 10 deletions

View File

@ -45,19 +45,47 @@ BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn)
*/ */
BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS ps) BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS ps)
{ {
WARN("(%p): stub, harmless.\n", ps); SYSTEM_BATTERY_STATE bs;
NTSTATUS status;
if (ps) TRACE("(%p)\n", ps);
{
ps->ACLineStatus = 255; ps->ACLineStatus = AC_LINE_UNKNOWN;
ps->BatteryFlag = 255; ps->BatteryFlag = BATTERY_FLAG_UNKNOWN;
ps->BatteryLifePercent = 255; ps->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
ps->SystemStatusFlag = 0; ps->SystemStatusFlag = 0;
ps->BatteryLifeTime = ~0u; ps->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
ps->BatteryFullLifeTime = ~0u; ps->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
return TRUE;
status = NtPowerInformation(SystemBatteryState, NULL, 0, &bs, sizeof(bs));
if (status == STATUS_NOT_IMPLEMENTED) return TRUE;
if (FAILED(status)) return FALSE;
ps->ACLineStatus = bs.AcOnLine;
if (bs.BatteryPresent)
{
ps->BatteryLifePercent = bs.MaxCapacity ? bs.RemainingCapacity / bs.MaxCapacity : 100;
ps->BatteryLifeTime = bs.EstimatedTime;
if (!bs.Charging && (LONG)bs.Rate < 0)
ps->BatteryFullLifeTime = 3600 * bs.MaxCapacity / -(LONG)bs.Rate;
ps->BatteryFlag = 0;
if (bs.Charging)
ps->BatteryFlag |= BATTERY_FLAG_CHARGING;
if (ps->BatteryLifePercent > 66)
ps->BatteryFlag |= BATTERY_FLAG_HIGH;
if (ps->BatteryLifePercent < 33)
ps->BatteryFlag |= BATTERY_FLAG_LOW;
if (ps->BatteryLifePercent < 5)
ps->BatteryFlag |= BATTERY_FLAG_CRITICAL;
} }
return FALSE; else
{
ps->BatteryFlag = BATTERY_FLAG_NO_BATTERY;
}
return TRUE;
} }
/*********************************************************************** /***********************************************************************