From 0b129fcf7cf535d8828713c75bbfc8cdfc1d2bea Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 20 Aug 2021 21:05:29 -0600 Subject: [PATCH] Fixed NetworkFileStream not resuming from cancellation. --- AaxDecrypter/AaxcDownloadConverter.cs | 8 ++------ AaxDecrypter/NetworkFileStream.cs | 6 ++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index c295f2e0..ef24b03e 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -118,12 +118,6 @@ namespace AaxDecrypter RetrievedTags?.Invoke(this, aaxFile.AppleTags); RetrievedCoverArt?.Invoke(this, aaxFile.AppleTags.Cover); - if (isCanceled) - { - aaxFile.Dispose(); - nfsPersister.Dispose(); - } - return !isCanceled; } private NetworkFileStreamPersister NewNetworkFilePersister() @@ -230,6 +224,8 @@ namespace AaxDecrypter isCanceled = true; aaxFile?.Cancel(); aaxFile?.Dispose(); + nfsPersister?.NetworkFileStream?.Close(); + nfsPersister?.Dispose(); } } } diff --git a/AaxDecrypter/NetworkFileStream.cs b/AaxDecrypter/NetworkFileStream.cs index 5d7544b5..01b63781 100644 --- a/AaxDecrypter/NetworkFileStream.cs +++ b/AaxDecrypter/NetworkFileStream.cs @@ -241,9 +241,12 @@ namespace AaxDecrypter } while (downloadPosition < ContentLength && !isCancelled); _writeFile.Close(); + _networkStream.Close(); WritePosition = downloadPosition; Update(); - _networkStream.Close(); + + downloadedPiece.Set(); + downloadEnded.Set(); if (!isCancelled && WritePosition < ContentLength) throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10})."); @@ -251,7 +254,6 @@ namespace AaxDecrypter if (WritePosition > ContentLength) throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10})."); - downloadEnded.Set(); } #endregion