Handle possible corrupt partial download.

This commit is contained in:
Michael Bucari-Tovo 2021-07-12 23:27:58 -06:00
parent 2a2faf6f7b
commit 732695c019

View File

@ -135,19 +135,24 @@ namespace AaxDecrypter
//Get metadata from the file over http //Get metadata from the file over http
if (File.Exists(jsonDownloadState)) if (File.Exists(jsonDownloadState))
{
try
{ {
nfsPersister = new NetworkFileStreamPersister(jsonDownloadState); nfsPersister = new NetworkFileStreamPersister(jsonDownloadState);
//If More thaan ~1 hour has elapsed since getting the download url, it will expire. //If More thaan ~1 hour has elapsed since getting the download url, it will expire.
//The new url will be to the same file. //The new url will be to the same file.
nfsPersister.NetworkFileStream.SetUriForSameFile(new Uri(downloadLicense.DownloadUrl)); nfsPersister.NetworkFileStream.SetUriForSameFile(new Uri(downloadLicense.DownloadUrl));
} }
catch
{
FileExt.SafeDelete(jsonDownloadState);
FileExt.SafeDelete(tempFile);
nfsPersister = NewNetworkFilePersister();
}
}
else else
{ {
var headers = new System.Net.WebHeaderCollection(); nfsPersister = NewNetworkFilePersister();
headers.Add("User-Agent", downloadLicense.UserAgent);
NetworkFileStream networkFileStream = new NetworkFileStream(tempFile, new Uri(downloadLicense.DownloadUrl), 0, headers);
nfsPersister = new NetworkFileStreamPersister(networkFileStream, jsonDownloadState);
} }
nfsPersister.NetworkFileStream.BeginDownloading(); nfsPersister.NetworkFileStream.BeginDownloading();
@ -159,6 +164,14 @@ namespace AaxDecrypter
return !isCanceled; return !isCanceled;
} }
private NetworkFileStreamPersister NewNetworkFilePersister()
{
var headers = new System.Net.WebHeaderCollection();
headers.Add("User-Agent", downloadLicense.UserAgent);
NetworkFileStream networkFileStream = new NetworkFileStream(tempFile, new Uri(downloadLicense.DownloadUrl), 0, headers);
return new NetworkFileStreamPersister(networkFileStream, jsonDownloadState);
}
public bool Step3_DownloadAndCombine() public bool Step3_DownloadAndCombine()
{ {