2 * Gameux library coclass GameExplorer implementation
4 * Copyright (C) 2010 Mariusz PluciĆski
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "gameux_private.h"
32 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gameux
);
37 /*******************************************************************************
38 * GameUX helper functions
40 /*******************************************************************************
43 * Internal helper function.
44 * Initializes GAME_DATA structure fields with proper values. Should be
45 * called always before first usage of this structure. Implemented in gameexplorer.c
48 * GameData [I/O] pointer to structure to initialize
50 static void GAMEUX_initGameData(struct GAMEUX_GAME_DATA
*GameData
)
52 GameData
->sGDFBinaryPath
= NULL
;
53 GameData
->sGameInstallDirectory
= NULL
;
54 GameData
->bstrName
= NULL
;
55 GameData
->bstrDescription
= NULL
;
57 /*******************************************************************************
58 * GAMEUX_uninitGameData
60 * Internal helper function.
61 * Properly frees all data stored or pointed by fields of GAME_DATA structure.
62 * Should be called before freeing this structure. Implemented in gameexplorer.c
65 * GameData [I/O] pointer to structure to uninitialize
67 static void GAMEUX_uninitGameData(struct GAMEUX_GAME_DATA
*GameData
)
69 free(GameData
->sGDFBinaryPath
);
70 free(GameData
->sGameInstallDirectory
);
71 SysFreeString(GameData
->bstrName
);
72 SysFreeString(GameData
->bstrDescription
);
74 /*******************************************************************************
75 * GAMEUX_buildGameRegistryPath
77 * Internal helper function. Description available in gameux_private.h file
79 HRESULT
GAMEUX_buildGameRegistryPath(GAME_INSTALL_SCOPE installScope
,
80 LPCGUID gameInstanceId
,
81 LPWSTR
* lpRegistryPath
)
85 PTOKEN_USER pTokenUser
= NULL
;
88 WCHAR sInstanceId
[40];
89 WCHAR sRegistryPath
[8192];
91 TRACE("(0x%x, %s, %p)\n", installScope
, debugstr_guid(gameInstanceId
), lpRegistryPath
);
93 /* this will make freeing it easier for user */
94 *lpRegistryPath
= NULL
;
96 lstrcpyW(sRegistryPath
, L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\");
98 if(installScope
== GIS_CURRENT_USER
)
100 /* build registry path containing user's SID */
101 if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
102 hr
= HRESULT_FROM_WIN32(GetLastError());
106 if(!GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &dwLength
) &&
107 GetLastError()!=ERROR_INSUFFICIENT_BUFFER
)
108 hr
= HRESULT_FROM_WIN32(GetLastError());
112 pTokenUser
= malloc(dwLength
);
118 if(!GetTokenInformation(hToken
, TokenUser
, (LPVOID
)pTokenUser
, dwLength
, &dwLength
))
119 hr
= HRESULT_FROM_WIN32(GetLastError());
122 if(!ConvertSidToStringSidW(pTokenUser
->User
.Sid
, &lpSID
))
123 hr
= HRESULT_FROM_WIN32(GetLastError());
127 lstrcatW(sRegistryPath
, lpSID
);
135 else if(installScope
== GIS_ALL_USERS
)
136 /* build registry path without SID */
137 lstrcatW(sRegistryPath
, L
"Games");
141 /* put game's instance id on the end of path, only if instance id was given */
145 hr
= (StringFromGUID2(gameInstanceId
, sInstanceId
, ARRAY_SIZE(sInstanceId
)) ? S_OK
: E_FAIL
);
149 lstrcatW(sRegistryPath
, L
"\\");
150 lstrcatW(sRegistryPath
, sInstanceId
);
156 *lpRegistryPath
= wcsdup(sRegistryPath
);
161 TRACE("result: 0x%lx, path: %s\n", hr
, debugstr_w(*lpRegistryPath
));
164 /*******************************************************************************
165 * GAMEUX_WriteRegistryRecord
167 * Helper function, writes data associated with game (stored in GAMEUX_GAME_DATA
168 * structure) into expected place in registry.
171 * GameData [I] structure with data which will
172 * be written into registry.
173 * Proper values of fields installScope
174 * and guidInstanceId are required
175 * to create registry key.
177 * Schema of naming registry keys associated with games is available in
178 * description of _buildGameRegistryPath internal function.
180 * List of registry keys associated with structure fields:
181 * Key Field in GAMEUX_GAME_DATA structure
182 * ApplicationId guidApplicationId
183 * ConfigApplicationPath sGameInstallDirectory
184 * ConfigGDFBinaryPath sGDFBinaryPath
188 static HRESULT
GAMEUX_WriteRegistryRecord(struct GAMEUX_GAME_DATA
*GameData
)
191 LPWSTR lpRegistryKey
;
193 WCHAR sGameApplicationId
[40];
195 TRACE("(%p)\n", GameData
);
197 hr
= GAMEUX_buildGameRegistryPath(GameData
->installScope
, &GameData
->guidInstanceId
, &lpRegistryKey
);
200 hr
= (StringFromGUID2(&GameData
->guidApplicationId
, sGameApplicationId
, ARRAY_SIZE(sGameApplicationId
)) ? S_OK
: E_FAIL
);
203 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, lpRegistryKey
,
204 0, NULL
, 0, KEY_ALL_ACCESS
| KEY_WOW64_64KEY
, NULL
,
209 /* write game data to registry key */
210 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"ConfigApplicationPath", 0,
211 REG_SZ
, (LPBYTE
)(GameData
->sGameInstallDirectory
),
212 (lstrlenW(GameData
->sGameInstallDirectory
)+1)*sizeof(WCHAR
)));
215 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"ConfigGDFBinaryPath", 0,
216 REG_SZ
, (LPBYTE
)(GameData
->sGDFBinaryPath
),
217 (lstrlenW(GameData
->sGDFBinaryPath
)+1)*sizeof(WCHAR
)));
220 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"ApplicationId", 0,
221 REG_SZ
, (LPBYTE
)(sGameApplicationId
),
222 (lstrlenW(sGameApplicationId
)+1)*sizeof(WCHAR
)));
225 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"Title", 0,
226 REG_SZ
, (LPBYTE
)(GameData
->bstrName
),
227 (lstrlenW(GameData
->bstrName
)+1)*sizeof(WCHAR
)));
230 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"Description", 0,
231 REG_SZ
, (LPBYTE
)(GameData
->bstrDescription
? GameData
->bstrDescription
: GameData
->bstrName
),
232 (lstrlenW(GameData
->bstrDescription
? GameData
->bstrDescription
: GameData
->bstrName
)+1)*sizeof(WCHAR
)));
238 /* if something failed, remove whole key */
239 hr2
= RegDeleteKeyExW(HKEY_LOCAL_MACHINE
, lpRegistryKey
, KEY_WOW64_64KEY
, 0);
240 /* do not overwrite old failure code with new success code */
247 TRACE("returning 0x%lx\n", hr
);
250 /*******************************************************************************
251 * GAMEUX_ProcessGameDefinitionElement
253 * Helper function, parses single element from Game Definition
256 * lpXMLElement [I] game definition element
257 * GameData [O] structure, where parsed
258 * data will be stored
260 static HRESULT
GAMEUX_ProcessGameDefinitionElement(
261 IXMLDOMElement
*element
,
262 struct GAMEUX_GAME_DATA
*GameData
)
265 BSTR bstrElementName
;
267 TRACE("(%p, %p)\n", element
, GameData
);
269 hr
= IXMLDOMElement_get_nodeName(element
, &bstrElementName
);
272 /* check element name */
273 if(lstrcmpW(bstrElementName
, L
"Name") == 0)
274 hr
= IXMLDOMElement_get_text(element
, &GameData
->bstrName
);
276 else if(lstrcmpW(bstrElementName
, L
"Description") == 0)
277 hr
= IXMLDOMElement_get_text(element
, &GameData
->bstrDescription
);
280 FIXME("entry %s in Game Definition File not yet supported\n", debugstr_w(bstrElementName
));
282 SysFreeString(bstrElementName
);
287 /*******************************************************************************
288 * GAMEUX_ParseGameDefinition
290 * Helper function, loads data from given XML element into fields of GAME_DATA
294 * lpXMLGameDefinitionElement [I] Game Definition XML element
295 * GameData [O] structure where data loaded from
296 * XML element will be stored in
298 static HRESULT
GAMEUX_ParseGameDefinition(IXMLDOMElement
*gamedef
, struct GAMEUX_GAME_DATA
*game_data
)
300 IXMLDOMNodeList
*props
;
305 TRACE("(%p, %p)\n", gamedef
, game_data
);
307 attr
= SysAllocString(L
"gameID");
309 return E_OUTOFMEMORY
;
311 hr
= IXMLDOMElement_getAttribute(gamedef
, attr
, &var
);
316 hr
= CLSIDFromString(V_BSTR(&var
), &game_data
->guidApplicationId
);
321 hr
= IXMLDOMElement_get_childNodes(gamedef
, &props
);
330 hr
= IXMLDOMNodeList_nextNode(props
, &prop
);
333 IXMLDOMElement
*element
;
335 hr
= IXMLDOMNode_QueryInterface(prop
, &IID_IXMLDOMElement
, (void**)&element
);
338 hr
= GAMEUX_ProcessGameDefinitionElement(element
, game_data
);
339 IXMLDOMElement_Release(element
);
342 IXMLDOMNode_Release(prop
);
346 IXMLDOMNodeList_Release(props
);
348 return FAILED(hr
) ? hr
: S_OK
;
351 struct parse_gdf_thread_param
353 struct GAMEUX_GAME_DATA
*GameData
;
357 /*******************************************************************************
358 * GAMEUX_ParseGDFBinary
360 * Helper function, loads given binary and parses embed GDF if there's any.
363 * GameData [I/O] Structure with game's data. Content of field
364 * sGDFBinaryPath defines path to binary, from
365 * which embed GDF will be loaded. Data from
366 * GDF will be stored in other fields of this
369 static DWORD WINAPI
GAMEUX_ParseGDFBinary(void *thread_param
)
371 struct parse_gdf_thread_param
*ctx
= thread_param
;
372 struct GAMEUX_GAME_DATA
*GameData
= ctx
->GameData
;
375 WCHAR sResourcePath
[MAX_PATH
];
377 VARIANT_BOOL isSuccessful
;
378 IXMLDOMDocument
*document
;
380 IXMLDOMElement
*root
, *gdElement
;
382 TRACE("(%p)->sGDFBinaryPath = %s\n", GameData
, debugstr_w(GameData
->sGDFBinaryPath
));
384 /* prepare path to GDF, using res:// prefix */
385 lstrcpyW(sResourcePath
, L
"res://");
386 lstrcatW(sResourcePath
, GameData
->sGDFBinaryPath
);
387 lstrcatW(sResourcePath
, L
"/DATA/");
388 lstrcatW(sResourcePath
, ID_GDF_XML_STR
);
392 hr
= CoCreateInstance(&CLSID_DOMDocument
, NULL
, CLSCTX_INPROC_SERVER
,
393 &IID_IXMLDOMDocument
, (void**)&document
);
397 /* load GDF into MSXML */
398 V_VT(&variant
) = VT_BSTR
;
399 V_BSTR(&variant
) = SysAllocString(sResourcePath
);
400 if(!V_BSTR(&variant
))
405 hr
= IXMLDOMDocument_load(document
, variant
, &isSuccessful
);
406 if(hr
== S_FALSE
|| isSuccessful
== VARIANT_FALSE
)
410 SysFreeString(V_BSTR(&variant
));
414 hr
= IXMLDOMDocument_get_documentElement(document
, &root
);
421 hr
= IXMLDOMElement_get_firstChild(root
, &gdNode
);
427 hr
= IXMLDOMNode_QueryInterface(gdNode
, &IID_IXMLDOMElement
, (LPVOID
*)&gdElement
);
430 hr
= GAMEUX_ParseGameDefinition(gdElement
, GameData
);
431 IXMLDOMElement_Release(gdElement
);
434 IXMLDOMNode_Release(gdNode
);
437 IXMLDOMElement_Release(root
);
440 IXMLDOMDocument_Release(document
);
448 /*******************************************************************
449 * GAMEUX_RemoveRegistryRecord
451 * Helper function, removes registry key associated with given game instance
453 static HRESULT
GAMEUX_RemoveRegistryRecord(GUID
* pInstanceID
)
456 LPWSTR lpRegistryPath
= NULL
;
457 TRACE("(%s)\n", debugstr_guid(pInstanceID
));
459 /* first, check is game installed for all users */
460 hr
= GAMEUX_buildGameRegistryPath(GIS_ALL_USERS
, pInstanceID
, &lpRegistryPath
);
462 hr
= HRESULT_FROM_WIN32(RegDeleteKeyExW(HKEY_LOCAL_MACHINE
, lpRegistryPath
, KEY_WOW64_64KEY
, 0));
464 free(lpRegistryPath
);
466 /* if not, check current user */
469 hr
= GAMEUX_buildGameRegistryPath(GIS_CURRENT_USER
, pInstanceID
, &lpRegistryPath
);
471 hr
= HRESULT_FROM_WIN32(RegDeleteKeyExW(HKEY_LOCAL_MACHINE
, lpRegistryPath
, KEY_WOW64_64KEY
, 0));
473 free(lpRegistryPath
);
478 /*******************************************************************************
479 * GAMEUX_RegisterGame
481 * Internal helper function. Registers game associated with given GDF binary in
482 * Game Explorer. Implemented in gameexplorer.c
485 * sGDFBinaryPath [I] path to binary containing GDF file in
487 * sGameInstallDirectory [I] path to directory, where game installed
489 * installScope [I] scope of game installation
490 * pInstanceID [I/O] pointer to game instance identifier.
491 * If pointing to GUID_NULL, then new
492 * identifier will be generated automatically
493 * and returned via this parameter
495 static HRESULT
GAMEUX_RegisterGame(LPCWSTR sGDFBinaryPath
,
496 LPCWSTR sGameInstallDirectory
,
497 GAME_INSTALL_SCOPE installScope
,
501 struct GAMEUX_GAME_DATA GameData
;
503 TRACE("(%s, %s, 0x%x, %s)\n", debugstr_w(sGDFBinaryPath
), debugstr_w(sGameInstallDirectory
), installScope
, debugstr_guid(pInstanceID
));
505 GAMEUX_initGameData(&GameData
);
506 GameData
.sGDFBinaryPath
= wcsdup(sGDFBinaryPath
);
507 GameData
.sGameInstallDirectory
= wcsdup(sGameInstallDirectory
);
508 GameData
.installScope
= installScope
;
510 /* generate GUID if it was not provided by user */
511 if(IsEqualGUID(pInstanceID
, &GUID_NULL
))
512 hr
= CoCreateGuid(pInstanceID
);
514 GameData
.guidInstanceId
= *pInstanceID
;
516 /* load data from GDF binary */
519 struct parse_gdf_thread_param thread_param
;
523 thread_param
.GameData
= &GameData
;
524 if(!(thread
= CreateThread(NULL
, 0, GAMEUX_ParseGDFBinary
, &thread_param
, 0, &ret
)))
526 ERR("Failed to create thread.\n");
530 ret
= WaitForSingleObject(thread
, INFINITE
);
532 if(ret
!= WAIT_OBJECT_0
)
534 ERR("Wait failed (%#lx).\n", ret
);
538 hr
= thread_param
.hr
;
541 /* save data to registry */
543 hr
= GAMEUX_WriteRegistryRecord(&GameData
);
546 GAMEUX_uninitGameData(&GameData
);
547 TRACE("returning 0x%08lx\n", hr
);
550 /*******************************************************************************
551 * GAMEUX_IsGameKeyExist
553 * Helper function, checks if game's registry ath exists in given scope
556 * installScope [I] scope to search game in
557 * InstanceID [I] game instance identifier
558 * lpRegistryPath [O] place to store address of registry path to
559 * the game. It is filled only if key exists.
560 * It must be freed by free(...)
563 * S_OK key was found properly
564 * S_FALSE key does not exists
567 static HRESULT
GAMEUX_IsGameKeyExist(GAME_INSTALL_SCOPE installScope
,
569 LPWSTR
* lpRegistryPath
) {
574 hr
= GAMEUX_buildGameRegistryPath(installScope
, InstanceID
, lpRegistryPath
);
577 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, *lpRegistryPath
,
578 0, KEY_WOW64_64KEY
, &hKey
));
580 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
587 /* if the key does not exist or another error occurred, do not return the path */
588 free(*lpRegistryPath
);
589 *lpRegistryPath
= NULL
;
594 /*******************************************************************************
595 * GAMEUX_LoadRegistryString
597 * Helper function, loads string from registry value and allocates buffer for it
599 static HRESULT
GAMEUX_LoadRegistryString(HKEY hRootKey
,
600 LPCWSTR lpRegistryKey
,
601 LPCWSTR lpRegistryValue
,
609 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRootKey
, lpRegistryKey
, lpRegistryValue
,
610 RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
614 *lpValue
= malloc(dwSize
);
620 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRootKey
, lpRegistryKey
, lpRegistryValue
,
621 RRF_RT_REG_SZ
, NULL
, *lpValue
, &dwSize
));
625 /*******************************************************************************
628 * Helper function, updates stored data about game with given InstanceID
630 static HRESULT
GAMEUX_UpdateGame(LPGUID InstanceID
) {
632 GAME_INSTALL_SCOPE installScope
;
633 LPWSTR lpRegistryPath
;
634 LPWSTR lpGDFBinaryPath
;
636 TRACE("(%s)\n", debugstr_guid(InstanceID
));
638 /* first, check is game exists in CURRENT_USER scope */
639 installScope
= GIS_CURRENT_USER
;
640 hr
= GAMEUX_IsGameKeyExist(installScope
, InstanceID
, &lpRegistryPath
);
644 /* game not found in CURRENT_USER scope, let's check in ALL_USERS */
645 installScope
= GIS_ALL_USERS
;
646 hr
= GAMEUX_IsGameKeyExist(installScope
, InstanceID
, &lpRegistryPath
);
650 /* still not found? let's inform user that game does not exists */
651 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
655 WCHAR
*lpGameInstallDirectory
= NULL
;
657 /* game found, its registry path is in lpRegistryPath and install
658 * scope in installScope */
659 TRACE("game found in registry (path %s), updating\n", debugstr_w(lpRegistryPath
));
661 /* first, read required data about game */
662 hr
= GAMEUX_LoadRegistryString(HKEY_LOCAL_MACHINE
, lpRegistryPath
,
663 L
"ConfigGDFBinaryPath", &lpGDFBinaryPath
);
666 hr
= GAMEUX_LoadRegistryString(HKEY_LOCAL_MACHINE
, lpRegistryPath
,
667 L
"ConfigApplicationPath", &lpGameInstallDirectory
);
669 /* now remove currently existing registry key */
671 hr
= GAMEUX_RemoveRegistryRecord(InstanceID
);
673 /* and add it again, it will cause in reparsing of whole GDF */
675 hr
= GAMEUX_RegisterGame(lpGDFBinaryPath
, lpGameInstallDirectory
,
676 installScope
, InstanceID
);
678 free(lpGDFBinaryPath
);
679 free(lpGameInstallDirectory
);
682 free(lpRegistryPath
);
683 TRACE("returning 0x%lx\n", hr
);
686 /*******************************************************************************
687 * GAMEUX_FindGameInstanceId
689 * Internal helper function. Description available in gameux_private.h file
691 HRESULT
GAMEUX_FindGameInstanceId(
692 LPCWSTR sGDFBinaryPath
,
693 GAME_INSTALL_SCOPE installScope
,
698 LPWSTR lpRegistryPath
= NULL
;
700 DWORD dwSubKeys
, dwSubKeyLen
, dwMaxSubKeyLen
, i
;
701 LPWSTR lpName
= NULL
, lpValue
= NULL
;
703 hr
= GAMEUX_buildGameRegistryPath(installScope
, NULL
, &lpRegistryPath
);
706 /* enumerate all subkeys of received one and search them for value "ConfigGGDFBinaryPath" */
707 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
708 lpRegistryPath
, 0, KEY_READ
| KEY_WOW64_64KEY
, &hRootKey
));
712 hr
= HRESULT_FROM_WIN32(RegQueryInfoKeyW(hRootKey
, NULL
, NULL
, NULL
,
713 &dwSubKeys
, &dwMaxSubKeyLen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
));
717 ++dwMaxSubKeyLen
; /* for string terminator */
718 lpName
= malloc(dwMaxSubKeyLen
* sizeof(WCHAR
));
719 if(!lpName
) hr
= E_OUTOFMEMORY
;
724 for(i
=0; i
<dwSubKeys
&& !found
; ++i
)
726 dwSubKeyLen
= dwMaxSubKeyLen
;
727 hr
= HRESULT_FROM_WIN32(RegEnumKeyExW(hRootKey
, i
, lpName
, &dwSubKeyLen
,
728 NULL
, NULL
, NULL
, NULL
));
731 hr
= GAMEUX_LoadRegistryString(hRootKey
, lpName
,
732 L
"ConfigGDFBinaryPath", &lpValue
);
736 if(lstrcmpW(lpValue
, sGDFBinaryPath
)==0)
738 /* key found, let's copy instance id and exit */
739 hr
= CLSIDFromString(lpName
, pInstanceId
);
748 RegCloseKey(hRootKey
);
751 free(lpRegistryPath
);
753 if((SUCCEEDED(hr
) && !found
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
758 /*******************************************************************************
759 * GameExplorer implementation
762 typedef struct _GameExplorerImpl
764 IGameExplorer IGameExplorer_iface
;
765 IGameExplorer2 IGameExplorer2_iface
;
769 static inline GameExplorerImpl
*impl_from_IGameExplorer(IGameExplorer
*iface
)
771 return CONTAINING_RECORD(iface
, GameExplorerImpl
, IGameExplorer_iface
);
774 static inline GameExplorerImpl
*impl_from_IGameExplorer2(IGameExplorer2
*iface
)
776 return CONTAINING_RECORD(iface
, GameExplorerImpl
, IGameExplorer2_iface
);
779 static HRESULT WINAPI
GameExplorerImpl_QueryInterface(
780 IGameExplorer
*iface
,
784 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
786 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
790 if(IsEqualGUID(riid
, &IID_IUnknown
) ||
791 IsEqualGUID(riid
, &IID_IGameExplorer
))
793 *ppvObject
= &This
->IGameExplorer_iface
;
795 else if(IsEqualGUID(riid
, &IID_IGameExplorer2
))
797 *ppvObject
= &This
->IGameExplorer2_iface
;
801 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
802 return E_NOINTERFACE
;
805 IGameExplorer_AddRef(iface
);
809 static ULONG WINAPI
GameExplorerImpl_AddRef(IGameExplorer
*iface
)
811 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
814 ref
= InterlockedIncrement(&This
->ref
);
816 TRACE("(%p): ref=%ld\n", This
, ref
);
820 static ULONG WINAPI
GameExplorerImpl_Release(IGameExplorer
*iface
)
822 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
825 ref
= InterlockedDecrement(&This
->ref
);
826 TRACE("(%p): ref=%ld\n", This
, ref
);
830 TRACE("freeing GameExplorer object\n");
837 static HRESULT WINAPI
GameExplorerImpl_AddGame(
838 IGameExplorer
*iface
,
839 BSTR bstrGDFBinaryPath
,
840 BSTR sGameInstallDirectory
,
841 GAME_INSTALL_SCOPE installScope
,
844 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
845 TRACE("(%p, %s, %s, 0x%x, %s)\n", This
, debugstr_w(bstrGDFBinaryPath
), debugstr_w(sGameInstallDirectory
), installScope
, debugstr_guid(pInstanceID
));
846 return GAMEUX_RegisterGame(bstrGDFBinaryPath
, sGameInstallDirectory
, installScope
, pInstanceID
);
849 static HRESULT WINAPI
GameExplorerImpl_RemoveGame(
850 IGameExplorer
*iface
,
853 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
855 TRACE("(%p, %s)\n", This
, debugstr_guid(&instanceID
));
856 return GAMEUX_RemoveRegistryRecord(&instanceID
);
859 static HRESULT WINAPI
GameExplorerImpl_UpdateGame(
860 IGameExplorer
*iface
,
863 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
865 TRACE("(%p, %s)\n", This
, debugstr_guid(&instanceID
));
866 return GAMEUX_UpdateGame(&instanceID
);
869 static HRESULT WINAPI
GameExplorerImpl_VerifyAccess(
870 IGameExplorer
*iface
,
874 GameExplorerImpl
*This
= impl_from_IGameExplorer(iface
);
876 FIXME("(%p, %s, %p)\n", This
, debugstr_w(sGDFBinaryPath
), pHasAccess
);
881 static const struct IGameExplorerVtbl GameExplorerImplVtbl
=
883 GameExplorerImpl_QueryInterface
,
884 GameExplorerImpl_AddRef
,
885 GameExplorerImpl_Release
,
886 GameExplorerImpl_AddGame
,
887 GameExplorerImpl_RemoveGame
,
888 GameExplorerImpl_UpdateGame
,
889 GameExplorerImpl_VerifyAccess
893 static HRESULT WINAPI
GameExplorer2Impl_QueryInterface(
894 IGameExplorer2
*iface
,
898 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
899 return GameExplorerImpl_QueryInterface(&This
->IGameExplorer_iface
, riid
, ppvObject
);
902 static ULONG WINAPI
GameExplorer2Impl_AddRef(IGameExplorer2
*iface
)
904 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
905 return GameExplorerImpl_AddRef(&This
->IGameExplorer_iface
);
908 static ULONG WINAPI
GameExplorer2Impl_Release(IGameExplorer2
*iface
)
910 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
911 return GameExplorerImpl_Release(&This
->IGameExplorer_iface
);
914 static HRESULT WINAPI
GameExplorer2Impl_CheckAccess(
915 IGameExplorer2
*iface
,
916 LPCWSTR binaryGDFPath
,
919 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
920 FIXME("stub (%p, %s, %p)\n", This
, debugstr_w(binaryGDFPath
), pHasAccess
);
924 static HRESULT WINAPI
GameExplorer2Impl_InstallGame(
925 IGameExplorer2
*iface
,
926 LPCWSTR binaryGDFPath
,
927 LPCWSTR installDirectory
,
928 GAME_INSTALL_SCOPE installScope
)
932 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
934 TRACE("(%p, %s, %s, 0x%x)\n", This
, debugstr_w(binaryGDFPath
), debugstr_w(installDirectory
), installScope
);
939 hr
= GAMEUX_FindGameInstanceId(binaryGDFPath
, GIS_CURRENT_USER
, &instanceId
);
942 hr
= GAMEUX_FindGameInstanceId(binaryGDFPath
, GIS_ALL_USERS
, &instanceId
);
946 /* if game isn't yet registered, then install it */
947 instanceId
= GUID_NULL
;
948 hr
= GAMEUX_RegisterGame(binaryGDFPath
, installDirectory
, installScope
, &instanceId
);
951 /* otherwise, update game */
952 hr
= GAMEUX_UpdateGame(&instanceId
);
957 static HRESULT WINAPI
GameExplorer2Impl_UninstallGame(
958 IGameExplorer2
*iface
,
959 LPCWSTR binaryGDFPath
)
963 GameExplorerImpl
*This
= impl_from_IGameExplorer2(iface
);
964 TRACE("(%p, %s)\n", This
, debugstr_w(binaryGDFPath
));
969 hr
= GAMEUX_FindGameInstanceId(binaryGDFPath
, GIS_CURRENT_USER
, &instanceId
);
972 hr
= GAMEUX_FindGameInstanceId(binaryGDFPath
, GIS_ALL_USERS
, &instanceId
);
975 hr
= GAMEUX_RemoveRegistryRecord(&instanceId
);
980 static const struct IGameExplorer2Vtbl GameExplorer2ImplVtbl
=
982 GameExplorer2Impl_QueryInterface
,
983 GameExplorer2Impl_AddRef
,
984 GameExplorer2Impl_Release
,
985 GameExplorer2Impl_InstallGame
,
986 GameExplorer2Impl_UninstallGame
,
987 GameExplorer2Impl_CheckAccess
991 * Construction routine
993 HRESULT
GameExplorer_create(
997 GameExplorerImpl
*pGameExplorer
;
999 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
1001 pGameExplorer
= malloc(sizeof(*pGameExplorer
));
1004 return E_OUTOFMEMORY
;
1006 pGameExplorer
->IGameExplorer_iface
.lpVtbl
= &GameExplorerImplVtbl
;
1007 pGameExplorer
->IGameExplorer2_iface
.lpVtbl
= &GameExplorer2ImplVtbl
;
1008 pGameExplorer
->ref
= 1;
1010 *ppObj
= (IUnknown
*)&pGameExplorer
->IGameExplorer_iface
;
1012 TRACE("returning iface: %p\n", *ppObj
);