System.nsi 5.1 KB

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