diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index fdf7080..be07460 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -57,20 +57,23 @@ namespace FileConverter Diagnostics.Log("Retrieve arguments..."); string[] args = Environment.GetCommandLineArgs(); +#if (DEBUG) if (args.Length <= 1) { this.debugMode = true; System.Array.Resize(ref args, 9); args[1] = "--output-type"; - args[2] = "mp3"; + args[2] = "Flac"; args[3] = @"D:\Projects\FileConverter\TestFiles\Herbie Hancock - Speak Like A Child [RVG Edition].flac"; + args[3] = @"D:\Projects\FileConverter\TestFiles\01 - Le Bruit Du Bang.wma"; args[4] = @"D:\Projects\FileConverter\TestFiles\test\Toccata.wav"; args[5] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (4).wav"; - //// args[5] = "--verbose"; + args[5] = "--verbose"; args[6] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (3).wav"; args[7] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (2).wav"; args[8] = @"D:\Projects\FileConverter\TestFiles\test\Toccata - Copie (5).wav"; } +#endif for (int index = 0; index < args.Length; index++) { @@ -111,6 +114,10 @@ namespace FileConverter outputType = OutputType.Ogg; break; + case "wav": + outputType = OutputType.Wav; + break; + case "flac": outputType = OutputType.Flac; break; @@ -196,6 +203,24 @@ namespace FileConverter } Diagnostics.Log("End of job queue."); + +#if !DEBUG + bool allConversionsSucceed = true; + for (int index = 0; index < this.conversionJobs.Count; index++) + { + allConversionsSucceed &= this.conversionJobs[index].State == ConversionJob.ConversionState.Done; + } + + if (allConversionsSucceed) + { + System.Threading.Thread.Sleep(3000); + + Dispatcher.BeginInvoke((Action)delegate + { + Application.Current.Shutdown(); + }); + } +#endif } } } diff --git a/Application/FileConverter/ConversionJob.cs b/Application/FileConverter/ConversionJob.cs index a20ae0f..dab3b9e 100644 --- a/Application/FileConverter/ConversionJob.cs +++ b/Application/FileConverter/ConversionJob.cs @@ -11,8 +11,8 @@ namespace FileConverter public class ConversionJob : INotifyPropertyChanged { - private readonly Regex durationRegex = new Regex(@"Duration: ([0-9][0-9]):([0-9][0-9]):([0-9][0-9])\.([0-9][0-9]), bitrate: ([0-9]+) kb\/s"); - private readonly Regex progressRegex = new Regex(@"size=[ ]*([0-9]+)kB time=([0-9][0-9]):([0-9][0-9]):([0-9][0-9]).([0-9][0-9]) bitrate= ([0-9]+.[0-9])kbits\/s"); + private readonly Regex durationRegex = new Regex(@"Duration:\s*([0-9][0-9]):([0-9][0-9]):([0-9][0-9])\.([0-9][0-9]),.*bitrate:\s*([0-9]+) kb\/s"); + private readonly Regex progressRegex = new Regex(@"size=\s*([0-9]+)kB\s+time=([0-9][0-9]):([0-9][0-9]):([0-9][0-9]).([0-9][0-9])\s+bitrate=\s*([0-9]+.[0-9])kbits\/s"); private TimeSpan fileDuration; private TimeSpan actualConvertedDuration; @@ -151,16 +151,23 @@ namespace FileConverter switch (this.OutputType) { case OutputType.Mp3: - arguments = string.Format("-n -i \"{0}\" -stats -ar 44100 -ab 320k -map_metadata 0:s:0 -id3v2_version 3 -write_id3v1 1 \"{1}\"", this.InputFilePath, this.OutputFilePath); + arguments = string.Format("-n -stats -i \"{0}\" -qscale:a 5 \"{1}\"", this.InputFilePath, this.OutputFilePath); break; case OutputType.Ogg: - arguments = string.Format("-n -i \"{0}\" -map_metadata 0:s:0 \"{1}\"", this.InputFilePath, this.OutputFilePath); + arguments = string.Format("-n -stats -i \"{0}\" -acodec libvorbis -qscale:a 5 \"{1}\"", this.InputFilePath, this.OutputFilePath); break; case OutputType.Flac: - arguments = string.Format("-n -i \"{0}\" -map_metadata 0:s:0 \"{1}\"", this.InputFilePath, this.OutputFilePath); + arguments = string.Format("-n -stats -i \"{0}\" \"{1}\"", this.InputFilePath, this.OutputFilePath); break; + + case OutputType.Wav: + arguments = string.Format("-n -stats -i \"{0}\" \"{1}\"", this.InputFilePath, this.OutputFilePath); + break; + + default: + throw new NotImplementedException("Converter not implemented for output file type " + this.OutputType); } if (string.IsNullOrEmpty(arguments) || this.ffmpegProcessStartInfo == null) @@ -198,12 +205,13 @@ namespace FileConverter throw; } - if (this.progress < 1f) + if (!string.IsNullOrEmpty(this.ExitingMessage)) { this.State = ConversionState.Failed; return; } + this.Progress = 1f; this.State = ConversionState.Done; Diagnostics.Log("\nDone!"); diff --git a/Application/FileConverter/OutputType.cs b/Application/FileConverter/OutputType.cs index f0eb0c9..40cd48b 100644 --- a/Application/FileConverter/OutputType.cs +++ b/Application/FileConverter/OutputType.cs @@ -8,5 +8,6 @@ namespace FileConverter Mp3, Ogg, Flac, + Wav, } } \ No newline at end of file diff --git a/Application/FileConverterExtension/FileConverterExtension.cs b/Application/FileConverterExtension/FileConverterExtension.cs index c4c774c..8ffd38f 100644 --- a/Application/FileConverterExtension/FileConverterExtension.cs +++ b/Application/FileConverterExtension/FileConverterExtension.cs @@ -43,6 +43,9 @@ namespace FileConverterExtension case "flac": return true; + + case "wma": + return true; } } @@ -60,9 +63,9 @@ namespace FileConverterExtension { ToolStripMenuItem subItem = new ToolStripMenuItem - { - Text = "To Ogg", - }; + { + Text = "To Ogg", + }; fileConverterItem.DropDownItems.Add(subItem); subItem.Click += (sender, args) => this.ConvertFiles(FileType.Ogg); @@ -88,6 +91,16 @@ namespace FileConverterExtension subItem.Click += (sender, args) => this.ConvertFiles(FileType.Flac); } + { + ToolStripMenuItem subItem = new ToolStripMenuItem + { + Text = "To Wav", + }; + + fileConverterItem.DropDownItems.Add(subItem); + subItem.Click += (sender, args) => this.ConvertFiles(FileType.Wav); + } + menu.Items.Add(fileConverterItem); RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter"); @@ -102,7 +115,6 @@ namespace FileConverterExtension private void ConvertFiles(FileType ouputType) { - this.fileConverterPath = @"D:\Projects\FileConverter\FileConverter\Application\FileConverter\bin\Debug\FileConverter.exe"; if (string.IsNullOrEmpty(this.fileConverterPath)) { MessageBox.Show(string.Format("Can't retrieve the file converter executable path. You should try to reinstall the application.")); diff --git a/Application/FileConverterExtension/FileType.cs b/Application/FileConverterExtension/FileType.cs index fee445d..eb8b033 100644 --- a/Application/FileConverterExtension/FileType.cs +++ b/Application/FileConverterExtension/FileType.cs @@ -9,5 +9,6 @@ namespace FileConverterExtension Mp3, Ogg, Flac, + Wav, } } \ No newline at end of file