Reg Key and Install Directory for Complete

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
Hey it's recently been brought to my attention that my install script may not work for users of complete. Since BUG uses an NSIS install script, and I'm pretty sure you guys have solved it, I figure you might have a solution for me. Here is what I currently have:

Code:
  ;Default installation folder
  InstallDir ""

  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "${BTSREGKEY}" "INSTALLDIR"

  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin

So How could I write actual code that accomplishes this pseudo code:

Code:
  ;Default installation folder
  InstallDir ""

  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "${BTSREGKEY}" "INSTALLDIR"
  ;if not found
     ;InstallDirRegKey HKLM "${WhateverComplete'sBTSRegKeyIs}" "INSTALLDIR"

  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin
 
OK, if I did something wrong and don't deserve an answer for this, where is the BUG install script? I know I've heard it said it's on the SVN, but I can't find anything on sourceforge that says install script.
 
Chillax, man! :D You can't subscribe to forums like you can threads, so I usually check the main forum once or twice a day, but sometimes I miss a day. I won't snub anyone for being annoying. Poorly dressed, sure, but not annoying! :mischief:

The install script is in our BEAST SVN where we hold the non-Civ parts of BUG/BAT.
 
Thanks for that link.

I'm confused though. You have this:

!define FIRAXIS_REG_ROOT "HKCU"
!define FIRAXIS_REG_KEY "Software\Firaxis Games"

Which is the main CivIV reg key. I can't figure out how you use this to find BtS and install to that custom assets. I keep scanning the script but I can't figure out how you jump from the vanilla folder to Beyond the Sword :confused:
 
I can't figure out how you use this to find BtS and install to that custom assets.

Scroll down midway to the function findCivInstallDir. Here it checks three reg keys, and I see that there's a small error (uses HKLM instead of the variable above):

  • Sid Meier's Civilization 4 - Beyond the Sword
  • Sid Meier's Civilization 4 Complete
  • Sid Meier's Civilization 4 Gold
 
Cool, cool, personal notes:

Function findCivInstallDir
Code:
	Push $0
	
	# standard Civ4:BTS
	ReadRegStr $0 HKLM "${FIRAXIS_REG_KEY}\Sid Meier's Civilization 4 - Beyond the Sword" 'INSTALLDIR'
	${If} ${FileExists} $0
		StrCpy $CivInstallDir $0
		Goto done
	${EndIf}
 
Ah, I should point out that i use the LogicLib library for the nice ${If} stuff. It made writing my script more like normal coding.
 
Scroll down midway to the function findCivInstallDir. Here it checks three reg keys, and I see that there's a small error (uses HKLM instead of the variable above):

  • Sid Meier's Civilization 4 - Beyond the Sword
  • Sid Meier's Civilization 4 Complete
  • Sid Meier's Civilization 4 Gold

I'm not sure that HKLM is wrong per se, thats where the info will be if its installed for All Users. Possibly in HKCU (only) if installed for single user.
 
Ah, I should point out that i use the LogicLib library for the nice ${If} stuff. It made writing my script more like normal coding.

Is this included in NSIS by default, or do I need to install an add on for it?
 
I'm not sure that HKLM is wrong per se, thats where the info will be if its installed for All Users. Possibly in HKCU (only) if installed for single user.

Notice that the third check uses the FIRAXIS_REG_ROOT constant I defined at the top of the script. I assumed it was HKLM as that's what the other two use, but now I see that it is defined as HKCU. I don't remember if I chose one or the other on purpose based on users who had those versions, but that doesn't sound familiar. More likely I made a typo and then added the constant later. :(

Is this included in NSIS by default, or do I need to install an add on for it?

It may be included now, otherwise you'll have to add it in yourself (it was easy). You'll know when you try to compile. I highly recommend using it, though.
 
Well I can't tell if it has logic lib or not. In the tutorial stuff for NSIS it says
Shipped with NSIS is version 2.6
Yet the most current version is 2.45 :hmm:

I also can't figure out how to add it. I can't find any examples or information on how to add a library to NSIS.

The error I get compiling is this:

Code:
Function: "findCivInstallDir"
Push: $0
ReadRegStr $0 HKLM\Software\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword\INSTALLDIR
!insertmacro: _If
!insertmacro: end of _If
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in script "C:\Documents and Settings\P\Desktop\CIV stuff\BtSModIconInstallScript.nsi" on line 49 -- aborting creation process

Did I just screw up the code? Pretty much coppied it straight from the BUG installer. It caused a cascade of changes in my script, but I think I did it correctly (and if not, I would have figured an error would have been thrown further down the script, since nothing above changed, except for the aditional variables for this function). If this error is saying it doesn't understand the if, where can I find it? I've tried googlying my fingers off, and can't find directions on how to include a library (and the only thing I've found that might have been the LogicLib library was in an old thread in the NSIS forums from 2003 lol. ) And yes I did add:
!include "LogicLib.nsh"
at the beggining of the script.


Nevermind, I forgot to initialize the variable CivInstallDir :mischief:

But now it's throwing me a warning :hmm:
 
But now it's throwing me a warning :hmm:

Yes, I've gotten that warning before. It's very mysterious and hard to solve. If only there was some way to help you . . . :mischief:
 
Yeah, I'm about to pull my hair out now. It just isn't using the function I inserted to find the install path. I tried copying what was used in BUG and copying over the original code, but it's just not working. After much cursing, and cutting and pasting, and trying things, I'm at a loss.

I'm going to go in depth into the script here, as I don't see any other way to explain what's going on.

The original Script uses this:

Code:
  ;Default installation folder
  InstallDir ""

  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "${BTSREGKEY}" "INSTALLDIR"

So this is where I am now (about the 20th itteration of things I have tried and failed):

Code:
  ;Default installation folder

  Var CivInstallDir ;EXE
  
Function findCivInstallDir

	Push $0
	
	ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${BTSREGKEY}" 'INSTALLDIR'
	${If} ${FileExists} $0
		StrCpy $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $0
			Goto done
		${EndIf}
	${EndIf}
	
done:
	Pop $0

FunctionEnd

  Var CurrentPage ; important for directory verification
  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin

;--------------------------------

Function .onInit

  Call findCivInstallDir

  ReadRegStr $R0 HKLM \
  "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

I've tried pulling other parts of the BUG install script and seeing if I could get things to work, but it got all confusing :confused:

Arg. Anyway there is a whole bunch of stuff that doing this changed, but that's not important really, at least not now. The script compiles, but if I run it, it doesn't detect the registry. I just want to get it to do that, and if I messed up other things, I think I can figure it out. But I'm at a complete loss as to what's different about the section of code above I replaced with what's below (well the OnInit is the same as the old script, just added in the call findCivInstallDir command, because I thought that was what was messing up in the detection, I guess I was wrong).
 
Where do you take what's in CivInstallDir and set it as the installation directory?

Also, isn't the first check you added (BTSREGKEY) the same reg key as the first check in the BUG code?
 
isn't the first check you added (BTSREGKEY) the same reg key as the first check in the BUG code?
I believe so. I just wanted to use the old one I knew worked, because in testing since things were failing I figured I'd try to keep the old function unaltered, since I knew it worked (at least for regular BtS, but it fails for Complete, which is the the whole point in this).


Where do you take what's in CivInstallDir and set it as the installation directory?

To be honest I'm not quite sure.

I assumed that this function just did it, at least it seemed to:

Code:
  ;Default installation folder
  InstallDir ""

  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "${BTSREGKEY}" "INSTALLDIR"

So I replaced that with this:

Code:
  ;Default installation folder

  Var CivInstallDir ;EXE
  
Function findCivInstallDir

	Push $0
	
	ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${BTSREGKEY}" 'INSTALLDIR'
	${If} ${FileExists} $0
		StrCpy $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $0
			Goto done
		${EndIf}
	${EndIf}
	
done:
	Pop $0

FunctionEnd

And changed all references to INSTDIR1 with CivInstallDir. It compiles, but no dice on the autodetection (haven't gone beyond this phase yet, since if autodetection failed, I haven't seen the point in seeing if the actual install functions).

I also tried changing this code:

Code:
  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

To this (and multiple itterations, moving around the various variables):
Code:
  Function onInitDirectoryPage1
  
    Call findCivInstallDir
	
    StrCpy $CurrentPage "DirectoryPage1"
    ;Section 1 selected?
    SectionGetFlags ${Section1} $0
    IntOp $R0 $0 & ${SF_SELECTED}
    IntCmp $R0 ${SF_SELECTED} findCivInstallDir
      Abort ;skip page
    findCivInstallDir:
      StrCmp $INSTDIR "" 0 checkDefaultLocation
        StrCpy $CivInstallDir "" ;we know nothing
        Return
      checkDefaultLocation:
          StrCpy $CivInstallDir "$INSTDIR" ;found it!
  FunctionEnd

No dice.

Here is the entirety of the default script in case that makes things easier.:

Spoiler :
Code:
    !include "MUI2.nsh"

;--------------------------------
;Constants
;These are the variables you need to define for your mod

  !define NAME "My Mod's Full Name" ;Full Name of Mod
  !define VERSION "X.X.X" ;Mod Version Number

  !define MOD_LOC "MyModFolder" ;Name of Mod Folder
  !define SHORT_NAME "MyModName" ;Abreviated mod name, example for WolfRevolution I would use WolfRev

  !define BTSREGKEY "SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword" ;Do not change this

  !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 ICON "${MYCLSDIR}\someicon.ico" ;place your icon in your mod folder change someicon to the icon's name
  !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 ""

  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "${BTSREGKEY}" "INSTALLDIR"

  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin

;--------------------------------
;Custom Varaiables

  Var INSTDIR1 ; Mods

  Var CurrentPage ; important for directory verification

;--------------------------------

Function .onInit

  ReadRegStr $R0 HKLM \
  "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
  ;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 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "DisplayName" "${NAME}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "UninstallString" "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir" "$INSTDIR1\Mods\"
    WriteUninstaller "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
  SectionEnd

  Section "Start Menu Shortcut" Section4
    CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "${ICON}" 0
  SectionEnd

  Section "Desktop Shortcut" Section5
    CreateShortCut "$DESKTOP\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "${ICON}" 0
  SectionEnd

  Section "Quick Launch Shortcut" Section6
    CreateShortCut "$QUICKLAUNCH\${SHORT_NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "${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 "Uninstall"
    ;get mod install path of from the registy
    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
    ;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"
    ;Delete Start Menu Shortcut
    Delete "$SMPROGRAMS\${NAME}.lnk"
    ;Delete Unistall Registry Entries
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
  SectionEnd

;Installer Functions

  Function myOnGUIInit
    ;preselect CulturalLinked Starts
    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
;--------------------------------

And here is the current last tested script (keep in mind I've had it fail about 50 times and have been scattering things around to try to fix it, so it might be a little messed up):

Spoiler :
Code:
  !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"
  !define FIRAXIS_REG_KEY "Software\Firaxis Games"
  !define BTSREGKEY "SOFTWARE\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword"	;Do not change these

  !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

  Var CivInstallDir ;EXE
  
Function findCivInstallDir

	Push $0
	
	ReadRegStr $0 ${FIRAXIS_REG_ROOT} "${BTSREGKEY}" 'INSTALLDIR'
	${If} ${FileExists} $0
		StrCpy $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $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 $CivInstallDir $0
			Goto done
		${EndIf}
	${EndIf}
	
done:
	Pop $0

FunctionEnd

  Var CurrentPage ; important for directory verification
  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin

;--------------------------------

Function .onInit

  Call findCivInstallDir

  ReadRegStr $R0 HKLM \
  "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 $CivInstallDir
  !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
  ;Source code scripting removed

  !insertmacro MUI_PAGE_INSTFILES

  !define MUI_FINISHPAGE_RUN "$CivInstallDir\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 "$CivInstallDir\Mods\${MOD_LOC}"
    File /r "${MYCLSDIR}\*.*"
      ; write uninstall information to the registry
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "DisplayName" "${NAME}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "UninstallString" "$CivInstallDir\Mods\${MOD_LOC}\Uninstall.exe"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir" "$CivInstallDir\Mods\"
    WriteUninstaller "$CivInstallDir\Mods\${MOD_LOC}\Uninstall.exe"
  SectionEnd

  Section "Start Menu Shortcut" Section4
    CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$CivInstallDir\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
  SectionEnd

  Section "Desktop Shortcut" Section5
    CreateShortCut "$DESKTOP\${NAME}.lnk" "$CivInstallDir\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
  SectionEnd

  Section "Quick Launch Shortcut" Section6
    CreateShortCut "$QUICKLAUNCH\${SHORT_NAME}.lnk" "$CivInstallDir\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 "Uninstall"
    ;get mod install path of from the registy
    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
    ;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"
    ;Delete Start Menu Shortcut
    Delete "$SMPROGRAMS\${NAME}.lnk"
    ;Delete Unistall Registry Entries
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
  SectionEnd

;Installer Functions

  Function myOnGUIInit
    ;preselect CulturalLinked Starts
    SectionGetFlags ${Section1} $0
    IntOp $R0 $0 | ${SF_SELECTED}
    SectionSetFlags ${Section1} $R0
  FunctionEnd

  Function .onVerifyInstDir
    StrCmp $CurrentPage "DirectoryPage1" check1 valid
    check1:
      IfFileExists "$CivInstallDir\Civ4BeyondSword.exe" valid invalid
    valid:
      Return
    invalid:
      Abort
  FunctionEnd

  Function onInitDirectoryPage1
  
    Call findCivInstallDir
	
    StrCpy $CurrentPage "DirectoryPage1"
    ;Section 1 selected?
    SectionGetFlags ${Section1} $0
    IntOp $R0 $0 & ${SF_SELECTED}
    IntCmp $R0 ${SF_SELECTED} findCivInstallDir
      Abort ;skip page
    findCivInstallDir:
      StrCmp $INSTDIR "" 0 checkDefaultLocation
        StrCpy $CivInstallDir "" ;we know nothing
        Return
      checkDefaultLocation:
          StrCpy $CivInstallDir "$INSTDIR" ;found it!
  FunctionEnd

Lastly keep in mind this is a shared install script. I have this uploaded this so other modders can easily use an installer without coding knowledge. I need the script to be able to just define all the !define stuff at the beggining of the script to use it. So I need the main body of the script softcoded.
 
Check out the function pickDefaultInstallDirectory. It checks the $IsMod variable to see if the user has chosen mod (multiplayer) or CustomAssets (singleplayer) installtion, and sets $INSTDIR appropriately. This is what you're missing.

In your case, you probably don't want to allow CustomAssets installation as it makes the script more complicated and most mods don't require it and cannot use it. In that case, change findInstallDir to setInstallDir and have it set $INSTDIR directly. No need for $CivInstallDir.

Note that finalizePaths modifies $INSTDIR for mod installs and sets the name/location of the assets folder and where the uninstaller goes.

BTW, the findCivRoot function is what locates the INI for CustomAssets installation. Also, that last code you posted that checks for Section 1 being selected I believe allows the user to override the default location.
 
Thank you very much EF.

I've almost got it working. Just two problems remain in the script.

When installing, it no longer drops you to the Set Install Directory menu, that shows you it's installing in Beyond the Sword (and allows you to manually set it if autodetection fails). And It no longer removes the Start Menu shortcut (I used BUGs, since the default didn't work well) when uninstalling. I thought I accounted for using the BUG code for the Start Menu Shortcut, but I must have missed something.

How could I correct these last two minor details?

Here is the Current Script:

Spoiler :
Code:
;BTS Install Script
;Written by André Götze aka Jean Elcard, phungus420, James Nicholls aka NikNaks, & Emperor Fool

;--------------------------------
;Include Modern UI

  !include "MUI2.nsh"
  !include "LogicLib.nsh"
  !include "Sections.nsh"


;--------------------------------
;Constants
;These are the variables you need to define for your mod

  !define NAME "MY_MOD_NAME" ;Full Name of Mod
  !define VERSION "X.X.X" ;Mod Version Number

  !define MOD_LOC "MOD_FOLDER" ;Name of Mod Folder
  !define SHORT_NAME "MY_MOD_NICK" ;Abreviated mod name, example for WolfRevolution I would use WolfRev

  !define FIRAXIS_REG_ROOT "HKLM"	;Do not change this block
  !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" 

  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin

;--------------------------------
;Custom Varaiables

  Var INSTDIR1 ; Mods
  Var StartMenuFolder

  Var CurrentPage ; important for directory verification

;--------------------------------
;Read the Registry and check for Civ Installation type.

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

;--------------------------------
;Set the Install Directory based off of the findINSTDIR1 function

Function setInstallDirectory
	Call findINSTDIR1
	StrCpy $INSTDIR "$INSTDIR1"

FunctionEnd

;--------------------------------

Function .onInit
  Call setInstallDirectory

  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_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 "Uninstall"
    ;get mod install path of from the registy
    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
    ;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"
    ;Delete Start Menu Shortcut
    Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
    ;Delete Unistall Registry Entries
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
  SectionEnd

;Installer Functions

  Function myOnGUIInit
    ;preselect CulturalLinked Starts
    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
;--------------------------------
 
That looks pretty different from BUG's script, and it took quite a bit of work for me to get that going. I have no idea why yours isn't working. I suggest adding some logging output along the way so you can trace it.
 
Well I figured out the first issue. It now fully functions :)

I still have a problem I cannot figure out though :dunno:

For some reason the uninstaller does not delete the start menu shortcut. Originally I couldn't get the start menu shortcut to work very well (it would only show up in the main list of programs, whereas I would prefer it to nest in the Firaxis Games Section). So I used BUG's code, and it installs all properly. But unfortantely the uninstaller doesn't remove it. Here is the code I added from BUG:
Code:
...
  !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Your $\"Beyond the Sword$\" folder:"
  !insertmacro MUI_PAGE_DIRECTORY
  [B]!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder[/B]
  ;Source code scripting removed

Code:
  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

Code:
  Section "Uninstall"
    ;get mod install path of from the registy
    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
    ;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"
    ;Delete Start Menu Shortcut
[b]    !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
    Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
    RMDir "$SMPROGRAMS\$StartMenuFolder"[/b]
    ;Delete Unistall Registry Entries
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
  SectionEnd

What am I missing here?

Also on a side note, how does the shortcut that doesn't get removed retain it's icon when everything else is uninstalled? I would have thought removing the icon would break the icon apearance in the link (as it's defined by this "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0). This doesn't matter, just curious.
 
If I had to guess - "CreateShortCut" that create the startMenu folders will query whether they should be created in:
c:\Users\Phungus420\Start Menu\Programs\ ...OR...
c:\Users\All Users\Start Menu\Programs\
Whereas "Delete" may be attempting to remove an absolute path, that doesn't exist as the Shortcut was created in "All Users" - when Civ is installed for ALL instead of just the current user (i.e. Phungus420)... but again, just a supposition/guess ;)

As for the ICON, Windows caches icons so they can be accessed quickly without causing harddrive thrashing - everytime an icon needs to be looked up. Nothing to be concerned about, after a few reboots or so, those icons will usually get removed from the icon cache. If you like, TweakUI can rebuild your own IconCache.
 
Back
Top Bottom