Module: wine Branch: master Commit: 5cac9d2cb2c020802a56a5b1b28348316f1087ba URL: http://source.winehq.org/git/wine.git/?a=commit;h=5cac9d2cb2c020802a56a5b1b2...
Author: Mariusz Pluciński vshader@gmail.com Date: Sun Sep 26 15:04:04 2010 +0200
gameux: Add implementation of IGameStatisticsMgr::RemoveGameStatistics.
---
dlls/gameux/gamestatistics.c | 114 +++++++++++++++++++++++------------- dlls/gameux/tests/gamestatistics.c | 4 +- 2 files changed, 76 insertions(+), 42 deletions(-)
diff --git a/dlls/gameux/gamestatistics.c b/dlls/gameux/gamestatistics.c index 83ee5cd..a82f03a 100644 --- a/dlls/gameux/gamestatistics.c +++ b/dlls/gameux/gamestatistics.c @@ -183,6 +183,64 @@ static HRESULT GAMEUX_buildStatisticsFilePath(
return hr; } +/******************************************************************************* + * GAMEUX_getAppIdFromGDFPath + * + * Loads application identifier associated with given GDF binary. + * Routine reads identifier from registry, so will fail if game + * is not registered. + * + * Parameters: + * GDFBinaryPath [I] path to gdf binary + * lpApplicationId [O] place to store application id. + * must be at least 49 characters + * to store guid and termination 0 + */ +static HRESULT GAMEUX_getAppIdFromGDFPath( + LPCWSTR GDFBinaryPath, + LPWSTR lpApplicationId) +{ + static const WCHAR sApplicationId[] = + {'A','p','p','l','i','c','a','t','i','o','n','I','d',0}; + + HRESULT hr; + GAME_INSTALL_SCOPE installScope; + GUID instanceId; + LPWSTR lpRegistryPath; + DWORD dwLength = 49*sizeof(WCHAR);/* place for GUID */ + + TRACE("(%s, %p)\n", debugstr_w(GDFBinaryPath), lpApplicationId); + + if(!GDFBinaryPath) + return E_INVALIDARG; + + installScope = GIS_CURRENT_USER; + hr = GAMEUX_FindGameInstanceId(GDFBinaryPath, installScope, &instanceId); + + if(hr == S_FALSE) + { + installScope = GIS_ALL_USERS; + hr = GAMEUX_FindGameInstanceId(GDFBinaryPath, installScope, &instanceId); + } + + if(hr == S_FALSE) + /* game not registered, so statistics cannot be used */ + hr = E_FAIL; + + if(SUCCEEDED(hr)) + /* game is registered, let's read it's application id from registry */ + hr = GAMEUX_buildGameRegistryPath(installScope, &instanceId, &lpRegistryPath); + + if(SUCCEEDED(hr)) + hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, + lpRegistryPath, sApplicationId, RRF_RT_REG_SZ, + NULL, lpApplicationId, &dwLength)); + + HeapFree(GetProcessHeap(), 0, lpRegistryPath); + + TRACE("found app id: %s, return: %#x\n", debugstr_w(lpApplicationId), hr); + return hr; +} /******************************************************************* * IGameStatistics implementation */ @@ -560,51 +618,16 @@ static HRESULT STDMETHODCALLTYPE GameStatisticsMgrImpl_GetGameStatistics( GAMESTATS_OPEN_RESULT *pOpenResult, IGameStatistics **ppiStats) { - static const WCHAR sApplicationId[] = - {'A','p','p','l','i','c','a','t','i','o','n','I','d',0}; - HRESULT hr; - GUID instanceId; - LPWSTR lpRegistryPath = NULL; WCHAR lpApplicationId[49]; - DWORD dwLength = sizeof(lpApplicationId); - GAME_INSTALL_SCOPE installScope; GameStatisticsImpl *statisticsImpl;
TRACE("(%p, %s, 0x%x, %p, %p)\n", iface, debugstr_w(GDFBinaryPath), openType, pOpenResult, ppiStats);
- if(!GDFBinaryPath) - return E_INVALIDARG; - - installScope = GIS_CURRENT_USER; - hr = GAMEUX_FindGameInstanceId(GDFBinaryPath, installScope, &instanceId); - - if(hr == S_FALSE) - { - installScope = GIS_ALL_USERS; - hr = GAMEUX_FindGameInstanceId(GDFBinaryPath, installScope, &instanceId); - } - - if(hr == S_FALSE) - /* game not registered, so statistics cannot be used */ - hr = E_FAIL; + hr = GAMEUX_getAppIdFromGDFPath(GDFBinaryPath, lpApplicationId);
if(SUCCEEDED(hr)) - /* game is registered, let's read it's application id from registry */ - hr = GAMEUX_buildGameRegistryPath(installScope, &instanceId, &lpRegistryPath); - - if(SUCCEEDED(hr)) - { - hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, - lpRegistryPath, sApplicationId, RRF_RT_REG_SZ, - NULL, lpApplicationId, &dwLength)); - } - - if(SUCCEEDED(hr)) - { - TRACE("found app id: %s\n", debugstr_w(lpApplicationId)); hr = create_IGameStatistics(&statisticsImpl); - }
if(SUCCEEDED(hr)) { @@ -618,8 +641,6 @@ static HRESULT STDMETHODCALLTYPE GameStatisticsMgrImpl_GetGameStatistics( hr = E_NOTIMPL; }
- HeapFree(GetProcessHeap(), 0, lpRegistryPath); - return hr; }
@@ -627,8 +648,21 @@ static HRESULT STDMETHODCALLTYPE GameStatisticsMgrImpl_RemoveGameStatistics( IGameStatisticsMgr* iface, LPCWSTR GDFBinaryPath) { - FIXME("stub (%p, %s)\n", iface, debugstr_w(GDFBinaryPath)); - return E_NOTIMPL; + HRESULT hr; + WCHAR lpApplicationId[49]; + WCHAR sStatsFile[MAX_PATH]; + + TRACE("(%p, %s)\n", iface, debugstr_w(GDFBinaryPath)); + + hr = GAMEUX_getAppIdFromGDFPath(GDFBinaryPath, lpApplicationId); + + if(SUCCEEDED(hr)) + hr = GAMEUX_buildStatisticsFilePath(lpApplicationId, sStatsFile); + + if(SUCCEEDED(hr)) + hr = (DeleteFileW(sStatsFile)==TRUE ? S_OK : HRESULT_FROM_WIN32(GetLastError())); + + return hr; }
static const struct IGameStatisticsMgrVtbl GameStatisticsMgrImplVtbl = diff --git a/dlls/gameux/tests/gamestatistics.c b/dlls/gameux/tests/gamestatistics.c index 759f6d5..29bfcf3 100644 --- a/dlls/gameux/tests/gamestatistics.c +++ b/dlls/gameux/tests/gamestatistics.c @@ -414,8 +414,8 @@ static void test_gamestatisticsmgr( void ) /* test of removing game statistics from underlying storage */ ok(_isFileExists(lpStatisticsFile) == TRUE, "statistics file %s does not exists\n", wine_dbgstr_w(lpStatisticsFile)); hr = IGameStatisticsMgr_RemoveGameStatistics(gsm, sExeName); - todo_wine ok(SUCCEEDED(hr), "cannot remove game statistics, error: 0x%x\n", hr); - todo_wine ok(_isFileExists(lpStatisticsFile) == FALSE, "statistics file %s still exists\n", wine_dbgstr_w(lpStatisticsFile)); + ok(SUCCEEDED(hr), "cannot remove game statistics, error: 0x%x\n", hr); + ok(_isFileExists(lpStatisticsFile) == FALSE, "statistics file %s still exists\n", wine_dbgstr_w(lpStatisticsFile)); }
hr = IGameStatisticsMgr_Release(gsm);