From fb90bef8bb76d9e69906c6515b877765578da93a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Brammer?= <gbrammer@gmx.de>
Date: Tue, 1 Nov 2011 20:37:58 +0100
Subject: [PATCH 08/10] win32: Installer uses a per-installation game explorer
 guid

---
 tools/install/GameExplorer.nsh |    7 -------
 tools/install/oc.nsi           |   37 +++++++++++++++++++++++++------------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/tools/install/GameExplorer.nsh b/tools/install/GameExplorer.nsh
index a1f7b17..c17b9cc 100644
--- a/tools/install/GameExplorer.nsh
+++ b/tools/install/GameExplorer.nsh
@@ -84,13 +84,6 @@
 
     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}()"
diff --git a/tools/install/oc.nsi b/tools/install/oc.nsi
index 25d23e7..bebf8fa 100644
--- a/tools/install/oc.nsi
+++ b/tools/install/oc.nsi
@@ -17,7 +17,6 @@
 !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
@@ -102,14 +101,24 @@ Section
   WriteIniStr "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
 
   ; Game Explorer integration
-  ${GameExplorer_AddGame} $MultiUser.InstallMode $INSTDIR\Clonk.exe $INSTDIR $INSTDIR\Clonk.exe ${PRODUCT_GAME_EXPLORER_INSTANCE}
-
-  IfErrors StartMenu 0
-    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\PlayTasks\1
-    CreateShortcut $APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\PlayTasks\1\Editor.lnk $INSTDIR\Clonk.exe --editor
-    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\SupportTasks\0
-    CreateShortcut "$APPDATA\Microsoft\Windows\GameExplorer\${PRODUCT_GAME_EXPLORER_INSTANCE}\SupportTasks\0\${PRODUCT_WEB_SITE_NAME}.lnk" "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url"
-    goto EndStartMenu
+  ReadINIStr $0 $INSTDIR\GameExplorer.txt GameExplorer InstanceID
+  IfErrors 0 UpdateInstallation
+    ${GameExplorer_GenerateGUID}
+    Pop $0
+    WriteIniStr $INSTDIR\GameExplorer.txt GameExplorer InstanceID $0
+    ${GameExplorer_AddGame} $MultiUser.InstallMode $INSTDIR\Clonk.exe $INSTDIR $INSTDIR\Clonk.exe $0
+    IfErrors StartMenu EndStartMenu
+    ; Create tasks. FIXME: Do this on XP along with the registry keys to support an update to a newer windows version
+    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\$0\PlayTasks\0
+    CreateShortcut $APPDATA\Microsoft\Windows\GameExplorer\$0\PlayTasks\0\Play.lnk $INSTDIR\Clonk.exe
+    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\$0\PlayTasks\1
+    CreateShortcut $APPDATA\Microsoft\Windows\GameExplorer\$0\PlayTasks\1\Editor.lnk $INSTDIR\Clonk.exe --editor
+    CreateDirectory $APPDATA\Microsoft\Windows\GameExplorer\$0\SupportTasks\0
+    CreateShortcut "$APPDATA\Microsoft\Windows\GameExplorer\$0\SupportTasks\0\${PRODUCT_WEB_SITE_NAME}.lnk" "$INSTDIR\${PRODUCT_WEB_SITE_NAME}.url"
+    IfErrors StartMenu EndStartMenu
+  UpdateInstallation:
+    ${GameExplorer_UpdateGame} $0
+    IfErrors StartMenu EndStartMenu
 
   StartMenu:
     ; Create desktop shortcut
@@ -127,6 +136,7 @@ Section
   EndStartMenu:
 
   ; Uninstaller info
+  ; FIXME: Use GameExplorer instanceid instead of ${PRODUCT_INSTDIR}
   WriteUninstaller "$INSTDIR\uninst.exe"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
   WriteRegStr SHELL_CONTEXT "${PRODUCT_UNINST_KEY}" "UninstallString" \
@@ -195,6 +205,11 @@ SectionEnd
 
 
 Section Uninstall
+  ; Game Explorer
+  ReadINIStr $0 $INSTDIR\GameExplorer.txt GameExplorer InstanceID
+  IfErrors NoGameExplorer 0
+    ${GameExplorer_RemoveGame} $0
+  NoGameExplorer:
 
   ; Installation directory
   Delete "$INSTDIR\Clonk.exe"
@@ -211,14 +226,12 @@ Section Uninstall
   Delete "$INSTDIR\Credits.txt"
 
   Delete "$INSTDIR\uninst.exe"
+  Delete "$INSTDIR\GameExplorer.txt"
   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"
 
-- 
1.7.7.1

