2 ; os_win32/installer.nsi - smartmontools install NSIS script
4 ; Home page of code is: http://www.smartmontools.org
6 ; Copyright (C) 2006-15 Christian Franke
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)
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/>.
16 ; $Id: installer.nsi 4174 2015-11-22 16:19:29Z chrfranke $
20 ;--------------------------------------------------------------------
21 ; Command line arguments:
22 ; makensis -DINPDIR=<input-dir> -DINPDIR64=<input-dir-64-bit> \
23 ; -DOUTFILE=<output-file> -DVERSTR=<version-string> installer.nsi
30 !define OUTFILE "smartmontools.win32-setup.exe"
33 ;--------------------------------------------------------------------
39 RequestExecutionLevel admin
41 SetCompressor /solid lzma
44 InstallColors /windows
47 ;InstallDir "$PROGRAMFILES\smartmontools"
48 ;InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
58 LicenseData "${INPDIR}\doc\COPYING.txt"
60 !include "FileFunc.nsh"
61 !include "LogicLib.nsh"
62 !include "Sections.nsh"
65 ;--------------------------------------------------------------------
71 Page directory CheckX64
77 UninstPage uninstConfirm
81 InstType "Extract files only"
85 InstType "Extract files only (x64)"
86 InstType "Drive menu (x64)"
90 ;--------------------------------------------------------------------
94 Section "64-bit version" X64_SECTION
96 ; Handled in Function CheckX64
99 !define FULL_TYPES "1 4"
100 !define EXTRACT_TYPES "2 5"
101 !define DRIVEMENU_TYPE "3 6"
103 !define FULL_TYPES "1"
104 !define EXTRACT_TYPES "2"
105 !define DRIVEMENU_TYPE "3"
108 SectionGroup "!Program files"
110 !macro FileExe path option
112 ; Use dummy SetOutPath to control archive location of executables
115 SetOutPath "$INSTDIR\bin64"
116 File ${option} '${INPDIR64}\${path}'
119 SetOutPath "$INSTDIR\bin"
120 File ${option} '${INPDIR}\${path}'
123 File ${option} '${INPDIR}\${path}'
127 Section "smartctl" SMARTCTL_SECTION
129 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
131 SetOutPath "$INSTDIR\bin"
132 !insertmacro FileExe "bin\smartctl.exe" ""
136 Section "smartd" SMARTD_SECTION
138 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
140 SetOutPath "$INSTDIR\bin"
144 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
145 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
147 ExecWait "net stop smartd" $1
150 !insertmacro FileExe "bin\smartd.exe" ""
152 IfFileExists "$INSTDIR\bin\smartd.conf" 0 +2
153 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Replace existing configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
154 File "${INPDIR}\doc\smartd.conf"
156 File "${INPDIR}\bin\smartd_warning.cmd"
157 !insertmacro FileExe "bin\wtssendmsg.exe" ""
161 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Restart smartd service ?" /SD IDNO IDYES 0 IDNO +2
162 ExecWait "net start smartd"
167 Section "smartctl-nc (GSmartControl)" SMARTCTL_NC_SECTION
169 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
171 SetOutPath "$INSTDIR\bin"
172 !insertmacro FileExe "bin\smartctl-nc.exe" ""
176 Section "drivedb.h (Drive Database)" DRIVEDB_SECTION
178 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
180 SetOutPath "$INSTDIR\bin"
181 File "${INPDIR}\bin\drivedb.h"
182 File "${INPDIR}\bin\update-smart-drivedb.exe"
188 Section "!Documentation" DOC_SECTION
190 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
192 SetOutPath "$INSTDIR\doc"
193 File "${INPDIR}\doc\AUTHORS.txt"
194 File "${INPDIR}\doc\ChangeLog.txt"
195 File "${INPDIR}\doc\ChangeLog-5.0-6.0.txt"
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"
203 File "${INPDIR64}\doc\checksums64.txt"
205 File "${INPDIR}\doc\checksums32.txt"
208 File "${INPDIR}\doc\checksums??.txt"
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"
220 Section "Uninstaller" UNINST_SECTION
222 SectionIn ${FULL_TYPES}
225 CreateDirectory "$INSTDIR"
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"
231 WriteRegStr HKLM "Software\smartmontools" "Install_Dir" "$INSTDIR"
234 ; Write uninstall keys and program
235 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools"
237 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayVersion" "${VERSTR}"
239 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation" "$INSTDIR"
240 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "UninstallString" '"$INSTDIR\uninst-smartmontools.exe"'
241 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "Publisher" "smartmontools.org"
242 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLInfoAbout" "https://www.smartmontools.org/"
243 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "HelpLink" "http://sourceforge.net/projects/smartmontools/support"
244 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLUpdateInfo" "http://builds.smartmontools.org/"
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"
251 Section "Start Menu Shortcuts" MENU_SECTION
253 SectionIn ${FULL_TYPES}
255 SetShellVarContext all
257 CreateDirectory "$SMPROGRAMS\smartmontools"
259 !macro CreateAdminShortCut link target args
260 CreateShortCut '${link}' '${target}' '${args}'
262 Call ShellLinkSetRunAs
266 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
267 ${OrIf} ${FileExists} "$INSTDIR\bin\smartd.exe"
268 SetOutPath "$INSTDIR\bin"
269 !insertmacro FileExe "bin\runcmdu.exe" ""
270 Delete "$INSTDIR\bin\runcmdu.exe.manifest" ; TODO: Remove after smartmontools 6.5
274 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
275 SetOutPath "$INSTDIR\bin"
276 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl (Admin CMD).lnk" "$WINDIR\system32\cmd.exe" '/k PATH=$INSTDIR\bin;%PATH%&cd /d "$INSTDIR\bin"'
277 CreateDirectory "$SMPROGRAMS\smartmontools\smartctl Examples"
278 FileOpen $0 "$SMPROGRAMS\smartmontools\smartctl Examples\!Read this first!.txt" "w"
279 FileWrite $0 "All the example commands in this directory$\r$\napply to the first drive (sda).$\r$\n"
281 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\All info (-x).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -x sda"
282 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Identify drive (-i).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -i sda"
283 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART attributes (-A -f brief).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -A -f brief sda"
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"
297 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
298 SetOutPath "$INSTDIR\bin"
299 CreateDirectory "$SMPROGRAMS\smartmontools\smartd Examples"
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"
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"
319 ${If} ${FileExists} "$INSTDIR\doc\README.TXT"
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"
328 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf sample.lnk" "$EDITOR" "$INSTDIR\doc\smartd.conf"
329 ${If} ${FileExists} "$INSTDIR\bin\drivedb.h"
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"
333 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\ChangeLog.lnk" "$INSTDIR\doc\ChangeLog.txt"
334 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\COPYING.lnk" "$INSTDIR\doc\COPYING.txt"
335 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\NEWS.lnk" "$INSTDIR\doc\NEWS.txt"
339 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "https://www.smartmontools.org/"
340 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Daily Builds.lnk" "http://builds.smartmontools.org/"
343 ${If} ${FileExists} "$INSTDIR\bin\update-smart-drivedb.exe"
344 SetOutPath "$INSTDIR\bin"
345 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\drivedb.h update.lnk" "$INSTDIR\bin\update-smart-drivedb.exe" ""
349 ${If} ${FileExists} "$INSTDIR\uninst-smartmontools.exe"
350 SetOutPath "$INSTDIR"
351 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe" ""
356 Section "Add install dir to PATH" PATH_SECTION
358 SectionIn ${FULL_TYPES}
365 SectionGroup "Add smartctl to drive menu"
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"
377 Section "Remove existing entries first" DRIVE_REMOVE_SECTION
378 SectionIn ${DRIVEMENU_TYPE}
379 !insertmacro DriveMenuRemove
382 !macro DriveSection id name args
383 Section 'smartctl ${args} ...' DRIVE_${id}_SECTION
384 SectionIn ${DRIVEMENU_TYPE}
386 DetailPrint 'Add drive menu entry "${name}": smartctl ${args} ...'
387 WriteRegStr HKCR "Drive\shell\smartctl${id}" "" "${name}"
388 WriteRegStr HKCR "Drive\shell\smartctl${id}\command" "" '"$INSTDIR\bin\runcmda.exe" "$INSTDIR\bin\smartctl.exe" ${args} %L'
392 !insertmacro DriveSection 0 "SMART all info" "-x"
393 !insertmacro DriveSection 1 "SMART status" "-Hc"
394 !insertmacro DriveSection 2 "SMART attributes" "-A -f brief"
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"'
401 ;--------------------------------------------------------------------
405 ; Stop & remove service
406 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
407 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
409 ExecWait "net stop smartd"
410 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Remove smartd service ?" /SD IDNO IDYES 0 IDNO +2
411 ExecWait "$INSTDIR\bin\smartd.exe remove"
415 ; Remove installer registry keys
416 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools"
417 DeleteRegKey HKLM "Software\smartmontools"
420 ${If} ${FileExists} "$INSTDIR\bin\smartd.conf"
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
425 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
426 Delete "$INSTDIR\bin\smartd.conf"
430 ${If} ${FileExists} "$INSTDIR\bin\smartd.log"
431 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" /SD IDNO IDYES 0 IDNO +2
432 Delete "$INSTDIR\bin\smartd.log"
435 ; Remove drivedb-add file ?
436 ${If} ${FileExists} "$INSTDIR\bin\drivedb-add.h"
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
438 Delete "$INSTDIR\bin\drivedb-add.h"
442 Delete "$INSTDIR\bin\smartctl.exe"
443 Delete "$INSTDIR\bin\smartctl-nc.exe"
444 Delete "$INSTDIR\bin\smartd.exe"
445 Delete "$INSTDIR\bin\smartd_warning.cmd" ; TODO: Check for modifications?
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"
451 Delete "$INSTDIR\bin\smartctl-run.bat"
452 Delete "$INSTDIR\bin\smartd-run.bat"
453 Delete "$INSTDIR\bin\net-run.bat"
454 Delete "$INSTDIR\bin\runcmda.exe"
455 Delete "$INSTDIR\bin\runcmda.exe.manifest" ; TODO: Remove after smartmontools 6.5
456 Delete "$INSTDIR\bin\runcmdu.exe"
457 Delete "$INSTDIR\bin\runcmdu.exe.manifest" ; TODO: Remove after smartmontools 6.5
458 Delete "$INSTDIR\bin\wtssendmsg.exe"
459 Delete "$INSTDIR\doc\AUTHORS.txt"
460 Delete "$INSTDIR\doc\ChangeLog.txt"
461 Delete "$INSTDIR\doc\ChangeLog-5.0-6.0.txt"
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"
467 Delete "$INSTDIR\doc\checksums*.txt"
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"
478 SetShellVarContext all
479 Delete "$SMPROGRAMS\smartmontools\*.*"
480 Delete "$SMPROGRAMS\smartmontools\Documentation\*.*"
481 Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*"
482 Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*"
485 RMDir "$SMPROGRAMS\smartmontools\Documentation"
486 RMDir "$SMPROGRAMS\smartmontools\smartctl Examples"
487 RMDir "$SMPROGRAMS\smartmontools\smartd Examples"
488 RMDir "$SMPROGRAMS\smartmontools"
493 ; Remove install dir from PATH
495 Call un.RemoveFromPath
497 ; Remove drive menu registry entries
498 !insertmacro DriveMenuRemove
500 ; Check for still existing entries
501 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
502 MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running." /SD IDOK
503 ${ElseIf} ${FileExists} "$INSTDIR"
504 MessageBox MB_OK "Note: $INSTDIR could not be removed." /SD IDOK
507 ${If} ${FileExists} "$SMPROGRAMS\smartmontools"
508 MessageBox MB_OK "Note: $SMPROGRAMS\smartmontools could not be removed." /SD IDOK
513 ;--------------------------------------------------------------------
516 !macro AdjustSectionSize section
517 SectionGetSize ${section} $0
519 SectionSetSize ${section} $0
524 ; Set default install directories
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"
532 StrCpy $INSTDIR32 $INSTDIR
533 StrCpy $INSTDIR64 "$PROGRAMFILES64\smartmontools"
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}
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}
557 ; Use Notepad++ if installed
558 StrCpy $EDITOR "$PROGRAMFILES\Notepad++\notepad++.exe"
559 ${IfNot} ${FileExists} "$EDITOR"
560 StrCpy $EDITOR "notepad.exe"
570 ; Check x64 section and update INSTDIR accordingly
574 ${IfNot} ${SectionIsSelected} ${X64_SECTION}
576 ${If} $INSTDIR32 != ""
577 ${AndIf} $INSTDIR == $INSTDIR64
578 StrCpy $INSTDIR $INSTDIR32
582 ${If} $INSTDIR64 != ""
583 ${AndIf} $INSTDIR == $INSTDIR32
584 StrCpy $INSTDIR $INSTDIR64
590 ; Command line parsing
592 !macro GetCmdLineOption var name
602 !macro CheckCmdLineOption name section
603 StrCpy $allopts "$allopts,${name}"
604 !insertmacro GetCmdLineOption $0 ${name}
606 !insertmacro UnselectSection ${section}
608 !insertmacro SelectSection ${section}
612 Function ParseCmdLine
616 ${GetOptions} $R0 "/SO" $opts
624 ; Change previous 64-bit setting
625 StrCpy $allopts ",x32|x64"
626 !insertmacro GetCmdLineOption $0 "x32"
628 !insertmacro UnselectSection ${X64_SECTION}
630 !insertmacro GetCmdLineOption $0 "x64"
632 !insertmacro SelectSection ${X64_SECTION}
634 ; Leave other sections unchanged if only "x32" or "x64" is specified
636 ${OrIf} $opts == "x64"
640 ; Turn sections on or off
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}
658 StrCpy $0 "$allopts,-" "" 1
659 MessageBox MB_OK "Usage: smartmontools-VERSION.win32-setup [/S] [/SO component,...] [/D=INSTDIR]$\n$\ncomponents:$\n $0"
665 ; Install runcmda.exe only once
667 Function CheckRunCmdA
671 SetOutPath "$INSTDIR\bin"
672 !insertmacro FileExe "bin\runcmda.exe" ""
673 Delete "$INSTDIR\bin\runcmda.exe.manifest" ; TODO: Remove after smartmontools 6.5
678 ;--------------------------------------------------------------------
681 ; Based on example from:
682 ; http://nsis.sourceforge.net/Path_Manipulation
686 !include "WinMessages.nsh"
688 ; Registry Entry for environment (NT4,2000,XP)
690 ;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
692 !define Environ 'HKCU "Environment"'
695 ; AddToPath - Appends dir to PATH
696 ; (does not work on Win9x/ME)
709 ; NSIS ReadRegStr returns empty string on string overflow
710 ; Native calls are used here to check actual length of PATH
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))
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)"
720 ${If} $4 = 234 ; ERROR_MORE_DATA
721 DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
722 MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}" /SD IDOK
726 ${If} $4 <> 0 ; NO_ERROR
727 ${If} $4 <> 2 ; ERROR_FILE_NOT_FOUND
728 DetailPrint "AddToPath: unexpected error code $4"
734 ; Check if already in PATH
746 ; Prevent NSIS string overflow
750 IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";")
751 ${If} $2 > ${NSIS_MAX_STRLEN}
752 DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}"
753 MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}." /SD IDOK
758 DetailPrint "Add to PATH: $0"
761 StrCpy $1 $1 -1 ; remove trailing ';'
763 ${If} $1 != "" ; no leading ';'
766 WriteRegExpandStr ${Environ} "PATH" $0
767 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
778 ; RemoveFromPath - Removes dir from PATH
782 ; Call RemoveFromPath
784 Function un.RemoveFromPath
793 ReadRegStr $1 ${Environ} "PATH"
796 StrCpy $1 "$1;" ; ensure trailing ';'
801 Pop $2 ; pos of our dir
804 DetailPrint "Remove from PATH: $0"
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
812 StrCpy $3 $3 -1 ; remove trailing ';'
814 WriteRegExpandStr ${Environ} "PATH" $3
815 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
828 ; StrStr - find substring in a string
831 ; Push "this is some string"
834 ; Pop $0 ; "some string"
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,...]
846 ; $R1=substring, $R2=string, $R3=strlen(substring)
849 StrCpy $R5 $R2 $R3 $R4
850 ${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
851 ${IfThen} $R5 == "" ${|} ${ExitDo} ${|}
854 StrCpy $R1 $R2 "" $R4
859 Exch $R1 ; $R1=old$R1, stack=[result,...]
862 !insertmacro StrStr ""
863 !insertmacro StrStr "un."
866 ;--------------------------------------------------------------------
867 ; Set Run As Administrator flag in shortcut
869 ; Slightly modified version from:
870 ; http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag
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}
879 !define IID_IShellLink ${IID_IShellLinkW}
881 !define IID_IShellLink ${IID_IShellLinkA}
884 Function ShellLinkSetRunAs
885 ; Set archive location of $PLUGINSDIR
887 SetOutPath "$INSTDIR"
889 System::Store S ; push $0-$9, $R0-$R9
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"
894 System::Call "$1->0(g'${IPersistFile}',*i.r2)i.r0" ; $0 = $1->QueryInterface(IPersistFile, &$2)
896 System::Call "$2->5(w '$9',i 0)i.r0" ; $0 = $2->Load($9, STGM_READ)
898 System::Call "$1->0(g'${IShellLinkDataList}',*i.r3)i.r0" ; $0 = $1->QueryInterface(IShellLinkDataList, &$3)
900 System::Call "$3->6(*i.r4)i.r0"; $0 = $3->GetFlags(&$4)
902 System::Call "$3->7(i $4|0x2000)i.r0" ; $0 = $3->SetFlags($4|SLDF_RUNAS_USER)
904 System::Call "$2->6(w '$9',i1)i.r0" ; $2->Save($9, TRUE)
907 System::Call "$3->2()" ; $3->Release()
909 System::Call "$2->2()" ; $2->Release()
912 System::Call "$1->2()" ; $1->Release()
915 DetailPrint "Set RunAsAdmin: $9 failed ($0)"
917 DetailPrint "Set RunAsAdmin: $9"
919 System::Store L ; pop $R9-$R0, $9-$0