From cbb2898db6b46d0bf5d19cde30365ba3f9f6a42a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Brammer?= <gbrammer@gmx.de>
Date: Sun, 30 Oct 2011 16:16:14 +0100
Subject: [PATCH 06/10] win32: register with the Game Explorer

---
 src/res/WindowsGamesExplorer.xml |   17 ++++
 src/res/engine.rc                |  103 +--------------------
 tools/install/GameExplorer.nsh   |  184 ++++++++++++++++++++++++++++++++++++++
 tools/install/oc.nsi             |   73 ++++++++++------
 4 files changed, 252 insertions(+), 125 deletions(-)
 create mode 100644 src/res/WindowsGamesExplorer.xml
 create mode 100644 tools/install/GameExplorer.nsh

diff --git a/src/res/WindowsGamesExplorer.xml b/src/res/WindowsGamesExplorer.xml
new file mode 100644
index 0000000..d4f5a72
--- /dev/null
+++ b/src/res/WindowsGamesExplorer.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<GameDefinitionFile xmlns:baseTypes="urn:schemas-microsoft-com:GamesExplorerBaseTypes.v1" xmlns="urn:schemas-microsoft-com:GameDescription.v1">
+    <GameDefinition gameID="{C90AA63B-E8DB-4EAF-88EC-B5257A86FF5A}">
+        <Name>OpenClonk</Name>
+        <Genres>
+            <Genre>Action</Genre>
+            <Genre>Strategy</Genre>
+        </Genres>
+        <Version>
+            <VersionFile path="Clonk.exe" />
+        </Version>
+        <SavedGames baseKnownFolderID="{f1b32785-6fba-4fcf-9d55-7b8e7f157091}" path="OpenClonk" />
+        <Developers>
+            <Developer URI="http://openclonk.org">OpenClonk Project</Developer>
+        </Developers>
+    </GameDefinition>
+</GameDefinitionFile>
\ No newline at end of file
diff --git a/src/res/engine.rc b/src/res/engine.rc
index a7d7ae4..8bfa48c 100644
--- a/src/res/engine.rc
+++ b/src/res/engine.rc
@@ -4,29 +4,16 @@
 
 #include "C4Version.h"
 
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
 #include <winresrc.h>
-#define IDC_STATIC (-1)
 
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// German (Germany) resources
+#define IDC_STATIC (-1)
 
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
-#ifdef _WIN32
 LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
 #pragma code_page(1252)
-#endif //_WIN32
 
 /////////////////////////////////////////////////////////////////////////////
 //
-// Icon
+// Icons
 //
 
 // Icon with lowest ID value placed first to ensure application icon
@@ -44,33 +31,13 @@ IDI_10_OCV              ICON    DISCARDABLE     "ocv.ico"
 IDI_11_OCL              ICON    DISCARDABLE     "ocl.ico"
 IDI_13_OCU              ICON    DISCARDABLE     "ocu.ico"
 
-#ifdef APSTUDIO_INVOKED
 /////////////////////////////////////////////////////////////////////////////
 //
-// TEXTINCLUDE
+// Game Explorer Integration
 //
 
-1 TEXTINCLUDE DISCARDABLE
-BEGIN
-    "resource.h\0"
-END
-
-2 TEXTINCLUDE DISCARDABLE
-BEGIN
-    "#include ""afxres.h""\r\n"
-    "\0"
-END
+__GDF_XML DATA	"WindowsGamesExplorer.xml"
 
-3 TEXTINCLUDE DISCARDABLE
-BEGIN
-    "\r\n"
-    "\0"
-END
-
-#endif    // APSTUDIO_INVOKED
-
-
-#ifndef _MAC
 /////////////////////////////////////////////////////////////////////////////
 //
 // Version
@@ -113,12 +80,9 @@ BEGIN
     END
 END
 
-#endif    // !_MAC
-
-
 /////////////////////////////////////////////////////////////////////////////
 //
-// Dialog
+// Dialogs
 //
 
 IDD_CONSOLE DIALOGEX 0, 0, 232, 127
@@ -203,50 +167,6 @@ BEGIN
                     ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
 END
 
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO DISCARDABLE
-BEGIN
-    IDD_CONSOLE, DIALOG
-    BEGIN
-        LEFTMARGIN, 1
-        RIGHTMARGIN, 230
-        TOPMARGIN, 1
-        BOTTOMMARGIN, 126
-    END
-
-    IDD_PROPERTIES, DIALOG
-    BEGIN
-        LEFTMARGIN, 2
-        RIGHTMARGIN, 166
-        TOPMARGIN, 2
-        BOTTOMMARGIN, 60
-    END
-
-    IDD_TOOLS, DIALOG
-    BEGIN
-        LEFTMARGIN, 2
-        RIGHTMARGIN, 192
-        TOPMARGIN, 2
-        BOTTOMMARGIN, 53
-    END
-
-    IDD_COMPONENT, DIALOG
-    BEGIN
-        LEFTMARGIN, 1
-        RIGHTMARGIN, 276
-        TOPMARGIN, 1
-        BOTTOMMARGIN, 148
-    END
-END
-#endif    // APSTUDIO_INVOKED
-
-
 /////////////////////////////////////////////////////////////////////////////
 //
 // Bitmap
@@ -322,16 +242,3 @@ BEGIN
     END
 END
 
-#endif    // German (Germany) resources
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif    // not APSTUDIO_INVOKED
-
diff --git a/tools/install/GameExplorer.nsh b/tools/install/GameExplorer.nsh
new file mode 100644
index 0000000..a1f7b17
--- /dev/null
+++ b/tools/install/GameExplorer.nsh
@@ -0,0 +1,184 @@
+# user interface
+
+!define GameExplorer_GenerateGUID '!insertmacro GameExplorer_GenerateGUID'
+!define GameExplorer_AddGame      '!insertmacro GameExplorer_AddGame'
+!define GameExplorer_UpdateGame   '!insertmacro GameExplorer_UpdateGame'
+!define GameExplorer_RemoveGame   '!insertmacro GameExplorer_RemoveGame'
+
+# internal stuff
+
+!define CLSCTX_INPROC_SERVER 1
+!define IID_IGameExplorer  {E7B2FB72-D728-49B3-A5F2-18EBF5F1349E}
+!define CLSID_GameExplorer {9A5EA990-3034-4D6F-9128-01F3C61022BC}
+
+!define GIS_CURRENT_USER 2
+!define GIS_ALL_USERS    3
+
+!define IGameExplorer_QueryInterface 0
+!define IGameExplorer_AddRef         1
+!define IGameExplorer_Release        2
+!define IGameExplorer_AddGame        3
+!define IGameExplorer_RemoveGame     4
+!define IGameExplorer_UpdateGame     5
+!define IGameExplorer_VerifyAccess   6
+
+# includes
+
+!include LogicLib.nsh
+
+# the actual code
+
+!macro GameExplorer_GenerateGUID
+
+  System::Call 'ole32::CoCreateGuid(g .s)'
+
+!macroend
+
+!macro GameExplorer_AddGame CONTEXT GDF INSTDIR EXE GUID
+
+  !define __GAME_EXPLORER_UNIQUE "${__LINE__}${__FILE__}"
+
+  Push $0
+  Push $1
+
+  Push $R0
+  Push $R1
+  Push $R2
+  Push $R3
+
+  Push "${EXE}"
+  Push "${GUID}"
+  Push "${INSTDIR}"
+  Push "${GDF}"
+
+  Pop $R0 # == ${GDF}
+  Pop $R1 # == ${INSTDIR}
+  Pop $R2 # == ${GUID}
+  Pop $R3 # == ${EXE}
+
+  ClearErrors
+
+  System::Call "ole32::CoCreateInstance( \
+    g '${CLSID_GameExplorer}', i 0, \
+    i ${CLSCTX_INPROC_SERVER}, \
+    g '${IID_IGameExplorer}', *i .r1) i .r0"
+
+  ${If} $0 != 0 # S_OK
+
+    SetErrors
+    Goto "done_${__GAME_EXPLORER_UNIQUE}"
+
+  ${EndIf}
+
+  ${If} ${CONTEXT} == AllUsers
+
+    System::Call "$1->${IGameExplorer_AddGame}(w R0, w R1, i ${GIS_ALL_USERS}, g R2) i .r0"
+
+  ${Else}
+
+    System::Call "$1->${IGameExplorer_AddGame}(w R0, w R1, i ${GIS_CURRENT_USER}, g R2) i .r0"
+
+  ${EndIf}
+
+  ${If} $0 != 0 # S_OK
+
+    SetErrors
+
+  ${Else}
+
+    # Create play task
+
+    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\$R2\PlayTasks\0
+    CreateShortcut $APPDATA\Microsoft\Windows\GameExplorer\$R2\PlayTasks\0\Play.lnk $R3
+
+  ${EndIf}
+
+  System::Call "$1->${IGameExplorer_Release}()"
+
+  "done_${__GAME_EXPLORER_UNIQUE}:"
+
+    Pop $R3
+    Pop $R2
+    Pop $R1
+    Pop $R0
+
+    Pop $1
+    Pop $0
+
+  !undef __GAME_EXPLORER_UNIQUE
+
+!macroend
+
+!macro _GameExplorer_GUID_Function Function GUID
+
+  !define __GAME_EXPLORER_UNIQUE "${__LINE__}${__FILE__}"
+
+  Push $0
+  Push $1
+  Push $2
+  Push $3
+  Push $4
+  Push $5
+
+  Push $R0
+
+  Push "${GUID}"
+
+  Pop $R0 # == ${GUID}
+
+  System::Alloc 16
+  Exch $R0
+  System::Call "ole32::CLSIDFromString(w s, i R0)"
+  System::Call "*$R0(i .r2, i .r3, i .r4, i .r5)"
+  System::Free $R0
+
+  ClearErrors
+
+  System::Call "ole32::CoCreateInstance( \
+    g '${CLSID_GameExplorer}', i 0, \
+    i ${CLSCTX_INPROC_SERVER}, \
+    g '${IID_IGameExplorer}', *i .r1) i .r0"
+
+  ${If} $0 != 0 # S_OK
+
+    SetErrors
+    Goto "done_${__GAME_EXPLORER_UNIQUE}"
+
+  ${EndIf}
+
+  System::Call "$1->${Function}(i r2, i r3, i r4, i r5) i .r0"
+
+  ${If} $0 != 0 # S_OK
+
+    SetErrors
+
+  ${EndIf}
+
+  System::Call "$1->${IGameExplorer_Release}()"
+
+  "done_${__GAME_EXPLORER_UNIQUE}:"
+
+    Pop $R0
+
+    Pop $5
+    Pop $4
+    Pop $3
+    Pop $2
+    Pop $1
+    Pop $0
+
+  !undef __GAME_EXPLORER_UNIQUE
+
+!macroend
+
+!macro GameExplorer_UpdateGame GUID
+
+  !insertmacro _GameExplorer_GUID_Function ${IGameExplorer_UpdateGame} "${GUID}"
+
+!macroend
+
+!macro GameExplorer_RemoveGame GUID
+
+  !insertmacro _GameExplorer_GUID_Function ${IGameExplorer_RemoveGame} "${GUID}"
+
+!macroend
diff --git a/tools/install/oc.nsi b/tools/install/oc.nsi
index e0d531b..df05750 100644
--- a/tools/install/oc.nsi
+++ b/tools/install/oc.nsi
@@ -17,6 +17,7 @@
 !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_INSTDIR}"
 !define PRODUCT_USER_KEY "Software\${PRODUCT_COMPANY}\OpenClonk"
 !define PRODUCT_COMPANY_KEY "Software\${PRODUCT_COMPANY}"
+!define PRODUCT_GAME_EXPLORER_INSTANCE {366C86B6-FD74-BD8E-0F02-F0AE847304A9}
 
 Name "${PRODUCT_NAME}"
 SetCompressor lzma
@@ -71,6 +72,9 @@ LangString MUI_TEXT_USERPATH ${LANG_English} "User Path"
 ;ReserveFile "${NSISDIR}\Plugins\*.dll"
 ; MUI end ------
 
+; Game Explorer
+!include "${SRCDIR}/tools/install\GameExplorer.nsh"
+
 ShowInstDetails show
 ShowUnInstDetails show
 
@@ -78,39 +82,49 @@ Section
   SetOutPath "$INSTDIR"
   SetOverwrite on
 
-; Main program files  
+  ; Main program files
   File "${CLONK}"
   File "${C4GROUP}"
 
   File "*.dll"
 
   File "*.oc?"
-  
+
   File "${SRCDIR}\planet\AUTHORS"
   File "${SRCDIR}\planet\COPYING"
   File "${SRCDIR}\licenses\LGPL.txt"
   File "${SRCDIR}\Credits.txt"
-  
-; Create user path (works for the installing user only... might also want to put an info.txt dummy in there...)
-  CreateDirectory "$APPDATA\OpenClonk"
 
-; Create desktop shortcut
-  CreateShortcut "$DESKTOP\OpenClonk.lnk" "$INSTDIR\Clonk.exe"
+  ; Create user path (works for the installing user only... might also want to put an info.txt dummy in there...)
+  CreateDirectory "$APPDATA\OpenClonk"
 
-; Create website url in program directory
+  ; Create website url in program directory
   WriteIniStr "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
 
-; Create user path shortcut in program directory
-  CreateShortCut "$INSTDIR\$(MUI_TEXT_USERPATH).lnk" "%APPDATA%\OpenClonk"
+  ; Game Explorer integration
+  ${GameExplorer_AddGame} $MultiUser.InstallMode $INSTDIR\Clonk.exe $INSTDIR $INSTDIR\Clonk.exe ${PRODUCT_GAME_EXPLORER_INSTANCE}
 
-  ; Start menu shortcuts
-  CreateDirectory "$SMPROGRAMS\OpenClonk"
-  CreateShortCut "$SMPROGRAMS\OpenClonk\OpenClonk.lnk" "$INSTDIR\Clonk.exe"
-  CreateShortCut "$SMPROGRAMS\OpenClonk\OpenClonk Editor.lnk" "$INSTDIR\Clonk.exe" "--editor"
-  CreateShortCut "$SMPROGRAMS\OpenClonk\${PRODUCT_WEB_SITE_NAME}.lnk" "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url"
-  CreateShortCut "$SMPROGRAMS\OpenClonk\$(MUI_TEXT_USERPATH).lnk" "%APPDATA%\OpenClonk"
+  IfErrors StartMenu 0
+    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\SupportTasks\0
+    CreateShortcut $APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\SupportTasks\0\Editor.lnk $INSTDIR\Clonk.exe --editor
+    goto EndStartMenu
+
+  StartMenu:
+    ; Create desktop shortcut
+    CreateShortcut "$DESKTOP\OpenClonk.lnk" "$INSTDIR\Clonk.exe"
 
-; Uninstaller info
+    ; Create user path shortcut in program directory
+    CreateShortCut "$INSTDIR\$(MUI_TEXT_USERPATH).lnk" "%APPDATA%\OpenClonk"
+
+    ; Start menu shortcuts
+    CreateDirectory "$SMPROGRAMS\OpenClonk"
+    CreateShortCut "$SMPROGRAMS\OpenClonk\OpenClonk.lnk" "$INSTDIR\Clonk.exe"
+    CreateShortCut "$SMPROGRAMS\OpenClonk\OpenClonk Editor.lnk" "$INSTDIR\Clonk.exe" "--editor"
+    CreateShortCut "$SMPROGRAMS\OpenClonk\${PRODUCT_WEB_SITE_NAME}.lnk" "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url"
+    CreateShortCut "$SMPROGRAMS\OpenClonk\$(MUI_TEXT_USERPATH).lnk" "%APPDATA%\OpenClonk"
+  EndStartMenu:
+
+  ; Uninstaller info
   WriteUninstaller "$INSTDIR\uninst.exe"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "UninstallString" \
@@ -123,7 +137,7 @@ Section
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"
-; Register file types  
+  ; Register file types
   WriteRegStr HKCR ".ocs" "" "OpenClonk.Scenario"
   WriteRegStr HKCR ".ocs\Content Type" "" "vnd.clonk.c4group"
   WriteRegStr HKCR ".ocg" "" "OpenClonk.Group"
@@ -146,7 +160,8 @@ Section
   WriteRegStr HKCR ".ocl\Content Type" "" "vnd.clonk.c4group"
   WriteRegStr HKCR ".ocu" "" "OpenClonk.Update"
   WriteRegStr HKCR ".ocu\Content Type" "" "vnd.clonk.c4group"
-; Register file classes  
+
+  ; Register file classes
   WriteRegStr HKCR "OpenClonk.Scenario" "" "OpenClonk Scenario"
   WriteRegStr HKCR "OpenClonk.Scenario\DefaultIcon" "" "$INSTDIR\Clonk.exe,1"
   WriteRegStr HKCR "OpenClonk.Group" "" "OpenClonk Group"
@@ -169,7 +184,8 @@ Section
   WriteRegStr HKCR "OpenClonk.Weblink\DefaultIcon" "" "$INSTDIR\Clonk.exe,10"
   WriteRegStr HKCR "OpenClonk.Update" "" "OpenClonk Update"
   WriteRegStr HKCR "OpenClonk.Update\DefaultIcon" "" "$INSTDIR\Clonk.exe,11"
-; Register additional file handling
+
+  ; Register additional file handling
   WriteRegStr HKCR "OpenClonk.Update\Shell\Update" "" "Update"
   WriteRegStr HKCR "OpenClonk.Update\Shell\Update\Command" "" "$\"$INSTDIR\Clonk.exe$\" $\"%1$\""
 
@@ -191,22 +207,29 @@ Section Uninstall
   Delete "$INSTDIR\LGPL.txt"
   Delete "$INSTDIR\OpenSSL.txt"  ; For installations up to 5.2.x
   Delete "$INSTDIR\Credits.txt"
-  
+
   Delete "$INSTDIR\uninst.exe"
   Delete "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url"
   Delete "$INSTDIR\$(MUI_TEXT_USERPATH).lnk"
 
   RMDir "$INSTDIR"
 
+  ; Game Explorer
+  ${GameExplorer_RemoveGame} ${PRODUCT_GAME_EXPLORER_INSTANCE}
+
   ; Desktop shortcut
   Delete "$DESKTOP\OpenClonk.lnk"
+
+  ; Start menu shortcuts
+  Delete "$SMPROGRAMS\OpenClonk\*.lnk"
+  RMDir "$SMPROGRAMS\OpenClonk"
 	
   ; Registry: config
   DeleteRegKey HKCU "${PRODUCT_USER_KEY}"
   DeleteRegKey /ifempty HKCU "${PRODUCT_COMPANY_KEY}"
   ; Registry: Uninstaller info
   DeleteRegKey SHELL_CONTEXT "${PRODUCT_UNINST_KEY}"
-  
+
   ; Registry: classes
   DeleteRegKey HKCR ".ocs"
   DeleteRegKey HKCR "OpenClonk.Scenario"
@@ -230,9 +253,5 @@ Section Uninstall
   DeleteRegKey HKCR "OpenClonk.Weblink"
   DeleteRegKey HKCR ".ocu"
   DeleteRegKey HKCR "OpenClonk.Update"
-  
-  ; Start menu shortcuts
-  Delete "$SMPROGRAMS\OpenClonk\*.lnk"
-  RMDir "$SMPROGRAMS\OpenClonk"
-  
+
 SectionEnd
-- 
1.7.7.1

