Happy new year 2014 :-)
[mplayer-setup-win32.git] / MPUI_Updater.nsi
blobc592b399594a4a8ec0a323f52e184cda2b211fe7
1 ; ///////////////////////////////////////////////////////////////////////////////
2 ; // MPlayer for Windows - Install Script
3 ; // Copyright (C) 2004-2014 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_DownloadTicketId
80 Var Update_DownloadAddress
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 "Failed to verify signature!"
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 "Failed to verify signature!"
171 ${EndIf}
172 !macroend
174 ; ----------------------------------------------------------------------------
176 Section "-Read Version Info"
177 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_VERINFO)"
178 InitPluginsDir
179 SetOutPath "$EXEDIR"
181 ClearErrors
182 ReadINIStr $Update_CurrentBuildNo "$EXEDIR\version.tag" "mplayer_version" "build_no"
183 ReadINIStr $Update_CurrentPkgDate "$EXEDIR\version.tag" "mplayer_version" "pkg_date"
185 ${If} ${Errors}
186 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
187 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_OK "$(MPLAYER_LANG_UPD_ERR_VERINFO)"
188 Abort
189 ${EndIf}
191 DetailPrint "$(MPLAYER_LANG_UPD_INSTALLED_VER) $Update_CurrentPkgDate (Build #$Update_CurrentBuildNo)"
192 SectionEnd
194 Section "-Select Mirror"
195 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_MIRROR)"
196 StrCpy $Update_MirrorURL "http://www.example.com/"
198 ; Randomize some more
199 ${For} $1 1 42
200 ${StdUtils.RandMax} $0 12
201 ${Next}
203 ; Select the mirror now!
204 ${Select} $0
205 ${Case} "0"
206 StrCpy $Update_MirrorURL "http://muldersoft.com/"
207 ${Case} "1"
208 StrCpy $Update_MirrorURL "http://mulder.bplaced.net/"
209 ${Case} "2"
210 StrCpy $Update_MirrorURL "http://mulder.cwsurf.de/"
211 ${Case} "3"
212 StrCpy $Update_MirrorURL "http://mulder.6te.net/"
213 ${Case} "4"
214 StrCpy $Update_MirrorURL "http://mulder.webuda.com/"
215 ${Case} "5"
216 StrCpy $Update_MirrorURL "http://mulder.byethost13.com/"
217 ${Case} "6"
218 StrCpy $Update_MirrorURL "http://muldersoft.kilu.de/"
219 ${Case} "7"
220 StrCpy $Update_MirrorURL "http://muldersoft.zxq.net/"
221 ${Case} "8"
222 StrCpy $Update_MirrorURL "http://lamexp.sourceforge.net/"
223 ${Case} "9"
224 StrCpy $Update_MirrorURL "http://lamexp.berlios.de/"
225 ${Case} "10"
226 StrCpy $Update_MirrorURL "http://lordmulder.github.com/LameXP/"
227 ${Case} "11"
228 StrCpy $Update_MirrorURL "http://lord_mulder.bitbucket.org/"
229 ${Case} "12"
230 StrCpy $Update_MirrorURL "http://www.tricksoft.de/"
231 ${CaseElse}
232 Abort "This is not supposed to happen!"
233 ${EndSelect}
235 DetailPrint "$(MPLAYER_LANG_UPD_MIRROR) $Update_MirrorURL"
236 SectionEnd
238 Section "-Download Update Info"
239 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)"
241 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver" "$PLUGINSDIR\update.ver"
242 ${DownloadFile.Get} "$(MPLAYER_LANG_UPD_STATUS_UPDINFO)" "$Update_MirrorURL/update.ver.sig" "$PLUGINSDIR\update.ver.sig"
244 ${VerfiySignature} "update.ver"
246 ClearErrors
247 ReadINIStr $Update_LatestBuildNo "$PLUGINSDIR\update.ver" "MPlayer for Windows" "BuildNo"
248 ReadINIStr $Update_DownloadFileName "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadFilename"
249 ReadINIStr $Update_DownloadTicketId "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadFilecode"
250 ReadINIStr $Update_DownloadAddress "$PLUGINSDIR\update.ver" "MPlayer for Windows" "DownloadAddress"
252 ${If} ${Errors}
253 Delete "$PLUGINSDIR\update.ver"
254 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_FAILED)"
255 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_OK "$(MPLAYER_LANG_UPD_ERR_UPDINFO)"
256 Abort
257 ${EndIf}
259 Delete "$PLUGINSDIR\update.ver"
260 DetailPrint "$(MPLAYER_LANG_UPD_LATEST_VER) Build #$Update_LatestBuildNo"
261 SectionEnd
263 Section "-Check Update Required"
264 ${If} $Update_CurrentBuildNo >= $Update_LatestBuildNo
265 ${StdUtils.GetDays} $0
266 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
267 MessageBox MB_TOPMOST|MB_ICONINFORMATION "$(MPLAYER_LANG_UPD_NO_UPDATES)"
268 Quit
269 ${EndIf}
270 SectionEnd
272 Section "-Download Update"
273 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)"
275 ${DownloadFile.Post} "file_name=$Update_DownloadFileName&file_code=$Update_DownloadTicketId" "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)" "$Update_DownloadAddress" "$PLUGINSDIR\$Update_DownloadFileName"
276 ${DownloadFile.Post} "sign_name=$Update_DownloadFileName" "$(MPLAYER_LANG_UPD_STATUS_DOWNLOAD)" "$Update_DownloadAddress" "$PLUGINSDIR\$Update_DownloadFileName.sig"
278 ${VerfiySignature} "$Update_DownloadFileName"
279 SectionEnd
281 Section "-Install Update Now"
282 ${StdUtils.GetDays} $0
283 WriteRegDWORD HKCU "${MPlayerRegPath}" "LastUpdateCheck" $0
285 StrCpy $5 '/Update /D=$EXEDIR'
287 ${SetStatus} "$(MPLAYER_LANG_UPD_STATUS_INSTALL)"
288 ${Do}
289 ClearErrors
290 ExecShell "open" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
291 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
293 ClearErrors
294 ExecShell "" "$PLUGINSDIR\$Update_DownloadFileName" '$5' SW_SHOWNORMAL
295 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
297 ClearErrors
298 Exec '"$PLUGINSDIR\$Update_DownloadFileName" $5'
299 ${IfNotThen} ${Errors} ${|} ${Break} ${|}
301 ${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} ${|}
302 ${Loop}
304 Delete /REBOOTOK "$PLUGINSDIR\$Update_DownloadFileName"
305 SectionEnd
307 ; ----------------------------------------------------------------------------
309 Function .onInstFailed
310 ${IfCmd} MessageBox MB_ICONQUESTION|MB_TOPMOST|MB_YESNO "$(MPLAYER_LANG_UPD_FAILED)" IDYES ${||} Exec `"$EXEPATH" /L=$LANGUAGE` ${|}
311 FunctionEnd