Game Explorer with Helper
From NSIS Wiki
Jump to navigationJump to search
Game Explorer with Helper
Microsoft provided a nice dll called GameuxInstallHelper.dll that allows games to show up in the Game Explorer that comes with Vista, and if it is used on a pre-Vista system, it can make the games show up once the user has upgraded to Vista. The script below is intended to be an improvement from the old Game Explorer Header
Download
GameuxInstallHelper.zip (48 KB) (from the March 2008 DirectX SDK)
Code
Var GameExplorer_ContextId !include "LogicLib.nsh" !define GameExplorer_AddGame "!insertmacro GameExplorer_AddGame" !define GameExplorer_AddPlayTask "!insertmacro GameExplorer_AddPlayTask" !define GameExplorer_AddSupportTask "!insertmacro GameExplorer_AddSupportTask" !define GameExplorer_RemoveGame "!insertmacro GameExplorer_RemoveGame" !macro GameExplorer_AddGame CONTEXT GDF INSTDIR RUNPATH RUNARGS SAVEGAMEEXT Push $0 Push $1 Push $2 Push $3 Push $4 SetOutPath $PLUGINSDIR !ifndef GAME_EXPLORER_DLL_EXISTS !ifdef GAME_EXPLORER_HELPER_PATH File "/oname=GameuxInstallHelper.dll" "${GAME_EXPLORER_HELPER_PATH}" !else File "GameuxInstallHelper.dll" !endif !define GAME_EXPLORER_DLL_EXISTS !endif !if "${CONTEXT}" == "current" StrCpy $GameExplorer_ContextId 2 !else if "${CONTEXT}" == "all" StrCpy $GameExplorer_ContextId 3 !else !error 'Context must be "current" or "all"' !endif System::Call 'GameuxInstallHelper::GenerateGUID(g .r0)' !ifndef GAME_EXPLORER_GUID_DECLARED Var /GLOBAL GameExplorer_GUID !define GAME_EXPLORER_GUID_DECLARED !endif ${If} $0 != "{00000000-0000-0000-0000-000000000000}" StrCpy $GameExplorer_GUID $0 StrCpy $1 "${GDF}" StrCpy $2 "${INSTDIR}" System::Call "GameuxInstallHelper::AddToGameExplorerA(t r1, t r2, \ i $GameExplorer_ContextId, g r0)" StrCpy $3 "${RUNPATH}" StrCpy $4 "${RUNARGS}" !ifndef GAME_EXPLORER_PLAYTASK_NUM_DECLARED Var /GLOBAL GameExplorer_PlaytaskNum !define GAME_EXPLORER_PLAYTASK_NUM_DECLARED !endif StrCpy $GameExplorer_PlaytaskNum 0 !ifndef GAME_EXPLORER_SUPPORTTASK_NUM_DECLARED Var /GLOBAL GameExplorer_SupporttaskNum !define GAME_EXPLORER_SUPPORTTASK_NUM_DECLARED !endif StrCpy $GameExplorer_SupporttaskNum 0 System::Call "GameuxInstallHelper::RegisterWithMediaCenterA(t r1, t r2, \ i $GameExplorer_ContextId, t r3, t r4, i 1)" !if "${SAVEGAMEEXT}" != "" StrCpy $2 "${SAVEGAMEEXT}" !if "${RUNARGS}" != "" StrCpy $4 "${RUNARGS} $\"%1$\"" !else StrCpy $4 '"%1"' !endif System::Call "GameuxInstallHelper::SetupRichSavedGamesA(t r2, t r3, t r4)" !endif ${EndIf} Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 !macroend !macro GameExplorer_AddPlayTask TASKNAME RUNPATH RUNARGS Push $0 Push $1 Push $2 StrCpy $0 "${TASKNAME}" StrCpy $1 "${RUNPATH}" StrCpy $2 "${RUNARGS}" !ifndef GAME_EXPLORER_GUID_DECLARED Var /GLOBAL GameExplorer_GUID !define GAME_EXPLORER_GUID_DECLARED !endif !ifndef GAME_EXPLORER_PLAYTASK_NUM_DECLARED Var /GLOBAL GameExplorer_PlaytaskNum !define GAME_EXPLORER_PLAYTASK_NUM_DECLARED !endif System::Call "GameuxInstallHelper::CreateTaskA(i $GameExplorer_ContextId, \ g '$GameExplorer_GUID', i 0, i $GameExplorer_PlaytaskNum, t r0, t r1, t r2)" IntOp $GameExplorer_PlaytaskNum $GameExplorer_PlaytaskNum + 1 Pop $2 Pop $1 Pop $0 !macroend !macro GameExplorer_AddSupportTask TASKNAME SUPPORTPATH Push $0 Push $1 StrCpy $0 "${TASKNAME}" StrCpy $1 "${SUPPORTPATH}" !ifndef GAME_EXPLORER_GUID_DECLARED Var /GLOBAL GameExplorer_GUID !define GAME_EXPLORER_GUID_DECLARED !endif !ifndef GAME_EXPLORER_SUPPORTTASK_NUM_DECLARED Var /GLOBAL GameExplorer_SupporttaskNum !define GAME_EXPLORER_SUPPORTTASK_NUM_DECLARED !endif System::Call "GameuxInstallHelper::CreateTaskA(i $GameExplorer_ContextId, \ g '$GameExplorer_GUID', i 0, i $GameExplorer_SupporttaskNum, t r0, t r1, '')" IntOp $GameExplorer_SupporttaskNum $GameExplorer_SupporttaskNum + 1 Pop $1 Pop $0 !macroend !macro GameExplorer_RemoveGame CONTEXT GDF INSTDIR RUNPATH SAVEGAMEEXT Push $0 Push $1 Push $2 Push $3 !if "${CONTEXT}" == "current" StrCpy $GameExplorer_ContextId 2 !else if "${CONTEXT}" == "all" StrCpy $GameExplorer_ContextId 3 !else !error 'Context must be "current" or "all"' !endif SetOutPath $PLUGINSDIR !ifndef UNGAME_EXPLORER_DLL_EXISTS !ifdef GAME_EXPLORER_HELPER_PATH File "/oname=GameuxInstallHelper.dll" "${GAME_EXPLORER_HELPER_PATH}" !else File "GameuxInstallHelper.dll" !endif !define UNGAME_EXPLORER_DLL_EXISTS !endif StrCpy $1 "${GDF}" System::Call "GameuxInstallHelper::RetrieveGUIDForApplicationA(t r1, g .r0)" System::Call "GameuxInstallHelper::RemoveTasks(g r0)" System::Call "GameuxInstallHelper::RemoveFromGameExplorer(g r0)" StrCpy $2 "${INSTDIR}" StrCpy $3 "${RUNPATH}" System::Call "GameuxInstallHelper::UnRegisterWithMediaCenterA(t r2, \ i $GameExplorer_ContextId, t r3, i 0)" !if "${SAVEGAMEEXT}" != "" StrCpy $2 "${SAVEGAMEEXT}" System::Call "GameuxInstallHelper::RemoveRichSavedGamesA(t r2)" !endif Pop $3 Pop $2 Pop $1 Pop $0 !macroend
Usage
Save the script above in a header file, such as GameExplorer.nsh and include it in an installer script. If GameuxInstallHeader.dll is not in the same directory as the installer script, define GAME_EXPLORER_HELPER_PATH as the path to that dll.
Adding a Game
${GameExplorer_AddGame} all "$INSTDIR\gdf.dll" "$INSTDIR" "$INSTDIR\game.exe" "" \ ".gamesave" # "all" means to install for all users; "current" is also supported # "$INSTDIR\gdf.dll" is the exe or dll with the GDF resource # "$INSTDIR" is the installation directory # "$INSTDIR\game.exe" is the path to the game (or a launcher application) # The next argument is the parameters to pass to the game or launcher # ".gamesave" is the save game extension. This can be left blank if you don't want the # save games associated with the game.
Adding tasks
${GameExplorer_AddPlayTask} "Tournament Mode" "$INSTDIR\game.exe" "/tournament" # "Tournament Mode" is the description of the play task # "$INSTDIR\game.exe" is the path to the game or launcher # "/tournament" is the parameter for the game or launcher
${GameExplorer_AddSupportTask} "Home Page" "http://www.game.com/" # "Home Page" is the description of the support task # "http://www.game.com/" is the url for the support link
Tasks are automatically added for the game most recently added.
Removing a Game
${GameExplorer_RemoveGame} all "$INSTDIR\gdf.dll" "$INSTDIR" "$INSTDIR\game.exe" \ ".gamesave" # "all" means to uninstall for all users; "current" is also supported # "$INSTDIR\gdf.dll" is the exe or dll with the GDF resource # "$INSTDIR" is the installation directory # "$INSTDIR\game.exe" is the path to the game (or a launcher application) # ".gamesave" is the save game extension. This can be left blank if you didn't associate the # save games with the game.