From: Robert Lippmann robert.lippmann.development@gmail.com
Implemented the following functions with a bit of a hack: PowerGetActiveScheme PowerSetActiveScheme PowerEnumerate PowerReadFriendlyName --- dlls/powrprof/powrprof.c | 90 +++++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 10 deletions(-)
diff --git a/dlls/powrprof/powrprof.c b/dlls/powrprof/powrprof.c index dcc7126b920..d00d240cec1 100644 --- a/dlls/powrprof/powrprof.c +++ b/dlls/powrprof/powrprof.c @@ -19,7 +19,7 @@
#include <stdarg.h> #include <stdlib.h> - +#include "initguid.h" #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -48,6 +48,23 @@ WINE_DEFAULT_DEBUG_CHANNEL(powrprof); static const WCHAR szPowerCfgSubKey[] = L"Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg"; static HANDLE PPRegSemaphore = NULL;
+/* Hacks to get and set power schemes + These should really be stored in the registry */ +typedef struct { + const GUID guid; + const WCHAR *name; + } power_scheme_info; + +/* Static array for storing predefined power schemes */ +static const power_scheme_info valid_power_schemes[] = +{ + {GUID_TYPICAL_POWER_SAVINGS, L"Balanced"}, + {GUID_MAX_POWER_SAVINGS, L"High Performance"}, + {GUID_MIN_POWER_SAVINGS, L"Power Saver"} +}; +/* Static variable for storing the active power scheme, set to Balanced by default */ +static GUID active_power_scheme = GUID_TYPICAL_POWER_SAVINGS; + NTSTATUS WINAPI CallNtPowerInformation( POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, @@ -286,14 +303,28 @@ BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescripti
DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid) { - FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid); - return ERROR_CALL_NOT_IMPLEMENTED; + /* Windows SDK docs say use LocalFree to free this */ + *polguid = LocalAlloc(LMEM_FIXED, sizeof(GUID)); + if (*polguid == NULL) + { + return ERROR_NOT_ENOUGH_MEMORY; + } + memcpy(*polguid, &active_power_scheme, sizeof(GUID)); + return ERROR_SUCCESS; }
DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid) { - FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid)); - return ERROR_SUCCESS; + size_t i; + for (i = 0; i < ARRAYSIZE(valid_power_schemes); i++) + { + if (IsEqualGUID(polguid, &valid_power_schemes[i].guid)) + { + active_power_scheme = *polguid; + return ERROR_SUCCESS; + } + } + return ERROR_INVALID_PARAMETER; }
DWORD WINAPI PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize) @@ -306,10 +337,36 @@ DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, UCHAR *Buffer, DWORD *BufferSize) { - FIXME("(%p,%s,%s,%s,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Buffer, BufferSize); - return ERROR_CALL_NOT_IMPLEMENTED; + size_t i; + const WCHAR *name; + DWORD name_len; + + /* Check for invalid sub-group or power-setting GUIDs */ + if (SubGroup != NULL || PowerSettings != NULL) + { + return ERROR_CALL_NOT_IMPLEMENTED; + } + for (i = 0; i < ARRAYSIZE(valid_power_schemes); i++) + { + if (IsEqualGUID(Scheme, &valid_power_schemes[i].guid)) + { + name = valid_power_schemes[i].name; + name_len = (wcslen(name) + 1) * sizeof(WCHAR); + if (*BufferSize < name_len) + { + *BufferSize = name_len; + return ERROR_MORE_DATA; + } + wcscpy((WCHAR *)Buffer, name); + *BufferSize = name_len; + return ERROR_SUCCESS; + } + } + + return ERROR_INVALID_PARAMETER; /* Scheme not found */ }
+ POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRole(void) { FIXME("stub\n"); @@ -325,9 +382,22 @@ POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRoleEx(ULONG version) DWORD WINAPI PowerEnumerate(HKEY key, const GUID *scheme, const GUID *subgroup, POWER_DATA_ACCESSOR flags, ULONG index, UCHAR *buffer, DWORD *buffer_size) { - FIXME("(%p,%s,%s,%d,%ld,%p,%p) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), - flags, index, buffer, buffer_size); - return ERROR_CALL_NOT_IMPLEMENTED; + /* Only care about ACCESS_SCHEME */ + if (flags != ACCESS_SCHEME || scheme != NULL || subgroup != NULL) + { + return ERROR_CALL_NOT_IMPLEMENTED; + } + if(index >= ARRAYSIZE(valid_power_schemes)) + { + return ERROR_NO_MORE_ITEMS; + } + if(buffer == NULL || *buffer_size < sizeof(GUID)) + { + *buffer_size = sizeof(GUID); + return ERROR_MORE_DATA; + } + memcpy(buffer, &valid_power_schemes[index].guid, sizeof(GUID)); + return ERROR_SUCCESS; }
DWORD WINAPI PowerRegisterSuspendResumeNotification(DWORD flags, HANDLE recipient, PHPOWERNOTIFY handle)