Тема: AHK: Не скачивает файл Беру url (файла) из файла txt на сервере
Я беру ссылку из файла на сервере .
В переменной Variable в msgbox появляется нужна и правильная ссылка ,но появляется process bar скачивая и сразу закрывается скачивание не начинается.
#SingleInstance,Force
url=https://raw.githubusercontent.com/Agressorx1/efttorg/main/file.txt----------Пример ссылки
Gui,Add,Edit,w800 h500 -Wrap,% URLDownloadToVar(url)
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
variable:=% URLDownloadToVar(url)
url = % variable
msgbox, % url -----------Вывод ссылки на файл и она правильная ,но скачивание нету
SplitPath,url,name, dir, ext, name_no_ext, drive
DownloadAs := "C:\Windows\SysWOW64\downlevel\lodsh\edit\" . name
Overwrite := True
UseProgressBar := True
DownloadFile(Url, DownloadAs, Overwrite, UseProgressBar)
return
;=================== Start Functions =====================================================================
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
Progress, H80 Cb018AF3, , Downloading..., %UrlToFile%
SetTimer, __UpdateProgressBar, 100
}
;Download the file
UrlDownloadToFile, %UrlToFile%, %SaveFileAs%
;Remove the timer and the progressbar because the download has finished
If (UseProgressBar) {
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
Progress, %PercentDone%, %PercentDone%`% Готовность, Подготовка к запуску, Подготовка к запуску (%PercentDone%`%)
Return
}