Removed a pointless loop.
[mplayer-setup-win32.git] / MPUI_Updater.nsi
bloba43d84bfb1fb331fa5c40fb95100a6624d8ba994
1 ; ///////////////////////////////////////////////////////////////////////////////
2 ; // MPlayer for Windows - Install Script
3 ; // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 ; //
5 ; // This program is free software; you can redistribute it and/or modify
6 ; // it under the terms of the GNU General Public License as published by
7 ; // the Free Software Foundation; either version 2 of the License, or
8 ; // (at your option) any later version.
9 ; //
10 ; // This program is distributed in the hope that it will be useful,
11 ; // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; // GNU General Public License for more details.
14 ; //
15 ; // You should have received a copy of the GNU General Public License along
16 ; // with this program; if not, write to the Free Software Foundation, Inc.,
17 ; // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 ; //
19 ; // http://www.gnu.org/licenses/gpl-2.0.txt
20 ; ///////////////////////////////////////////////////////////////////////////////
23 !ifndef MPLAYER_DATE
24 !error "MPLAYER_DATE is not defined !!!"
25 !endif
27 !ifndef MPLAYER_OUTFILE
28 !error "MPLAYER_OUTFILE is not defined !!!"
29 !endif
31 !ifndef UPX_PATH
32 !error "UPX_PATH is not defined !!!"
33 !endif
35 ; UUID
36 !define MPlayerRegPath "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{97D341C8-B0D1-4E4A-A49A-C30B52F168E9}"
38 ; ----------------------------------------------------------------------------
40 !define /date BUILD_DATE "%Y%m%d"
41 !packhdr "exehead.tmp" '"${UPX_PATH}\upx.exe" --brute exehead.tmp'
43 ; ----------------------------------------------------------------------------
45 XPStyle on
46 RequestExecutionLevel user
47 InstallColors /windows
48 AutoCloseWindow true
49 ShowInstDetails show
50 SetCompressor LZMA
52 ; ----------------------------------------------------------------------------
54 LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
55 LoadLanguageFile "${NSISDIR}\Contrib\Language files\German.nlf"
57 !include "Language\MPUI_EN.nsh"
58 !include "Language\MPUI_DE.nsh"
60 ; ----------------------------------------------------------------------------
62 Name "$(MPLAYER_LANG_MPLAYER_WIN32) $(MPLAYER_LANG_AUTO_UPDATE)"
63 Caption "$(MPLAYER_LANG_MPLAYER_WIN32) Auto-Update"
64 BrandingText "MPlayer Update [${MPLAYER_DATE}]"
65 Icon "Artwork\update.ico"
66 OutFile "${MPLAYER_OUTFILE}"
68 ; ----------------------------------------------------------------------------
70 !include "MPUI_Download.nsh"
72 ; ----------------------------------------------------------------------------
74 Var Update_CurrentBuildNo
75 Var Update_CurrentPkgDate
76 Var Update_MirrorURL
77 Var Update_LatestBuildNo
78 Var Update_DownloadFileName
79 Var Update_DownloadAddress
80 Var Update_DownloadChecksum
82 ; ----------------------------------------------------------------------------
84 SubCaption 0 " "
85 SubCaption 1 " "
86 SubCaption 2 " "
87 SubCaption 3 " "
88 SubCaption 4 " "
90 ; ----------------------------------------------------------------------------
92 ReserveFile "${NSISDIR}\Plugins\Aero.dll"
93 ReserveFile "${NSISDIR}\Plugins\inetc.dll"
94 ReserveFile "${NSISDIR}\Plugins\LangDLL.dll"
95 ReserveFile "${NSISDIR}\Plugins\nsExec.dll"
96 ReserveFile "${NSISDIR}\Plugins\StdUtils.dll"
97 ReserveFile "${NSISDIR}\Plugins\System.dll"
99 ; ----------------------------------------------------------------------------
101 Function .onInit
102 ; AutoCheck support
103 ${StdUtils.GetParameter} $0 "AutoCheck" "?"
104 ${IfNot} "$0" == "?"
105 ClearErrors
106 ReadRegDWORD $1 HKCU "${MPlayerRegPath}" "LastUpdateCheck"
107 ${IfNot} ${Errors}
108 ${StdUtils.GetDays} $2
109 IntOp $1 $1 + 30
110 ${IfThen} $2 < $1 ${|} Quit ${|}
111 ${EndIf}
112 ${EndIf}
114 ; Handle command-line
115 ${StdUtils.GetParameter} $0 "L" "?"
116 ${If} "$0" == "${LANG_ENGLISH}"
117 ${OrIf} "$0" == "${LANG_GERMAN}"
118 StrCpy $LANGUAGE "$0"
119 Return
120 ${EndIf}
122 ; Language selection dialog
123 Push ""
124 Push ${LANG_ENGLISH}
125 Push English
126 Push ${LANG_GERMAN}
127 Push German
128 Push A
129 LangDLL::LangDialog "Updater Language" "Please select the language:"
130 Pop $LANGUAGE
131 ${IfThen} $LANGUAGE == "cancel" ${|} Quit ${|}
132 FunctionEnd
134 Function .onGuiInit
135 StrCpy $0 $HWNDPARENT
136 System::Call "user32::SetWindowPos(i r0, i -1, i 0, i 0, i 0, i 0, i 3)"
137 Aero::Apply
138 FunctionEnd
140 ; ----------------------------------------------------------------------------
142 !define VerfiySignature "!insertmacro _VerfiySignature"
144 !macro _VerfiySignature filename
145 DetailPrint "$(MPLAYER_LANG_UPD_VERIFYING) ${filename}"
147 File "/oname=$PLUGINSDIR\gpgv.exe" "Resources\GnuPG.exe"
148 File "/oname=$PLUGINSDIR\pubring.gpg" "Resources\GnuPG.gpg"
150 SetOutPath $PLUGINSDIR
151 nsExec::ExecToLog '"$PLUGINSDIR\gpgv.exe" --homedir . --keyring pubring.gpg "${filename}.sig" "${filename}"'
152 Pop $9
154 Delete "$PLUGINSDIR\pubring.gpg"
155 Delete "$PLUGINSDIR\${filename}.sig"
156 Delete "$PLUGINSDIR\gpgv.exe"
158 ${If} "$9" == "error"
159 ${OrIf} "$9" == "timeout"
160 Delete "$PLUGINSDIR\$1"
161 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
162 MessageBox MB_ICONSTOP|MB_TOPMOST "$(MPLAYER_LANG_UPD_ERR_GNUPG)"
163 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
164 ${EndIf}
166 ${IfNot} "$9" == "0"
167 Delete "$PLUGINSDIR\$1"
168 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
169 MessageBox MB_ICONSTOP|MB_TOPMOST "$(MPLAYER_LANG_UPD_ERR_VERIFY)"
170 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
171 ${EndIf}
172 !macroend
174 ; ----------------------------------------------------------------------------
176 !define VerfiyChecksum "!insertmacro _VerfiyChecksum"
178 !macro _VerfiyChecksum filename expected_value
179 DetailPrint "$(MPLAYER_LANG_UPD_VERIFYING) ${filename}"
181 ${StdUtils.HashFile} $9 "SHA3-384" '${filename}'
183 ${If} "$9" == "error"
184 ${OrIf} "$9" == "invalid"
185 Delete '${filename}'
186 MessageBox MB_ICONSTOP|MB_TOPMOST "$(MPLAYER_LANG_UPD_ERR_VERIFY)"
187 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
188 ${EndIf}
190 DetailPrint "Expected checksum: ${expected_value}"
191 DetailPrint "Computed checksum: $9"
193 ${IfNot} "$9" == "${expected_value}"
194 Delete '${filename}'
195 MessageBox MB_ICONSTOP|MB_TOPMOST "$(MPLAYER_LANG_UPD_ERR_VERIFY)"
196 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
197 ${EndIf}
198 !macroend
201 ; ----------------------------------------------------------------------------
203 Section "-Read Version Info"
204 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_VERINFO)"
205 InitPluginsDir
206 SetOutPath "$EXEDIR"
208 ClearErrors
209 ReadINIStr $Update_CurrentBuildNo "$EXEDIR\version.tag" "mplayer_version" "build_no"
210 ReadINIStr $Update_CurrentPkgDate "$EXEDIR\version.tag" "mplayer_version" "pkg_date"
212 ${If} ${Errors}
213 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
214 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_OK "$(MPLAYER_LANG_UPD_ERR_VERINFO)"
215 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
216 ${EndIf}
218 DetailPrint "$(MPLAYER_LANG_UPD_INSTALLED_VER) $Update_CurrentPkgDate (Build #$Update_CurrentBuildNo)"
219 SectionEnd
221 Section "-Select Mirror"
222 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_MIRROR)"
223 StrCpy $Update_MirrorURL "http://www.example.com/"
225 ; Randomize!
226 ${StdUtils.RandMax} $0 15
228 ; Select the mirror now!
229 ${Select} $0
230 ${Case} "0"
231 StrCpy $Update_MirrorURL "http://muldersoft.com/"
232 ${Case} "1"
233 StrCpy $Update_MirrorURL "http://mulder.bplaced.net/"
234 ${Case} "2"
235 StrCpy $Update_MirrorURL "http://mulder.6te.net/"
236 ${Case} "3"
237 StrCpy $Update_MirrorURL "http://mulder.000webhostapp.com/"
238 ${Case} "4"
239 StrCpy $Update_MirrorURL "http://mulder.pe.hu/"
240 ${Case} "5"
241 StrCpy $Update_MirrorURL "http://muldersoft.square7.ch/"
242 ${Case} "6"
243 StrCpy $Update_MirrorURL "http://muldersoft.co.nf/"
244 ${Case} "7"
245 StrCpy $Update_MirrorURL "http://muldersoft.lima-city.de/"
246 ${Case} "8"
247 StrCpy $Update_MirrorURL "http://www.muldersoft.keepfree.de/"
248 ${Case} "9"
249 StrCpy $Update_MirrorURL "http://lamexp.sourceforge.net/"
250 ${Case} "10"
251 StrCpy $Update_MirrorURL "http://muldersoft.sourceforge.net/"
252 ${Case} "11"
253 StrCpy $Update_MirrorURL "http://lordmulder.github.io/LameXP/"
254 ${Case} "12"
255 StrCpy $Update_MirrorURL "http://muldersoft.bitbucket.io/"
256 ${Case} "13"
257 StrCpy $Update_MirrorURL "http://www.tricksoft.de/"
258 ${Case} "14"
259 StrCpy $Update_MirrorURL "http://repo.or.cz/LameXP.git/blob_plain/gh-pages:/"
260 ${Case} "15"
261 StrCpy $Update_MirrorURL "http://gitlab.com/lamexp/lamexp/raw/gh-pages/"
262 ${CaseElse}
263 Abort "This is not supposed to happen!"
264 ${EndSelect}
266 DetailPrint "$(MPLAYER_LANG_UPD_MIRROR) $Update_MirrorURL"
267 SectionEnd
269 Section "-Download Update Info"
270 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)"
272 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver" "$PLUGINSDIR\update.ver"
273 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver.sig2" "$PLUGINSDIR\update.ver.sig"
275 ${VerfiySignature} "update.ver"
277 ClearErrors
278 ReadINIStr $Update_LatestBuildNo "$PLUGINSDIR\update.ver" "MPlayer for Windows" "BuildNo"
279 ReadINIStr $Update_DownloadFileName "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadFilename"
280 ReadINIStr $Update_DownloadAddress "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadAddress"
281 ReadINIStr $Update_DownloadChecksum "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadChecksum"
283 ${If} ${Errors}
284 Delete "$PLUGINSDIR\update.ver"
285 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
286 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_OK "$(MPLAYER_LANG_UPD_ERR_UPDINFO)"
287 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
288 ${EndIf}
290 StrCpy $0 "$Update_DownloadAddress" "" -1
291 ${IfNotThen} "$0" == "/" ${|} StrCpy $Update_DownloadAddress "$Update_DownloadAddress/" ${|}
293 Delete "$PLUGINSDIR\update.ver"
294 DetailPrint "$(MPLAYER_LANG_UPD_LATEST_VER) Build #$Update_LatestBuildNo"
295 SectionEnd
297 Section "-Check Update Required"
298 ${If} $Update_CurrentBuildNo >= $Update_LatestBuildNo
299 ${StdUtils.GetDays} $0
300 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
301 MessageBox MB_TOPMOST|MB_ICONINFORMATION "$(MPLAYER_LANG_UPD_NO_UPDATES)"
302 Quit
303 ${EndIf}
304 SectionEnd
306 Section "-Download Update"
307 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)"
309 ${DownloadFile.Popup} "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)" "$Update_DownloadAddress$Update_DownloadFileName" "$PLUGINSDIR\$Update_DownloadFileName"
310 ${VerfiyChecksum} "$Update_DownloadFileName" "$Update_DownloadChecksum"
311 SectionEnd
313 Section "-Install Update Now"
314 ${StdUtils.GetDays} $0
315 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
317 StrCpy $5 '/Update /D=$EXEDIR'
319 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_INSTALL)"
320 ${Do}
321 ClearErrors
322 ExecShell "open" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
323 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
325 ClearErrors
326 ExecShell "" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
327 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
329 ClearErrors
330 Exec '"$PLUGINSDIR\$Update_DownloadFileName" $5'
331 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
333 ${IfCmd} MessageBox MB_ICONSTOP|MB_TOPMOST|MB_RETRYCANCEL "$(MPLAYER_LANG_UPD_ERR_LAUNCH)$\n$PLUGINSDIR\$Update_DownloadFileName$\n$\n$(MPLAYER_LANG_UPD_ACCESS_RIGHTS)" IDCANCEL ${||} ${Break} ${|}
334 ${Loop}
336 Delete /REBOOTOK "$PLUGINSDIR\$Update_DownloadFileName"
338 ${If} ${FileExists} "$PLUGINSDIR\$Update_DownloadFileName"
339 File "/oname=$PLUGINSDIR\update-helper.exe" "Utils\AutoDel.exe"
340 Exec '"$PLUGINSDIR\update-helper.exe" "$PLUGINSDIR\$Update_DownloadFileName"'
341 Delete /REBOOTOK "$PLUGINSDIR\update-helper.exe"
342 ${EndIf}
343 SectionEnd
345 ; ----------------------------------------------------------------------------
347 Function .onInstFailed
348 ${IfCmd} MessageBox MB_ICONQUESTION|MB_TOPMOST|MB_YESNO "$(MPLAYER_LANG_UPD_FAILED)" IDYES ${||} Exec `"$EXEPATH" /L=$LANGUAGE` ${|}
349 FunctionEnd