2016-11-25 149 views
0

我在我的nsi腳本中添加了一個${NSD_CreateIPaddress}框,但驗證IP的每個字段默認爲0。我通過使用${GetText}來獲取IP地址值。NSIS:如何驗證IP地址框

有什麼方法可以刪除默認值0並驗證每個IP地址字段。請幫助我。

+0

是'$ {}的getText'在離開功能?請添加腳本的*最小*示例 – idleberg

回答

0

我不確定你在問什麼。如果您想告訴空白地址與有效的「0.0.0.0」地址之間的區別,您可以使用IPM_ISBLANK消息。不應該有任何需要驗證的各個字段,因爲它們已經限制爲0..255,你甚至可以設定IPM_SETRANGE.

自定義範圍如果你仍然覺得有必要看一下各個字段可以

A)手動解析您自己從$ {NSD_GetText}中獲得的字符串。

B)拆開的32位地址,你從IPM_GETADDRESS得到:

Page Custom myPage myPageLeave 
Page InstFiles 

!include nsDialogs.nsh 
; Using custom version of http://nsis.sourceforge.net/NsDialogs_CreateIPaddress 
!ifndef NSD_CreateIPaddress 
!define NSD_CreateIPaddress "!insertmacro NSD_CreateIPaddress " 
!include LogicLib.nsh 
!include WinMessages.nsh 
!ifndef ICC_INTERNET_CLASSES 
!define ICC_INTERNET_CLASSES 0x00000800 
!endif 
Function CCInitIP 
!insertmacro _LOGICLIB_TEMP 
System::Call '*(i8,i${ICC_INTERNET_CLASSES})p.s' ; NSIS 2.50+ 
System::Call 'COMCTL32::InitCommonControlsEx(pss)' 
Pop $_LOGICLIB_TEMP 
System::Free $_LOGICLIB_TEMP 
FunctionEnd 
!macro NSD_CreateIPaddress x y w h t 
!insertmacro _LOGICLIB_TEMP 
Call CCInitIP 
nsDialogs::CreateControl "SysIPAddress32" ${DEFAULT_STYLES}|${WS_TABSTOP} 0 ${x} ${y} ${w} ${h} "${t}" 
Exch $0 
CreateFont $_LOGICLIB_TEMP "$(^Font)" "$(^FontSize)" 
SendMessage $0 ${WM_SETFONT} $_LOGICLIB_TEMP 1 
Exch $0 
!macroend 
!define /math IPM_GETADDRESS ${WM_USER} + 102 
!define /math IPM_ISBLANK ${WM_USER} + 105 
!endif 

Function OnIPNotify ; This function displays some information about the IP 
Pop $0 ; Not used 

${NSD_GetText} $1 $3 
StrCpy $4 "NSD_GetText: $3" 

SendMessage $1 ${IPM_ISBLANK} 0 0 $0 
StrCpy $4 "$4$\nIPM_ISBLANK: $0" 

System::Call 'USER32::SendMessage(pr1, i ${IPM_GETADDRESS}, p 0, *i0 r3)p.r0' ; NSIS 2.50+ 
IntFmt $5 "0x%.8x" $3 
StrCpy $4 "$4$\nIPM_GETADDRESS: ValidFields=$0 PackedIP=$5" 
IntOp $0 $3 >> 24 
IntOp $0 $0 & 0xff 
StrCpy $4 "$4$\n$\t Field1=$0" 
IntOp $0 $3 >> 16 
IntOp $0 $0 & 0xff 
StrCpy $4 "$4$\n$\t Field2=$0" 
IntOp $0 $3 >> 8 
IntOp $0 $0 & 0xff 
StrCpy $4 "$4$\n$\t Field3=$0" 
IntOp $0 $3 & 0xff 
StrCpy $4 "$4$\n$\t Field4=$0" 

${NSD_SetText} $2 $4 
FunctionEnd 

Function myPage 
nsDialogs::Create 1018 
Pop $0 
${NSD_CreateIPaddress} 1% 0 50% 12u "" 
Pop $1 
${NSD_CreateLabel} 1% 20u 98% -20u "Enter an IP address to see information here..." 
Pop $2 

${NSD_OnNotify} $1 OnIPNotify ; Display some information when the control is changed 
nsDialogs::Show 
FunctionEnd 

Function myPageLeave 
Push 0 
Call OnIPNotify 
MessageBox mb_ok $4 
FunctionEnd