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