Trigger "update" mode, if MPlayer for Windows is installed already (Part #2).
[mplayer-setup-win32.git] / MPUI_Download.nsh
blobd8f305fa504d0261a7e3185df01e516160ac72e2
1 ; ///////////////////////////////////////////////////////////////////////////////
2 ; // MPlayer for Windows - Install Script
3 ; // Copyright (C) 2004-2013 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 !include "LogicLib.nsh"
24 !include "WinMessages.nsh"
25 !include "StdUtils.nsh"
27 !define HWND_TOPMOST -1
29 Var errors
30 Var dl_tmp
32 ; ----------------------------------------------------------------------------
34 !define SetStatus "!insertmacro _SetStatus"
36 !macro _SetStatus text
37         SetDetailsPrint textonly
38         DetailPrint '${text}'
39         SetDetailsPrint listonly
40         Sleep 333
41 !macroend
43 ; ----------------------------------------------------------------------------
45 !define DownloadFile.Get  '!insertmacro _DownloadFile "get" ""'
46 !define DownloadFile.Post '!insertmacro _DownloadFile "post"'
48 !define user_agent "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111106 IceCat/7.0.1"
50 !macro _DownloadFile action dl_post status_txt dl_url destfile
51         StrCpy $errors 0
53         ${Do}
54                 ${SetStatus} "${status_txt}"
55                 DetailPrint "$(MPLAYER_LANG_DL_PROGRESS)"
56                 !if "${action}" == "get"
57                         inetc::get /CONNECTTIMEOUT 30 /RECEIVETIMEOUT 30 /CANCELTEXT "$(^CancelBtn)" /USERAGENT "${user_agent}" /SILENT "${dl_url}" "${destfile}" /END
58                 !endif
59                 !if "${action}" == "post"
60                         inetc::post "${dl_post}" /CONNECTTIMEOUT 30 /RECEIVETIMEOUT 30 /CANCELTEXT "$(^CancelBtn)" /USERAGENT "${user_agent}" /CAPTION "${status_txt}" /POPUP "" "${dl_url}" "${destfile}" /END
61                 !endif
62                 Pop $dl_tmp
64                 ${IfThen} "$dl_tmp" == "OK" ${|} ${Break} ${|}
66                 ${If} "$dl_tmp" == "File Open Error"
67                         ${SetStatus} "$(MPLAYER_LANG_DL_FAILED)"
68                         DetailPrint "Error: $dl_tmp"
69                         MessageBox MB_TOPMOST|MB_ICONSTOP "$(MPLAYER_LANG_DL_UPDATE_FAILED)"
70                         Abort "$(MPLAYER_LANG_DL_FAILED)"
71                 ${EndIf}
73                 ${If} "$dl_tmp" == "Cancelled"
74                         ${SetStatus} "$(MPLAYER_LANG_DL_ABORTED)"
75                         DetailPrint "$(MPLAYER_LANG_DL_ERROR): $dl_tmp"
76                         ${IfCmd} MessageBox MB_TOPMOST|MB_RETRYCANCEL|MB_ICONSTOP "$(MPLAYER_LANG_DL_USER_ABORTED)" IDRETRY ${||} ${Continue} ${|}
77                         Abort "$(MPLAYER_LANG_DL_FAILED)"
78                 ${EndIf}
80                 IntOp $errors $errors + 3
81                 DetailPrint "$(MPLAYER_LANG_DL_ERROR): $dl_tmp"
83                 ${If} $errors > 5
84                         ${SetStatus} "$(MPLAYER_LANG_DL_FAILED)"
85                         StrCpy $errors 0
86                         MessageBox MB_TOPMOST|MB_ICONSTOP "$(MPLAYER_LANG_DL_FAILED_MSG) $dl_tmp$\n$\n$(MPLAYER_LANG_DL_RETRY)"
87                         Abort "$(MPLAYER_LANG_DL_FAILED)"
88                 ${Else}
89                         ${SetStatus} "$(MPLAYER_LANG_DL_RESTARTING)"
90                         Sleep 333
91                 ${EndIf}
92         ${Loop}
94         DetailPrint "$(MPLAYER_LANG_DL_SUCCESSFULL)"
95         ${SetStatus} "$(MPLAYER_LANG_DL_COMPELETED)"
96 !macroend