|
|
@ -68,6 +68,8 @@ public class TrackedDownload |
|
|
|
[JsonIgnore] |
|
|
|
[JsonIgnore] |
|
|
|
public Exception? Exception { get; private set; } |
|
|
|
public Exception? Exception { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int attempts; |
|
|
|
|
|
|
|
|
|
|
|
#region Events |
|
|
|
#region Events |
|
|
|
private WeakEventManager<ProgressReport>? progressUpdateEventManager; |
|
|
|
private WeakEventManager<ProgressReport>? progressUpdateEventManager; |
|
|
|
|
|
|
|
|
|
|
@ -120,22 +122,14 @@ public class TrackedDownload |
|
|
|
private async Task StartDownloadTask(long resumeFromByte, CancellationToken cancellationToken) |
|
|
|
private async Task StartDownloadTask(long resumeFromByte, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var progress = new Progress<ProgressReport>(OnProgressUpdate); |
|
|
|
var progress = new Progress<ProgressReport>(OnProgressUpdate); |
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
await downloadService!.ResumeDownloadToFileAsync( |
|
|
|
await downloadService! |
|
|
|
SourceUrl.ToString(), |
|
|
|
.ResumeDownloadToFileAsync( |
|
|
|
DownloadDirectory.JoinFile(TempFileName), |
|
|
|
SourceUrl.ToString(), |
|
|
|
resumeFromByte, |
|
|
|
DownloadDirectory.JoinFile(TempFileName), |
|
|
|
progress, |
|
|
|
resumeFromByte, |
|
|
|
cancellationToken: cancellationToken |
|
|
|
progress, |
|
|
|
); |
|
|
|
cancellationToken: cancellationToken |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Logger.Warn(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If hash validation is enabled, validate the hash |
|
|
|
// If hash validation is enabled, validate the hash |
|
|
|
if (ValidateHash) |
|
|
|
if (ValidateHash) |
|
|
@ -313,6 +307,23 @@ public class TrackedDownload |
|
|
|
// Set the exception |
|
|
|
// Set the exception |
|
|
|
Exception = task.Exception; |
|
|
|
Exception = task.Exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
(Exception is IOException || Exception?.InnerException is IOException) |
|
|
|
|
|
|
|
&& attempts < 3 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
attempts++; |
|
|
|
|
|
|
|
Logger.Warn( |
|
|
|
|
|
|
|
"Download {Download} failed with {Exception}, retrying ({Attempt})", |
|
|
|
|
|
|
|
FileName, |
|
|
|
|
|
|
|
Exception, |
|
|
|
|
|
|
|
attempts |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
ProgressState = ProgressState.Inactive; |
|
|
|
|
|
|
|
Resume(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ProgressState = ProgressState.Failed; |
|
|
|
ProgressState = ProgressState.Failed; |
|
|
|
} |
|
|
|
} |
|
|
|
// Otherwise success |
|
|
|
// Otherwise success |
|
|
|