Old 20th August 2003, 15:13   #1
ijerkovi
Member
 
Join Date: Jul 2003
Posts: 61
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.
ijerkovi is offline   Reply With Quote
Old 20th August 2003, 15:22   #2
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to 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:

code:
SetOutPath $INSTDIR


And use "File" commands after.

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

code:
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.

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 20th August 2003, 15:22   #3
ijerkovi
Member
 
Join Date: Jul 2003
Posts: 61
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.
ijerkovi is offline   Reply With Quote
Old 20th August 2003, 15:22   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,433
You could scrap MUI_PRODUCT_DIR define, and use

StrCpy $INSTDIR "C:\whatever"

Or

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

-Stu
Afrow UK is offline   Reply With Quote
Old 20th August 2003, 15:24   #5
ijerkovi
Member
 
Join Date: Jul 2003
Posts: 61
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 is offline   Reply With Quote
Old 20th August 2003, 15:25   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,433
Place in Function .onInit

-Stu
Afrow UK is offline   Reply With Quote
Old 20th August 2003, 15:30   #7
ijerkovi
Member
 
Join Date: Jul 2003
Posts: 61
Thumbs up 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
ijerkovi is offline   Reply With Quote
Old 20th August 2003, 15:32   #8
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Wow, everyone are speaking faster today! Three persons posting in the same time!

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 20th August 2003, 15:34   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,433
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
Afrow UK is offline   Reply With Quote
Old 20th August 2003, 15:37   #10
ijerkovi
Member
 
Join Date: Jul 2003
Posts: 61
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.
ijerkovi is offline   Reply With Quote
Old 20th August 2003, 15:38   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,433
No, use inside .onInstallSuccess Function.
The code will then be called when the user clicks the Finish button.

-Stu
Afrow UK is offline   Reply With Quote
Old 20th August 2003, 17:53   #12
RDaneel
Member
 
Join Date: Nov 2001
Location: Seattle, Washington
Posts: 78
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:

PHP Code:
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 is offline   Reply With Quote
Old 20th August 2003, 17:56   #13
RDaneel
Member
 
Join Date: Nov 2001
Location: Seattle, Washington
Posts: 78
Ack, the backslashes got removed by the "PHP" quoting. Sigh. Here is what that should look like, if anyone was confused:

Quote:
InstallDir "$PROGRAMFILES\RFtpPRO"
InstallDirRegKey HKCU "Software\RHpS\RFtp\Settings" "AppFile"
RDaneel is offline   Reply With Quote
Old 20th August 2003, 20:11   #14
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,433
Use [ code] [/code ]

-Stu
Afrow UK is offline   Reply With Quote
Old 20th August 2003, 20:25   #15
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to 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 ]

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump