<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Прогресс загрузки файла]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11669&amp;type=atom" />
	<updated>2016-06-05T03:17:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11669</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прогресс загрузки файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=104712#p104712" />
			<content type="html"><![CDATA[<p><strong>ypppu</strong>, спасибо.</p><p>Может пригодится кому-то:<br /></p><div class="codebox"><pre><code>
Url            = https://www.autohotkey.com/download/ahk-install.exe
	DownloadAs     = ahk.exe
	Overwrite      := True 
	UseProgressBar := True
	DownloadFile(Url, DownloadAs, Overwrite, UseProgressBar)
	

;=================== Start Functions =====================================================================

DownloadFile(UrlToFile, SaveFileAs, Overwrite := True, UseProgressBar := True) {
    ;Check if the file already exists and if we must not overwrite it
      If (!Overwrite &amp;&amp; FileExist(SaveFileAs))
          Return
    ;Check if the user wants a progressbar
      If (UseProgressBar) {
          ;Initialize the WinHttpRequest Object
            WebRequest := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
          ;Download the headers
            WebRequest.Open(&quot;HEAD&quot;, UrlToFile)
            WebRequest.Send()
          ;Store the header which holds the file size in a variable:
            FinalSize := WebRequest.GetResponseHeader(&quot;Content-Length&quot;)
          ;Create the progressbar and the timer
            Progress, H80, , 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, &quot;r&quot;).Length ;FileGetSize wouldn&#039;t return reliable results
            CurrentSizeTick := A_TickCount
          ;Calculate the downloadspeed
            Speed := Round((CurrentSize/1024-LastSize/1024)/((CurrentSizeTick-LastSizeTick)/1000)) . &quot; Kb/s&quot;
          ;Save the current filesize and tick for the next time
            LastSizeTick := CurrentSizeTick
            LastSize := FileOpen(SaveFileAs, &quot;r&quot;).Length
          ;Calculate percent done
            PercentDone := Round(CurrentSize/FinalSize*100)
          ;Update the ProgressBar
            Progress, %PercentDone%, %PercentDone%`% Done, Downloading...  (%Speed%), Downloading %SaveFileAs% (%PercentDone%`%)
      Return
}
</code></pre></div><p>Я просто только Яндексом искал... <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[senyaonis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33915</uri>
			</author>
			<updated>2016-06-05T03:17:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=104712#p104712</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Прогресс загрузки файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=104675#p104675" />
			<content type="html"><![CDATA[<p><a href="http://cse.google.com/cse?cref=https%3A%2F%2Fcse.google.com%2Ftools%2Fmakecse%3Furl%3Dhttps%253A%252F%252Fwww.autohotkey.com%252F&amp;ie=UTF-8&amp;hl=&amp;cx=010629462602499112316%3Aywoq_rufgic&amp;q=UrlDownloadToFile+progress&amp;sa=Search&amp;siteurl=www.autohotkey.com%2F&amp;ref=&amp;ss=9333j12115149j19#gsc.tab=0&amp;gsc.q=UrlDownloadToFile%20progress&amp;gsc.page=1">http://cse.google.com/cse?cref=https%3A … gsc.page=1</a></p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-06-04T11:25:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=104675#p104675</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Прогресс загрузки файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=104660#p104660" />
			<content type="html"><![CDATA[<p>Возможно сделать прогресс бар для UrlDownloadToFile?</p>]]></content>
			<author>
				<name><![CDATA[senyaonis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33915</uri>
			</author>
			<updated>2016-06-03T19:18:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=104660#p104660</id>
		</entry>
</feed>
