Cleanup
This commit is contained in:
parent
0b20aa751f
commit
2ed1076fab
@ -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;
|
||||||
|
|
||||||
FileStream createOutputFileStream(MultiConvertFileProperties multiConvertFileProperties)
|
OnFileCreated(workingFileStream.Name);
|
||||||
{
|
}
|
||||||
var fileName = DownloadOptions.GetMultipartFileName(multiConvertFileProperties);
|
|
||||||
FileUtility.SaferDelete(fileName);
|
|
||||||
|
|
||||||
workingFileStream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
FileStream createOutputFileStream(MultiConvertFileProperties multiConvertFileProperties)
|
||||||
OnFileCreated(fileName);
|
{
|
||||||
|
var fileName = DownloadOptions.GetMultipartFileName(multiConvertFileProperties);
|
||||||
return workingFileStream;
|
FileUtility.SaferDelete(fileName);
|
||||||
}
|
return File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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,8 +183,7 @@ namespace AaxDecrypter
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (nfsp?.NetworkFileStream is not null)
|
nfsp.NetworkFileStream.SpeedLimit = DownloadOptions.DownloadSpeedBps;
|
||||||
nfsp.NetworkFileStream.SpeedLimit = DownloadOptions.DownloadSpeedBps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkFileStreamPersister newNetworkFilePersister()
|
NetworkFileStreamPersister newNetworkFilePersister()
|
||||||
|
|||||||
@ -5,56 +5,56 @@ using System.Text;
|
|||||||
|
|
||||||
namespace AaxDecrypter
|
namespace AaxDecrypter
|
||||||
{
|
{
|
||||||
public static class Cue
|
public static class Cue
|
||||||
{
|
{
|
||||||
public static string CreateContents(string filePath, ChapterInfo chapters)
|
public static string CreateContents(string filePath, ChapterInfo chapters)
|
||||||
{
|
{
|
||||||
var stringBuilder = new StringBuilder();
|
var stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
stringBuilder.AppendLine(GetFileLine(filePath, "MP3"));
|
stringBuilder.AppendLine(GetFileLine(filePath, "MP3"));
|
||||||
|
|
||||||
var startOffset = chapters.StartOffset;
|
var startOffset = chapters.StartOffset;
|
||||||
|
|
||||||
var trackCount = 1;
|
var trackCount = 1;
|
||||||
foreach (var c in chapters.Chapters)
|
foreach (var c in chapters.Chapters)
|
||||||
{
|
{
|
||||||
var startTime = c.StartOffset - startOffset;
|
var startTime = c.StartOffset - startOffset;
|
||||||
|
|
||||||
stringBuilder.AppendLine($"TRACK {trackCount++} AUDIO");
|
stringBuilder.AppendLine($"TRACK {trackCount++} AUDIO");
|
||||||
stringBuilder.AppendLine($" TITLE \"{c.Title}\"");
|
stringBuilder.AppendLine($" TITLE \"{c.Title}\"");
|
||||||
stringBuilder.AppendLine($" INDEX 01 {(int)startTime.TotalMinutes}:{startTime:ss}:{(int)(startTime.Milliseconds * 75d / 1000):D2}");
|
stringBuilder.AppendLine($" INDEX 01 {(int)startTime.TotalMinutes}:{startTime:ss}:{(int)(startTime.Milliseconds * 75d / 1000):D2}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringBuilder.ToString();
|
return stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateFileName(FileInfo cueFileInfo, string audioFilePath)
|
public static void UpdateFileName(FileInfo cueFileInfo, string audioFilePath)
|
||||||
=> UpdateFileName(cueFileInfo.FullName, audioFilePath);
|
=> UpdateFileName(cueFileInfo.FullName, audioFilePath);
|
||||||
|
|
||||||
public static void UpdateFileName(string cueFilePath, FileInfo audioFileInfo)
|
public static void UpdateFileName(string cueFilePath, FileInfo audioFileInfo)
|
||||||
=> UpdateFileName(cueFilePath, audioFileInfo.FullName);
|
=> UpdateFileName(cueFilePath, audioFileInfo.FullName);
|
||||||
|
|
||||||
public static void UpdateFileName(FileInfo cueFileInfo, FileInfo audioFileInfo)
|
public static void UpdateFileName(FileInfo cueFileInfo, FileInfo audioFileInfo)
|
||||||
=> UpdateFileName(cueFileInfo.FullName, audioFileInfo.FullName);
|
=> UpdateFileName(cueFileInfo.FullName, audioFileInfo.FullName);
|
||||||
|
|
||||||
public static void UpdateFileName(string cueFilePath, string audioFilePath)
|
public static void UpdateFileName(string cueFilePath, string audioFilePath)
|
||||||
{
|
{
|
||||||
var cueContents = File.ReadAllLines(cueFilePath);
|
var cueContents = File.ReadAllLines(cueFilePath);
|
||||||
|
|
||||||
for (var i = 0; i < cueContents.Length; i++)
|
for (var i = 0; i < cueContents.Length; i++)
|
||||||
{
|
{
|
||||||
var line = cueContents[i];
|
var line = cueContents[i];
|
||||||
if (!line.Trim().StartsWith("FILE") || !line.Contains(' '))
|
if (!line.Trim().StartsWith("FILE") || !line.Contains(' '))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var fileTypeBegins = line.LastIndexOf(" ") + 1;
|
var fileTypeBegins = line.LastIndexOf(" ") + 1;
|
||||||
cueContents[i] = GetFileLine(audioFilePath, line[fileTypeBegins..]);
|
cueContents[i] = GetFileLine(audioFilePath, line[fileTypeBegins..]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllLines(cueFilePath, cueContents);
|
File.WriteAllLines(cueFilePath, cueContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetFileLine(string filePath, string audioType) => $"FILE {Path.GetFileName(filePath).SurroundWithQuotes()} {audioType}";
|
private static string GetFileLine(string filePath, string audioType) => $"FILE {Path.GetFileName(filePath).SurroundWithQuotes()} {audioType}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace AaxDecrypter
|
namespace AaxDecrypter
|
||||||
{
|
{
|
||||||
public class MultiConvertFileProperties
|
public class MultiConvertFileProperties
|
||||||
{
|
{
|
||||||
public string OutputFileName { get; set; }
|
public string OutputFileName { get; set; }
|
||||||
public int PartsPosition { get; set; }
|
public int PartsPosition { get; set; }
|
||||||
public int PartsTotal { get; set; }
|
public int PartsTotal { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public DateTime FileDate { get; } = DateTime.Now;
|
public DateTime FileDate { get; } = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user