This commit is contained in:
Michael Bucari-Tovo 2023-01-24 23:13:50 -07:00
parent 0b20aa751f
commit 2ed1076fab
5 changed files with 68 additions and 72 deletions

View File

@ -116,21 +116,19 @@ That naming may not be desirable for everyone, but it's an easy change to instea
moveMoovToBeginning(workingFileStream?.Name).GetAwaiter().GetResult(); moveMoovToBeginning(workingFileStream?.Name).GetAwaiter().GetResult();
newSplitCallback.OutputFile = createOutputFileStream(props); newSplitCallback.OutputFile = workingFileStream = createOutputFileStream(props);
newSplitCallback.TrackTitle = DownloadOptions.GetMultipartTitle(props); newSplitCallback.TrackTitle = DownloadOptions.GetMultipartTitle(props);
newSplitCallback.TrackNumber = currentChapter; newSplitCallback.TrackNumber = currentChapter;
newSplitCallback.TrackCount = splitChapters.Count; newSplitCallback.TrackCount = splitChapters.Count;
OnFileCreated(workingFileStream.Name);
}
FileStream createOutputFileStream(MultiConvertFileProperties multiConvertFileProperties) FileStream createOutputFileStream(MultiConvertFileProperties multiConvertFileProperties)
{ {
var fileName = DownloadOptions.GetMultipartFileName(multiConvertFileProperties); var fileName = DownloadOptions.GetMultipartFileName(multiConvertFileProperties);
FileUtility.SaferDelete(fileName); FileUtility.SaferDelete(fileName);
return File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
workingFileStream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
OnFileCreated(fileName);
return workingFileStream;
}
} }
} }

View File

@ -21,7 +21,6 @@ namespace AaxDecrypter
public event EventHandler<string> FileCreated; public event EventHandler<string> FileCreated;
public bool IsCanceled { get; protected set; } public bool IsCanceled { get; protected set; }
protected AsyncStepSequence AsyncSteps { get; } = new(); protected AsyncStepSequence AsyncSteps { get; } = new();
protected string OutputFileName { get; } protected string OutputFileName { get; }
protected IDownloadOptions DownloadOptions { get; } protected IDownloadOptions DownloadOptions { get; }
@ -66,10 +65,10 @@ namespace AaxDecrypter
public async Task<bool> RunAsync() public async Task<bool> RunAsync()
{ {
AsyncSteps[$"Final Step: Cleanup"] = CleanupAsync; AsyncSteps[$"Cleanup"] = CleanupAsync;
(bool success, var elapsed) = await AsyncSteps.RunAsync(); (bool success, var elapsed) = await AsyncSteps.RunAsync();
var speedup = DownloadOptions.RuntimeLength.TotalSeconds / elapsed.TotalSeconds; var speedup = DownloadOptions.RuntimeLength / elapsed;
Serilog.Log.Information($"Speedup is {speedup:F0}x realtime."); Serilog.Log.Information($"Speedup is {speedup:F0}x realtime.");
return success; return success;
@ -119,7 +118,7 @@ namespace AaxDecrypter
protected async Task<bool> Step_CreateCueAsync() protected async Task<bool> Step_CreateCueAsync()
{ {
if (!DownloadOptions.CreateCueSheet) return true; if (!DownloadOptions.CreateCueSheet) return !IsCanceled;
// not a critical step. its failure should not prevent future steps from running // not a critical step. its failure should not prevent future steps from running
try try
@ -159,7 +158,7 @@ namespace AaxDecrypter
else else
FileUtility.SaferDelete(tempFilePath); FileUtility.SaferDelete(tempFilePath);
return true; return !IsCanceled;
} }
private NetworkFileStreamPersister OpenNetworkFileStream() private NetworkFileStreamPersister OpenNetworkFileStream()
@ -184,7 +183,6 @@ namespace AaxDecrypter
} }
finally finally
{ {
if (nfsp?.NetworkFileStream is not null)
nfsp.NetworkFileStream.SpeedLimit = DownloadOptions.DownloadSpeedBps; nfsp.NetworkFileStream.SpeedLimit = DownloadOptions.DownloadSpeedBps;
} }

View File

@ -38,28 +38,28 @@ namespace AaxDecrypter
if (double.IsNormal(estTimeRemaining)) if (double.IsNormal(estTimeRemaining))
OnDecryptTimeRemaining(TimeSpan.FromSeconds(estTimeRemaining)); OnDecryptTimeRemaining(TimeSpan.FromSeconds(estTimeRemaining));
var progressPercent = (double)InputFileStream.WritePosition / InputFileStream.Length; var progressPercent = 100d * InputFileStream.WritePosition / InputFileStream.Length;
OnDecryptProgressUpdate( OnDecryptProgressUpdate(
new DownloadProgress new DownloadProgress
{ {
ProgressPercentage = 100 * progressPercent, ProgressPercentage = progressPercent,
BytesReceived = (long)(InputFileStream.Length * progressPercent), BytesReceived = InputFileStream.WritePosition,
TotalBytesToReceive = InputFileStream.Length TotalBytesToReceive = InputFileStream.Length
}); });
await Task.Delay(200); await Task.Delay(200);
} }
FinalizeDownload(); if (IsCanceled)
return false;
if (!IsCanceled) else
{ {
FinalizeDownload();
FileUtility.SaferMove(InputFileStream.SaveFilePath, OutputFileName); FileUtility.SaferMove(InputFileStream.SaveFilePath, OutputFileName);
OnFileCreated(OutputFileName); OnFileCreated(OutputFileName);
return true;
} }
return !IsCanceled;
} }
} }
} }