Added "AutoDel" tool to auto updater.
[mplayer-setup-win32.git] / MPUI_Download.nsh
blob4f2bbd6102fb8c99415d35625f1899115e319b05
1 ; ///////////////////////////////////////////////////////////////////////////////
2 ; // MPlayer for Windows - Install Script
3 ; // Copyright (C) 2004-2016 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.Popup '!insertmacro _DownloadFile "popup"'
48 !define user_agent "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111106 IceCat/7.0.1"
50 !macro _DownloadFile action status_txt dl_url destfile
51         StrCpy $errors 0
53         !if "${action}" != "get"
54                 !if "${action}" != "popup"
55                         !error "Invalid 'action' value has been specified!"
56                 !endif
57         !endif
59         ${Do}
60                 ${SetStatus} "${status_txt}"
61                 DetailPrint "$(MPLAYER_LANG_DL_PROGRESS)"
62                 !if "${action}" == "get"
63                         inetc::get /CONNECTTIMEOUT 30 /RECEIVETIMEOUT 30 /CANCELTEXT "$(^CancelBtn)" /USERAGENT "${user_agent}" /SILENT "${dl_url}" "${destfile}" /END
64                 !endif
65                 !if "${action}" == "popup"
66                         inetc::get /CONNECTTIMEOUT 30 /RECEIVETIMEOUT 30 /CANCELTEXT "$(^CancelBtn)" /USERAGENT "${user_agent}" /CAPTION "${status_txt}" /POPUP "" "${dl_url}" "${destfile}" /END
67                 !endif
68                 Pop $dl_tmp
70                 ${IfThen} "$dl_tmp" == "OK" ${|} ${Break} ${|}
72                 ${If} "$dl_tmp" == "File Open Error"
73                         ${SetStatus} "$(MPLAYER_LANG_DL_FAILED)"
74                         DetailPrint "Error: $dl_tmp"
75                         MessageBox MB_TOPMOST|MB_ICONSTOP "$(MPLAYER_LANG_DL_UPDATE_FAILED)"
76                         Abort "$(MPLAYER_LANG_DL_FAILED)"
77                 ${EndIf}
79                 ${If} "$dl_tmp" == "Cancelled"
80                         ${SetStatus} "$(MPLAYER_LANG_DL_ABORTED)"
81                         DetailPrint "$(MPLAYER_LANG_DL_ERROR): $dl_tmp"
82                         ${IfCmd} MessageBox MB_TOPMOST|MB_RETRYCANCEL|MB_ICONSTOP "$(MPLAYER_LANG_DL_USER_ABORTED)" IDRETRY ${||} ${Continue} ${|}
83                         Abort "$(MPLAYER_LANG_DL_FAILED)"
84                 ${EndIf}
86                 IntOp $errors $errors + 3
87                 DetailPrint "$(MPLAYER_LANG_DL_ERROR): $dl_tmp"
89                 ${If} $errors > 5
90                         ${SetStatus} "$(MPLAYER_LANG_DL_FAILED)"
91                         StrCpy $errors 0
92                         MessageBox MB_TOPMOST|MB_ICONSTOP "$(MPLAYER_LANG_DL_FAILED_MSG) $dl_tmp$\n$\n$(MPLAYER_LANG_DL_RETRY)"
93                         Abort "$(MPLAYER_LANG_DL_FAILED)"
94                 ${Else}
95                         ${SetStatus} "$(MPLAYER_LANG_DL_RESTARTING)"
96                         Sleep 333
97                 ${EndIf}
98         ${Loop}
100         DetailPrint "$(MPLAYER_LANG_DL_SUCCESSFULL)"
101         ${SetStatus} "$(MPLAYER_LANG_DL_COMPELETED)"
102 !macroend