From b08a0212ff7ba6bf280ae081f633b25c41a6fe2a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 27 Nov 2019 13:15:02 +0800 Subject: [PATCH] Update DownloadHandle.cs --- v2rayN/v2rayN/Handler/DownloadHandle.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs index 9ef170d2949..68f5d9db323 100644 --- a/v2rayN/v2rayN/Handler/DownloadHandle.cs +++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs @@ -96,6 +96,7 @@ public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int } progressPercentage = -1; + totalBytesToReceive = 0; WebClientEx ws = new WebClientEx(); DownloadTimeout = downloadTimeout; @@ -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) { @@ -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; @@ -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;