ontrack16
31st December 2006 14:38 UTC
How to set the installation directory depending on a choice user made earlier ?
A user can select either installation locally or on a network.
When the user selects local, the install dir should be by default eg C:\Install.
When the user selects network, the install dir should be by defalt eg F:\Install.
When I call the Directory page however, I can't get to set the right default installation directory.
The directory page uses InstallDir and I can't change the value of that InstallDir from inside a section/function.
Red Wine
31st December 2006 14:51 UTC
The directory page uses InstallDir and I can't change the value of that InstallDir from inside a section/function.
You can't do that. InstallDir means the suggested default directory that installer adds on directory page.
It'd change once users hit the browse button and specify another directory.
ontrack16
31st December 2006 15:06 UTC
I think I got it.
There was already a topic with title : "overwrite default InstallDir"
I will use the same technique.
Sorry for asking the same question twice.
Red Wine
31st December 2006 15:22 UTC
If you want to show a suggested dir on directory page different than the one specified with InstallDir then you should do something like this:
Name "My Application"
OutFile test.exe
LicenseData '${NSISDIR}\License.txt'
LicenseBkColor 0xFFFFFF
InstallDir '$PROGRAMFILES\$(^name)'
!include winmessages.nsh
Page License
Page Components
Page Directory '' dir_show
Page InstFiles
Section "boo"
######
SectionEnd
Function dir_show
FindWindow $R1 "#32770" "" $HWNDPARENT
GetDlgItem $R2 $R1 '1019'
ExpandEnvStrings $R0 '%USERPROFILE%'
SendMessage $R2 ${WM_SETTEXT} 1 'STR:$R0\$(^name)'
GetDlgItem $R2 $HWNDPARENT 1
System::Call "user32::SetFocus(i R2)i"
FunctionEnd
Red Wine
1st January 2007 12:03 UTC
When the user selects local, the install dir should be by default eg C:\Install.
When the user selects network, the install dir should be by defalt eg F:\Install.
You're able to achieve this only in Function .onInit.
However you must use messageboxes to interact with users since there is no GUI yet.
EXAMPLE:
Name "My Application"
OutFile test.exe
LicenseData '${NSISDIR}\License.txt'
LicenseBkColor 0xFFFFFF
InstallDir '$PROGRAMFILES\$(^name)'
Page License
Page Components
Page Directory
Page InstFiles
Section "boo"
;;;;;;;;;
SectionEnd
Function .onInit
StrCpy $0 0
EnumRegKey $1 HKCU Network $0
StrCmp $1 "" end ;there is no network drive mapped
;found mapped drive(s) ask user if install either on local or network
MessageBox MB_ICONQUESTION|MB_YESNO \
"Install on local or Network drive?$\n$\n\
Either select Yes for local or No for network" IDYES end ;user selection is local installation
EnumRegKey $1 HKCU Network $0
StrCpy '$R0' '$1:'
IntOp $0 $0 + 1
EnumRegKey $1 HKCU Network $0
StrCmp $1 "" done ;there is only one mapped net drive we shall use this
StrCpy $0 0
loop: ;find all available network drives and promt user to select one
EnumRegKey $1 HKCU Network $0
StrCpy '$R0' '$1:'
IntOp $0 $0 + 1
EnumRegKey $1 HKCU Network $0
StrCmp $1 "" last
MessageBox MB_YESNO|MB_ICONQUESTION \
"Install on $R0 network drive?$\n$\n\
Select Yes to install on $R0, No to select another drive" IDYES done
goto loop
last:
MessageBox MB_YESNO|MB_ICONQUESTION \
"Last network drive found $R0 install here?$\n$\n\
Select Yes to install on $R0, No to start over" IDYES done
StrCpy $0 0
goto loop
done:
StrCpy '$INSTDIR' '$R0\$(^name)'
end:
FunctionEnd