Windows Installer: Check if already installed

Installer update:

- Updated welcome.bmp image, simple screenshot from the game looks a
little cleaner (see attached preview).

- Added a check to see if the game is already installed, this is done
via a registry read which pulls out the uninstall path, parses it and
uses that as the currently installed path. The installer then proceeds
with this path for the install. If this data isn't found in the registry
the default directory is used. Tested on Windows 8.0 x64 and Windows 7
x64(TheCycoONE), compiled clean on MakeNSIS v3.0b1.

- Small cleanup of the .nsi file for readability and to remove some old
unused code.
This commit is contained in:
SimplyRyan
2015-02-20 21:39:24 +00:00
committed by Stephen E. Baker
parent 74e09428b3
commit 490849a4f7
2 changed files with 30 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
; Copyright (c) 2012 Edvin "Lego3" Linge
; Copyright (c) 2015 Edvin "Lego3" Linge
; Permission is hereby granted, free of charge, to any person obtaining a copy of
; this software and associated documentation files (the "Software"), to deal in
@@ -19,6 +19,7 @@
; SOFTWARE.
; Base Script generated by the HM NIS Edit Script Wizard.
; Last compiled on MakeNSIS v3.0b1.
;---------------------------------- Definitions for the game -----------------------------------
@@ -35,9 +36,14 @@ InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
; MUI 1.67 compatible ------
!include "MUI.nsh"
; Compatible with x64 systems
!include "x64.nsh"
; Include FileFunc to allow GetParent support
!include "FileFunc.nsh"
!insertmacro GetParent
; This is needed to be able to install into the program files directory
RequestExecutionLevel admin
@@ -59,19 +65,20 @@ RequestExecutionLevel admin
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "..\LICENSE.txt"
; Directory page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ValidateDirectory
!insertmacro MUI_PAGE_DIRECTORY
; Another directory page to choose where the original game is
Var ORIGINALPATH
Var CONFIGAPPDATA
;!define MUI_DIRECTORYPAGE_TEXT_TOP $(original_text)
;!define MUI_DIRECTORYPAGE_VARIABLE $OriginalPath
;!define MUI_DIRECTORYPAGE_TEXT_DESTINATION $(original_folder)
;!insertmacro MUI_PAGE_DIRECTORY
Page Custom OptionsPage OptionsPageLeave
; Start menu page
var ICONS_GROUP
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}"
@@ -79,8 +86,10 @@ var ICONS_GROUP
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\CorsixTH_SDL.exe"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
@@ -126,11 +135,20 @@ Icon "..\CorsixTH\corsixTH.ico"
Function .onInit
; Set default Theme Hospital vanilla install directory.
; TODO: try to find the correct one in the registry (or "AppData") from
; previous install of CorsixTH
StrCpy $OriginalPath "$PROGRAMFILES\Bullfrog\Hospital\"
${If} ${RunningX64}
; Read Uninstall data from CorsixTH section of the registry.
ReadRegStr $R0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
; Check to see if game is already installed.
; Temporary $R0 NSIS register is used for storage while we pull the registry data, if CorsixTH data exists we parse the path and set it as the installer location, if not the installer defaults to stock location.
${If} $R0 != ''
${GetParent} $R0, $R0
StrCpy $INSTDIR $R0
${Else}
${If} ${RunningX64}
StrCpy $INSTDIR $PROGRAMFILES64\${PRODUCT_NAME}
${EndIf}
${EndIf}
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
@@ -159,6 +177,7 @@ Function OptionsPage
ReserveFile "OptionsPage.ini"
!insertmacro MUI_HEADER_TEXT $(options_title) $(options_subtitle)
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "OptionsPage.ini"
; The ini file is actually static. Set strings so that they are localized.
WriteINIStr "$PLUGINSDIR\OptionsPage.ini" "Field 1" "Text" $(save_in_appdata)
WriteINIStr "$PLUGINSDIR\OptionsPage.ini" "Field 3" "Text" $(original_folder)
@@ -206,6 +225,7 @@ Section "MainSection" SEC01
${If} $CONFIGAPPDATA == 1
SetOutPath "$APPDATA\CorsixTH"
IfFileExists "$APPDATA\CorsixTH\Saves" saves
; Don't overwrite previous installations though!
CreateDirectory "$APPDATA\CorsixTH\Saves"
${Else}
@@ -229,12 +249,13 @@ Section "MainSection" SEC01
!insertmacro ReplaceInFile config_template.txt SCREEN_SIZE_WIDTH "$0"
!insertmacro ReplaceInFile config_template.txt SCREEN_SIZE_HEIGHT "$1"
!insertmacro ReplaceInFile config_template.txt SCREEN_FULLSCREEN "true"
; TODO: Let the user choose if new music files exist and where they are in that case.
Rename config_template.txt config.txt
Delete config_t*
; Continue here if the saves folder and config file was already present
saves:
; The three other needed folders
; The old Lua folder is deleted first, if any exists, so that the game can start properly.
SetOutPath "$INSTDIR\Lua"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

After

Width:  |  Height:  |  Size: 218 KiB