Skip to content
⌘ NSIS Forum Archive

Destination Folder

15 posts

ijerkovi#

Destination Folder

How can I dynamically set MUI_PRODUCT_DIR?? I want to be able to put anything in destination folder.

Any help is appreciated.
deguix#
You don't need define anything. Use the $INSTDIR variable. This is the default variable used to install program files in, contains the install folder written by the user.

To put files in the folder written in $INSTDIR var, use:

SetOutPath $INSTDIR
And use "File" commands after.

If want to put files in a subfolder of $INSTDIR:

SetOutPath $INSTDIR\SubFolder
Where SubFolder is the subfolder name.

If you want another variable to use it, try using the default $0-$9, $R0-$R9 variables.
ijerkovi#
I should say how can I override
InstallDir "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

so that "Destination Folder" would show up with a value I have in registry.
Afrow UK#
You could scrap MUI_PRODUCT_DIR define, and use

StrCpy $INSTDIR "C:\whatever"

Or

StrCpy $INSTDIR "C:\whatever${MUI_PRODUCT_DIR}"

-Stu
ijerkovi#
OK but then how could I make it to show up in the Destination folder? This code can not be put outside a Section.
ijerkovi#
It worked

Thanks a bunch!! I put my function call in the init function and it worked...for anyone's reference here it is...

Function installDirectory
; set $INSTDIR to registry value if previous installation detected
ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "Installed"
StrCmp $0 "" NotPresent Present
NotPresent:
WriteRegStr HKCU "SOFTWARE\Sandvine" "Installed" "1"
WriteRegStr HKCU "SOFTWARE\Sandvine" "InstalledDirectory" "$INSTDIR"
StrCpy $INSTDIR "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

Goto Done
Present:
ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "InstalledDirectory"
StrCpy $INSTDIR "$0"

Done:
FunctionEnd
Afrow UK#
You don't need that StrCpy in there if used like this:

InstallDir "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

Function InstallDirectory
; set $INSTDIR to registry value if previous installation detected
ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "Installed"
StrCmp $0 "" NotPresent Present
NotPresent:
WriteRegStr HKCU "SOFTWARE\Sandvine" "Installed" "1"
WriteRegStr HKCU "SOFTWARE\Sandvine" "InstalledDirectory" "$INSTDIR"

Goto Done
Present:
ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "InstalledDirectory"
StrCpy $INSTDIR "$0"

Done:
FunctionEnd

I was also thinking that maybe you should write the install directory and Installed 1 to the registry after installation.
The user may quit and not install the software, though on re-run it will assume that the installation has already taken place.

-Stu
ijerkovi#
Good point. I will change the code to take care of that scanario ...effectivelly write to registry after all the files have been copied for some other section.
Afrow UK#
No, use inside .onInstallSuccess Function.
The code will then be called when the user clicks the Finish button.

-Stu
RDaneel#
Hmmm... there is a much easier way to handle the situation of figuring out an install dir while defaulting to whatever was used by an existing installation. 😁

Just take a look at both the InstallDir and InstallDirRegKey documentation - the NSIS guys put some effort into solving this particular problem, since it is so common.

This whole mess can usually be handled by something like this:

InstallDir "$PROGRAMFILES\RFtpPRO"
InstallDirRegKey HKCU "Software\RHpS\RFtp\Settings" "AppFile" 
The "InstallDir" sets up your default, and the "InstallDirRegKey" attempts to override it if there is already a path set in whatever reg entry you tell it to look in... note that it is smart, and if the the reg entry has a path to an .exe file, the filename will be stripped, leaving only the directories.

Finally, note that these are "configuration" statements, and are not actually in a section (or a .on<anything>).
RDaneel#
Ack, the backslashes got removed by the "PHP" quoting. Sigh. Here is what that should look like, if anyone was confused:

InstallDir "$PROGRAMFILES\RFtpPRO"
InstallDirRegKey HKCU "Software\RHpS\RFtp\Settings" "AppFile"
deguix#
Or when using the [PHP ] and [/PHP ] (without that space) use two insteed of one "\".

In Example:

[PHP ]StrCpy $INSTDIR "C:\\Folder\\SubFolder"[/PHP ]