I am using nsis to execute a file from specific location. For that I need to select a path from one browse button and select a file from another browse button and store those values in the variables. I created an .ini file. I am able to retrieve the values from the textbox. But I am not able to make the browse buttons work.
The browse buttons should work automatically when setting the type to FileRequest or DirRequest:
Page Custom IOPageCreate IOPageLeave
Page InstFiles
var myfile
var mydir
Function IOPageCreate
InitPluginsDir
!tempfile INI ; We will generate the .ini on the fly in this example script
!appendfile "${INI}" '[Settings]$\r$\n'
!appendfile "${INI}" 'NumFields=2$\r$\n'
!appendfile "${INI}" '[Field 1]$\r$\n'
!appendfile "${INI}" 'Type=FileRequest$\r$\n'
!appendfile "${INI}" 'Left=1$\r$\n'
!appendfile "${INI}" 'Right=-1$\r$\n'
!appendfile "${INI}" 'Top=1$\r$\n'
!appendfile "${INI}" 'Bottom=14$\r$\n'
!appendfile "${INI}" 'Filter=Text Files|*.txt|Programs|*.exe;*.com|All Files|*.*$\r$\n'
!appendfile "${INI}" 'Flags=PATH_MUST_EXIST|FILE_EXPLORER|FILE_HIDEREADONLY $\r$\n'
!appendfile "${INI}" '[Field 2]$\r$\n'
!appendfile "${INI}" 'Type=DirRequest$\r$\n'
!appendfile "${INI}" 'Left=1$\r$\n'
!appendfile "${INI}" 'Right=-1$\r$\n'
!appendfile "${INI}" 'Top=20$\r$\n'
!appendfile "${INI}" 'Bottom=33$\r$\n'
!appendfile "${INI}" 'Flags=PATH_MUST_EXIST|FILE_EXPLORER|FILE_HIDEREADONLY $\r$\n'
File "/oname=$PluginsDir\page.ini" "${INI}"
!delfile "${INI}"
WriteIniStr "$PluginsDir\page.ini" "Field 2" "State" $AppData ; Initial value
InstallOptions::dialog "$PluginsDir\page.ini"
FunctionEnd
!include LogicLib.nsh
Function IOPageLeave
ReadIniStr $myfile "$PluginsDir\page.ini" "Field 1" "State"
ReadIniStr $mydir "$PluginsDir\page.ini" "Field 2" "State"
${IfNot} ${FileExists} $myfile
${OrIfNot} ${FileExists} $mydir
MessageBox mb_iconstop "Both the file and directory must exist, please try again..."
Abort
${EndIf}
FunctionEnd
Section
DetailPrint File=$myfile
DetailPrint Directory=$mydir
SectionEnd