2011-11-04 52 views
-1

我想要做的是让用户浏览文件系统的某个特定值,如果文件名匹配则继续。 具体而言,我希望用户找到那里的PHP可执行文件,也是我想的目录(不知道我将如何从完整路径中提取目录)。NSIS选择一个文件

回答

8

您可以用自定义页面做到这一点:

!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