#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=_Icon\Kodi.ico
#AutoIt3Wrapper_Outfile=_kompiliert\EPG Downloader.exe
#AutoIt3Wrapper_Res_Fileversion=0.2.0.1
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <InetConstants.au3>
#include <Array.au3>
Local Const $sProgName = _get_ProgName ()
Local Const $Source = IniRead ( @WorkingDir&"\"&$sProgName&".ini", "config", "SourceFileURL", -1 )
Local Const $FileName = _get_FileName ($Source)
Local Const $Destination = IniRead ( @WorkingDir&"\"&$sProgName&".ini", "config", "DestinationFolder", -1 )&$FileName
Local $avData
If $sProgName=-1 Or $Source=-1 Or $Destination=-1 Or $Source="" Or $Destination="" Then
MsgBox ( 16, "ERROR", "Something went wrong. It seems that some configurations are missing or wrong."&@CRLF&@CRLF&"Therefore please check the INI file and containing data within the INI file before running this tool again." )
Exit
EndIf
ProgressOn ( "EPG Downloader", "Preparing the Download...", "0%", Default, Default, 2+16)
$hDownload = InetGet ( $Source, $Destination, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND )
Do
Sleep (250)
$avData = InetGetInfo ( $hDownload )
$iPercent = Round ( $avData[$INET_DOWNLOADREAD] / $avData[$INET_DOWNLOADSIZE] * 100 )
If $avData[$INET_DOWNLOADSIZE] > 0 Then ProgressSet ( $iPercent, $iPercent&"%", "Downloading the EPG data..." )
Until InetGetInfo ( $hDownload, $INET_DOWNLOADCOMPLETE )
ProgressSet ( $iPercent, $iPercent&"%", "Verifying the downloaded EPG data..." )
If $avData[$INET_DOWNLOADREAD] < $avData[$INET_DOWNLOADSIZE] Then MsgBox ( 16, "ERROR", "Something went wrong. The file size of downloaded EPG data is below the file size of EPG data on the source."&@CRLF&@CRLF&"Please try again later to ensure that the EPG data on your destination works." )
If $avData[$INET_DOWNLOADERROR] <> 0 Then MsgBox ( 16, "ERROR", "Something went wrong. The file copy function of this tool statet an unknown error."&@CRLF&@CRLF&"Please try again later to ensure that the EPG data on your destination works." )
InetClose ( $hDownload )
ProgressOff ( )
Exit
Func _get_ProgName ()
Local $avStringSplit[0]
$avStringSplit = StringSplit ( @ScriptName, ".exe", 1)
If @Error = 1 Then $avStringSplit[1] = -1
Return $avStringSplit[1]
EndFunc
Func _get_FileName ($sString)
Local $avStringSplit
$avStringSplit = StringSplit ( $sString, "/" )
Return $avStringSplit[$avStringSplit[0]]
EndFunc