]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_win32/installer.nsi
Imported Upstream version 6.4+svn4214
[mirror_smartmontools-debian.git] / os_win32 / installer.nsi
CommitLineData
4d59bff9 1;
6b80b4d2 2; os_win32/installer.nsi - smartmontools install NSIS script
4d59bff9 3;
6b80b4d2 4; Home page of code is: http://www.smartmontools.org
4d59bff9 5;
293b5ab8 6; Copyright (C) 2006-15 Christian Franke
4d59bff9 7;
cfbba5b9
GI
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2, or (at your option)
11; any later version.
4d59bff9 12;
cfbba5b9
GI
13; You should have received a copy of the GNU General Public License
14; (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
15;
6b80b4d2 16; $Id: installer.nsi 4174 2015-11-22 16:19:29Z chrfranke $
4d59bff9
GG
17;
18
19
20;--------------------------------------------------------------------
21; Command line arguments:
f4e463df
GI
22; makensis -DINPDIR=<input-dir> -DINPDIR64=<input-dir-64-bit> \
23; -DOUTFILE=<output-file> -DVERSTR=<version-string> installer.nsi
4d59bff9
GG
24
25!ifndef INPDIR
26 !define INPDIR "."
27!endif
28
29!ifndef OUTFILE
30 !define OUTFILE "smartmontools.win32-setup.exe"
31!endif
32
33;--------------------------------------------------------------------
34; General
35
36Name "smartmontools"
37OutFile "${OUTFILE}"
38
6b80b4d2
JD
39RequestExecutionLevel admin
40
4d59bff9
GG
41SetCompressor /solid lzma
42
43XPStyle on
44InstallColors /windows
45
f4e463df
GI
46; Set in .onInit
47;InstallDir "$PROGRAMFILES\smartmontools"
6b80b4d2 48;InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
d008864d
GI
49
50Var EDITOR
f4e463df
GI
51
52!ifdef INPDIR64
53 Var X64
54 Var INSTDIR32
55 Var INSTDIR64
56!endif
4d59bff9
GG
57
58LicenseData "${INPDIR}\doc\COPYING.txt"
59
a7e8ffec 60!include "FileFunc.nsh"
6b80b4d2 61!include "LogicLib.nsh"
a7e8ffec
GI
62!include "Sections.nsh"
63
a7e8ffec 64
4d59bff9
GG
65;--------------------------------------------------------------------
66; Pages
67
68Page license
69Page components
f4e463df
GI
70!ifdef INPDIR64
71 Page directory CheckX64
72!else
73 Page directory
74!endif
4d59bff9
GG
75Page instfiles
76
77UninstPage uninstConfirm
78UninstPage instfiles
79
80InstType "Full"
81InstType "Extract files only"
a37e7145 82InstType "Drive menu"
6b80b4d2
JD
83!ifdef INPDIR64
84InstType "Full (x64)"
85InstType "Extract files only (x64)"
86InstType "Drive menu (x64)"
87!endif
4d59bff9
GG
88
89
90;--------------------------------------------------------------------
91; Sections
92
f4e463df 93!ifdef INPDIR64
ee38a438 94 Section "64-bit version" X64_SECTION
6b80b4d2 95 SectionIn 4 5 6
f4e463df
GI
96 ; Handled in Function CheckX64
97 SectionEnd
6b80b4d2
JD
98
99 !define FULL_TYPES "1 4"
100 !define EXTRACT_TYPES "2 5"
101 !define DRIVEMENU_TYPE "3 6"
102!else
103 !define FULL_TYPES "1"
104 !define EXTRACT_TYPES "2"
105 !define DRIVEMENU_TYPE "3"
f4e463df
GI
106!endif
107
a37e7145 108SectionGroup "!Program files"
4d59bff9 109
f4e463df
GI
110 !macro FileExe path option
111 !ifdef INPDIR64
112 ; Use dummy SetOutPath to control archive location of executables
6b80b4d2 113 ${If} $X64 != ""
f4e463df
GI
114 Goto +2
115 SetOutPath "$INSTDIR\bin64"
116 File ${option} '${INPDIR64}\${path}'
6b80b4d2 117 ${Else}
f4e463df
GI
118 Goto +2
119 SetOutPath "$INSTDIR\bin"
120 File ${option} '${INPDIR}\${path}'
6b80b4d2 121 ${EndIf}
f4e463df
GI
122 !else
123 File ${option} '${INPDIR}\${path}'
124 !endif
125 !macroend
126
a37e7145 127 Section "smartctl" SMARTCTL_SECTION
4d59bff9 128
6b80b4d2 129 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
4d59bff9
GG
130
131 SetOutPath "$INSTDIR\bin"
f4e463df 132 !insertmacro FileExe "bin\smartctl.exe" ""
4d59bff9
GG
133
134 SectionEnd
135
a37e7145 136 Section "smartd" SMARTD_SECTION
4d59bff9 137
6b80b4d2 138 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
4d59bff9
GG
139
140 SetOutPath "$INSTDIR\bin"
a37e7145
GG
141
142 ; Stop service ?
143 StrCpy $1 ""
6b80b4d2 144 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
a37e7145 145 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
6b80b4d2 146 ${If} $0 != ""
a37e7145 147 ExecWait "net stop smartd" $1
6b80b4d2
JD
148 ${EndIf}
149 ${EndIf}
f4e463df 150 !insertmacro FileExe "bin\smartd.exe" ""
4d59bff9
GG
151
152 IfFileExists "$INSTDIR\bin\smartd.conf" 0 +2
ee38a438 153 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Replace existing configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
4d59bff9
GG
154 File "${INPDIR}\doc\smartd.conf"
155
ee38a438
GI
156 File "${INPDIR}\bin\smartd_warning.cmd"
157 !insertmacro FileExe "bin\wtssendmsg.exe" ""
4d59bff9 158
a37e7145 159 ; Restart service ?
6b80b4d2 160 ${If} $1 == "0"
ee38a438 161 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Restart smartd service ?" /SD IDNO IDYES 0 IDNO +2
a37e7145 162 ExecWait "net start smartd"
6b80b4d2 163 ${EndIf}
a37e7145 164
4d59bff9
GG
165 SectionEnd
166
2127e193
GI
167 Section "smartctl-nc (GSmartControl)" SMARTCTL_NC_SECTION
168
6b80b4d2 169 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
2127e193
GI
170
171 SetOutPath "$INSTDIR\bin"
f4e463df 172 !insertmacro FileExe "bin\smartctl-nc.exe" ""
2127e193
GI
173
174 SectionEnd
175
cfbba5b9
GI
176 Section "drivedb.h (Drive Database)" DRIVEDB_SECTION
177
6b80b4d2 178 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
cfbba5b9
GI
179
180 SetOutPath "$INSTDIR\bin"
181 File "${INPDIR}\bin\drivedb.h"
182 File "${INPDIR}\bin\update-smart-drivedb.exe"
183
184 SectionEnd
185
4d59bff9
GG
186SectionGroupEnd
187
a37e7145 188Section "!Documentation" DOC_SECTION
4d59bff9 189
6b80b4d2 190 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
4d59bff9
GG
191
192 SetOutPath "$INSTDIR\doc"
193 File "${INPDIR}\doc\AUTHORS.txt"
ee38a438
GI
194 File "${INPDIR}\doc\ChangeLog.txt"
195 File "${INPDIR}\doc\ChangeLog-5.0-6.0.txt"
4d59bff9
GG
196 File "${INPDIR}\doc\COPYING.txt"
197 File "${INPDIR}\doc\INSTALL.txt"
198 File "${INPDIR}\doc\NEWS.txt"
199 File "${INPDIR}\doc\README.txt"
200 File "${INPDIR}\doc\TODO.txt"
f4e463df 201!ifdef INPDIR64
6b80b4d2 202 ${If} $X64 != ""
f4e463df 203 File "${INPDIR64}\doc\checksums64.txt"
6b80b4d2 204 ${Else}
f4e463df 205 File "${INPDIR}\doc\checksums32.txt"
6b80b4d2 206 ${EndIf}
f4e463df
GI
207!else
208 File "${INPDIR}\doc\checksums??.txt"
209!endif
4d59bff9
GG
210 File "${INPDIR}\doc\smartctl.8.html"
211 File "${INPDIR}\doc\smartctl.8.txt"
212 File "${INPDIR}\doc\smartd.8.html"
213 File "${INPDIR}\doc\smartd.8.txt"
214 File "${INPDIR}\doc\smartd.conf"
215 File "${INPDIR}\doc\smartd.conf.5.html"
216 File "${INPDIR}\doc\smartd.conf.5.txt"
217
218SectionEnd
219
a37e7145 220Section "Uninstaller" UNINST_SECTION
4d59bff9 221
6b80b4d2 222 SectionIn ${FULL_TYPES}
f4e463df 223 AddSize 40
4d59bff9
GG
224
225 CreateDirectory "$INSTDIR"
226
d2e702cf
GI
227 ; Keep old Install_Dir registry entry for GSmartControl
228 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GSmartControl" "InstallLocation"
229 ReadRegStr $1 HKLM "Software\smartmontools" "Install_Dir"
6b80b4d2 230 ${If} "$0$1" != ""
d2e702cf 231 WriteRegStr HKLM "Software\smartmontools" "Install_Dir" "$INSTDIR"
6b80b4d2 232 ${EndIf}
4d59bff9
GG
233
234 ; Write uninstall keys and program
235 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools"
2127e193
GI
236!ifdef VERSTR
237 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayVersion" "${VERSTR}"
238!endif
d2e702cf 239 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation" "$INSTDIR"
4d59bff9 240 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "UninstallString" '"$INSTDIR\uninst-smartmontools.exe"'
d2e702cf 241 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "Publisher" "smartmontools.org"
6b80b4d2 242 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLInfoAbout" "https://www.smartmontools.org/"
d2e702cf 243 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "HelpLink" "http://sourceforge.net/projects/smartmontools/support"
6b80b4d2 244 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLUpdateInfo" "http://builds.smartmontools.org/"
4d59bff9
GG
245 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoModify" 1
246 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoRepair" 1
247 WriteUninstaller "uninst-smartmontools.exe"
248
249SectionEnd
250
a37e7145 251Section "Start Menu Shortcuts" MENU_SECTION
4d59bff9 252
6b80b4d2 253 SectionIn ${FULL_TYPES}
4d59bff9 254
a7e8ffec
GI
255 SetShellVarContext all
256
4d59bff9
GG
257 CreateDirectory "$SMPROGRAMS\smartmontools"
258
d008864d
GI
259 !macro CreateAdminShortCut link target args
260 CreateShortCut '${link}' '${target}' '${args}'
261 push '${link}'
262 Call ShellLinkSetRunAs
263 !macroend
264
265 ; runcmdu
6b80b4d2
JD
266 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
267 ${OrIf} ${FileExists} "$INSTDIR\bin\smartd.exe"
d008864d 268 SetOutPath "$INSTDIR\bin"
f4e463df 269 !insertmacro FileExe "bin\runcmdu.exe" ""
6b80b4d2
JD
270 Delete "$INSTDIR\bin\runcmdu.exe.manifest" ; TODO: Remove after smartmontools 6.5
271 ${EndIf}
d008864d 272
4d59bff9 273 ; smartctl
6b80b4d2 274 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
4d59bff9 275 SetOutPath "$INSTDIR\bin"
ee38a438 276 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl (Admin CMD).lnk" "$WINDIR\system32\cmd.exe" '/k PATH=$INSTDIR\bin;%PATH%&cd /d "$INSTDIR\bin"'
4d59bff9
GG
277 CreateDirectory "$SMPROGRAMS\smartmontools\smartctl Examples"
278 FileOpen $0 "$SMPROGRAMS\smartmontools\smartctl Examples\!Read this first!.txt" "w"
a37e7145 279 FileWrite $0 "All the example commands in this directory$\r$\napply to the first drive (sda).$\r$\n"
4d59bff9 280 FileClose $0
ee38a438 281 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\All info (-x).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -x sda"
d008864d 282 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Identify drive (-i).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -i sda"
ee38a438 283 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART attributes (-A -f brief).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -A -f brief sda"
d008864d
GI
284 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART capabilities (-c).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -c sda"
285 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART health status (-H).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -H sda"
286 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART error log (-l error).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -l error sda"
287 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART selftest log (-l selftest).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -l selftest sda"
288 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start long selftest (-t long).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t long sda"
289 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start offline test (-t offline).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t offline sda"
290 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start short selftest (-t short).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t short sda"
291 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Stop(Abort) selftest (-X).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -X sda"
292 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART off (-s off).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -s off sda"
293 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART on (-s on).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -s on sda"
6b80b4d2 294 ${EndIf}
4d59bff9
GG
295
296 ; smartd
6b80b4d2 297 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
4d59bff9 298 SetOutPath "$INSTDIR\bin"
4d59bff9 299 CreateDirectory "$SMPROGRAMS\smartmontools\smartd Examples"
d008864d
GI
300 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, smartd.log.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -l local0"
301 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, eventlog.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd"
302 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon stop.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd stop"
303 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Do all tests once (-q onecheck).lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -q onecheck"
304 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Debug mode (-d).lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -d"
305 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.conf (edit).lnk" "$EDITOR" "$INSTDIR\bin\smartd.conf"
306 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.conf (view).lnk" "$EDITOR" "$INSTDIR\bin\smartd.conf"
307 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.log (view).lnk" "$EDITOR" "$INSTDIR\bin\smartd.log"
4d59bff9 308
ee38a438
GI
309 ; smartd service
310 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, eventlog, 30min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install"
311 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, smartd.log, 10min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install -l local0 -i 600"
312 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, smartd.log, 30min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install -l local0"
313 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service remove.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd remove"
314 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service start.lnk" "$INSTDIR\bin\runcmdu.exe" "net start smartd"
315 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service stop.lnk" "$INSTDIR\bin\runcmdu.exe" "net stop smartd"
6b80b4d2 316 ${EndIf}
4d59bff9
GG
317
318 ; Documentation
6b80b4d2 319 ${If} ${FileExists} "$INSTDIR\doc\README.TXT"
4d59bff9
GG
320 SetOutPath "$INSTDIR\doc"
321 CreateDirectory "$SMPROGRAMS\smartmontools\Documentation"
322 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (html).lnk" "$INSTDIR\doc\smartctl.8.html"
323 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (html).lnk" "$INSTDIR\doc\smartd.8.html"
324 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (html).lnk" "$INSTDIR\doc\smartd.conf.5.html"
325 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (txt).lnk" "$INSTDIR\doc\smartctl.8.txt"
326 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (txt).lnk" "$INSTDIR\doc\smartd.8.txt"
327 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (txt).lnk" "$INSTDIR\doc\smartd.conf.5.txt"
d008864d 328 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf sample.lnk" "$EDITOR" "$INSTDIR\doc\smartd.conf"
6b80b4d2 329 ${If} ${FileExists} "$INSTDIR\bin\drivedb.h"
d008864d
GI
330 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\drivedb.h (view).lnk" "$EDITOR" "$INSTDIR\bin\drivedb.h"
331 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Documentation\drivedb-add.h (create, edit).lnk" "$EDITOR" "$INSTDIR\bin\drivedb-add.h"
6b80b4d2 332 ${EndIf}
ee38a438 333 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\ChangeLog.lnk" "$INSTDIR\doc\ChangeLog.txt"
4d59bff9 334 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\COPYING.lnk" "$INSTDIR\doc\COPYING.txt"
4d59bff9 335 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\NEWS.lnk" "$INSTDIR\doc\NEWS.txt"
6b80b4d2 336 ${EndIf}
4d59bff9
GG
337
338 ; Homepage
6b80b4d2
JD
339 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "https://www.smartmontools.org/"
340 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Daily Builds.lnk" "http://builds.smartmontools.org/"
4d59bff9 341
cfbba5b9 342 ; drivedb.h update
6b80b4d2 343 ${If} ${FileExists} "$INSTDIR\bin\update-smart-drivedb.exe"
d008864d
GI
344 SetOutPath "$INSTDIR\bin"
345 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\drivedb.h update.lnk" "$INSTDIR\bin\update-smart-drivedb.exe" ""
6b80b4d2 346 ${EndIf}
cfbba5b9 347
4d59bff9 348 ; Uninstall
6b80b4d2 349 ${If} ${FileExists} "$INSTDIR\uninst-smartmontools.exe"
d008864d
GI
350 SetOutPath "$INSTDIR"
351 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe" ""
6b80b4d2 352 ${EndIf}
4d59bff9
GG
353
354SectionEnd
355
a37e7145 356Section "Add install dir to PATH" PATH_SECTION
4d59bff9 357
6b80b4d2 358 SectionIn ${FULL_TYPES}
4d59bff9 359
ee38a438
GI
360 Push "$INSTDIR\bin"
361 Call AddToPath
4d59bff9
GG
362
363SectionEnd
364
a37e7145
GG
365SectionGroup "Add smartctl to drive menu"
366
367!macro DriveMenuRemove
368 DetailPrint "Remove drive menu entries"
369 DeleteRegKey HKCR "Drive\shell\smartctl0"
370 DeleteRegKey HKCR "Drive\shell\smartctl1"
371 DeleteRegKey HKCR "Drive\shell\smartctl2"
372 DeleteRegKey HKCR "Drive\shell\smartctl3"
373 DeleteRegKey HKCR "Drive\shell\smartctl4"
374 DeleteRegKey HKCR "Drive\shell\smartctl5"
375!macroend
376
a7e8ffec 377 Section "Remove existing entries first" DRIVE_REMOVE_SECTION
6b80b4d2 378 SectionIn ${DRIVEMENU_TYPE}
a37e7145
GG
379 !insertmacro DriveMenuRemove
380 SectionEnd
381
382!macro DriveSection id name args
383 Section 'smartctl ${args} ...' DRIVE_${id}_SECTION
6b80b4d2 384 SectionIn ${DRIVEMENU_TYPE}
d008864d 385 Call CheckRunCmdA
a37e7145
GG
386 DetailPrint 'Add drive menu entry "${name}": smartctl ${args} ...'
387 WriteRegStr HKCR "Drive\shell\smartctl${id}" "" "${name}"
d008864d 388 WriteRegStr HKCR "Drive\shell\smartctl${id}\command" "" '"$INSTDIR\bin\runcmda.exe" "$INSTDIR\bin\smartctl.exe" ${args} %L'
a37e7145
GG
389 SectionEnd
390!macroend
391
ee38a438 392 !insertmacro DriveSection 0 "SMART all info" "-x"
a37e7145 393 !insertmacro DriveSection 1 "SMART status" "-Hc"
ee38a438 394 !insertmacro DriveSection 2 "SMART attributes" "-A -f brief"
a37e7145
GG
395 !insertmacro DriveSection 3 "SMART short selftest" "-t short"
396 !insertmacro DriveSection 4 "SMART long selftest" "-t long"
397 !insertmacro DriveSection 5 "SMART continue selective selftest" '-t "selective,cont"'
398
399SectionGroupEnd
400
4d59bff9
GG
401;--------------------------------------------------------------------
402
403Section "Uninstall"
404
a37e7145 405 ; Stop & remove service
6b80b4d2 406 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
a37e7145 407 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
6b80b4d2 408 ${If} $0 != ""
a37e7145 409 ExecWait "net stop smartd"
6b80b4d2 410 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Remove smartd service ?" /SD IDNO IDYES 0 IDNO +2
a37e7145 411 ExecWait "$INSTDIR\bin\smartd.exe remove"
6b80b4d2
JD
412 ${EndIf}
413 ${EndIf}
a37e7145
GG
414
415 ; Remove installer registry keys
4d59bff9
GG
416 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools"
417 DeleteRegKey HKLM "Software\smartmontools"
418
cfbba5b9 419 ; Remove conf file ?
6b80b4d2 420 ${If} ${FileExists} "$INSTDIR\bin\smartd.conf"
4d59bff9
GG
421 ; Assume unchanged if timestamp is equal to sample file
422 GetFileTime "$INSTDIR\bin\smartd.conf" $0 $1
423 GetFileTime "$INSTDIR\doc\smartd.conf" $2 $3
424 StrCmp "$0:$1" "$2:$3" +2 0
6b80b4d2 425 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
4d59bff9 426 Delete "$INSTDIR\bin\smartd.conf"
6b80b4d2 427 ${EndIf}
4d59bff9 428
cfbba5b9 429 ; Remove log file ?
6b80b4d2 430 ${If} ${FileExists} "$INSTDIR\bin\smartd.log"
ee38a438 431 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" /SD IDNO IDYES 0 IDNO +2
4d59bff9 432 Delete "$INSTDIR\bin\smartd.log"
6b80b4d2 433 ${EndIf}
4d59bff9 434
cfbba5b9 435 ; Remove drivedb-add file ?
6b80b4d2 436 ${If} ${FileExists} "$INSTDIR\bin\drivedb-add.h"
ee38a438 437 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete local drive database file$\n$INSTDIR\bin\drivedb-add.h ?" /SD IDNO IDYES 0 IDNO +2
cfbba5b9 438 Delete "$INSTDIR\bin\drivedb-add.h"
6b80b4d2 439 ${EndIf}
cfbba5b9 440
4d59bff9
GG
441 ; Remove files
442 Delete "$INSTDIR\bin\smartctl.exe"
2127e193 443 Delete "$INSTDIR\bin\smartctl-nc.exe"
4d59bff9 444 Delete "$INSTDIR\bin\smartd.exe"
ee38a438 445 Delete "$INSTDIR\bin\smartd_warning.cmd" ; TODO: Check for modifications?
cfbba5b9
GI
446 Delete "$INSTDIR\bin\drivedb.h"
447 Delete "$INSTDIR\bin\drivedb.h.error"
448 Delete "$INSTDIR\bin\drivedb.h.lastcheck"
449 Delete "$INSTDIR\bin\drivedb.h.old"
450 Delete "$INSTDIR\bin\update-smart-drivedb.exe"
4d59bff9
GG
451 Delete "$INSTDIR\bin\smartctl-run.bat"
452 Delete "$INSTDIR\bin\smartd-run.bat"
453 Delete "$INSTDIR\bin\net-run.bat"
d008864d 454 Delete "$INSTDIR\bin\runcmda.exe"
6b80b4d2 455 Delete "$INSTDIR\bin\runcmda.exe.manifest" ; TODO: Remove after smartmontools 6.5
d008864d 456 Delete "$INSTDIR\bin\runcmdu.exe"
6b80b4d2 457 Delete "$INSTDIR\bin\runcmdu.exe.manifest" ; TODO: Remove after smartmontools 6.5
ee38a438 458 Delete "$INSTDIR\bin\wtssendmsg.exe"
4d59bff9 459 Delete "$INSTDIR\doc\AUTHORS.txt"
ee38a438
GI
460 Delete "$INSTDIR\doc\ChangeLog.txt"
461 Delete "$INSTDIR\doc\ChangeLog-5.0-6.0.txt"
4d59bff9
GG
462 Delete "$INSTDIR\doc\COPYING.txt"
463 Delete "$INSTDIR\doc\INSTALL.txt"
464 Delete "$INSTDIR\doc\NEWS.txt"
465 Delete "$INSTDIR\doc\README.txt"
466 Delete "$INSTDIR\doc\TODO.txt"
f4e463df 467 Delete "$INSTDIR\doc\checksums*.txt"
4d59bff9
GG
468 Delete "$INSTDIR\doc\smartctl.8.html"
469 Delete "$INSTDIR\doc\smartctl.8.txt"
470 Delete "$INSTDIR\doc\smartd.8.html"
471 Delete "$INSTDIR\doc\smartd.8.txt"
472 Delete "$INSTDIR\doc\smartd.conf"
473 Delete "$INSTDIR\doc\smartd.conf.5.html"
474 Delete "$INSTDIR\doc\smartd.conf.5.txt"
475 Delete "$INSTDIR\uninst-smartmontools.exe"
476
477 ; Remove shortcuts
a7e8ffec 478 SetShellVarContext all
4d59bff9
GG
479 Delete "$SMPROGRAMS\smartmontools\*.*"
480 Delete "$SMPROGRAMS\smartmontools\Documentation\*.*"
481 Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*"
482 Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*"
483
484 ; Remove folders
485 RMDir "$SMPROGRAMS\smartmontools\Documentation"
a37e7145
GG
486 RMDir "$SMPROGRAMS\smartmontools\smartctl Examples"
487 RMDir "$SMPROGRAMS\smartmontools\smartd Examples"
4d59bff9
GG
488 RMDir "$SMPROGRAMS\smartmontools"
489 RMDir "$INSTDIR\bin"
490 RMDir "$INSTDIR\doc"
491 RMDir "$INSTDIR"
492
493 ; Remove install dir from PATH
ee38a438
GI
494 Push "$INSTDIR\bin"
495 Call un.RemoveFromPath
4d59bff9 496
a37e7145
GG
497 ; Remove drive menu registry entries
498 !insertmacro DriveMenuRemove
499
500 ; Check for still existing entries
6b80b4d2 501 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
ee38a438 502 MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running." /SD IDOK
6b80b4d2 503 ${ElseIf} ${FileExists} "$INSTDIR"
ee38a438 504 MessageBox MB_OK "Note: $INSTDIR could not be removed." /SD IDOK
6b80b4d2 505 ${EndIf}
4d59bff9 506
6b80b4d2 507 ${If} ${FileExists} "$SMPROGRAMS\smartmontools"
ee38a438 508 MessageBox MB_OK "Note: $SMPROGRAMS\smartmontools could not be removed." /SD IDOK
6b80b4d2 509 ${EndIf}
a37e7145 510
4d59bff9
GG
511SectionEnd
512
513;--------------------------------------------------------------------
a37e7145 514; Functions
4d59bff9 515
f4e463df
GI
516!macro AdjustSectionSize section
517 SectionGetSize ${section} $0
518 IntOp $0 $0 / 2
519 SectionSetSize ${section} $0
520!macroend
521
4d59bff9
GG
522Function .onInit
523
f4e463df 524 ; Set default install directories
6b80b4d2
JD
525 ${If} $INSTDIR == "" ; /D=PATH option not specified ?
526 ReadRegStr $INSTDIR HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
527 ${If} $INSTDIR == "" ; Not already installed ?
528 ReadRegStr $INSTDIR HKLM "Software\smartmontools" "Install_Dir"
529 ${If} $INSTDIR == "" ; Not already installed (smartmontools < r3911/6.3) ?
530 StrCpy $INSTDIR "$PROGRAMFILES\smartmontools"
f4e463df 531!ifdef INPDIR64
6b80b4d2
JD
532 StrCpy $INSTDIR32 $INSTDIR
533 StrCpy $INSTDIR64 "$PROGRAMFILES64\smartmontools"
f4e463df 534!endif
6b80b4d2
JD
535 ${EndIf}
536 ${EndIf}
537 ${EndIf}
f4e463df
GI
538
539!ifdef INPDIR64
6b80b4d2
JD
540 ; Check for 64-bit unless already installed in 32-bit location
541 ${If} $INSTDIR64 != ""
542 ${OrIf} $INSTDIR != "$PROGRAMFILES\smartmontools"
543 ; $1 = IsWow64Process(GetCurrentProcess(), ($0=FALSE, &$0))
544 System::Call "kernel32::GetCurrentProcess() i.s"
545 System::Call "kernel32::IsWow64Process(i s, *i 0 r0) i.r1"
546 ${If} "$0 $1" == "1 1" ; 64-bit Windows ?
547 !insertmacro SelectSection ${X64_SECTION}
548 ${EndIf}
549 ${EndIf}
550
f4e463df
GI
551 ; Sizes of binary sections include 32-bit and 64-bit executables
552 !insertmacro AdjustSectionSize ${SMARTCTL_SECTION}
553 !insertmacro AdjustSectionSize ${SMARTD_SECTION}
554 !insertmacro AdjustSectionSize ${SMARTCTL_NC_SECTION}
555!endif
556
d008864d
GI
557 ; Use Notepad++ if installed
558 StrCpy $EDITOR "$PROGRAMFILES\Notepad++\notepad++.exe"
6b80b4d2 559 ${IfNot} ${FileExists} "$EDITOR"
d008864d 560 StrCpy $EDITOR "notepad.exe"
6b80b4d2 561 ${EndIf}
d008864d 562
a7e8ffec 563 Call ParseCmdLine
6b80b4d2
JD
564
565!ifdef INPDIR64
566 Call CheckX64
567!endif
a7e8ffec
GI
568FunctionEnd
569
f4e463df
GI
570; Check x64 section and update INSTDIR accordingly
571
572!ifdef INPDIR64
573Function CheckX64
6b80b4d2 574 ${IfNot} ${SectionIsSelected} ${X64_SECTION}
f4e463df 575 StrCpy $X64 ""
6b80b4d2
JD
576 ${If} $INSTDIR32 != ""
577 ${AndIf} $INSTDIR == $INSTDIR64
f4e463df 578 StrCpy $INSTDIR $INSTDIR32
6b80b4d2
JD
579 ${EndIf}
580 ${Else}
f4e463df 581 StrCpy $X64 "t"
6b80b4d2
JD
582 ${If} $INSTDIR64 != ""
583 ${AndIf} $INSTDIR == $INSTDIR32
f4e463df 584 StrCpy $INSTDIR $INSTDIR64
6b80b4d2
JD
585 ${EndIf}
586 ${EndIf}
f4e463df
GI
587FunctionEnd
588!endif
589
a7e8ffec 590; Command line parsing
6b80b4d2
JD
591
592!macro GetCmdLineOption var name
a7e8ffec
GI
593 Push ",$opts,"
594 Push ",${name},"
595 Call StrStr
6b80b4d2
JD
596 Pop ${var}
597 ${If} ${var} != ""
598 StrCpy $nomatch ""
599 ${EndIf}
600!macroend
601
602!macro CheckCmdLineOption name section
603 StrCpy $allopts "$allopts,${name}"
604 !insertmacro GetCmdLineOption $0 ${name}
605 ${If} $0 == ""
606 !insertmacro UnselectSection ${section}
607 ${Else}
608 !insertmacro SelectSection ${section}
609 ${EndIf}
a7e8ffec
GI
610!macroend
611
612Function ParseCmdLine
613 ; get /SO option
614 Var /global opts
615 ${GetParameters} $R0
616 ${GetOptions} $R0 "/SO" $opts
6b80b4d2 617 ${If} ${Errors}
a7e8ffec 618 Return
6b80b4d2 619 ${EndIf}
a7e8ffec 620 Var /global allopts
a7e8ffec
GI
621 Var /global nomatch
622 StrCpy $nomatch "t"
f4e463df 623!ifdef INPDIR64
6b80b4d2
JD
624 ; Change previous 64-bit setting
625 StrCpy $allopts ",x32|x64"
626 !insertmacro GetCmdLineOption $0 "x32"
627 ${If} $0 != ""
628 !insertmacro UnselectSection ${X64_SECTION}
629 ${EndIf}
630 !insertmacro GetCmdLineOption $0 "x64"
631 ${If} $0 != ""
632 !insertmacro SelectSection ${X64_SECTION}
633 ${EndIf}
634 ; Leave other sections unchanged if only "x32" or "x64" is specified
635 ${If} $opts == "x32"
636 ${OrIf} $opts == "x64"
637 Return
638 ${EndIf}
f4e463df 639!endif
6b80b4d2 640 ; Turn sections on or off
a7e8ffec
GI
641 !insertmacro CheckCmdLineOption "smartctl" ${SMARTCTL_SECTION}
642 !insertmacro CheckCmdLineOption "smartd" ${SMARTD_SECTION}
643 !insertmacro CheckCmdLineOption "smartctlnc" ${SMARTCTL_NC_SECTION}
644 !insertmacro CheckCmdLineOption "drivedb" ${DRIVEDB_SECTION}
645 !insertmacro CheckCmdLineOption "doc" ${DOC_SECTION}
646 !insertmacro CheckCmdLineOption "uninst" ${UNINST_SECTION}
647 !insertmacro CheckCmdLineOption "menu" ${MENU_SECTION}
648 !insertmacro CheckCmdLineOption "path" ${PATH_SECTION}
649 !insertmacro CheckCmdLineOption "driveremove" ${DRIVE_REMOVE_SECTION}
650 !insertmacro CheckCmdLineOption "drive0" ${DRIVE_0_SECTION}
651 !insertmacro CheckCmdLineOption "drive1" ${DRIVE_1_SECTION}
652 !insertmacro CheckCmdLineOption "drive2" ${DRIVE_2_SECTION}
653 !insertmacro CheckCmdLineOption "drive3" ${DRIVE_3_SECTION}
654 !insertmacro CheckCmdLineOption "drive4" ${DRIVE_4_SECTION}
655 !insertmacro CheckCmdLineOption "drive5" ${DRIVE_5_SECTION}
6b80b4d2
JD
656 ${If} $opts != "-"
657 ${If} $nomatch != ""
658 StrCpy $0 "$allopts,-" "" 1
659 MessageBox MB_OK "Usage: smartmontools-VERSION.win32-setup [/S] [/SO component,...] [/D=INSTDIR]$\n$\ncomponents:$\n $0"
660 Abort
661 ${EndIf}
662 ${EndIf}
4d59bff9
GG
663FunctionEnd
664
6b80b4d2 665; Install runcmda.exe only once
cfbba5b9 666
d008864d 667Function CheckRunCmdA
6b80b4d2
JD
668 Var /global runcmda
669 ${If} $runcmda == ""
670 StrCpy $runcmda "t"
cfbba5b9 671 SetOutPath "$INSTDIR\bin"
f4e463df 672 !insertmacro FileExe "bin\runcmda.exe" ""
6b80b4d2
JD
673 Delete "$INSTDIR\bin\runcmda.exe.manifest" ; TODO: Remove after smartmontools 6.5
674 ${EndIf}
cfbba5b9
GI
675FunctionEnd
676
4d59bff9
GG
677
678;--------------------------------------------------------------------
a37e7145 679; Path functions
4d59bff9
GG
680;
681; Based on example from:
682; http://nsis.sourceforge.net/Path_Manipulation
683;
684
685
686!include "WinMessages.nsh"
687
688; Registry Entry for environment (NT4,2000,XP)
689; All users:
690;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
691; Current user only:
692!define Environ 'HKCU "Environment"'
693
694
695; AddToPath - Appends dir to PATH
696; (does not work on Win9x/ME)
697;
698; Usage:
699; Push "dir"
700; Call AddToPath
701
702Function AddToPath
703 Exch $0
704 Push $1
705 Push $2
706 Push $3
293b5ab8 707 Push $4
a37e7145 708
293b5ab8
JD
709 ; NSIS ReadRegStr returns empty string on string overflow
710 ; Native calls are used here to check actual length of PATH
711
712 ; $4 = RegOpenKey(HKEY_CURRENT_USER, "Environment", &$3)
713 System::Call "advapi32::RegOpenKey(i 0x80000001, t'Environment', *i.r3) i.r4"
714 IntCmp $4 0 0 done done
715 ; $4 = RegQueryValueEx($3, "PATH", (DWORD*)0, (DWORD*)0, &$1, ($2=NSIS_MAX_STRLEN, &$2))
716 ; RegCloseKey($3)
717 System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
718 System::Call "advapi32::RegCloseKey(i $3)"
719
6b80b4d2 720 ${If} $4 = 234 ; ERROR_MORE_DATA
293b5ab8 721 DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
6b80b4d2 722 MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}" /SD IDOK
293b5ab8 723 Goto done
6b80b4d2 724 ${EndIf}
293b5ab8 725
6b80b4d2
JD
726 ${If} $4 <> 0 ; NO_ERROR
727 ${If} $4 <> 2 ; ERROR_FILE_NOT_FOUND
293b5ab8
JD
728 DetailPrint "AddToPath: unexpected error code $4"
729 Goto done
6b80b4d2 730 ${EndIf}
293b5ab8 731 StrCpy $1 ""
6b80b4d2 732 ${EndIf}
293b5ab8
JD
733
734 ; Check if already in PATH
4d59bff9
GG
735 Push "$1;"
736 Push "$0;"
737 Call StrStr
738 Pop $2
a37e7145 739 StrCmp $2 "" 0 done
4d59bff9
GG
740 Push "$1;"
741 Push "$0\;"
742 Call StrStr
743 Pop $2
a37e7145
GG
744 StrCmp $2 "" 0 done
745
293b5ab8
JD
746 ; Prevent NSIS string overflow
747 StrLen $2 $0
748 StrLen $3 $1
749 IntOp $2 $2 + $3
750 IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";")
6b80b4d2 751 ${If} $2 > ${NSIS_MAX_STRLEN}
293b5ab8 752 DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}"
6b80b4d2 753 MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}." /SD IDOK
293b5ab8 754 Goto done
6b80b4d2 755 ${EndIf}
293b5ab8
JD
756
757 ; Append dir to PATH
4d59bff9
GG
758 DetailPrint "Add to PATH: $0"
759 StrCpy $2 $1 1 -1
6b80b4d2 760 ${If} $2 == ";"
4d59bff9 761 StrCpy $1 $1 -1 ; remove trailing ';'
6b80b4d2
JD
762 ${EndIf}
763 ${If} $1 != "" ; no leading ';'
4d59bff9 764 StrCpy $0 "$1;$0"
6b80b4d2 765 ${EndIf}
4d59bff9
GG
766 WriteRegExpandStr ${Environ} "PATH" $0
767 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
a37e7145 768
4d59bff9 769done:
293b5ab8 770 Pop $4
4d59bff9
GG
771 Pop $3
772 Pop $2
773 Pop $1
774 Pop $0
775FunctionEnd
776
777
778; RemoveFromPath - Removes dir from PATH
779;
780; Usage:
781; Push "dir"
782; Call RemoveFromPath
a37e7145 783
4d59bff9
GG
784Function un.RemoveFromPath
785 Exch $0
786 Push $1
787 Push $2
788 Push $3
789 Push $4
790 Push $5
791 Push $6
a37e7145 792
4d59bff9
GG
793 ReadRegStr $1 ${Environ} "PATH"
794 StrCpy $5 $1 1 -1
6b80b4d2 795 ${If} $5 != ";"
4d59bff9 796 StrCpy $1 "$1;" ; ensure trailing ';'
6b80b4d2 797 ${EndIf}
4d59bff9
GG
798 Push $1
799 Push "$0;"
800 Call un.StrStr
801 Pop $2 ; pos of our dir
802 StrCmp $2 "" done
803
804 DetailPrint "Remove from PATH: $0"
805 StrLen $3 "$0;"
806 StrLen $4 $2
807 StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove
808 StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
809 StrCpy $3 "$5$6"
810 StrCpy $5 $3 1 -1
6b80b4d2 811 ${If} $5 == ";"
4d59bff9 812 StrCpy $3 $3 -1 ; remove trailing ';'
6b80b4d2 813 ${EndIf}
4d59bff9
GG
814 WriteRegExpandStr ${Environ} "PATH" $3
815 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
816
817done:
818 Pop $6
819 Pop $5
820 Pop $4
821 Pop $3
822 Pop $2
823 Pop $1
824 Pop $0
825FunctionEnd
826
827
828; StrStr - find substring in a string
829;
830; Usage:
831; Push "this is some string"
832; Push "some"
833; Call StrStr
834; Pop $0 ; "some string"
a37e7145 835
4d59bff9
GG
836!macro StrStr un
837Function ${un}StrStr
838 Exch $R1 ; $R1=substring, stack=[old$R1,string,...]
839 Exch ; stack=[string,old$R1,...]
840 Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...]
841 Push $R3
842 Push $R4
843 Push $R5
844 StrLen $R3 $R1
845 StrCpy $R4 0
846 ; $R1=substring, $R2=string, $R3=strlen(substring)
847 ; $R4=count, $R5=tmp
6b80b4d2 848 ${Do}
4d59bff9 849 StrCpy $R5 $R2 $R3 $R4
6b80b4d2
JD
850 ${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
851 ${IfThen} $R5 == "" ${|} ${ExitDo} ${|}
4d59bff9 852 IntOp $R4 $R4 + 1
6b80b4d2 853 ${Loop}
4d59bff9
GG
854 StrCpy $R1 $R2 "" $R4
855 Pop $R5
856 Pop $R4
857 Pop $R3
858 Pop $R2
859 Exch $R1 ; $R1=old$R1, stack=[result,...]
860FunctionEnd
861!macroend
862!insertmacro StrStr ""
863!insertmacro StrStr "un."
d008864d
GI
864
865
866;--------------------------------------------------------------------
867; Set Run As Administrator flag in shortcut
868;
869; Slightly modified version from:
870; http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag
871;
872
d008864d
GI
873!define IPersistFile {0000010b-0000-0000-c000-000000000046}
874!define CLSID_ShellLink {00021401-0000-0000-C000-000000000046}
875!define IID_IShellLinkA {000214EE-0000-0000-C000-000000000046}
876!define IID_IShellLinkW {000214F9-0000-0000-C000-000000000046}
877!define IShellLinkDataList {45e2b4ae-b1c3-11d0-b92f-00a0c90312e1}
878!ifdef NSIS_UNICODE
879 !define IID_IShellLink ${IID_IShellLinkW}
880!else
881 !define IID_IShellLink ${IID_IShellLinkA}
882!endif
883
884Function ShellLinkSetRunAs
f4e463df
GI
885 ; Set archive location of $PLUGINSDIR
886 Goto +2
887 SetOutPath "$INSTDIR"
888
d008864d
GI
889 System::Store S ; push $0-$9, $R0-$R9
890 pop $9
891 ; $0 = CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER, IID_IShellLink, &$1)
892 System::Call "ole32::CoCreateInstance(g'${CLSID_ShellLink}',i0,i1,g'${IID_IShellLink}',*i.r1)i.r0"
893 ${If} $0 = 0
894 System::Call "$1->0(g'${IPersistFile}',*i.r2)i.r0" ; $0 = $1->QueryInterface(IPersistFile, &$2)
895 ${If} $0 = 0
896 System::Call "$2->5(w '$9',i 0)i.r0" ; $0 = $2->Load($9, STGM_READ)
897 ${If} $0 = 0
898 System::Call "$1->0(g'${IShellLinkDataList}',*i.r3)i.r0" ; $0 = $1->QueryInterface(IShellLinkDataList, &$3)
899 ${If} $0 = 0
900 System::Call "$3->6(*i.r4)i.r0"; $0 = $3->GetFlags(&$4)
901 ${If} $0 = 0
902 System::Call "$3->7(i $4|0x2000)i.r0" ; $0 = $3->SetFlags($4|SLDF_RUNAS_USER)
903 ${If} $0 = 0
904 System::Call "$2->6(w '$9',i1)i.r0" ; $2->Save($9, TRUE)
905 ${EndIf}
906 ${EndIf}
907 System::Call "$3->2()" ; $3->Release()
908 ${EndIf}
909 System::Call "$2->2()" ; $2->Release()
910 ${EndIf}
911 ${EndIf}
912 System::Call "$1->2()" ; $1->Release()
913 ${EndIf}
914 ${If} $0 <> 0
915 DetailPrint "Set RunAsAdmin: $9 failed ($0)"
916 ${Else}
917 DetailPrint "Set RunAsAdmin: $9"
918 ${EndIf}
6b80b4d2 919 System::Store L ; pop $R9-$R0, $9-$0
d008864d 920FunctionEnd