1; winapcupsd.nsi
2;
3; Adapted by Kern Sibbald for apcupsd from Bacula code
4; Further modified by Adam Kropelin
5;
6
7;
8; Basics
9;
10Name "Apcupsd"
11OutFile "winapcupsd-${VERSION}.exe"
12SetCompressor lzma
13InstallDir "c:\apcupsd"
14
15;
16; Include files
17;
18!include "MUI.nsh"
19!include "LogicLib.nsh"
20!include "StrReplace.nsh"
21!include "WinVer.nsh"
22!include "DrvSetup.nsh"
23!include "FileFunc.nsh"
24
25; Global variables
26Var ExistingConfig
27Var MainInstalled
28Var TrayInstalled
29Var OrigInstDir
30
31; Paths
32!define WINDIR ${TOPDIR}/src/win32
33
34; Icon indexes in shell32.dll
35!define START_ICON_INDEX  137
36!define STOP_ICON_INDEX   131
37!define CONFIG_ICON_INDEX 21
38!define HELP_ICON_INDEX   23
39!define MANUAL_ICON_INDEX 23
40
41;
42; Pull in pages
43;
44!insertmacro MUI_PAGE_WELCOME
45!insertmacro MUI_PAGE_LICENSE ${TOPDIR}/COPYING
46!insertmacro MUI_PAGE_COMPONENTS
47!insertmacro MUI_PAGE_DIRECTORY
48!insertmacro MUI_PAGE_INSTFILES
49Page custom EditApcupsdConfEnter EditApcupsdConfExit ""
50Page custom InstallServiceEnter InstallServiceExit ""
51Page custom ApctrayEnter ApctrayExit ""
52!define MUI_FINISHPAGE_SHOWREADME
53!define MUI_FINISHPAGE_SHOWREADME_TEXT "View the ReleaseNotes"
54!define MUI_FINISHPAGE_SHOWREADME_FUNCTION "ShowReadme"
55!define MUI_FINISHPAGE_LINK "Visit Apcupsd Website"
56!define MUI_FINISHPAGE_LINK_LOCATION "http://www.apcupsd.org"
57!define MUI_PAGE_CUSTOMFUNCTION_SHOW DisableBackButton
58!insertmacro MUI_PAGE_FINISH
59
60!insertmacro MUI_UNPAGE_WELCOME
61!insertmacro MUI_UNPAGE_CONFIRM
62!insertmacro MUI_UNPAGE_INSTFILES
63!insertmacro MUI_UNPAGE_FINISH
64
65!define      MUI_ABORTWARNING
66
67!insertmacro MUI_LANGUAGE "English"
68
69DirText "Setup will install Apcupsd ${VERSION} to the directory \
70         specified below."
71
72; Disable back button
73!define FINISH_BUTTON_ID 3
74Function DisableBackButton
75	GetDlgItem $R1 $HWNDPARENT ${FINISH_BUTTON_ID}
76	EnableWindow $R1 0
77FunctionEnd
78
79; Post-process apcupsd.conf.in by replacing @FOO@ tokens
80; with proper values.
81Function PostProcConfig
82  FileOpen $0 "$INSTDIR\etc\apcupsd\apcupsd.conf.in" "r"
83  FileOpen $1 "$INSTDIR\etc\apcupsd\apcupsd.conf.new" "w"
84
85  ClearErrors
86  FileRead $0 $2
87
88  ${DoUntil} ${Errors}
89    ${StrReplace} $2 "@VERSION@"    "${VERSION}"           $2
90    ${StrReplace} $2 "@sysconfdir@" "$INSTDIR\etc\apcupsd" $2
91    ${StrReplace} $2 "@PWRFAILDIR@" "$INSTDIR\etc\apcupsd" $2
92    ${StrReplace} $2 "@LOGDIR@"     "$INSTDIR\etc\apcupsd" $2
93    ${StrReplace} $2 "@nologdir@"   "$INSTDIR\etc\apcupsd" $2
94    FileWrite $1 $2
95    FileRead $0 $2
96  ${Loop}
97
98  FileClose $0
99  FileClose $1
100
101  Delete "$INSTDIR\etc\apcupsd\apcupsd.conf.in"
102FunctionEnd
103
104Function ShowReadme
105  ExecShell "open" "$INSTDIR\ReleaseNotes.txt"
106FunctionEnd
107
108Function EditApcupsdConfEnter
109  ; Skip this page if config file was preexisting
110  ${If} $ExistingConfig == 1
111    Abort
112  ${EndIf}
113
114  ; Also skip if apcupsd main package was not installed
115  ${If} $MainInstalled != 1
116    Abort
117  ${EndIf}
118
119  ; Configure header text and instantiate the page
120  !insertmacro MUI_HEADER_TEXT "Edit Configuration File" "Configure Apcupsd for your UPS."
121  !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "EditApcupsdConf.ini"
122  Pop $R0 ;HWND of dialog
123
124  ; Set contents of text field
125  !insertmacro MUI_INSTALLOPTIONS_READ $R0 "EditApcupsdConf.ini" "Field 1" "HWND"
126  SendMessage $R0 ${WM_SETTEXT} 0 \
127      "STR:The default configuration is suitable for UPSes connected with a USB cable. \
128       All other types of connections require editing the client configuration file, \
129       apcupsd.conf.$\r$\r\
130       Please edit $INSTDIR\etc\apcupsd\apcupsd.conf to fit your installation. \
131       When you click the Next button, Wordpad will open to allow you to do this.$\r$\r\
132       Be sure to save your changes before closing Wordpad and before continuing \
133       with the installation."
134
135  ; Display the page
136  !insertmacro MUI_INSTALLOPTIONS_SHOW
137FunctionEnd
138
139Function EditApcupsdConfExit
140  ; Launch wordpad to edit apcupsd.conf if checkbox is checked
141  !insertmacro MUI_INSTALLOPTIONS_READ $R1 "EditApcupsdConf.ini" "Field 2" "State"
142  ${If} $R1 == 1
143    ExecWait 'notepad "$INSTDIR\etc\apcupsd\apcupsd.conf"'
144  ${EndIf}
145FunctionEnd
146
147Function InstallServiceEnter
148  ; Skip if apcupsd main package was not installed
149  ${If} $MainInstalled != 1
150    Abort
151  ${EndIf}
152
153  ; Configure header text and instantiate the page
154  !insertmacro MUI_HEADER_TEXT "Install/Start Service" "Install Apcupsd Service and start it."
155  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "InstallService.ini"
156FunctionEnd
157
158Function InstallServiceExit
159  ; Create Start Menu Directory
160  CreateDirectory "$SMPROGRAMS\Apcupsd"
161  ; Create start menu link for configuring apcupsd
162  CreateShortCut "$SMPROGRAMS\Apcupsd\Edit Configuration File.lnk" "notepad" "$INSTDIR\etc\apcupsd\apcupsd.conf" "$SYSDIR\shell32.dll" ${CONFIG_ICON_INDEX}
163
164  ; If installed as a service already, remove it
165  ReadRegDWORD $R0 HKLM "Software\Apcupsd" "InstalledService"
166  ${If} $R0 == 1
167    ExecWait '"$INSTDIR\bin\apcupsd.exe" /quiet /remove'
168    Sleep 1000
169  ${EndIf}
170
171  ; Install as service and create start menu shortcuts
172  !insertmacro MUI_INSTALLOPTIONS_READ $R1 "InstallService.ini" "Field 2" "State"
173  ${If} $R1 == 1
174    ; Install service
175    ExecWait '"$INSTDIR\bin\apcupsd.exe" /install'
176    ${If} ${IsNT}
177      ; Installed as a service and we're on NT
178      CreateShortCut "$SMPROGRAMS\Apcupsd\Start Apcupsd.lnk" "$SYSDIR\net.exe" "start apcupsd" "$SYSDIR\shell32.dll" ${START_ICON_INDEX}
179      CreateShortCut "$SMPROGRAMS\Apcupsd\Stop Apcupsd.lnk"  "$SYSDIR\net.exe" "stop apcupsd"  "$SYSDIR\shell32.dll" ${STOP_ICON_INDEX}
180    ${Else}
181      ; Installed as a service, but not on NT
182      CreateShortCut "$SMPROGRAMS\Apcupsd\Start Apcupsd.lnk" "$INSTDIR\bin\apcupsd.exe" "/service" "$SYSDIR\shell32.dll" ${START_ICON_INDEX}
183      CreateShortCut "$SMPROGRAMS\Apcupsd\Stop Apcupsd.lnk"  "$INSTDIR\bin\apcupsd.exe" "/kill"    "$SYSDIR\shell32.dll" ${STOP_ICON_INDEX}
184    ${EndIf}
185  ${Else}
186    ; Not installed as a service
187    CreateShortCut "$SMPROGRAMS\Apcupsd\Start Apcupsd.lnk" "$INSTDIR\bin\apcupsd.exe" ""       "$SYSDIR\shell32.dll" ${START_ICON_INDEX}
188    CreateShortCut "$SMPROGRAMS\Apcupsd\Stop Apcupsd.lnk"  "$INSTDIR\bin\apcupsd.exe" "/kill"  "$SYSDIR\shell32.dll" ${STOP_ICON_INDEX}
189  ${EndIf}
190
191  ; Start Apcupsd now, if so requested
192  !insertmacro MUI_INSTALLOPTIONS_READ $R2 "InstallService.ini" "Field 4" "State"
193  ${If} $R2 == 1
194    ExecShell "" "$SMPROGRAMS\Apcupsd\Start Apcupsd.lnk" "" SW_HIDE
195  ${Endif}
196FunctionEnd
197
198Function ApctrayEnter
199  ; Skip if apctray package was not installed
200  ${If} $TrayInstalled != 1
201    Abort
202  ${EndIf}
203
204  ; If Apctray is already configured to start automatically, start it now
205  ; and skip this page
206  ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "Apctray"
207  ${If} $R0 != ""
208    Exec $R0
209    Abort
210  ${EndIf}
211
212  ; Configure header text and instantiate the page
213  !insertmacro MUI_HEADER_TEXT "Configure Tray Icon" "Configure Apctray icon for your preferences."
214  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "Apctray.ini"
215FunctionEnd
216
217Function ApctrayExit
218  ; We get called when checkbox changes or next button is pressed
219  ; Figure out which this is.
220
221  !insertmacro MUI_INSTALLOPTIONS_READ $R1 "Apctray.ini" "Settings" "State"
222  ${If} $R1 == 2
223    ; Return to the page
224    Abort
225  ${EndIf}
226
227  ; Regular exit due to Next button press...
228
229  ; (Un)Install apctray
230  !insertmacro MUI_INSTALLOPTIONS_READ $R1 "Apctray.ini" "Field 2" "State"
231  ${If} $R1 == 1
232    ; Install and start
233    ExecWait '"$INSTDIR\bin\apctray.exe" $R0 /install'
234    Exec '"$INSTDIR\bin\apctray.exe" $R0'
235  ${EndIf}
236FunctionEnd
237
238Section "-Startup"
239  SetShellVarContext all
240
241  ; Check for existing config file
242  ${If} ${FileExists} "$INSTDIR\etc\apcupsd\apcupsd.conf"
243    StrCpy $ExistingConfig 1
244  ${Else}
245    StrCpy $ExistingConfig 0
246  ${EndIf}
247
248  ; Save the new install path in the registry
249  WriteRegStr HKLM "Software\Apcupsd\" "InstDir" "$INSTDIR"
250
251  ; Create base installation directory
252  CreateDirectory "$INSTDIR"
253
254  ; Install common files
255  SetOutPath "$INSTDIR"
256  File COPYING.txt
257  File ChangeLog.txt
258  File ReleaseNotes.txt
259
260  ; Clean up old non-txt versions of these files
261  Delete /REBOOTOK "$INSTDIR\COPYING"
262  Delete /REBOOTOK "$INSTDIR\ChangeLog"
263  Delete /REBOOTOK "$INSTDIR\ReleaseNotes"
264
265SectionEnd
266
267Section "Apcupsd Service" SecService
268  ; We're installing the main package
269  StrCpy $MainInstalled 1
270
271  ; Shutdown any apcupsd or apctray that might be running
272  ExecWait '"$OrigInstDir\bin\apctray.exe" /kill'
273  ExecWait '"$OrigInstDir\bin\apcupsd.exe" /kill'
274  DetailPrint "Waiting for apcupsd and apctray to exit..."
275  Sleep 3000
276
277  ; Create installation directories
278  CreateDirectory "$INSTDIR\bin"
279  CreateDirectory "$INSTDIR\driver"
280  CreateDirectory "$INSTDIR\etc"
281  CreateDirectory "$INSTDIR\etc\apcupsd"
282  CreateDirectory "c:\tmp"
283
284  ;
285  ; NOTE: If you add new files here, be sure to remove them
286  ;       in the uninstaller!
287  ;
288
289  SetOutPath "$INSTDIR\bin"
290  File ${CROSSTOOLS}\mingw32\mingw32\bin\mingwm10.dll
291  File ${DEPKGS}\libroot\lib\pthreadGCE.dll
292  File ${TOPDIR}\src\apcupsd.exe
293  File ${TOPDIR}\src\smtp.exe
294  File ${TOPDIR}\src\apcaccess.exe
295  File ${TOPDIR}\src\apctest.exe
296  File ${WINDIR}\popup.exe
297  File ${WINDIR}\shutdown.exe
298  File ${WINDIR}\email.exe
299  File ${WINDIR}\background.exe
300
301  SetOutPath "$INSTDIR\driver"
302  File ${TOPDIR}\platforms\mingw\winusb\install.txt
303  File ${TOPDIR}\platforms\mingw\winusb\apcupsd.inf
304  File ${TOPDIR}\platforms\mingw\winusb\apcupsd.cat
305  SetOutPath "$INSTDIR\driver\i386"
306  File ${DEPKGS}\winddk\redist\wdf\x86\*.dll
307  File ${DEPKGS}\winddk\redist\winusb\x86\*.dll
308  SetOutPath "$INSTDIR\driver\amd64"
309  File ${DEPKGS}\winddk\redist\wdf\amd64\*.dll
310  File ${DEPKGS}\winddk\redist\winusb\amd64\*.dll
311
312  SetOutPath "$INSTDIR\etc\apcupsd"
313  File ${TOPDIR}\platforms\mingw\apccontrol.bat
314  File ${TOPDIR}\platforms\mingw\apcupsd.conf.in
315  File /oname=onbattery.vbs.example ${TOPDIR}\platforms\mingw\onbattery.vbs
316  File /oname=offbattery.vbs.example ${TOPDIR}\platforms\mingw\offbattery.vbs
317  File /oname=commfailure.vbs.example ${TOPDIR}\platforms\mingw\commfailure.vbs
318
319  ; Post-process apcupsd.conf.in into apcupsd.conf.new
320  Call PostProcConfig
321
322  ; Rename apcupsd.conf.new to apcupsd.conf if it does not already exist
323  ${Unless} ${FileExists} "$INSTDIR\etc\apcupsd\apcupsd.conf"
324    Rename apcupsd.conf.new apcupsd.conf
325  ${EndUnless}
326SectionEnd
327
328Section "Tray Applet" SecApctray
329  ; We're installing the apctray package
330  StrCpy $TrayInstalled 1
331
332  ; Shut down any running copy
333  ${If} $MainInstalled != 1
334    ExecWait '"$OrigInstDir\bin\apctray.exe" /kill'
335    DetailPrint "Waiting for apctray to exit..."
336    Sleep 2000
337  ${EndIf}
338
339  ; Install files
340  CreateDirectory "$INSTDIR"
341  CreateDirectory "$INSTDIR\bin"
342  SetOutPath "$INSTDIR\bin"
343  File ${WINDIR}\apctray.exe
344  File ${CROSSTOOLS}\mingw32\mingw32\bin\mingwm10.dll
345  File ${DEPKGS}\libroot\lib\pthreadGCE.dll
346
347  ; Create start menu link for apctray
348  CreateDirectory "$SMPROGRAMS\Apcupsd"
349  CreateShortCut "$SMPROGRAMS\Apcupsd\Apctray.lnk" "$INSTDIR\bin\apctray.exe"
350SectionEnd
351
352Section "Multimon CGI programs" SecMultimon
353  CreateDirectory "$INSTDIR"
354  CreateDirectory "$INSTDIR\cgi"
355  CreateDirectory "$INSTDIR\etc"
356  CreateDirectory "$INSTDIR\etc\apcupsd"
357
358  SetOutPath "$INSTDIR\cgi"
359  File ${TOPDIR}\src\cgi\multimon.cgi
360  File ${TOPDIR}\src\cgi\upsstats.cgi
361  File ${TOPDIR}\src\cgi\upsfstats.cgi
362  File ${TOPDIR}\src\cgi\upsimage.cgi
363  File ${CROSSTOOLS}\mingw32\mingw32\bin\mingwm10.dll
364
365  SetOutPath "$INSTDIR\etc\apcupsd"
366  File ${TOPDIR}\src\cgi\apcupsd.css
367  File /oname=hosts.conf.new ${TOPDIR}\platforms\etc\hosts.conf
368
369  ; Rename hosts.conf.new to hosts.conf if it does not already exist
370  ${Unless} ${FileExists} "$INSTDIR\etc\apcupsd\hosts.conf"
371    Rename hosts.conf.new hosts.conf
372  ${EndUnless}
373SectionEnd
374
375Section "USB Driver" SecUsbDrv
376  ${InstallUpgradeDriver} "$INSTDIR\driver" $INSTDIR\driver\apcupsd.inf "USB\VID_051d&PID_0002"
377  ${If} $0 != 1
378    MessageBox MB_OK|MB_ICONEXCLAMATION  \
379      "The USB driver could not be automatically installed. You can ignore \
380       this if you do not plan to use Apcupsd with a USB UPS. Otherwise, please \
381       see $INSTDIR\driver\install.txt for instructions on installing the \
382       USB driver by hand."
383  ${EndIf}
384SectionEnd
385
386Section "Documentation" SecDoc
387  SetOutPath "$INSTDIR\doc"
388  CreateDirectory "$INSTDIR\doc"
389  File ${TOPDIR}\doc\manual\manual.html
390  File ${TOPDIR}\doc\manual\*.png
391  File *.man.txt
392
393  ; Create Start Menu entry
394  CreateDirectory "$SMPROGRAMS\Apcupsd\Documentation"
395  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\Apcupsd User Manual.lnk"     "$INSTDIR\doc\manual.html"          "" "$SYSDIR\shell32.dll" ${MANUAL_ICON_INDEX}
396  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\apcupsd Reference.lnk"       "$INSTDIR\doc\apcupsd.man.txt"      "" "$SYSDIR\shell32.dll" ${HELP_ICON_INDEX}
397  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\apcaccess Reference.lnk"     "$INSTDIR\doc\apcaccess.man.txt"    "" "$SYSDIR\shell32.dll" ${HELP_ICON_INDEX}
398  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\apctest Reference.lnk"       "$INSTDIR\doc\apctest.man.txt"      "" "$SYSDIR\shell32.dll" ${HELP_ICON_INDEX}
399  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\apccontrol Reference.lnk"    "$INSTDIR\doc\apccontrol.man.txt"   "" "$SYSDIR\shell32.dll" ${HELP_ICON_INDEX}
400  CreateShortCut "$SMPROGRAMS\Apcupsd\Documentation\Configuration Reference.lnk" "$INSTDIR\doc\apcupsd.conf.man.txt" "" "$SYSDIR\shell32.dll" ${HELP_ICON_INDEX}
401SectionEnd
402
403!define UNINSTREG "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apcupsd"
404
405Section "-Finish"
406  ; Write the uninstall keys for Windows & create Start Menu entry
407  SetShellVarContext all
408
409  WriteRegStr   HKLM "${UNINSTREG}" "DisplayName"     "Apcupsd"
410  WriteRegStr   HKLM "${UNINSTREG}" "UninstallString" "$INSTDIR\uninstall.exe"
411  WriteRegStr   HKLM "${UNINSTREG}" "DisplayVersion"  "${VERSION}"
412  WriteRegStr   HKLM "${UNINSTREG}" "Version"         "${VERSION}"
413  WriteRegStr   HKLM "${UNINSTREG}" "Publisher"       "apcupsd.org"
414  WriteRegStr   HKLM "${UNINSTREG}" "URLInfoAbout"    "http://apcupsd.org"
415  WriteRegDWord HKLM "${UNINSTREG}" "NoRepair"        1
416  WriteRegDWord HKLM "${UNINSTREG}" "NoModify"        1
417
418  ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
419  IntFmt $0 "0x%08X" $0
420  WriteRegDWORD HKLM "${UNINSTREG}" "EstimatedSize" "$0"
421
422  WriteUninstaller "$INSTDIR\Uninstall.exe"
423  CreateShortCut "$SMPROGRAMS\Apcupsd\Uninstall Apcupsd.lnk" "$INSTDIR\Uninstall.exe"
424SectionEnd
425
426;
427; Initialization Callback
428;
429Function .onInit
430  ; If there is an existing installation, default INSTDIR to location of that
431  ; install. Otherwise, if user did not specify INSTDIR on cmdline (using /D),
432  ; default it to %SystemDrive%\apcupsd.
433  ReadRegStr $0 HKLM "Software\Apcupsd" "InstDir"
434  ${If} $0 != ''
435    StrCpy $INSTDIR $0
436  ${ElseIf} "$INSTDIR" == ''
437    ReadEnvStr $0 SystemDrive
438    ${If} $0 == ''
439      StrCpy $0 'c:'
440    ${EndIf}
441    StrCpy $INSTDIR $0\apcupsd
442  ${EndIf}
443
444  ; Preserve a copy of original install dir string before user possibly
445  ; changes it. This will be used to run existing apcupsd and apctray exes
446  ; with /kill switch to shut down running instances.
447  StrCpy $OrigInstDir $INSTDIR
448
449  ; Extract custom pages. Automatically deleted when installer exits.
450  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "EditApcupsdConf.ini"
451  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "InstallService.ini"
452  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "Apctray.ini"
453
454  ; Nothing installed yet
455  StrCpy $MainInstalled 0
456  StrCpy $TrayInstalled 0
457FunctionEnd
458
459
460;
461; Extra Page descriptions
462;
463
464LangString DESC_SecService ${LANG_ENGLISH} "Install Apcupsd on this system."
465LangString DESC_SecApctray ${LANG_ENGLISH} "Install Apctray. Shows status icon in the system tray."
466LangString DESC_SecUsbDrv ${LANG_ENGLISH} "Install USB driver. Required if you have a USB UPS. Not available on Windows 95 or NT."
467LangString DESC_SecDoc ${LANG_ENGLISH} "Install Documentation on this system."
468LangString DESC_SecMultimon ${LANG_ENGLISH} "Install MULTIMON cgi scripts for web-based monitoring."
469
470!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
471  !insertmacro MUI_DESCRIPTION_TEXT ${SecService} $(DESC_SecService)
472  !insertmacro MUI_DESCRIPTION_TEXT ${SecApctray} $(DESC_SecApctray)
473  !insertmacro MUI_DESCRIPTION_TEXT ${SecMultimon} $(DESC_SecMultimon)
474  !insertmacro MUI_DESCRIPTION_TEXT ${SecUsbDrv} $(DESC_SecUsbDrv)
475  !insertmacro MUI_DESCRIPTION_TEXT ${SecDoc} $(DESC_SecDoc)
476!insertmacro MUI_FUNCTION_DESCRIPTION_END
477
478
479
480; Uninstall section
481
482UninstallText "This will uninstall Apcupsd. Hit next to continue."
483
484Section "Uninstall"
485
486  ; Shutdown any apcupsd & apctray that might be running
487  ExecWait '"$INSTDIR\bin\apctray.exe" /kill'
488  ExecWait '"$INSTDIR\bin\apcupsd.exe" /kill'
489  DetailPrint "Waiting for apcupsd and apctray to exit..."
490  Sleep 3000
491
492  ; Remove apcuspd service, if needed
493  ReadRegDWORD $R0 HKLM "Software\Apcupsd" "InstalledService"
494  ${If} $R0 == 1
495    ExecWait '"$INSTDIR\bin\apcupsd.exe" /quiet /remove'
496  ${EndIf}
497
498  ; Remove apctray autorun, if needed
499  ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "Apctray"
500  ${If} $R0 != ""
501    ExecWait '"$INSTDIR\bin\apctray.exe" /quiet /remove'
502  ${EndIf}
503
504  ; remove registry keys
505  DeleteRegKey HKLM "${UNINSTREG}"
506  DeleteRegKey HKLM "Software\Apcupsd"
507  DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "Apctray"
508
509  ; remove start menu items
510  SetShellVarContext all
511  RMDir /r /REBOOTOK "$SMPROGRAMS\Apcupsd"
512
513  ; remove files and uninstaller (preserving config for now)
514  Delete /REBOOTOK "$INSTDIR\bin\mingwm10.dll"
515  Delete /REBOOTOK "$INSTDIR\bin\pthreadGCE.dll"
516  Delete /REBOOTOK "$INSTDIR\bin\libusb0.dll"
517  Delete /REBOOTOK "$INSTDIR\bin\apcupsd.exe"
518  Delete /REBOOTOK "$INSTDIR\bin\smtp.exe"
519  Delete /REBOOTOK "$INSTDIR\bin\apcaccess.exe"
520  Delete /REBOOTOK "$INSTDIR\bin\apctest.exe"
521  Delete /REBOOTOK "$INSTDIR\bin\popup.exe"
522  Delete /REBOOTOK "$INSTDIR\bin\shutdown.exe"
523  Delete /REBOOTOK "$INSTDIR\bin\email.exe"
524  Delete /REBOOTOK "$INSTDIR\bin\background.exe"
525  Delete /REBOOTOK "$INSTDIR\bin\apctray.exe"
526  Delete /REBOOTOK "$INSTDIR\driver\libusb0.dll"
527  Delete /REBOOTOK "$INSTDIR\driver\libusb0_x64.dll"
528  Delete /REBOOTOK "$INSTDIR\driver\libusb0.sys"
529  Delete /REBOOTOK "$INSTDIR\driver\libusb0_x64.sys"
530  Delete /REBOOTOK "$INSTDIR\driver\apcupsd.inf"
531  Delete /REBOOTOK "$INSTDIR\driver\apcupsd.cat"
532  Delete /REBOOTOK "$INSTDIR\driver\apcupsd_x64.cat"
533  Delete /REBOOTOK "$INSTDIR\driver\install.txt"
534  Delete /REBOOTOK "$INSTDIR\driver\i386\*.dll"
535  Delete /REBOOTOK "$INSTDIR\driver\amd64\*.dll"
536  Delete /REBOOTOK "$INSTDIR\README*"
537  Delete /REBOOTOK "$INSTDIR\COPYING*"
538  Delete /REBOOTOK "$INSTDIR\ChangeLog*"
539  Delete /REBOOTOK "$INSTDIR\ReleaseNotes*"
540  Delete /REBOOTOK "$INSTDIR\Uninstall.exe"
541  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\apccontrol.bat"
542  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\apcupsd.conf.new"
543  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\hosts.conf.new"
544  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\onbattery.vbs.example"
545  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\offbattery.vbs.example"
546  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\commfailure.vbs.example"
547  Delete /REBOOTOK "$INSTDIR\doc\*"
548  Delete /REBOOTOK "$INSTDIR\cgi\multimon.cgi"
549  Delete /REBOOTOK "$INSTDIR\cgi\upsstats.cgi"
550  Delete /REBOOTOK "$INSTDIR\cgi\upsfstats.cgi"
551  Delete /REBOOTOK "$INSTDIR\cgi\upsimage.cgi"
552  Delete /REBOOTOK "$INSTDIR\cgi\mingwm10.dll"
553  Delete /REBOOTOK "$INSTDIR\etc\apcupsd\apcupsd.css"
554
555  ; Delete conf if user approves
556  ${If} ${FileExists} "$INSTDIR\etc\apcupsd\apcupsd.conf"
557  ${OrIf} ${FileExists} "$INSTDIR\etc\apcupsd\apcupsd.events"
558    ${If} ${Cmd} 'MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to delete the current configuration and events files?" /SD IDYES IDYES'
559      Delete /REBOOTOK "$INSTDIR\etc\apcupsd\apcupsd.conf"
560      Delete /REBOOTOK "$INSTDIR\etc\apcupsd\apcupsd.events"
561      Delete /REBOOTOK "$INSTDIR\etc\apcupsd\hosts.conf"
562    ${EndIf}
563  ${EndIf}
564
565  ; remove directories used
566  RMDir "$INSTDIR\bin"
567  RMDir "$INSTDIR\cgi"
568  RMDir "$INSTDIR\driver\i386"
569  RMDir "$INSTDIR\driver\amd64"
570  RMDir "$INSTDIR\driver"
571  RMDir "$INSTDIR\etc\apcupsd"
572  RMDir "$INSTDIR\etc"
573  RMDir "$INSTDIR\doc"
574  RMDir "$INSTDIR\examples"
575  RMDir "$INSTDIR"
576  RMDir "C:\tmp"
577
578SectionEnd
579
580; eof
581