This is the repository for Yandols' Bachelor's Degree Final Year Project Game (2019). Game created in Construct 2 and Launcher/Updater is created with AHK.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ResistanceSaga/Launcher/lib/ssdp-i.ahk

53 lines
2.6 KiB

DownloadFile(UrlToFile, SaveFileAs, Overwrite := True, UseProgressBar := True) {
;Check if the file already exists and if we must not overwrite it
If (!Overwrite && FileExist(SaveFileAs))
Return
;Check if the user wants a progressbar
If (UseProgressBar) {
;Initialize the WinHttpRequest Object
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
;Download the headers
WebRequest.Open("HEAD", UrlToFile)
WebRequest.Send()
;Store the header which holds the file size in a variable:
FinalSize := WebRequest.GetResponseHeader("Content-Length")
;Create the progressbar and the timer
global TheProgressText, TheProgressBar
Gui, Color, FFFFFF
Gui, Font, s11
Gui, Add, Text, x0 y20 w400 h34 Center vTheProgressText, Establishing server link...
Gui, Add, Progress, x20 y70 w360 h20 vTheProgressBar -Smooth +Theme, 0
Gui, -MaximizeBox +MinimizeBox -SysMenu -Resize
Gui, Show, w400 h110, Singularity Updater
;Progress, W400 H110 ZX20 ZY20 WM500 M T, , Establishing server link...`n, Singularity Updater ;%UrlToFile%
SetTimer, __UpdateProgressBar, 100
}
;Download the file
UrlDownloadToFile, %UrlToFile%, %SaveFileAs%
;Remove the timer and the progressbar because the download has finished
If (UseProgressBar) {
Gui, Destroy
;Progress, Off
SetTimer, __UpdateProgressBar, Off
}
Return
;The label that updates the progressbar
__UpdateProgressBar:
;Get the current filesize and tick
CurrentSize := FileOpen(SaveFileAs, "r").Length ;FileGetSize wouldn't return reliable results
CurrentSizeTick := A_TickCount
;Calculate the downloadspeed
Speed := Round((CurrentSize/1024-LastSize/1024)/((CurrentSizeTick-LastSizeTick)/1000)) . " Kb/s"
;Save the current filesize and tick for the next time
LastSizeTick := CurrentSizeTick
LastSize := FileOpen(SaveFileAs, "r").Length
;Calculate percent done
PercentDone := Round(CurrentSize/FinalSize*100)
;Update the ProgressBar
GuiControl,, TheProgressText, Downloading patch file at %Speed%`n(%SaveFileAs%)
GuiControl,, TheProgressBar, %PercentDone%
Gui, Show, NA, Singularity Updater (%PercentDone%`%)
;Progress, %PercentDone%, , Downloading patch file at %Speed%`n(%SaveFileAs%), Singularity Updater (%PercentDone%`%)
Return
}