我正在使用nsis从特定位置执行文件。为此,我需要从一个浏览按钮中选择一个路径,然后从另一个浏览按钮中选择一个文件,并将这些值存储在变量中。我创建了一个.ini文件。我能够从文本框中检索值。但我无法使浏览按钮工作。
答案 0 :(得分:0)
将类型设置为FileRequest或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