Improved cancellation routine.
This commit is contained in:
parent
0c26c34bdd
commit
1ee6f3b9f2
@ -52,6 +52,7 @@ namespace AaxDecrypter
|
|||||||
private StepSequence steps { get; }
|
private StepSequence steps { get; }
|
||||||
private DownloadLicense downloadLicense { get; set; }
|
private DownloadLicense downloadLicense { get; set; }
|
||||||
private FFMpegAaxcProcesser aaxcProcesser;
|
private FFMpegAaxcProcesser aaxcProcesser;
|
||||||
|
private bool isCanceled { get; set; }
|
||||||
|
|
||||||
public static AaxcDownloadConverter Create(string outDirectory, DownloadLicense dlLic, ChapterInfo chapters = null)
|
public static AaxcDownloadConverter Create(string outDirectory, DownloadLicense dlLic, ChapterInfo chapters = null)
|
||||||
{
|
{
|
||||||
@ -81,6 +82,9 @@ namespace AaxDecrypter
|
|||||||
["Step 6: Create Nfo"] = Step6_CreateNfo,
|
["Step 6: Create Nfo"] = Step6_CreateNfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
aaxcProcesser = new FFMpegAaxcProcesser(dlLic);
|
||||||
|
aaxcProcesser.ProgressUpdate += AaxcProcesser_ProgressUpdate;
|
||||||
|
|
||||||
downloadLicense = dlLic;
|
downloadLicense = dlLic;
|
||||||
this.chapters = chapters;
|
this.chapters = chapters;
|
||||||
}
|
}
|
||||||
@ -123,7 +127,7 @@ namespace AaxDecrypter
|
|||||||
ProcessRunner.WorkingDir = outDir;
|
ProcessRunner.WorkingDir = outDir;
|
||||||
Directory.CreateDirectory(outDir);
|
Directory.CreateDirectory(outDir);
|
||||||
|
|
||||||
return true;
|
return !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Step2_GetMetadata()
|
public bool Step2_GetMetadata()
|
||||||
@ -143,14 +147,11 @@ namespace AaxDecrypter
|
|||||||
RetrievedTags?.Invoke(this, aaxcTagLib);
|
RetrievedTags?.Invoke(this, aaxcTagLib);
|
||||||
RetrievedCoverArt?.Invoke(this, coverArt);
|
RetrievedCoverArt?.Invoke(this, coverArt);
|
||||||
|
|
||||||
return true;
|
return !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Step3_DownloadAndCombine()
|
public bool Step3_DownloadAndCombine()
|
||||||
{
|
{
|
||||||
aaxcProcesser = new FFMpegAaxcProcesser(downloadLicense);
|
|
||||||
aaxcProcesser.ProgressUpdate += AaxcProcesser_ProgressUpdate;
|
|
||||||
|
|
||||||
bool userSuppliedChapters = chapters != null;
|
bool userSuppliedChapters = chapters != null;
|
||||||
|
|
||||||
string metadataPath = null;
|
string metadataPath = null;
|
||||||
@ -177,7 +178,7 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
DecryptProgressUpdate?.Invoke(this, 0);
|
DecryptProgressUpdate?.Invoke(this, 0);
|
||||||
|
|
||||||
return aaxcProcesser.Succeeded;
|
return aaxcProcesser.Succeeded && !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AaxcProcesser_ProgressUpdate(object sender, AaxcProcessUpdate e)
|
private void AaxcProcesser_ProgressUpdate(object sender, AaxcProcessUpdate e)
|
||||||
@ -208,24 +209,25 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
outFile.Save();
|
outFile.Save();
|
||||||
|
|
||||||
return true;
|
return !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Step5_CreateCue()
|
public bool Step5_CreateCue()
|
||||||
{
|
{
|
||||||
File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".cue"), Cue.CreateContents(Path.GetFileName(outputFileName), chapters));
|
File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".cue"), Cue.CreateContents(Path.GetFileName(outputFileName), chapters));
|
||||||
return true;
|
return !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Step6_CreateNfo()
|
public bool Step6_CreateNfo()
|
||||||
{
|
{
|
||||||
File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".nfo"), NFO.CreateContents(AppName, aaxcTagLib, chapters));
|
File.WriteAllText(PathLib.ReplaceExtension(outputFileName, ".nfo"), NFO.CreateContents(AppName, aaxcTagLib, chapters));
|
||||||
return true;
|
return !isCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel()
|
public void Cancel()
|
||||||
{
|
{
|
||||||
aaxcProcesser?.Cancel();
|
isCanceled = true;
|
||||||
|
aaxcProcesser.Cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ namespace AaxDecrypter
|
|||||||
private static Regex processedTimeRegex = new Regex("time=(\\d{2}):(\\d{2}):(\\d{2}).\\d{2}.*speed=\\s{0,1}([0-9]*[.]?[0-9]+)(?:e\\+([0-9]+)){0,1}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static Regex processedTimeRegex = new Regex("time=(\\d{2}):(\\d{2}):(\\d{2}).\\d{2}.*speed=\\s{0,1}([0-9]*[.]?[0-9]+)(?:e\\+([0-9]+)){0,1}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
private Process downloader;
|
private Process downloader;
|
||||||
private Process remuxer;
|
private Process remuxer;
|
||||||
|
private bool isCanceled = false;
|
||||||
|
|
||||||
public FFMpegAaxcProcesser( DownloadLicense downloadLicense)
|
public FFMpegAaxcProcesser( DownloadLicense downloadLicense)
|
||||||
{
|
{
|
||||||
@ -72,6 +73,9 @@ namespace AaxDecrypter
|
|||||||
remuxer.Start();
|
remuxer.Start();
|
||||||
remuxer.BeginErrorReadLine();
|
remuxer.BeginErrorReadLine();
|
||||||
|
|
||||||
|
//Thic check needs to be placed after remuxer has started
|
||||||
|
if (isCanceled) return;
|
||||||
|
|
||||||
var pipedOutput = downloader.StandardOutput.BaseStream;
|
var pipedOutput = downloader.StandardOutput.BaseStream;
|
||||||
var pipedInput = remuxer.StandardInput.BaseStream;
|
var pipedInput = remuxer.StandardInput.BaseStream;
|
||||||
|
|
||||||
@ -106,8 +110,12 @@ namespace AaxDecrypter
|
|||||||
}
|
}
|
||||||
public void Cancel()
|
public void Cancel()
|
||||||
{
|
{
|
||||||
|
isCanceled = true;
|
||||||
|
|
||||||
if (IsRunning && !remuxer.HasExited)
|
if (IsRunning && !remuxer.HasExited)
|
||||||
remuxer.Kill();
|
remuxer.Kill();
|
||||||
|
if (IsRunning && !downloader.HasExited)
|
||||||
|
downloader.Kill();
|
||||||
}
|
}
|
||||||
private void Downloader_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
private void Downloader_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user