super-llooyd
8th December 2005 02:47 UTC
how to use commmand line tool / how to write a function
I wrote a command line tool (in human C language) which performs a few check at install time.
I would like to invoke it during installation and take measure accordingly to its result.
I try ty to write a function like that:
Function IsDotNETInstalled
ExecWait 'InstallUtil.exe Check.NET2' $0
IntCmp $0 0 +2
$0 = "no.NETFramework"
return
$0 = "foundDotNET"
FunctionEnd
and the compiler don't accept it, it says:
Invalid command: '$0'
I had the feeling value should be returned in $0.
so, how do I return a value?
super-llooyd
8th December 2005 03:05 UTC
BTW how do I:
- affect a variable?
- return a value?
dandaman32
8th December 2005 03:22 UTC
I feel your pain - NSIS functions don't "return" values as C does. To assign a value to $0, use:
StrCpy $0 VALUE
. NSIS doesn't use different types of variables (integers, boolean, strings) - in NSIS, everything's a string - BUT strings can be treated as integers.
You can use Push and Pop to get return values from functions:
Function PushPop
  MessageBox MB_YESNO "Do you want to do something?" IDYES DoSomething
  Push "0"
  Return
  DoSomething:
  Push "1"
  Return
FunctionEnd
Section "A Section"
  Call PushPop
  Pop $0
  ; at this point $0 is either 1 (user clicked yes) or 0 (user clicked no)
  StrCmp $0 1 0 +2
  MessageBox MB_OK "Doing something"
SectionEnd
Variables can be used directly inside of strings. For example, in PHP:
      
$var2="Contents of var1 are " . $var1;
but in NSIS:
      
StrCpy $Var2 "Contents of var1 are $Var1"
      
      I know it's different - NSIS isn't a "typical" programming language. If you want for-loops, C-style conditionals, et cetera, use LogicLib.
      
      Kichik - maybe using $0="value" would be nice for newbies that are used to C[++].
      
      -dandaman32
    
 
    
      super-llooyd
      8th December 2005 06:35 UTC
      thanks again dandaman
     
    
      Takhir
      8th December 2005 07:19 UTC
      Did you saw archive function for "IsDotNETInstalled"?
      http://nsis.sourceforge.net/How_to_D....NET_Framework
      http://nsis.sourceforge.net/How_to_i...k_is_installed
      http://nsis.sourceforge.net/Get_.NET_Version
      If you need 2.0 version, in the first script you can check current value:
      
...
EnumStart:
     EnumRegKey $2 HKEY_LOCAL_MACHINE "Software\Microsoft\.NETFramework\Policy"  $0
     IntOp $0 $0 + 1
     StrCmp $2 "" noDotNET
     StrCmp $2 "v1.0" EnumStart ; >=1.1 required
     StrCmp $2 "v1.1" EnumStart ; >=2.0 required
...