From f7fee0139cbca59400cb93bc25ff4f879d05bab2 Mon Sep 17 00:00:00 2001 From: Grigory Chudov Date: Sun, 7 Apr 2013 22:05:21 -0400 Subject: [PATCH] More graceful handling of Ctrl-C by FLACCL --- CUETools.FLACCL.cmd/Program.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CUETools.FLACCL.cmd/Program.cs b/CUETools.FLACCL.cmd/Program.cs index f755216..ad7d76b 100644 --- a/CUETools.FLACCL.cmd/Program.cs +++ b/CUETools.FLACCL.cmd/Program.cs @@ -73,7 +73,7 @@ namespace CUETools.FLACCL.cmd TextWriter stdout = Console.Out; Console.SetOut(Console.Error); - var settings = new FLACCLWriterSettings(); + var settings = new FLACCLWriterSettings() { AllowNonSubset = true }; TimeSpan lastPrint = TimeSpan.FromMilliseconds(0); bool debug = false, quiet = false; string stereo_method = null; @@ -305,6 +305,16 @@ namespace CUETools.FLACCL.cmd Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.PCM.SampleRate, audioSource.PCM.ChannelCount, audioSource.PCM.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.PCM.SampleRate)); } + bool keepRunning = true; + Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) + { + keepRunning = false; + if (e.SpecialKey == ConsoleSpecialKey.ControlC) + e.Cancel = true; + else + audioDest.Delete(); + }; + DateTime start = DateTime.Now; try { @@ -327,7 +337,9 @@ namespace CUETools.FLACCL.cmd lastPrint = elapsed; } } - } + if (!keepRunning) + throw new Exception("Aborted"); + } audioDest.Close(); } catch (OpenCLNet.OpenCLBuildException ex)