#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

#include '_DownloadWithProgress.au3'

Opt('GUIOnEventMode', 1)
Global $sDownloadDir = @ScriptDir
Global $aDownloadsURL = StringSplit( _
		'https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe' & ',' & _
		'https://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.zip' & ',' & _
		'https://www.dotpdn.com/files/paint.net.4.2.16.install.zip' & ',' & _
		'https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.1.4/npp.8.1.4.Installer.x64.exe' & ',' & _
		'https://mh-nexus.de/downloads/HxDSetup.zip' & ',' & _
		'https://freecommander.com/downloads/FreeCommanderXE-32-public_setup.zip' & ',' & _
		'https://SunSITE.Informatik.RWTH-Aachen.DE/ftp/pub/packages/SELFHTML/selfhtml812.zip' & ',' & _
		'https://download.documentfoundation.org/libreoffice/stable/7.2.1/win/x86_64/LibreOffice_7.2.1_Win_x64.msi' & ',' & _
		'https://www.jpg-illuminator.de/downloads/JPG-Illuminator-x64_v53.zip' & ',' & _
		'https://ftp.halifax.rwth-aachen.de/videolan/vlc/3.0.16/win64/vlc-3.0.16-win64.exe', ',', 2)

Global $aidDownloads[UBound($aDownloadsURL)], $sDownloadName = '', $iLanguage = 1031

Global $hGui = GUICreate('Download with progress', 640, 580)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

GUICtrlCreateLabel('Downloads:', 220, 20, 200, 42, $SS_CENTER)
GUICtrlSetFont(-1, 24, 800, 6, 'Arial', 5)

Global $idLanguage = GUICtrlCreateCombo('deutsch', 530, 28, 90, 30, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, 'englisch')
GUICtrlSetFont(-1, 10, 800, 0, 'Arial', 5)
GUICtrlSetOnEvent(-1, '_ChangeLanguage')

For $i = 0 To UBound($aDownloadsURL) - 1
	$sDownloadName = StringRegExpReplace($aDownloadsURL[$i], '.+\/(.+)', '$1')
	$aidDownloads[$i] = GUICtrlCreateButton($sDownloadName, 120, 80 + $i * 50, 400, 32)
	GUICtrlSetFont(-1, 12, 400, 0, 'Arial', 5)
	GUICtrlSetOnEvent(-1, '_StartDownload')
Next

GUISetState(@SW_SHOW, $hGui)
While Sleep(1000)
WEnd

Func _Exit()
	Exit
EndFunc   ;==>_Exit

Func _StartDownload()
	Local $iDownloadNum = @GUI_CtrlId - $aidDownloads[0]
	_DownloadWithProgress($aDownloadsURL[$iDownloadNum], $sDownloadDir, $iLanguage, 'AutoIt-Download-Tool', -1, -1, $hGui)
	ConsoleWrite('ERROR = ' & @error & @CR)
EndFunc   ;==>_StartDownload

Func _ChangeLanguage()
	Switch GUICtrlRead($idLanguage)
		Case 'deutsch'
			$iLanguage = 1031
		Case 'englisch'
			$iLanguage = 1033
	EndSwitch
EndFunc   ;==>_ChangeLanguage
