Skip to content

Commit dd31c62

Browse files
committed
Update DownloadHelper.cs
1 parent 9ca0a26 commit dd31c62

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
236236
var filePath = Path.Combine(downloadFile.DownloadPath, downloadFile.FileName);
237237
var timeout = TimeSpan.FromMilliseconds(downloadSettings.Timeout * 2);
238238

239+
var isLatestFileCheckSucceeded = true;
239240
List<DownloadRange> readRanges = null;
240241

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

426427
if (!doneRanges.IsEmpty)
427428
{
428-
var ex = new AggregateException(new Exception("没有完全下载所有的分片"));
429+
// var ex = new AggregateException(new Exception("没有完全下载所有的分片"));
429430

430431
downloadFile.RetryCount++;
431-
downloadFile.OnCompleted(false, ex, aSpeed);
432432

433-
if (File.Exists(filePath))
434-
File.Delete(filePath);
433+
// downloadFile.OnCompleted(false, ex, aSpeed);
434+
435+
// if (File.Exists(filePath))
436+
// File.Delete(filePath);
435437

436438
continue;
437439
}
@@ -469,18 +471,20 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
469471
if (!checkResult)
470472
{
471473
downloadFile.RetryCount++;
474+
isLatestFileCheckSucceeded = false;
472475
continue;
473476
}
477+
478+
isLatestFileCheckSucceeded = true;
474479
}
475480
}
476481

477-
downloadFile.OnCompleted(true, null, aSpeed);
478-
479482
streamBlock.Complete();
480483
writeActionBlock.Complete();
481-
484+
482485
#endregion
483486

487+
downloadFile.OnCompleted(true, null, aSpeed);
484488
return;
485489
}
486490
catch (Exception ex)
@@ -503,9 +507,18 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, D
503507
}
504508

505509
if (exceptions.Any())
510+
{
506511
downloadFile.OnCompleted(false, new AggregateException(exceptions), 0);
507-
else
508-
downloadFile.OnCompleted(true, null, 0);
512+
return;
513+
}
514+
515+
if (!isLatestFileCheckSucceeded)
516+
{
517+
downloadFile.OnCompleted(false, null, 0);
518+
return;
519+
}
520+
521+
downloadFile.OnCompleted(true, null, 0);
509522
}
510523

511524
#endregion

0 commit comments

Comments
 (0)