Archive: Multiple install directories


Hi all, my first post here so I hope I haven't missed a previous post about this.

I've just started using NSIS, and I'm trying to make an installer that can default to installing to two different locations. I've added a new function to the source (IfRegKeyExists) that will check if a registry key exists (to see if a product is installed). This works like IfFileExists and jumps a certain distance depending on if the key is found or not.

So, for testing I have a structure in the script like this:

IfRegKeyExists HKEY_LOCAL_MACHINE "key" "value" 0 2
SetOutPath '$PROGRAMFILES\Dave Exp Reg Found'
Jump 1
SetOutPath '$PROGRAMFILES\Dave Exp Reg Not Found'

If the key isn't found, the first SetOP and Jump are successfully jumped and only the not found directory is created. However, if the key is found, I get both the directories made :( It seems the second SetOP isn't jumped properly.

I've tried experiments just using the Jump command and a list of SetOutPath's and it looks like you can jump over all but the last one, so:
Jump 1
SetOutPath '$PROGRAMFILES\Dave Exp1'
SetOutPath '$PROGRAMFILES\Dave Exp2'
SetOutPath '$PROGRAMFILES\Dave Exp3'

makes the last two directories but:

Jump 3
SetOutPath '$PROGRAMFILES\Dave Exp1'
SetOutPath '$PROGRAMFILES\Dave Exp2'
SetOutPath '$PROGRAMFILES\Dave Exp3'

Still makes the third directory :(
Any info or suggestions on this?


I am not sure if this is much help but why do you not just use one of the 4 default sections in the installer and with the InstallDir tag get the user to select which directioy structure the want


Try using a Nop (no-op) command and then jumping to beyond that. So instead of
Jump 1
SetOutputPath "Directory"
try
Jump 2
SetOutputPath "Directory"
Nop

Regardless if that works, Justin will be interested in this to see if its his code or not...


Man, this is getting complicated!

OK, I tried some experiments which boil down to the following code:

Section ""
SetOutPath c:\temp2\DaveBeforeJumps

Jump 2
SetOutPath c:\temp2\DaveExp1
SetOutPath c:\temp2\DaveExp2

File "C:\Temp3\File1.txt"
File "C:\Temp3\File2.txt"

;File "C:\Temp3\*.*"

;File /r "C:\Temp3\*.*"

SectionEnd

I compiled this into three .exe's, first as it is with the two files, then I commented out the first two and tried with the *.* wildcard instead, and lastly tried it with wildcards and recursion into a subdirectory.
The first and second installers worked as you'd expect, with the files being installed to c:\temp2\DaveBeforeJumps.
The third installer doesn't work properly. File1 and File 2 are installed to DaveBeforeJumps correctly, but when the installer creates the subdirectory, it somehow picks up on the last SetOutPath c:\temp2\DaveExp2, despite the fact it has been jumped over.

It's a bit hard to explain, but if anyone's interested they should be able to recreate it!


Thanks for the suggestion WebSpider, if there's an easier way of doing what I'm trying to do, that's great!

The problem is I'm trying to distribute an add on that can work in two products. It needs to cope with either one or both being installed. If both are installed, the file only needs to be copied to product 1. The directory to be installed to is stored in the registry. The pseudo-code for what I'm trying to do is something like:

if (prod1 installed)
Get prod1 dir from reg
else if (prod2 installed)
Get prod2 dir from reg
Show the user that the directory has been found
install file there

I may be able to use your suggestion to do this, but it's a real shame the InstallDir and InstallDirRegKey commands are done outside of the "sections". I'll carry on fiddling and see how I get on. :)


I know the InstallDir commant is outside the section tag but the SetOutPath command is not. Its seems, from my test anyway, overrides the InstallDir command. Have a look at the .nsi scripting notes in the NSIS documentation. I do not know what to do about the reg key but perhaps this is of some help to you. I still maintain if you get the user the select if they own one, the other or both products from the 4 default sections will work especially with this SetOutPath command. I am not sure that this is any good but good luck anyway. In case you are intrested someone has created a patcher for UO in this forum, perhaps contacting them would be of use.


OK, my solution was to write two new functions into the source :)

IfRegKeyExists rootkey subkey goto_found goto_not_found
SetOutPathToReg rootkey subkey value

My script ended up like this: (edited for size)
<snip>
ComponentText "Welcome! Choose the products you have."

Section ""
Nop ; Nothing installed by default
SectionEnd

Section "Product 1"

IfRegKeyExists H_L_M "software\product1" LabFound LabNotFound

LabFound:
SetOutPathToReg H_L_M "Software\product1" "maindir"
File "Source\MyFileToInstall"
Goto LabEnd

LabNotFound:
MessageBox MB_OK "Program not found."
Goto LabEnd

LabEnd:
SectionEnd

Section "Product 2"
; Similar to product 1 but checking a different reg key
; for if it's installed and getting a different install
; dir from a different reg key
SectionEnd

Questions: A) Does anyone else want these functions? Obviously I found them pretty useful, but I don't know how often people are going to want to do so many registry related things in their installers.
B) If people do want them, how do I go about submitting the code for a release?


Originally posted by Dave Carter
OK, my solution was to write two new functions into the source :)

IfRegKeyExists rootkey subkey goto_found goto_not_found
SetOutPathToReg rootkey subkey value


You know, with NSIS 1.4 you don't need these functions to accomplish what you want...

My script ended up like this: (edited for size)
<snip>
ComponentText "Welcome! Choose the products you have."

Section ""
Nop ; Nothing installed by default
SectionEnd

Section "Product 1"
ReadRegStr $0 HKLM "software\product1" "maindir"
StrCmp $0 "" LabNotFound LabFound
LabFound:
StrCpy $INSTDIR $0 ; optional, if you want to use $INSTDIR later.
SetOutPath $0
File "Source\MyFileToInstall"
Goto LabEnd
LabNotFound:
MessageBox MB_OK "Program not found."
Goto LabEnd
LabEnd:
SectionEnd

Section "Product 2"
; Similar to product 1 but checking a different reg key
; for if it's installed and getting a different install
; dir from a different reg key
SectionEnd

And that's it.


Questions: A) Does anyone else want these functions? Obviously I found them pretty useful, but I don't know how often people are going to want to do so many registry related things in their installers.
B) If people do want them, how do I go about submitting the code for a release?
:)

-Justin

Doh!

And I was feeling so clever as well :) Thanks Justin, I'll update my script to use the standard functions, and stick with the release version of NSIS.

Dave.