-
Notifications
You must be signed in to change notification settings - Fork 3
/
cwupdater.nsi
230 lines (189 loc) · 6.34 KB
/
cwupdater.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
; ClamWin NSIS/VPatch updater
;
; Copyright (c) 2008-2018 Gianluigi Tiesi <[email protected]>
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU Library General Public
; License as published by the Free Software Foundation; either
; version 2 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Library General Public License for more details.
;
; You should have received a copy of the GNU Library General Public
; License along with this software; if not, write to the
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
; VPatch NSIS Plugin: Copyright (C) 2001-2008 Koen van de Sande / Van de Sande Productions
; please look at http://www.tibed.net/vpatch for licensing informations
;!define NOCHECK
!define NOSPLASH
Caption "ClamWin Free Antivirus Updater"
BrandingText "ClamWin Updater"
SetCompressor /solid lzma
Name "ClamWin Free Antivirus Upgrade"
OutFile "cwupdater.exe"
;!packhdr tmp.dat "upx --best tmp.dat"
XPStyle on
SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal
ShowInstDetails show
InstallColors FF8080 000030
Icon "cwupdater.ico"
CompletedText "Done"
!include "MUI2.nsh"
!include "TextFunc.nsh"
!include "WinVer.nsh"
!include "cWelcome.nsh"
!include "cUtils.nsh"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "header.bmp"
!define MUI_ICON "cwupdater.ico"
!define MUI_ABORTWARNING
Page custom cwelcome
!insertmacro MUI_PAGE_LICENSE "License.rtf"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function .onInit
InitPluginsDir
!ifndef NOSPLASH
File /oname=$PLUGINSDIR\splash.bmp splash.bmp
advsplash::show 1000 600 400 0x04025C $PLUGINSDIR\splash
Pop $0
Delete $PLUGINSDIR\splash.bmp
!endif
FunctionEnd
Section "CwUpdater"
Var /GLOBAL DESTDIR
Var /GLOBAL BINDIR
Var /GLOBAL TARGETV
Var /GLOBAL NEWVERDW
Var /GLOBAL NEWVERSZ
Var /GLOBAL FD
Var /GLOBAL REGUNI
StrCpy $REGUNI "Software\Microsoft\Windows\CurrentVersion\Uninstall\ClamWin Free Antivirus_is1"
; Search for ClamWin installation path
${_ReadRegStr} $BINDIR "Software\ClamWin" "Path"
IfErrors 0 begin
DetailPrint "Cannot find ClamWin Free Antivirus Installation, aborting..."
Goto abort
begin:
InitPluginsDir
SetDetailsPrint none
File /oname=$PLUGINSDIR\cwupdate.pat cwupdate.pat
File /oname=$PLUGINSDIR\cwupdate.lst cwupdate.lst
SetDetailsPrint both
FileOpen $FD $PLUGINSDIR\cwupdate.lst r
; Target version
FileRead $FD $TARGETV
Push $TARGETV
Call StripEol
Pop $TARGETV
; New version DWORD
FileRead $FD $NEWVERDW
Push $NEWVERDW
Call StripEol
Pop $NEWVERDW
; New version String for Uninstaller
FileRead $FD $NEWVERSZ
Push $NEWVERSZ
Call StripEol
Pop $NEWVERSZ
GetDllVersion "$BINDIR\ClamWin.exe" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000ffff
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000ffff
StrCpy $R8 "$R2.$R3.$R4.$R5"
!ifndef NOCHECK
; Check if we have the correct version installed
${If} $TARGETV != $R8
DetailPrint "Required version for this update is $TARGETV, found $R8"
DetailPrint "You cannot upgrade your ClamWin Free Antivirus installation with this setup"
DetailPrint "Please download the full installation from http://www.clamwin.com/download/"
DetailPrint "Update unsuccessful."
Goto abort
${EndIf}
!endif
DetailPrint "Closing ClamWin and ClamTray..."
SetDetailsPrint none
${CloseApp} "wxWindowClass" "ClamWin Free Antivirus"
${CloseApp} "#32770" "ClamWin Internet Update Status"
${CloseApp} "#32770" "ClamWin Preferences"
${CloseApp} "ClamWinTrayWindow" "ClamWin"
SetDetailsPrint both
; Extracting missing files
StrCpy $DESTDIR $BINDIR -3
SetDetailsPrint none
SetOutPath $DESTDIR
SetDetailsPrint both
; Specific files
${If} ${IsNT}
DetailPrint "Checking for OS specific files to add"
SetDetailsPrint none
File /nonfatal /r "missing\windows\*"
SetDetailsPrint both
${Else}
DetailPrint "Checking for Windows 98/ME specific files to add"
SetDetailsPrint none
File /nonfatal /r "missing\win9x\*"
SetDetailsPrint both
${EndIf}
; Common Files
DetailPrint "Checking for Common files to add"
SetDetailsPrint none
File /nonfatal /r "missing\common\*"
SetDetailsPrint both
DetailPrint "Upgrading ClamWin Free Antivirus to version $NEWVERSZ ($NEWVERDW)"
Loop:
ClearErrors
; Read a line from the manifest
FileRead $FD $1
IfErrors loopend
; Strip end of line char
Push $1
Call StripEol
Pop $1
StrCpy $1 "$DESTDIR$1"
; Check if the destination file exists, if not skip the patch
; to avoid creating 0 sized files
IfFileExists $1 gentemp
DetailPrint "Skipping $1 since is not installed"
Goto Loop
gentemp:
; Generate a temp file in the app dir, this is better than
; using a temp file and renaming it on reboot (tmp can be cleaned)
StrCpy $0 "$1.cwu"
DetailPrint "Patching $1"
; PatchIt
ClearErrors
${VPatchFile} "$PLUGINSDIR\cwupdate.pat" $1 $0
Goto Loop
loopend:
FileClose $FD
DetailPrint "Updating registry keys..."
${_WriteRegDWORD} "Software\ClamWin" "Version" $NEWVERDW
IfErrors 0 reguni
DetailPrint "Cannot update version key in the registry"
StrCpy $REGUNI "Software\Microsoft\Windows\CurrentVersion\Uninstall\ClamWin Free Antivirus_is1"
reguni:
${_WriteRegStr} $REGUNI "DisplayName" "ClamWin Free Antivirus $NEWVERSZ"
IfErrors 0 checkreboot
DetailPrint "Cannot update uninstall string in the registry"
checkreboot:
IfRebootFlag 0 startctray
MessageBox MB_YESNO "A reboot is required to finish the upgrade. Do you wish to reboot now?" IDNO end
Reboot
startctray:
SetDetailsPrint none
Exec '"$BINDIR\ClamTray.exe"'
SetDetailsPrint both
end:
DetailPrint "ClamWin Free Antivirus Upgraded to $NEWVERSZ"
Return
abort:
SetDetailsPrint none
SectionEnd