Skip to content

Commit

Permalink
Update DownloadHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Apr 4, 2022
1 parent 9ca0a26 commit dd31c62
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
var filePath = Path.Combine(downloadFile.DownloadPath, downloadFile.FileName);
var timeout = TimeSpan.FromMilliseconds(downloadSettings.Timeout * 2);

var isLatestFileCheckSucceeded = true;
List<DownloadRange> readRanges = null;

for (var r = 0; r <= downloadSettings.RetryCount; r++)
Expand Down Expand Up @@ -425,13 +426,14 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D

if (!doneRanges.IsEmpty)
{
var ex = new AggregateException(new Exception("没有完全下载所有的分片"));
// var ex = new AggregateException(new Exception("没有完全下载所有的分片"));

downloadFile.RetryCount++;
downloadFile.OnCompleted(false, ex, aSpeed);

if (File.Exists(filePath))
File.Delete(filePath);
// downloadFile.OnCompleted(false, ex, aSpeed);

// if (File.Exists(filePath))
// File.Delete(filePath);

continue;
}
Expand Down Expand Up @@ -469,18 +471,20 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
if (!checkResult)
{
downloadFile.RetryCount++;
isLatestFileCheckSucceeded = false;
continue;
}

isLatestFileCheckSucceeded = true;
}
}

downloadFile.OnCompleted(true, null, aSpeed);

streamBlock.Complete();
writeActionBlock.Complete();

#endregion

downloadFile.OnCompleted(true, null, aSpeed);
return;
}
catch (Exception ex)
Expand All @@ -503,9 +507,18 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
}

if (exceptions.Any())
{
downloadFile.OnCompleted(false, new AggregateException(exceptions), 0);
else
downloadFile.OnCompleted(true, null, 0);
return;
}

if (!isLatestFileCheckSucceeded)
{
downloadFile.OnCompleted(false, null, 0);
return;
}

downloadFile.OnCompleted(true, null, 0);
}

#endregion
Expand Down

0 comments on commit dd31c62

Please sign in to comment.