diff --git a/dlls/gameux/tests/gameexplorer.c b/dlls/gameux/tests/gameexplorer.c index 3a72d203897..8553890e332 100644 --- a/dlls/gameux/tests/gameexplorer.c +++ b/dlls/gameux/tests/gameexplorer.c @@ -33,6 +33,9 @@ #include "wine/test.h" +/* function from Shell32, not defined in header */ +extern BOOL WINAPI GUIDFromStringW(LPCWSTR psz, LPGUID pguid); + /******************************************************************************* * Pointers used instead of direct calls. These procedures are not available on * older system, which causes problem while loading test binary. @@ -68,7 +71,8 @@ static BOOL _loadDynamicRoutines(void) * * Parameters: * installScope [I] the scope which was used in AddGame/InstallGame call - * gameInstanceId [I] game instance GUID + * gameInstanceId [I] game instance GUID. If NULL, then only + * path to scope is returned * lpRegistryPath [O] pointer which will receive address to string * containing expected registry path. Path * is relative to HKLM registry key. It @@ -138,14 +142,17 @@ static HRESULT _buildGameRegistryPath(GAME_INSTALL_SCOPE installScope, else hr = E_INVALIDARG; - /* put game's instance id on the end of path */ - if(SUCCEEDED(hr)) - hr = (StringFromGUID2(gameInstanceId, sInstanceId, sizeof(sInstanceId)/sizeof(sInstanceId[0])) ? S_OK : E_FAIL); - - if(SUCCEEDED(hr)) + /* put game's instance id on the end of path, but only if id was passes */ + if(gameInstanceId) { - lstrcatW(sRegistryPath, sBackslash); - lstrcatW(sRegistryPath, sInstanceId); + if(SUCCEEDED(hr)) + hr = (StringFromGUID2(gameInstanceId, sInstanceId, sizeof(sInstanceId)/sizeof(sInstanceId[0])) ? S_OK : E_FAIL); + + if(SUCCEEDED(hr)) + { + lstrcatW(sRegistryPath, sBackslash); + lstrcatW(sRegistryPath, sInstanceId); + } } if(SUCCEEDED(hr)) @@ -365,6 +372,128 @@ static void _validateGameRegistryKey(int line, CoTaskMemFree(lpRegistryPath); } +/******************************************************************************* + * _LoadRegistryString + * + * Helper function, loads string from registry value and allocates buffer for it + * + * Parameters: + * hRootKey [I] base key for reading. Should be opened + * with KEY_READ permission + * lpRegistryKey [I] name of registry key, subkey of root key + * lpRegistryValue [I] name of registry value + * lpValue [O] pointer where address of received + * value will be stored. Value should be + * freed by CoTaskMemFree call + */ +static HRESULT _LoadRegistryString(HKEY hRootKey, + LPCWSTR lpRegistryKey, + LPCWSTR lpRegistryValue, + LPWSTR* lpValue) +{ + HRESULT hr; + DWORD dwSize; + + *lpValue = NULL; + + hr = HRESULT_FROM_WIN32(_RegGetValueW(hRootKey, lpRegistryKey, lpRegistryValue, + RRF_RT_REG_SZ, NULL, NULL, &dwSize)); + + if(SUCCEEDED(hr)) + { + *lpValue = CoTaskMemAlloc(dwSize); + if(!*lpValue) + hr = E_OUTOFMEMORY; + } + if(SUCCEEDED(hr)) + hr = HRESULT_FROM_WIN32(_RegGetValueW(hRootKey, lpRegistryKey, lpRegistryValue, + RRF_RT_REG_SZ, NULL, *lpValue, &dwSize)); + + return hr; +} +/******************************************************************************* + * _findGameInstanceId + * + * Helper funtion. Searches for instance identifier of given game in given + * installation scope. + * + * Parameters: + * line [I] line to display messages + * sGDFBinaryPath [I] path to binary containing GDF + * installScope [I] game install scope to search in + * pInstanceId [O] instance identifier of given game + */ +static void _findGameInstanceId(int line, + LPWSTR sGDFBinaryPath, + GAME_INSTALL_SCOPE installScope, + GUID* pInstanceId) +{ + static const WCHAR sConfigGDFBinaryPath[] = + {'C','o','n','f','i','g','G','D','F','B','i','n','a','r','y','P','a','t','h',0}; + + HRESULT hr; + BOOL found = FALSE; + LPWSTR lpRegistryPath = NULL; + HKEY hRootKey; + DWORD dwSubKeys, dwSubKeyLen, dwMaxSubKeyLen, i; + LPWSTR lpName = NULL, lpValue = NULL; + + hr = _buildGameRegistryPath(installScope, NULL, &lpRegistryPath); + ok_(__FILE__, line)(SUCCEEDED(hr), "cannot get registry path to given scope: %d\n", installScope); + + if(SUCCEEDED(hr)) + /* enumerate all subkeys of received one and search them for value "ConfigGGDFBinaryPath" */ + hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, + lpRegistryPath, 0, KEY_READ | KEY_WOW64_64KEY, &hRootKey)); + ok_(__FILE__, line)(SUCCEEDED(hr), "cannot open key registry key: %s\n", wine_dbgstr_w(lpRegistryPath)); + + if(SUCCEEDED(hr)) + { + hr = HRESULT_FROM_WIN32(RegQueryInfoKeyW(hRootKey, NULL, NULL, NULL, + &dwSubKeys, &dwMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL, NULL)); + + if(SUCCEEDED(hr)) + { + ++dwMaxSubKeyLen; /* for string terminator */ + lpName = CoTaskMemAlloc(dwMaxSubKeyLen*sizeof(WCHAR)); + if(!lpName) hr = E_OUTOFMEMORY; + ok_(__FILE__, line)(SUCCEEDED(hr), "cannot allocate memory for key name"); + } + + if(SUCCEEDED(hr)) + { + for(i=0; i