;BTS Install Script
;Written by André Götze aka Jean Elcard, phungus420 & James Nicholls aka NikNaks
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
!include "LogicLib.nsh"
;--------------------------------
;Constants
;These are the variables you need to define for your mod
!define NAME "Charlemagne" ;Full Name of Mod
!define VERSION "X.X.X" ;Mod Version Number
!define MOD_LOC "Charlemagne" ;Name of Mod Folder
!define SHORT_NAME "Charlemagne" ;Abreviated mod name, example for WolfRevolution I would use WolfRev
!define FIRAXIS_REG_ROOT "HKLM" ;Do not change this block
!define MOD_REG_ROOT "HKCU"
!define FIRAXIS_REG_KEY "Software\Firaxis Games"
!define BTSREGKEY "SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword" ;Do not change this block
!define MYBTSDIR "C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword" ;Path where your Beyond the Sword .exe is
!define MYCLSDIR "C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\${MOD_LOC}" ;Path where your mod is (Leave ${MOD_LOC} on the end of the path)
!define RAW_ICON "Legends4b.ico" ;place your icon in your mod folder change someicon to the icon's name
!define ICON "${MYCLSDIR}\${RAW_ICON}"
!define MUI_ICON "${ICON}"
;You should not need to change anything below this line
;Source Code scripting removed
;--------------------------------
;General
;Name and file
Name "${NAME}"
!ifdef ICON
Icon "${ICON}"
!endif
OutFile "${NAME} v${VERSION} Setup.exe"
;Default installation folder
InstallDir ""
;Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
;Custom Varaiables
Var INSTDIR1 ; Mods
Var StartMenuFolder
Var CurrentPage ; important for directory verification
Function findINSTDIR1
Push $0
ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${BTSREGKEY}" 'INSTALLDIR'
${If} ${FileExists} $0
StrCpy $INSTDIR1 $0
Goto done
${EndIf}
# standard Civ4:BTS
ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${FIRAXIS_REG_KEY}\Sid Meier's Civilization 4 - Beyond the Sword" 'INSTALLDIR'
${If} ${FileExists} $0
StrCpy $INSTDIR1 $0
Goto done
${EndIf}
# Civ4 Complete
ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${FIRAXIS_REG_KEY}\Sid Meier's Civilization 4 Complete" 'INSTALLDIR'
${If} ${FileExists} $0
StrCpy $0 "$0\Beyond the Sword"
${If} ${FileExists} $0
StrCpy $INSTDIR1 $0
Goto done
${EndIf}
${EndIf}
# Civ4 Gold
ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${FIRAXIS_REG_KEY}\Sid Meier's Civilization 4 Gold" 'INSTALLDIR'
${If} ${FileExists} $0
StrCpy $0 "$0\Beyond the Sword"
${If} ${FileExists} $0
StrCpy $INSTDIR1 $0
Goto done
${EndIf}
${EndIf}
done:
Pop $0
FunctionEnd
;--------------------------------
Function .onInit
SetShellVarContext "current"
Call findINSTDIR1
StrCpy $INSTDIR "$INSTDIR1"
ReadRegStr $R0 ${FIRAXIS_REG_ROOT} \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" \
"UninstallString"
StrCmp $R0 "" done
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"${NAME} is already installed. $\n$\nDo you wish to uninstall?" \
IDOK uninst
Abort
;Run the uninstaller
uninst:
ClearErrors
ExecWait '"$INSTDIR\Mods\${MOD_LOC}\Uninstall.exe" _?=$INSTDIR'
done:
FunctionEnd
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
!define MUI_HEADERIMAGE
ShowInstDetails show
ShowUninstDetails show
;--------------------------------
;Pages
!define MUI_CUSTOMFUNCTION_GUIINIT myOnGUIInit
; INSTALLER PAGES:
!define MUI_WELCOMEPAGE_TITLE "Welcome to the Setup of ${SHORT_NAME} v${VERSION}"
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of ${NAME}.$\n$\n\
Please ensure that Civilization 4 is not running while installing, \
otherwise the installation may not work as expected.$\n$\nVersion ${VERSION}$\n$\nRequires Beyond the Sword 3.17.$\n$\n\
Click $\"Next$\" to continue."
!insertmacro MUI_PAGE_WELCOME
!define MUI_COMPONENTSPAGE_SMALLDESC
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_DIRECTORYPAGE_VARIABLE $INSTDIR1
!define MUI_PAGE_CUSTOMFUNCTION_PRE onInitDirectoryPage1
!define MUI_PAGE_HEADER_TEXT "${SHORT_NAME} v${VERSION}"
!define MUI_PAGE_HEADER_SUBTEXT "Please locate your $\"Beyond the Sword$\" folder"
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install ${NAME} in the Mods folder of the folder below. $\n$\n\
If the automatic folder detection should have failed, then type in or browse to the correct location. $\n$\n\
Click Install to complete the installation."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Your $\"Beyond the Sword$\" folder:"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
;Source code scripting removed
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR1\Civ4BeyondSword.exe"
!define MUI_FINISHPAGE_RUN_PARAMETERS "mod=\${MOD_LOC}"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!insertmacro MUI_PAGE_FINISH
;UN INSTALLER PAGES:
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
LangString DESC_Section1 ${LANG_ENGLISH} "Installs ${NAME} for Beyond the Sword."
LangString DESC_Section4 ${LANG_ENGLISH} "Adds a shortcut on the Start Menu."
LangString DESC_Section5 ${LANG_ENGLISH} "Creates a shortcut on the Desktop, allowing you to launch the mod \
without the need to load BtS first."
LangString DESC_Section6 ${LANG_ENGLISH} "Creates a shortcut on the Quick Launch bar, allowing you to launch \
the mod directly from the task bar."
;--------------------------------
;Installer Sections
;the mod files itself:
Section /o "${MOD_LOC}" Section1
SectionIn RO
SetOutPath "$INSTDIR1\Mods\${MOD_LOC}"
File /r "${MYCLSDIR}\*.*"
; write uninstall information to the registry
WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "DisplayName" "${NAME}"
WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "UninstallString" "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir" "$INSTDIR1\Mods\"
WriteUninstaller "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
SectionEnd
Section "Start Menu Shortcut" Section4
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "Desktop Shortcut" Section5
CreateShortCut "$DESKTOP\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
SectionEnd
Section "Quick Launch Shortcut" Section6
CreateShortCut "$QUICKLAUNCH\${SHORT_NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
SectionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} $(DESC_Section1)
!insertmacro MUI_DESCRIPTION_TEXT ${Section4} $(DESC_Section4)
!insertmacro MUI_DESCRIPTION_TEXT ${Section5} $(DESC_Section5)
!insertmacro MUI_DESCRIPTION_TEXT ${Section6} $(DESC_Section6)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "un.Core" SecUnCore
;Delete Files
RMDir /r "$0\${MOD_LOC}\*.*"
;Remove the installation directory
RMDir "$0\${MOD_LOC}"
;Delete Desktop Shortcut
Delete "$DESKTOP\${NAME}.lnk"
;Delete Quicklaunch Shortcut
Delete "$QUICKLAUNCH\${SHORT_NAME}.lnk"
SectionEnd
Section "-un.StartMenu" SecUnStartMenu
;Delete Start Menu Shortcut
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
RMDir "$SMPROGRAMS\$StartMenuFolder"
SectionEnd
Section "-un.Registry" SecUnRegistry
DeleteRegValue "${MOD_REG_ROOT}" "Software\${MOD_LOC}" "Start Menu"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
SectionEnd
Section "-un.Uninstaller" SecUnUninstaller
# delete uninstaller
Delete "$INSTDIR\Uninstall.exe"
SectionEnd
Function un.onInit
;get mod install path of from the registy
SetShellVarContext "current"
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
FunctionEnd
;--------------------------------
;Installer Functions
Function myOnGUIInit
SectionGetFlags ${Section1} $0
IntOp $R0 $0 | ${SF_SELECTED}
SectionSetFlags ${Section1} $R0
FunctionEnd
Function .onVerifyInstDir
StrCmp $CurrentPage "DirectoryPage1" check1 valid
check1:
IfFileExists "$INSTDIR1\Civ4BeyondSword.exe" valid invalid
valid:
Return
invalid:
Abort
FunctionEnd
Function onInitDirectoryPage1
StrCpy $CurrentPage "DirectoryPage1"
;Section 1 selected?
SectionGetFlags ${Section1} $0
IntOp $R0 $0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} checkRegEntry
Abort ;skip page
checkRegEntry:
StrCmp $INSTDIR "" 0 checkDefaultLocation
StrCpy $INSTDIR1 "" ;we know nothing
Return
checkDefaultLocation:
StrCpy $INSTDIR1 "$INSTDIR" ;found it!
FunctionEnd
;--------------------------------