System.nsi 4.5 KB

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