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