2017-10-28 82 views
0

需要InstallOptionsEx驗證的一些幫助。在InstallOptions我們使用標誌=通知,然後我們在功能NSIS InstallOptionsEx驗證

ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State" 
    StrCmp $0 0 validate ; Next button? 
    StrCmp $0 2 supportx ; "Install support for X"? 
    StrCmp $0 9 clearbtn ; "Clear" button? 
    StrCmp $0 11 droplist ; "Show|Hide" drop-list? 
    Abort ; Return to the page 

沒有服用點這樣但在InstallOptionsEx他們說,他們贊成新方法廢除了它。

這是從InstallOptionsEx自述文件:

Step 5: Validate the Output 
If you want to validate the input on the page, for example, you want to check whether the user has filled in a textbox, use the leave function of the Page command and Abort when the validation has failed: 
    Function ValidateCustom 

    ReadINIStr $R0 "$PLUGINSDIR\test.ini" "Field 1" "State" 
    StrCmp $0 "" 0 +3 
     MessageBox MB_ICONEXCLAMATION|MB_OK "Please enter your name." 
     Abort 

    FunctionEnd 

  Step 6: Return Value 
After you have called the DLL, InstallOptionsEx adds one string to the stack, with one of the following values: 
success - The user has pressed the Next button 
back - The user has pressed the Back button 
cancel - The user has pressed the Cancel button 
error - An error has occurred, the dialog cannot be displayed. 
Usually, you don't need to check this value, but you still have to remove it from the stack (have a look at the example above). 
You only have to check this value if you need something really special, such as doing something when the user pressed the Back button. 

有人可以幫我找出新的方法?如果你看下面的代碼文件有一箇舊的和新的部分,並在新的部分,你會看到我想要做的。需要幫助的代碼。

這裏是一個INI文件和代碼文件:

ini文件

[Settings] 
NumFields=5 

[Field 1] 
Type=Label 
Left=160 
Right=235 
Top=9 
Bottom=18 
Text="DropDown 1" 
txtAlign=Center 


[Field 2] 
Type=DROPLIST 
ListItems=Option 1a|Option 1b|Option 1c 
State= 
Flags= 
Left=160 
Right=235 
Top=18 
Bottom=25 

[Field 3] 
Type=Label 
Left=240 
Right=295 
Top=9 
Bottom=18 
Text="DropDown 2" 
txtAlign=Center 


[Field 4] 
Type=DROPLIST 
ListItems=Option 2a|Option 2b|Option 2c 
State= 
Flags= 
Left=240 
Right=295 
Top=18 
Bottom=28 

[Field 5] 
Type=Button 
Flags=NOTIFY 
State= 
Text="More Info" 
Left=200 
Right=250 
Top=125 
Bottom=140 
txtAlign=Center 

代碼文件

!include WinVer.nsh 
!include LogicLib.nsh 
!include x64.nsh 
!include FileFunc.nsh 
!include MUI2.nsh 
!include WinMessages.nsh 
!include InstallOptions.nsh 
!include Sections.nsh 
!include nsDialogs.nsh 

!define MUI_HEADERIMAGE 

    !define TEMP1 $R0 ;Temp variable 

Page custom ShowCustom LeaveCustom ;Custom page. InstallOptions gets called in SetCustom. 
!insertmacro MUI_LANGUAGE "English" 

Function .onInit 
    InitPluginsDir 
    File /oname=$PLUGINSDIR\pagesetup.ini "pagesetup.ini" 
FunctionEnd 


Function ShowCustom 
    InstallOptionsEx::initDialog "$PLUGINSDIR\pagesetup.ini" 
    Pop $0 
    InstallOptionsEx::show 
    Pop $0 
FunctionEnd 


#Old Method 
/* 
Function LeaveCustom 
    ReadINIStr $0 "$PLUGINSDIR\pagesetup.ini" "Settings" "State" 
    StrCmp $0 0 validate ; Next button? 
    StrCmp $0 5 Infobtn ; 
    Abort ; Return to the page 
Infobtn 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Infobtn Pressed" 
Abort ; Return to the page 

validate: 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Next Pressed" 
    #Some Code to check if Field 2 and Field 4 have something selected 
    Abort 
FunctionEnd 
*/ 

#New Method 
Function LeaveCustom 
#Not sure correct code 

#If Back Btn Pressed goto backbtn 
#If Cancel Btn Pressed goto cancelbtn 
#If Next Btn Pressed goto nextbtn 
#If Info btn Press goto infobtn 

backbtn: 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Backbtn Pressed" 
Abort 

cancelbtn: 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Cancelbtn Pressed" 
Abort 

nextbtn: 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Nextbtn Pressed" 
Abort 

infobtn: 
    MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Infobtn Pressed" 
Abort 

FunctionEnd 

Section 

SectionEnd 

回答

0

嗯,我終於想通了,雖然我會後櫃面別人需要。

我有這樣的:

Function ShowCustom 
    InstallOptionsEx::initDialog "$PLUGINSDIR\pagesetup.ini" 
    Pop $0 
    InstallOptionsEx::show 
    Pop $0 
FunctionEnd 

而且它應該是這樣:(例如不應該在那裏)

Function ShowCustom 
    InstallOptions::initDialog "$PLUGINSDIR\pagesetup.ini" 
    Pop $0 
    InstallOptions::show 
    Pop $0 
FunctionEnd 

然後,只需使用當前的檢查

ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State" 
    StrCmp $0 0 validate ; Next button? 
    StrCmp $0 2 supportx ; "Install support for X"? 
    StrCmp $0 9 clearbtn ; "Clear" button? 
    StrCmp $0 11 droplist ; "Show|Hide" drop-list? 
    Abort ; Return to the page