Some improvements GUI tweaks.
[mplayer-setup-win32.git] / MPUI_Updater.nsi
blob187e72f90f1986bf8103dac71c95a19b82cc7f58
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 some more
226 ${For} $1 1 97
227 ${StdUtils.RandMax} $0 15
228 ${Next}
230 ; Select the mirror now!
231 ${Select} $0
232 ${Case} "0"
233 StrCpy $Update_MirrorURL "http://muldersoft.com/"
234 ${Case} "1"
235 StrCpy $Update_MirrorURL "http://mulder.bplaced.net/"
236 ${Case} "2"
237 StrCpy $Update_MirrorURL "http://mulder.6te.net/"
238 ${Case} "3"
239 StrCpy $Update_MirrorURL "http://mulder.000webhostapp.com/"
240 ${Case} "4"
241 StrCpy $Update_MirrorURL "http://mulder.pe.hu/"
242 ${Case} "5"
243 StrCpy $Update_MirrorURL "http://muldersoft.square7.ch/"
244 ${Case} "6"
245 StrCpy $Update_MirrorURL "http://muldersoft.co.nf/"
246 ${Case} "7"
247 StrCpy $Update_MirrorURL "http://muldersoft.lima-city.de/"
248 ${Case} "8"
249 StrCpy $Update_MirrorURL "http://www.muldersoft.keepfree.de/"
250 ${Case} "9"
251 StrCpy $Update_MirrorURL "http://lamexp.sourceforge.net/"
252 ${Case} "10"
253 StrCpy $Update_MirrorURL "http://muldersoft.sourceforge.net/"
254 ${Case} "11"
255 StrCpy $Update_MirrorURL "http://lordmulder.github.io/LameXP/"
256 ${Case} "12"
257 StrCpy $Update_MirrorURL "http://muldersoft.bitbucket.io/"
258 ${Case} "13"
259 StrCpy $Update_MirrorURL "http://www.tricksoft.de/"
260 ${Case} "14"
261 StrCpy $Update_MirrorURL "http://repo.or.cz/LameXP.git/blob_plain/gh-pages:/"
262 ${Case} "15"
263 StrCpy $Update_MirrorURL "http://gitlab.com/lamexp/lamexp/raw/gh-pages/"
264 ${CaseElse}
265 Abort "This is not supposed to happen!"
266 ${EndSelect}
268 DetailPrint "$(MPLAYER_LANG_UPD_MIRROR) $Update_MirrorURL"
269 SectionEnd
271 Section "-Download Update Info"
272 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)"
274 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver" "$PLUGINSDIR\update.ver"
275 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver.sig2" "$PLUGINSDIR\update.ver.sig"
277 ${VerfiySignature} "update.ver"
279 ClearErrors
280 ReadINIStr $Update_LatestBuildNo "$PLUGINSDIR\update.ver" "MPlayer for Windows" "BuildNo"
281 ReadINIStr $Update_DownloadFileName "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadFilename"
282 ReadINIStr $Update_DownloadAddress "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadAddress"
283 ReadINIStr $Update_DownloadChecksum "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadChecksum"
285 ${If} ${Errors}
286 Delete "$PLUGINSDIR\update.ver"
287 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
288 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_OK "$(MPLAYER_LANG_UPD_ERR_UPDINFO)"
289 Abort "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
290 ${EndIf}
292 StrCpy $0 "$Update_DownloadAddress" "" -1
293 ${IfNotThen} "$0" == "/" ${|} StrCpy $Update_DownloadAddress "$Update_DownloadAddress/" ${|}
295 Delete "$PLUGINSDIR\update.ver"
296 DetailPrint "$(MPLAYER_LANG_UPD_LATEST_VER) Build #$Update_LatestBuildNo"
297 SectionEnd
299 Section "-Check Update Required"
300 ${If} $Update_CurrentBuildNo >= $Update_LatestBuildNo
301 ${StdUtils.GetDays} $0
302 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
303 MessageBox MB_TOPMOST|MB_ICONINFORMATION "$(MPLAYER_LANG_UPD_NO_UPDATES)"
304 Quit
305 ${EndIf}
306 SectionEnd
308 Section "-Download Update"
309 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)"
311 ${DownloadFile.Popup} "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)" "$Update_DownloadAddress$Update_DownloadFileName" "$PLUGINSDIR\$Update_DownloadFileName"
312 ${VerfiyChecksum} "$Update_DownloadFileName" "$Update_DownloadChecksum"
313 SectionEnd
315 Section "-Install Update Now"
316 ${StdUtils.GetDays} $0
317 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
319 StrCpy $5 '/Update /D=$EXEDIR'
321 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_INSTALL)"
322 ${Do}
323 ClearErrors
324 ExecShell "open" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
325 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
327 ClearErrors
328 ExecShell "" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
329 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
331 ClearErrors
332 Exec '"$PLUGINSDIR\$Update_DownloadFileName" $5'
333 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
335 ${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} ${|}
336 ${Loop}
338 Delete /REBOOTOK "$PLUGINSDIR\$Update_DownloadFileName"
340 ${If} ${FileExists} "$PLUGINSDIR\$Update_DownloadFileName"
341 File "/oname=$PLUGINSDIR\update-helper.exe" "Utils\AutoDel.exe"
342 Exec '"$PLUGINSDIR\update-helper.exe" "$PLUGINSDIR\$Update_DownloadFileName"'
343 Delete /REBOOTOK "$PLUGINSDIR\update-helper.exe"
344 ${EndIf}
345 SectionEnd
347 ; ----------------------------------------------------------------------------
349 Function .onInstFailed
350 ${IfCmd} MessageBox MB_ICONQUESTION|MB_TOPMOST|MB_YESNO "$(MPLAYER_LANG_UPD_FAILED)" IDYES ${||} Exec `"$EXEPATH" /L=$LANGUAGE` ${|}
351 FunctionEnd