Debian Codegraph @

Contrib/System/System.nsi

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