home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / System / System.nsi < prev    next >
Text File  |  2003-09-11  |  5KB  |  143 lines

  1. ; This is just an example of System Plugin
  2. ; (c) brainsucker, 2002
  3. ; (r) BSForce
  4.  
  5. Name "System Plugin Example"
  6. OutFile "System.exe"
  7. SetPluginUnload  alwaysoff
  8.  
  9. !include "${NSISDIR}\Contrib\System\sysfunc.nsh"
  10.  
  11. Section "ThisNameIsIgnoredSoWhyBother?"
  12.      SetOutPath $TEMP
  13.  
  14.      ; ----- Sample 1 ----- Message box with custom icon -----
  15.  
  16.      ; there are no default beeps for custom message boxes, use sysMessageBeep
  17.      ; in case you need it (see next message box example)
  18.      !insertmacro smMessageBox "i 0" "Message box with custom icon!" "System Example 1a" ${MB_OK} "i 103"
  19.      ; i 0 - installer exe as module
  20.      ; i 103 - icon ID
  21.  
  22.      ; The same example but using icon from resource.dll.
  23.      ; You could use this dll for storing your resources, just replace FAR icon
  24.      ; with something you really need.   
  25.      File "${NSISDIR}\Contrib\System\Resource.dll"
  26.      System::Call '${sysMessageBeep} (${MB_ICONHAND})'  ; custom beep
  27.      !insertmacro smMessageBox "`$TEMP\resource.dll`" "Message box with custom icon from resource.dll!" "System Example 1b" ${MB_OKCANCEL} "i 103"
  28.      Delete $TEMP\resource.dll
  29.  
  30.      ; ----- Sample 2 ----- Fixed disks size/space -----
  31.  
  32.      StrCpy $7 '               Disk,                Size,                Free,                Free for user:$\n$\n'
  33.  
  34.      ; Memory for paths   
  35.      System::Alloc 1024
  36.      Pop $1
  37.      ; Get drives   
  38.      System::Call '${sysGetLogicalDriveStrings}(1024, r1)'
  39. enumok:
  40.      ; One more drive?   
  41.      System::Call '${syslstrlen}(i r1) .r2'
  42.      IntCmp $2 0 enumex
  43.  
  44.      ; Is it DRIVE_FIXED?
  45.      System::Call '${sysGetDriveType} (i r1) .r3'
  46.      StrCmp $3 ${DRIVE_FIXED} 0 enumnext
  47.  
  48.      ; Drive space   
  49.      System::Call '${sysGetDiskFreeSpaceEx}(i r1, .r3, .r4, .r5)'
  50.  
  51.      ; Pretty KBs will be saved on stack
  52.      System::Int64Op $3 / 1048576
  53.      System::Int64Op $5 / 1048576
  54.      System::Int64Op $4 / 1048576
  55.  
  56.      ; Get pretty drive path string   
  57.      System::Call '*$1(&t1024 .r6)'
  58.      System::Call '${syswsprintf} (.r7, "%s%20s    %20s mb    %20s mb    %20s mb$\n", tr7, tr6, ts, ts, ts)'
  59.  
  60. enumnext:
  61.      ; Next drive path       
  62.      IntOp $1 $1 + $2
  63.      IntOp $1 $1 + 1
  64.      goto enumok   
  65. enumex: ; End of drives or user cancel
  66.      ; Free memory for paths   
  67.      System::Free $1   
  68.  
  69.      ; Message box      
  70.      System::Call '${sysMessageBox}($HWNDPARENT, s, "System Example 2", ${MB_OKCANCEL})' "$7"
  71.  
  72.      ; ----- Sample 3 ----- Direct proc defenition -----
  73.  
  74.      ; Direct specification demo
  75.      System::Call 'user32::MessageBoxA(i $HWNDPARENT, t "Just direct MessageBoxA specification demo ;)", t "System Example 3", i ${MB_OK}) i.s'
  76.      Pop $0
  77.  
  78.      ; ----- Sample 4 ----- Int64, mixed definition demo -----
  79.  
  80.      ; Long int demo
  81.      StrCpy $2 "12312312"
  82.      StrCpy $3 "12345678903"
  83.      System::Int64Op $2 "*" $3
  84.      Pop $4
  85.  
  86.      ; Cdecl demo (uses 3 defenitions (simple example))
  87.      System::Call "${syswsprintf}(.R1, s,,, t, ir0) .R0 (,,tr2,tr3,$4_)" "Int64 ops and strange defenition demo, %s x %s == %s, and previous msgbox result = %d"
  88.      MessageBox MB_OKCANCEL "Cool: '$R1'"
  89.  
  90.      ; ----- Sample 5 ----- Small structure example -----
  91.  
  92.      ; Create & Fill structure
  93.      System::Call "*(i 123123123, &t10 'Hello', &i1 0x123dd, &i2 0xffeeddccaa) i.s"
  94.      Pop $1
  95.      ; Read data from structure   
  96.      System::Call "*$1(i .r2, &t10 .r3, &i1 .r4, &i2 .r5, &l0 .r6)"
  97.      ; Show data and delete structure
  98.      MessageBox MB_OK "Structure example: $\nint == $2 $\nstring == $3 $\nbyte == $4 $\nshort == $5 $\nsize == $6"
  99.      System::Free $1
  100.  
  101.      ; ----- Sample 6 ----- systemGetFileSysTime demo -----
  102.      Call       GetInstallerExeName
  103.      pop        $0
  104.  
  105.      !insertmacro smGetFileSysTime $0
  106.      System::Call '*$R0${stSYSTEMTIME}(.r1, .r2, .r3, .r4, .r5, .r6, .r7, .r8)'
  107.  
  108.      MessageBox MB_OK "GetFileSysTime example: file '$0', year $1, month $2, dow $3, day $4, hour $5, min $6, sec $7, ms $8"     
  109.  
  110.      ; free memory from SYSTEMTIME
  111.      System::Free $R0   
  112.  
  113.      ; ----- Sample 7 ----- systemSplash -> Callbacks demonstration -----
  114.  
  115.      ; Logo
  116.      File /oname=spltmp.bmp "${NSISDIR}\Contrib\Makensisw\logo.bmp"
  117. ;     File /oname=spltmp.wav "d:\Windows\Media\tada.wav"
  118.  
  119.      ; I. systemSplash variant
  120.      !insertmacro smSystemSplash 2000 "$TEMP\spltmp"
  121.  
  122.      ; II. Splash Plugin variant
  123. ;    splash::show 2000 $TEMP\spltmp
  124. ;    Pop $R0 ; $R0 has '1' if the user closed the splash screen early,
  125.  
  126.      ; remove logo
  127.      Delete $TEMP\spltmp.bmp
  128. ;     Delete $TEMP\spltmp.wav
  129.  
  130.      ; Display splash result
  131.      pop $0
  132.      MessageBox MB_OK "Splash (callbacks) demo result $R0"
  133.  
  134.      ; last plugin call must not have /NOUNLOAD so NSIS will be able to delete the temporary DLL
  135.      SetPluginUnload manual
  136.      ; do nothing
  137.      System::Free 0
  138.  
  139. SectionEnd 
  140.  
  141. ; eof
  142.