File NSIS选择一个文件

File NSIS选择一个文件,file,nsis,File,Nsis,我想做的是创建一个页面,用户在其中浏览文件系统以获取特定值,如果文件名匹配,则继续。 具体来说,我希望用户能够找到php可执行文件,以及我不确定如何从完整路径中提取目录的目录。这可以通过定制的nsDialogs页面和nsDialogs::SelectFileDialog轻松实现,nsDialogs::SelectFileDialog正是为此而设计的 您可以使用自定义页面执行此操作: !include nsDialogs.nsh !include FileFunc.nsh Page Custom

我想做的是创建一个页面,用户在其中浏览文件系统以获取特定值,如果文件名匹配,则继续。
具体来说,我希望用户能够找到php可执行文件,以及我不确定如何从完整路径中提取目录的目录。

这可以通过定制的nsDialogs页面和nsDialogs::SelectFileDialog轻松实现,nsDialogs::SelectFileDialog正是为此而设计的


您可以使用自定义页面执行此操作:

!include nsDialogs.nsh
!include FileFunc.nsh

Page Custom MyPageCreate MyPageLeave

Var PhpPath

Function MyPageLeave
${NSD_GetText} $PhpPath $0
${GetFileName} $0 $1
${IfNot} ${FileExists} $0
${OrIf} $1 != "php.exe"
    MessageBox mb_iconstop "You must locate php.exe to continue!"
    Abort
${Else}
    #php path is in $0, do something with it...
${EndIf}
FunctionEnd

Function MyPageComDlgSelectPHP
Pop $0
${NSD_GetText} $PhpPath $0
nsDialogs::SelectFileDialog open $0 "php.exe|php.exe"
Pop $0
${If} $0 != ""
    ${NSD_SetText} $PhpPath $0
${EndIf}
FunctionEnd

Function MyPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateText} 0 5u -25u 13u "$ProgramFiles\PHP\php.exe"
Pop $PhpPath

${NSD_CreateBrowseButton} -23u 4u 20u 15u "..."
Pop $0
${NSD_OnClick} $0 MyPageComDlgSelectPHP

nsDialogs::Show
FunctionEnd
或者您可以使用目录页:

!include LogicLib.nsh

Var PhpPath

Function .onInit
StrCpy $PhpPath "$ProgramFiles\PHP" ; Default (You could probably do better by checking the registry)
FunctionEnd

PageEx Directory
    DirVar $PhpPath
    DirVerify leave
    PageCallbacks "" PhpPageShow PhpPageLeave
    DirText "Select PHP folder" "PHP Folder" "" "Select PHP folder"
PageExEnd

Function PhpPageShow
;Hide space texts
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 0x3FF
ShowWindow $1 0
GetDlgItem $1 $0 0x400
ShowWindow $1 0
FunctionEnd

Function PhpPageLeave
GetInstDirError $0
${If} $0 <> 0
${OrIfNot} ${FileExists} "$PhpPath\php.exe"
    MessageBox mb_iconstop "You must locate the php folder to continue!"
    Abort
${EndIf}
FunctionEnd

我希望能举个例子。我看了很多页,但我还是不太明白。