Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   How to set the installation directory depending on a choice user made earlier ? (http://forums.winamp.com/showthread.php?t=262773)

ontrack16 31st December 2006 13:38

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 13:51

Quote:

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 14:06

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 14:22

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:
code:
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 11:03

Quote:

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



All times are GMT. The time now is 04:35.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.