Archive: Force user to select only drive letter


Force user to select only drive letter
I have an application that works on a drive folder like
c:\myapp, d:\myapp, e:\myapp ..... how can I replace MUI_PAGE_DIRECTORY with a combobox for selecting only drives letter available.I'm new with nsis and please I want a small script file to see that.For 2 days I'm looking for a solution.
Many thanks !!


Already discussed here:
http://forums.winamp.com/showthread....hreadid=262165


Originally posted by Red Wine
Already discussed here:
http://forums.winamp.com/showthread....hreadid=262165
Thanks for answer.... but this is not what i'm looking for, user can also chose a subdir ...and i want to force it to choose only drive letter from a combo.

Nope, this is exactly what you're looking, though, feel free to build a custom page with a combo, find all available HDD with GetDrives, and add them to ListItems.


Originally posted by Red Wine
Nope, this is exactly what you're looking, though, feel free to build a custom page with a combo, find all available HDD with GetDrives, and add them to ListItems.
Thanks again ...this is my problem...i don't know how i can do it.I use nsis for 3 days,I wand i script for exemple.Thanks !

I dont think there is one available, but the concept is very simple:

Enumerate the drives with the plugin, and add them to your custom page's combo with the WriteINIStr. You should probably start by looking through the InstallOptions examples provided with NSIS. It looks a bit daunting at first, but its quite simple.


Take this as a starting point :-)

!define APPNAME "My Application"
Name '${APPNAME}'
OutFile 'test.exe'
LicenseData '${NSISDIR}\License.txt'
LicenseBkColor 0xFFFFFF
ShowInstDetails show
AllowRootDirInstall true

!include FileFunc.nsh
!insertmacro GetDrives

Page License
Page Custom CustomCreate CustomLeave
Page InstFiles

Section "boo"
SetOutPath '$INSTDIR'
SectionEnd

Function CustomCreate
WriteIniStr '$PLUGINSDIR\custom.ini' 'Settings' 'NumFields' '2'

WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Type' 'Label'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Left' '5'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Top' '5'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Right' '-6'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Bottom' '17'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Text' \
'Select Installation drive:'

StrCpy $R2 0
StrCpy $R0 ''
${GetDrives} "HDD" GetDrivesCallBack

WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Type' 'DropList'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Left' '30'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Top' '25'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Right' '-31'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Bottom' '105'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'State' '$R1'
WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'ListItems' '$R0'

push $0
InstallOptions::Dialog '$PLUGINSDIR\custom.ini'
pop $0
pop $0
FunctionEnd

Function CustomLeave
ReadIniStr $0 '$PLUGINSDIR\custom.ini' 'Field 2' 'State'
StrCpy '$INSTDIR' '$0'
FunctionEnd

Function GetDrivesCallBack
IntCmp $R2 '0' def next next
def:
StrCpy $R1 '$9${APPNAME}'
next:
IntOp $R2 $R2 + 1
StrCpy $R0 '$R0$9${APPNAME}|'
Push $0
FunctionEnd

Function .onInit
InitPluginsDir
GetTempFileName $0
Rename $0 '$PLUGINSDIR\custom.ini'
FunctionEnd

Originally posted by Red Wine
Take this as a starting point :-)
!define APPNAME "My Application"
Name '${APPNAME}'
OutFile 'test.exe'
......................
Thanks very much ... is seems ok. I'll start learnig nsis deeply.

You're welcome!
Just added a wiki page with the complete example that calculates the free space of every drive and adds only those drives that they have enough space for the uncompressed installation.