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