Merge pull request #282 from Mbucari/master
Fixed rare bug that would hang if an error occured while downloading
This commit is contained in:
commit
ab82a1656d
@ -5,7 +5,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AAXClean.Codecs" Version="0.2.9" />
|
<PackageReference Include="AAXClean.Codecs" Version="0.2.10" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -145,8 +145,15 @@ namespace AaxDecrypter
|
|||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
RequestHeaders = HttpRequest.Headers;
|
RequestHeaders = HttpRequest.Headers;
|
||||||
|
try
|
||||||
|
{
|
||||||
Updated?.Invoke(this, EventArgs.Empty);
|
Updated?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Error(ex, "An error was encountered while saving the download progress to JSON");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set a different <see cref="System.Uri"/> to the same file targeted by this instance of <see cref="NetworkFileStream"/>
|
/// Set a different <see cref="System.Uri"/> to the same file targeted by this instance of <see cref="NetworkFileStream"/>
|
||||||
@ -245,9 +252,6 @@ namespace AaxDecrypter
|
|||||||
WritePosition = downloadPosition;
|
WritePosition = downloadPosition;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
downloadedPiece.Set();
|
|
||||||
downloadEnded.Set();
|
|
||||||
|
|
||||||
if (!IsCancelled && WritePosition < ContentLength)
|
if (!IsCancelled && WritePosition < ContentLength)
|
||||||
throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10}).");
|
throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10}).");
|
||||||
|
|
||||||
@ -257,7 +261,11 @@ namespace AaxDecrypter
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Serilog.Log.Error(ex, "An error was encountered while downloading {Uri}", Uri);
|
Serilog.Log.Error(ex, "An error was encountered while downloading {Uri}", Uri);
|
||||||
IsCancelled = true;
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
downloadedPiece.Set();
|
||||||
|
downloadEnded.Set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,14 +434,20 @@ namespace AaxDecrypter
|
|||||||
/// <param name="requiredPosition">The minimum required flished data length in <see cref="SaveFilePath"/>.</param>
|
/// <param name="requiredPosition">The minimum required flished data length in <see cref="SaveFilePath"/>.</param>
|
||||||
private void WaitToPosition(long requiredPosition)
|
private void WaitToPosition(long requiredPosition)
|
||||||
{
|
{
|
||||||
while (requiredPosition > WritePosition && !IsCancelled && hasBegunDownloading && !downloadedPiece.WaitOne(1000)) ;
|
while (WritePosition < requiredPosition
|
||||||
|
&& hasBegunDownloading
|
||||||
|
&& !IsCancelled
|
||||||
|
&& !downloadEnded.WaitOne(0))
|
||||||
|
{
|
||||||
|
downloadedPiece.WaitOne(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Close()
|
public override void Close()
|
||||||
{
|
{
|
||||||
IsCancelled = true;
|
IsCancelled = true;
|
||||||
|
|
||||||
while (downloadEnded is not null && !downloadEnded.WaitOne(1000)) ;
|
while (downloadEnded is not null && !downloadEnded.WaitOne(100)) ;
|
||||||
|
|
||||||
_readFile.Close();
|
_readFile.Close();
|
||||||
_writeFile.Close();
|
_writeFile.Close();
|
||||||
|
|||||||
@ -18,7 +18,8 @@ namespace FileManager
|
|||||||
/// <summary>Generate a valid path for this file or directory</summary>
|
/// <summary>Generate a valid path for this file or directory</summary>
|
||||||
public LongPath GetFilePath(bool returnFirstExisting = false)
|
public LongPath GetFilePath(bool returnFirstExisting = false)
|
||||||
{
|
{
|
||||||
string fileName = Template;
|
|
||||||
|
string fileName = Template.EndsWith(Path.DirectorySeparatorChar) ? Template[..^1] : Template;
|
||||||
List<string> pathParts = new();
|
List<string> pathParts = new();
|
||||||
|
|
||||||
var paramReplacements = ParameterReplacements.ToDictionary(r => $"<{formatKey(r.Key)}>", r => formatValue(r.Value));
|
var paramReplacements = ParameterReplacements.ToDictionary(r => $"<{formatKey(r.Key)}>", r => formatValue(r.Value));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user