]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/installer.nsi
Imported Upstream version 6.4+svn4214
[mirror_smartmontools-debian.git] / os_win32 / installer.nsi
1 ;
2 ; os_win32/installer.nsi - smartmontools install NSIS script
3 ;
4 ; Home page of code is: http://www.smartmontools.org
5 ;
6 ; Copyright (C) 2006-15 Christian Franke
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 4174 2015-11-22 16:19:29Z 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 RequestExecutionLevel admin
40
41 SetCompressor /solid lzma
42
43 XPStyle on
44 InstallColors /windows
45
46 ; Set in .onInit
47 ;InstallDir "$PROGRAMFILES\smartmontools"
48 ;InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
49
50 Var EDITOR
51
52 !ifdef INPDIR64
53 Var X64
54 Var INSTDIR32
55 Var INSTDIR64
56 !endif
57
58 LicenseData "${INPDIR}\doc\COPYING.txt"
59
60 !include "FileFunc.nsh"
61 !include "LogicLib.nsh"
62 !include "Sections.nsh"
63
64
65 ;--------------------------------------------------------------------
66 ; Pages
67
68 Page license
69 Page components
70 !ifdef INPDIR64
71 Page directory CheckX64
72 !else
73 Page directory
74 !endif
75 Page instfiles
76
77 UninstPage uninstConfirm
78 UninstPage instfiles
79
80 InstType "Full"
81 InstType "Extract files only"
82 InstType "Drive menu"
83 !ifdef INPDIR64
84 InstType "Full (x64)"
85 InstType "Extract files only (x64)"
86 InstType "Drive menu (x64)"
87 !endif
88
89
90 ;--------------------------------------------------------------------
91 ; Sections
92
93 !ifdef INPDIR64
94 Section "64-bit version" X64_SECTION
95 SectionIn 4 5 6
96 ; Handled in Function CheckX64
97 SectionEnd
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"
106 !endif
107
108 SectionGroup "!Program files"
109
110 !macro FileExe path option
111 !ifdef INPDIR64
112 ; Use dummy SetOutPath to control archive location of executables
113 ${If} $X64 != ""
114 Goto +2
115 SetOutPath "$INSTDIR\bin64"
116 File ${option} '${INPDIR64}\${path}'
117 ${Else}
118 Goto +2
119 SetOutPath "$INSTDIR\bin"
120 File ${option} '${INPDIR}\${path}'
121 ${EndIf}
122 !else
123 File ${option} '${INPDIR}\${path}'
124 !endif
125 !macroend
126
127 Section "smartctl" SMARTCTL_SECTION
128
129 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
130
131 SetOutPath "$INSTDIR\bin"
132 !insertmacro FileExe "bin\smartctl.exe" ""
133
134 SectionEnd
135
136 Section "smartd" SMARTD_SECTION
137
138 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
139
140 SetOutPath "$INSTDIR\bin"
141
142 ; Stop service ?
143 StrCpy $1 ""
144 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
145 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
146 ${If} $0 != ""
147 ExecWait "net stop smartd" $1
148 ${EndIf}
149 ${EndIf}
150 !insertmacro FileExe "bin\smartd.exe" ""
151
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"
155
156 File "${INPDIR}\bin\smartd_warning.cmd"
157 !insertmacro FileExe "bin\wtssendmsg.exe" ""
158
159 ; Restart service ?
160 ${If} $1 == "0"
161 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Restart smartd service ?" /SD IDNO IDYES 0 IDNO +2
162 ExecWait "net start smartd"
163 ${EndIf}
164
165 SectionEnd
166
167 Section "smartctl-nc (GSmartControl)" SMARTCTL_NC_SECTION
168
169 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
170
171 SetOutPath "$INSTDIR\bin"
172 !insertmacro FileExe "bin\smartctl-nc.exe" ""
173
174 SectionEnd
175
176 Section "drivedb.h (Drive Database)" DRIVEDB_SECTION
177
178 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
179
180 SetOutPath "$INSTDIR\bin"
181 File "${INPDIR}\bin\drivedb.h"
182 File "${INPDIR}\bin\update-smart-drivedb.exe"
183
184 SectionEnd
185
186 SectionGroupEnd
187
188 Section "!Documentation" DOC_SECTION
189
190 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
191
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"
201 !ifdef INPDIR64
202 ${If} $X64 != ""
203 File "${INPDIR64}\doc\checksums64.txt"
204 ${Else}
205 File "${INPDIR}\doc\checksums32.txt"
206 ${EndIf}
207 !else
208 File "${INPDIR}\doc\checksums??.txt"
209 !endif
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
218 SectionEnd
219
220 Section "Uninstaller" UNINST_SECTION
221
222 SectionIn ${FULL_TYPES}
223 AddSize 40
224
225 CreateDirectory "$INSTDIR"
226
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"
230 ${If} "$0$1" != ""
231 WriteRegStr HKLM "Software\smartmontools" "Install_Dir" "$INSTDIR"
232 ${EndIf}
233
234 ; Write uninstall keys and program
235 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools"
236 !ifdef VERSTR
237 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayVersion" "${VERSTR}"
238 !endif
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"
248
249 SectionEnd
250
251 Section "Start Menu Shortcuts" MENU_SECTION
252
253 SectionIn ${FULL_TYPES}
254
255 SetShellVarContext all
256
257 CreateDirectory "$SMPROGRAMS\smartmontools"
258
259 !macro CreateAdminShortCut link target args
260 CreateShortCut '${link}' '${target}' '${args}'
261 push '${link}'
262 Call ShellLinkSetRunAs
263 !macroend
264
265 ; runcmdu
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
271 ${EndIf}
272
273 ; smartctl
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"
280 FileClose $0
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"
294 ${EndIf}
295
296 ; smartd
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"
308
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"
316 ${EndIf}
317
318 ; Documentation
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"
332 ${EndIf}
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"
336 ${EndIf}
337
338 ; Homepage
339 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "https://www.smartmontools.org/"
340 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Daily Builds.lnk" "http://builds.smartmontools.org/"
341
342 ; drivedb.h update
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" ""
346 ${EndIf}
347
348 ; Uninstall
349 ${If} ${FileExists} "$INSTDIR\uninst-smartmontools.exe"
350 SetOutPath "$INSTDIR"
351 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe" ""
352 ${EndIf}
353
354 SectionEnd
355
356 Section "Add install dir to PATH" PATH_SECTION
357
358 SectionIn ${FULL_TYPES}
359
360 Push "$INSTDIR\bin"
361 Call AddToPath
362
363 SectionEnd
364
365 SectionGroup "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
377 Section "Remove existing entries first" DRIVE_REMOVE_SECTION
378 SectionIn ${DRIVEMENU_TYPE}
379 !insertmacro DriveMenuRemove
380 SectionEnd
381
382 !macro DriveSection id name args
383 Section 'smartctl ${args} ...' DRIVE_${id}_SECTION
384 SectionIn ${DRIVEMENU_TYPE}
385 Call CheckRunCmdA
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'
389 SectionEnd
390 !macroend
391
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"'
398
399 SectionGroupEnd
400
401 ;--------------------------------------------------------------------
402
403 Section "Uninstall"
404
405 ; Stop & remove service
406 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
407 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
408 ${If} $0 != ""
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"
412 ${EndIf}
413 ${EndIf}
414
415 ; Remove installer registry keys
416 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools"
417 DeleteRegKey HKLM "Software\smartmontools"
418
419 ; Remove conf file ?
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"
427 ${EndIf}
428
429 ; Remove log file ?
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"
433 ${EndIf}
434
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"
439 ${EndIf}
440
441 ; Remove files
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"
476
477 ; Remove shortcuts
478 SetShellVarContext all
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"
486 RMDir "$SMPROGRAMS\smartmontools\smartctl Examples"
487 RMDir "$SMPROGRAMS\smartmontools\smartd Examples"
488 RMDir "$SMPROGRAMS\smartmontools"
489 RMDir "$INSTDIR\bin"
490 RMDir "$INSTDIR\doc"
491 RMDir "$INSTDIR"
492
493 ; Remove install dir from PATH
494 Push "$INSTDIR\bin"
495 Call un.RemoveFromPath
496
497 ; Remove drive menu registry entries
498 !insertmacro DriveMenuRemove
499
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
505 ${EndIf}
506
507 ${If} ${FileExists} "$SMPROGRAMS\smartmontools"
508 MessageBox MB_OK "Note: $SMPROGRAMS\smartmontools could not be removed." /SD IDOK
509 ${EndIf}
510
511 SectionEnd
512
513 ;--------------------------------------------------------------------
514 ; Functions
515
516 !macro AdjustSectionSize section
517 SectionGetSize ${section} $0
518 IntOp $0 $0 / 2
519 SectionSetSize ${section} $0
520 !macroend
521
522 Function .onInit
523
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"
531 !ifdef INPDIR64
532 StrCpy $INSTDIR32 $INSTDIR
533 StrCpy $INSTDIR64 "$PROGRAMFILES64\smartmontools"
534 !endif
535 ${EndIf}
536 ${EndIf}
537 ${EndIf}
538
539 !ifdef INPDIR64
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
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
557 ; Use Notepad++ if installed
558 StrCpy $EDITOR "$PROGRAMFILES\Notepad++\notepad++.exe"
559 ${IfNot} ${FileExists} "$EDITOR"
560 StrCpy $EDITOR "notepad.exe"
561 ${EndIf}
562
563 Call ParseCmdLine
564
565 !ifdef INPDIR64
566 Call CheckX64
567 !endif
568 FunctionEnd
569
570 ; Check x64 section and update INSTDIR accordingly
571
572 !ifdef INPDIR64
573 Function CheckX64
574 ${IfNot} ${SectionIsSelected} ${X64_SECTION}
575 StrCpy $X64 ""
576 ${If} $INSTDIR32 != ""
577 ${AndIf} $INSTDIR == $INSTDIR64
578 StrCpy $INSTDIR $INSTDIR32
579 ${EndIf}
580 ${Else}
581 StrCpy $X64 "t"
582 ${If} $INSTDIR64 != ""
583 ${AndIf} $INSTDIR == $INSTDIR32
584 StrCpy $INSTDIR $INSTDIR64
585 ${EndIf}
586 ${EndIf}
587 FunctionEnd
588 !endif
589
590 ; Command line parsing
591
592 !macro GetCmdLineOption var name
593 Push ",$opts,"
594 Push ",${name},"
595 Call StrStr
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}
610 !macroend
611
612 Function ParseCmdLine
613 ; get /SO option
614 Var /global opts
615 ${GetParameters} $R0
616 ${GetOptions} $R0 "/SO" $opts
617 ${If} ${Errors}
618 Return
619 ${EndIf}
620 Var /global allopts
621 Var /global nomatch
622 StrCpy $nomatch "t"
623 !ifdef INPDIR64
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}
639 !endif
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}
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}
663 FunctionEnd
664
665 ; Install runcmda.exe only once
666
667 Function CheckRunCmdA
668 Var /global runcmda
669 ${If} $runcmda == ""
670 StrCpy $runcmda "t"
671 SetOutPath "$INSTDIR\bin"
672 !insertmacro FileExe "bin\runcmda.exe" ""
673 Delete "$INSTDIR\bin\runcmda.exe.manifest" ; TODO: Remove after smartmontools 6.5
674 ${EndIf}
675 FunctionEnd
676
677
678 ;--------------------------------------------------------------------
679 ; Path functions
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
702 Function AddToPath
703 Exch $0
704 Push $1
705 Push $2
706 Push $3
707 Push $4
708
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
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
723 Goto done
724 ${EndIf}
725
726 ${If} $4 <> 0 ; NO_ERROR
727 ${If} $4 <> 2 ; ERROR_FILE_NOT_FOUND
728 DetailPrint "AddToPath: unexpected error code $4"
729 Goto done
730 ${EndIf}
731 StrCpy $1 ""
732 ${EndIf}
733
734 ; Check if already in PATH
735 Push "$1;"
736 Push "$0;"
737 Call StrStr
738 Pop $2
739 StrCmp $2 "" 0 done
740 Push "$1;"
741 Push "$0\;"
742 Call StrStr
743 Pop $2
744 StrCmp $2 "" 0 done
745
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(";")
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
754 Goto done
755 ${EndIf}
756
757 ; Append dir to PATH
758 DetailPrint "Add to PATH: $0"
759 StrCpy $2 $1 1 -1
760 ${If} $2 == ";"
761 StrCpy $1 $1 -1 ; remove trailing ';'
762 ${EndIf}
763 ${If} $1 != "" ; no leading ';'
764 StrCpy $0 "$1;$0"
765 ${EndIf}
766 WriteRegExpandStr ${Environ} "PATH" $0
767 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
768
769 done:
770 Pop $4
771 Pop $3
772 Pop $2
773 Pop $1
774 Pop $0
775 FunctionEnd
776
777
778 ; RemoveFromPath - Removes dir from PATH
779 ;
780 ; Usage:
781 ; Push "dir"
782 ; Call RemoveFromPath
783
784 Function un.RemoveFromPath
785 Exch $0
786 Push $1
787 Push $2
788 Push $3
789 Push $4
790 Push $5
791 Push $6
792
793 ReadRegStr $1 ${Environ} "PATH"
794 StrCpy $5 $1 1 -1
795 ${If} $5 != ";"
796 StrCpy $1 "$1;" ; ensure trailing ';'
797 ${EndIf}
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
811 ${If} $5 == ";"
812 StrCpy $3 $3 -1 ; remove trailing ';'
813 ${EndIf}
814 WriteRegExpandStr ${Environ} "PATH" $3
815 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
816
817 done:
818 Pop $6
819 Pop $5
820 Pop $4
821 Pop $3
822 Pop $2
823 Pop $1
824 Pop $0
825 FunctionEnd
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"
835
836 !macro StrStr un
837 Function ${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
848 ${Do}
849 StrCpy $R5 $R2 $R3 $R4
850 ${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
851 ${IfThen} $R5 == "" ${|} ${ExitDo} ${|}
852 IntOp $R4 $R4 + 1
853 ${Loop}
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,...]
860 FunctionEnd
861 !macroend
862 !insertmacro StrStr ""
863 !insertmacro StrStr "un."
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
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
884 Function ShellLinkSetRunAs
885 ; Set archive location of $PLUGINSDIR
886 Goto +2
887 SetOutPath "$INSTDIR"
888
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}
919 System::Store L ; pop $R9-$R0, $9-$0
920 FunctionEnd