Skip to content

Commit

Permalink
Update DownloadHandle.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Nov 27, 2019
1 parent 3f1688f commit b08a021
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions v2rayN/v2rayN/Handler/DownloadHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int
}

progressPercentage = -1;
totalBytesToReceive = 0;

WebClientEx ws = new WebClientEx();
DownloadTimeout = downloadTimeout;
Expand All @@ -106,8 +107,7 @@ public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int

ws.DownloadFileCompleted += ws_DownloadFileCompleted;
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName));
totalBytesToReceive = 0;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName));
}
catch (Exception ex)
{
Expand All @@ -122,14 +122,6 @@ void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs
{
if (UpdateCompleted != null)
{
if (DownloadTimeout != -1)
{
if ((DateTime.Now - totalDatetime).TotalSeconds > DownloadTimeout)
{
((WebClientEx)sender).CancelAsync();
}
}

if (totalBytesToReceive == 0)
{
totalDatetime = DateTime.Now;
Expand All @@ -138,6 +130,13 @@ void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs
}
totalBytesToReceive = e.BytesReceived;

if (DownloadTimeout != -1)
{
if ((DateTime.Now - totalDatetime).TotalSeconds > DownloadTimeout)
{
((WebClientEx)sender).CancelAsync();
}
}
if (progressPercentage != e.ProgressPercentage && e.ProgressPercentage % 10 == 0)
{
progressPercentage = e.ProgressPercentage;
Expand Down

0 comments on commit b08a021

Please sign in to comment.