2010-11-09 5 views
0

pour obtenir -n 0 valeur passant en tant que chaîne (pas besoin d'option) à l'installateur, je ne comprends pas très bien ce que cette fonction fonctionne?NSIS obtenir le paramètre

; 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 

Répondre

3

GetParameters obtient juste les paramètres (« yourapp.exe/foo/bar » vous donnera «/foo/bar », etc.) Il en fait des bandes tout de suite le premier jeton (avec traitement de devis) Utilisez GetOptions pour obtenir la valeur d'un paramètre.

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

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

Très bon code, il semble vraiment beaucoup moins de code. – Proyb2

Questions connexes