Archive: Problem with the $INSTDIR and registry


Problem with the $INSTDIR and registry
I'm currently makin a mappack for CS.

I need to know the exact path of the cstrike directory.

So I've coded it that way :

;DIF.nsi
;
;Install script by Jubijub
;
;
;
;init numero de version
!define VER_MAJOR 1
!define VER_MINOR 1

;Nom de l'installer
Name "DIF-Mappack v${VER_MAJOR}.${VER_MINOR}"
Caption "-=[D.I.F]=- Mappack v${VER_MAJOR}.${VER_MINOR} by Jubijub"
;Nom du fichier
OutFile "DIF-mappack_v${VER_MAJOR}.${VER_MINOR}.exe"

;parametres generaux
Icon main.ico
MiscButtonText "Retour" "Suivant" "Annuler" "Fermer"
;Composants
EnabledBitmap d:\test\three-check.bmp
DisabledBitmap d:\test\three-nocheck.bmp
AutoCloseWindow false
ShowInstDetails show
ShowUninstDetails show
SetCompress auto
SetDatablockOptimize on
CRCCheck on
BGGradient 000000 e21c00 FFFFFF
InstallColors e21c00 000000
InstProgressFlags smooth colored
SetOverwrite ifnewer
DirShow hide
DirText ""

;detection rep half-life
section ""
ReadRegStr $INSTDIR HKLM "software\Valve\Half-Life" InstallPath
SectionEnd

;licence
LicenseText "Vous devez accepter ce qui suit avant de continuer:"
LicenseData license.txt
;caption
ComponentText "Ceci installera le pack -=[D.I.F]=- dans le repertoire de Counter-strike"
DetailsButtonText "Details"
CompletedText "Operation terminée avec succès"

InstallDir $INSTDIR
InstallDirRegKey HKLM SOFTWARE\DIF "Install_Dir"


;INSTALL
; Section principale
Section "Maps (requis)"
SetOutPath $INSTDIR\cstrike
file d:\test\*.wad
SetOutPath $INSTDIR\cstrike\maps
file d:\test\maps\*.*
;SetOutPath $INSTDIR\cstrike\sound
;SetOutPath $INSTDIR\cstrike\gfx
WriteRegStr HKLM SOFTWARE\DIF "Install_Dir" "$INSTDIR\cstrike"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DIF" "DisplayName" "DIF Mappack (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DIF" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteUninstaller "uninstall.exe"
SectionEnd

; section bonus
Section "Bonus sons kevlar+NV"
SetOutPath $INSTDIR\cstrike\sound\items
file d:\test\sounds\items\*.wav
SectionEnd

; section uninstall
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DIF"
DeleteRegKey HKLM SOFTWARE\DIF
Delete $INSTDIR\cstrike\porno.wad
Delete $INSTDIR\cstrike\cs_thunder.wad
Delete $INSTDIR\cstrike\maps\cs_beirut.bsp
Delete $INSTDIR\cstrike\maps\cs_beirut.txt
Delete $INSTDIR\cstrike\maps\cs_docks_v1.bsp
Delete $INSTDIR\cstrike\maps\cs_docks_v1.txt
Delete $INSTDIR\cstrike\maps\cs_thunder.bsp
Delete $INSTDIR\cstrike\maps\cs_vineyard.bsp
Delete $INSTDIR\cstrike\maps\cs_vineyard.txt
Delete $INSTDIR\cstrike\maps\de_dust4ever.bsp
Delete $INSTDIR\cstrike\maps\de_dust4ever.txt
Delete $INSTDIR\cstrike\maps\de_kaktus.bsp
Delete $INSTDIR\cstrike\maps\de_kaktus.txt
Delete $INSTDIR\cstrike\maps\de_rotterdam.bsp
Delete $INSTDIR\cstrike\maps\de_rotterdam.txt
Delete $INSTDIR\cstrike\maps\pa_kruncinator(fr).txt
Delete $INSTDIR\cstrike\maps\pa_krunchinator.bsp
Delete $INSTDIR\cstrike\maps\pa_krunchinator.txt
Delete $INSTDIR\cstrike\maps\pa_krunchinator_readme.txt
Delete $INSTDIR\cstrike\maps\pa_krunchinator_readme(fr).txt
Delete $INSTDIR\cstrike\sound\items\equip_nvg.wav
Delete $INSTDIR\cstrike\sound\items\kevlar.wav
Delete $INSTDIR\cstrike\sound\items\nvg_off.wav
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\cstrike\uninstall.exe
SectionEnd

; eof
I had to disable the directory selection page, because when it was enabled, the detected path (that works) wasn't displayed in the editbox...and the browse function was of no use, because whatever directory you choosed, the mappack installed in the righ directory, the $INSTDIR\cstrike.

I would like to turn this feature back on, so that people could be able to check if the detected path is right or not

You should replace this:

;detection rep half-life 
section ""
ReadRegStr $INSTDIR HKLM "software\Valve\Half-Life" InstallPath
SectionEnd


with this:
InstallDirRegKey HKLM "software\Valve\Half-Life" "InstallPath "


Notice that this part of the code is not located in any section.

InstallDir $INSTDIR
InstallDirRegKey HKLM SOFTWARE\DIF "Install_Dir"

thanks, my parameters were wrong :D

yours are too :D

-->no "" for the string you want to read...

InstallDirRegKey HKLM "software\Valve\Half-Life" InstallPath

et not

InstallDirRegKey HKLM "software\Valve\Half-Life" "InstallPath"


You do need quotes if you have spaces in the name. I accidently put space after InstallPath, that is what was wrong.

The InstallDir $INSTDIR is useless. With InstallDir you should set the default install dir if no other found by InstallDirRegKey.

So it should be:

InstallDir "C:\Half-Life" 
InstallDirRegKey HKLM "software\Valve\Half-Life" "InstallPath"

I realised that my instdir system was not implemented...

that's ok now...I've tested with a fake key : the program follow the changes, and if I delete the key, the default path is activated...