2010-11-09 37 views
0

得到-n 0作爲字符串(不需要選項)傳遞給安裝程序的值,我不太明白這個函數的作用是什麼?NSIS得到參數

; GetParameters 
; input, none 
; output, top of stack (replaces, with e.g. whatever) 
; modifies no other variables. 

Function GetParameters 

    Push $R0 
    Push $R1 
    Push $R2 
    Push $R3 

    StrCpy $R2 1 
    StrLen $R3 $CMDLINE 

    ;Check for quote or space 
    StrCpy $R0 $CMDLINE $R2 
    StrCmp $R0 '"' 0 +3 
    StrCpy $R1 '"' 
    Goto loop 
    StrCpy $R1 " " 

    loop: 
    IntOp $R2 $R2 + 1 
    StrCpy $R0 $CMDLINE 1 $R2 
    StrCmp $R0 $R1 get 
    StrCmp $R2 $R3 get 
    Goto loop 

    get: 
    IntOp $R2 $R2 + 1 
    StrCpy $R0 $CMDLINE 1 $R2 
    StrCmp $R0 " " get 
    StrCpy $R0 $CMDLINE "" $R2 

    Pop $R3 
    Pop $R2 
    Pop $R1 
    Exch $R0 

FunctionEnd 

回答

3

GetParameters剛剛得到的參數(「yourapp.exe /富/條」將會給你「/富/酒吧」等),它基本上只是除掉第一令牌(帶引號處理)使用GetOptions得到參數的值。

!include "FileFunc.nsh" 
!include "LogicLib.nsh" 

function .onInit 
${GetParameters} $0 
ClearErrors 
${GetOptions} $0 "-n" $1 
${IfNot} ${Errors} 
    MessageBox mb_ok $1 
${EndIf} 
functionend 
+0

偉大的代碼,它實際上看起來少了很多代碼。 – Proyb2 2010-11-09 16:08:42