From 5db9c09cffcf28d20a4a32031f6eb42abca0af1c Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Sat, 22 Aug 2015 15:50:19 +0200 Subject: [PATCH] Stylecop --- .../ConversionJobs/ConversionJob_FFMPEG.cs | 76 +++++----- .../ConversionPreset.cs | 0 .../ConversionPreset/ConversionSettings.cs | 10 ++ .../ConversionPreset/IConversionSettings.cs | 10 ++ .../FileConverter/ConversionSettings.cs | 12 -- Application/FileConverter/EncodingMode.cs | 2 +- .../FileConverter/FileConverter.csproj | 14 +- .../FileConverter.sln.DotSettings | 2 + .../ValueConverters/BitrateToString.cs | 2 +- .../ConversionSettingsToString.cs | 2 +- .../Generic/EqualsConverter.cs | 1 - .../Generic/ObjectToValueType.cs | 2 +- .../ValueConverters/OutputTypeToVisibility.cs | 7 +- Application/FileConverter/Version.cs | 6 +- .../Windows/DiagnosticsWindow.xaml.cs | 18 +-- .../FileConverter/Windows/MainWindow.xaml.cs | 2 - Application/FileConverter/XmlHelpers.cs | 137 ++++++++++-------- .../FileConverterExtension.cs | 3 + .../FileConverterExtension.csproj | 8 +- .../PresetDefinition.cs | 15 +- .../FileConverterExtension/Settings.StyleCop | 24 +++ Installer/Product.wxs | 14 +- 22 files changed, 207 insertions(+), 160 deletions(-) rename Application/FileConverter/{ => ConversionPreset}/ConversionPreset.cs (100%) create mode 100644 Application/FileConverter/ConversionPreset/ConversionSettings.cs create mode 100644 Application/FileConverter/ConversionPreset/IConversionSettings.cs delete mode 100644 Application/FileConverter/ConversionSettings.cs create mode 100644 Application/FileConverterExtension/Settings.StyleCop diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index d8e727d..40f3d21 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -1,7 +1,5 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using System.Windows.Markup.Localizer; - namespace FileConverter.ConversionJobs { using System; @@ -96,6 +94,43 @@ namespace FileConverter.ConversionJobs this.ffmpegProcessStartInfo.Arguments = arguments; } + protected override void Convert() + { + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + Diagnostics.Log("Convert file {0} to {1}.", this.InputFilePath, this.OutputFilePath); + Diagnostics.Log(string.Empty); + Diagnostics.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments); + + try + { + using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo)) + { + using (StreamReader reader = exeProcess.StandardError) + { + while (!reader.EndOfStream) + { + string result = reader.ReadLine(); + + this.ParseFFMPEGOutput(result); + + Diagnostics.Log("ffmpeg output: {0}", result); + } + } + + exeProcess.WaitForExit(); + } + } + catch + { + this.ConvertionFailed("Failed to launch FFMPEG process."); + throw; + } + } + private int VBRBitrateToQualityIndex(int bitrate) { switch (bitrate) @@ -134,43 +169,6 @@ namespace FileConverter.ConversionJobs throw new Exception("Unknown VBR bitrate."); } - protected override void Convert() - { - if (this.ConversionPreset == null) - { - throw new Exception("The conversion preset must be valid."); - } - - Diagnostics.Log("Convert file {0} to {1}.", this.InputFilePath, this.OutputFilePath); - Diagnostics.Log(string.Empty); - Diagnostics.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments); - - try - { - using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo)) - { - using (StreamReader reader = exeProcess.StandardError) - { - while (!reader.EndOfStream) - { - string result = reader.ReadLine(); - - this.ParseFFMPEGOutput(result); - - Diagnostics.Log("ffmpeg output: {0}", result); - } - } - - exeProcess.WaitForExit(); - } - } - catch - { - this.ConvertionFailed("Failed to launch FFMPEG process."); - throw; - } - } - private void ParseFFMPEGOutput(string input) { Match match = this.durationRegex.Match(input); diff --git a/Application/FileConverter/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs similarity index 100% rename from Application/FileConverter/ConversionPreset.cs rename to Application/FileConverter/ConversionPreset/ConversionPreset.cs diff --git a/Application/FileConverter/ConversionPreset/ConversionSettings.cs b/Application/FileConverter/ConversionPreset/ConversionSettings.cs new file mode 100644 index 0000000..41ce227 --- /dev/null +++ b/Application/FileConverter/ConversionPreset/ConversionSettings.cs @@ -0,0 +1,10 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + using System.Collections.Generic; + + public class ConversionSettings : Dictionary, IConversionSettings + { + } +} \ No newline at end of file diff --git a/Application/FileConverter/ConversionPreset/IConversionSettings.cs b/Application/FileConverter/ConversionPreset/IConversionSettings.cs new file mode 100644 index 0000000..f1b1a33 --- /dev/null +++ b/Application/FileConverter/ConversionPreset/IConversionSettings.cs @@ -0,0 +1,10 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + using System.Collections.Generic; + + public interface IConversionSettings : IReadOnlyDictionary + { + } +} \ No newline at end of file diff --git a/Application/FileConverter/ConversionSettings.cs b/Application/FileConverter/ConversionSettings.cs deleted file mode 100644 index a9dae02..0000000 --- a/Application/FileConverter/ConversionSettings.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; - -namespace FileConverter -{ - public interface IConversionSettings : IReadOnlyDictionary - { - } - - public class ConversionSettings : Dictionary, IConversionSettings - { - } -} \ No newline at end of file diff --git a/Application/FileConverter/EncodingMode.cs b/Application/FileConverter/EncodingMode.cs index 44b348d..0900832 100644 --- a/Application/FileConverter/EncodingMode.cs +++ b/Application/FileConverter/EncodingMode.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter { diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index a0e96f1..73bc59c 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -78,10 +78,11 @@ - + + - + @@ -130,9 +131,12 @@ - + + true + Code + true True @@ -166,11 +170,11 @@ - - \ No newline at end of file + diff --git a/Application/FileConverter/FileConverter.sln.DotSettings b/Application/FileConverter/FileConverter.sln.DotSettings index 570b5eb..6c4d4f7 100644 --- a/Application/FileConverter/FileConverter.sln.DotSettings +++ b/Application/FileConverter/FileConverter.sln.DotSettings @@ -14,6 +14,8 @@ UseExplicitType UseExplicitType // <copyright file="$FILENAME$" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright> + CBR + VBR <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> diff --git a/Application/FileConverter/ValueConverters/BitrateToString.cs b/Application/FileConverter/ValueConverters/BitrateToString.cs index 4d8bf0c..213b843 100644 --- a/Application/FileConverter/ValueConverters/BitrateToString.cs +++ b/Application/FileConverter/ValueConverters/BitrateToString.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.ValueConverters { diff --git a/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs b/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs index 8cf883f..4ed87db 100644 --- a/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs +++ b/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.ValueConverters { diff --git a/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs b/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs index 65f34c0..572be61 100644 --- a/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs +++ b/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs @@ -1,6 +1,5 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. - namespace FileConverter.ValueConverters.Generic { using System; diff --git a/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs b/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs index 1334b25..6647e28 100644 --- a/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs +++ b/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs @@ -6,7 +6,7 @@ namespace FileConverter.ValueConverters.Generic using System.Globalization; using System.Windows.Data; - public class ObjectToValueType: IValueConverter + public class ObjectToValueType : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs index 52e10ab..eded1f2 100644 --- a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs +++ b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs @@ -3,7 +3,6 @@ namespace FileConverter.ValueConverters { using System; - using System.Collections.Generic; using System.Globalization; using System.Windows.Data; @@ -21,13 +20,13 @@ namespace FileConverter.ValueConverters string referenceTypeName = parameter as string; if (string.IsNullOrEmpty(referenceTypeName)) { - return false; + return "Hidden"; } OutputType referenceType; - if (System.Enum.TryParse(referenceTypeName,out referenceType)) + if (!Enum.TryParse(referenceTypeName, out referenceType)) { - + return "Hidden"; } return outputType == referenceType ? "Visible" : "Hidden"; diff --git a/Application/FileConverter/Version.cs b/Application/FileConverter/Version.cs index 95f2a0c..585c3c5 100644 --- a/Application/FileConverter/Version.cs +++ b/Application/FileConverter/Version.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter { diff --git a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs index d307a44..5e89bf6 100644 --- a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs +++ b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs @@ -1,19 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.Windows { + using System.Windows; + /// /// Interaction logic for DiagnosticsWindow.xaml /// @@ -21,7 +11,7 @@ namespace FileConverter.Windows { public DiagnosticsWindow() { - InitializeComponent(); + this.InitializeComponent(); } } } diff --git a/Application/FileConverter/Windows/MainWindow.xaml.cs b/Application/FileConverter/Windows/MainWindow.xaml.cs index 4e356a0..612a01c 100644 --- a/Application/FileConverter/Windows/MainWindow.xaml.cs +++ b/Application/FileConverter/Windows/MainWindow.xaml.cs @@ -11,8 +11,6 @@ namespace FileConverter public partial class MainWindow : Window, INotifyPropertyChanged { - private bool verboseMode; - private DiagnosticsWindow diagnosticsWindow; private SettingsWindow settingsWindow; diff --git a/Application/FileConverter/XmlHelpers.cs b/Application/FileConverter/XmlHelpers.cs index 1f05e8a..fd40edd 100644 --- a/Application/FileConverter/XmlHelpers.cs +++ b/Application/FileConverter/XmlHelpers.cs @@ -1,75 +1,90 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Windows.Documents; -using System.Xml; -using System.Xml.Serialization; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using FileConverter; - -public class XmlHelpers +namespace FileConverter { - public static void LoadFromFile(string root, string path, ref ICollection collection) + using System; + using System.Collections.Generic; + using System.IO; + using System.Xml; + using System.Xml.Serialization; + + public class XmlHelpers { - if (string.IsNullOrEmpty(path)) + public static void LoadFromFile(string root, string path, ref ICollection collection) { - throw new ArgumentNullException("path"); - } - - XmlRootAttribute xmlRoot = new XmlRootAttribute - { - ElementName = root - }; - - XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); - - try - { - using (StreamReader reader = new StreamReader(path)) - using (XmlReader xmlReader = XmlReader.Create(reader, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true })) + if (string.IsNullOrEmpty(path)) { - List elements = (List)serializer.Deserialize(xmlReader); - foreach (T element in elements) + throw new ArgumentNullException("path"); + } + + XmlRootAttribute xmlRoot = new XmlRootAttribute + { + ElementName = root + }; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); + + try + { + using (StreamReader reader = new StreamReader(path)) { - collection.Add(element); + XmlReaderSettings xmlReaderSettings = new XmlReaderSettings + { + IgnoreWhitespace = true, IgnoreComments = true + }; + + using (XmlReader xmlReader = XmlReader.Create(reader, xmlReaderSettings)) + { + List elements = (List)serializer.Deserialize(xmlReader); + for (int index = 0; index < elements.Count; index++) + { + collection.Add(elements[index]); + } + } } } - } - catch (System.Exception exception) - { - Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); - } - } - - public static void SaveToFile(string root, string path, ICollection objectsToSerialize) - { - if (string.IsNullOrEmpty(path)) - { - return; - } - - List list = new List(); - list.AddRange(objectsToSerialize); - - XmlRootAttribute xmlRoot = new XmlRootAttribute - { - ElementName = root - }; - - XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); - - try - { - using (StreamWriter writer = new StreamWriter(path)) - using (XmlWriter xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { Indent = true, IndentChars = " " })) + catch (System.Exception exception) { - serializer.Serialize(xmlWriter, list); + Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); } } - catch (System.Exception exception) + + public static void SaveToFile(string root, string path, ICollection objectsToSerialize) { - Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); + if (string.IsNullOrEmpty(path)) + { + return; + } + + List list = new List(); + list.AddRange(objectsToSerialize); + + XmlRootAttribute xmlRoot = new XmlRootAttribute + { + ElementName = root + }; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); + + try + { + using (StreamWriter writer = new StreamWriter(path)) + { + XmlWriterSettings xmlWriterSettings = new XmlWriterSettings + { + Indent = true, IndentChars = " " + }; + + using (XmlWriter xmlWriter = XmlWriter.Create(writer, xmlWriterSettings)) + { + serializer.Serialize(xmlWriter, list); + } + } + } + catch (System.Exception exception) + { + Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); + } } } -} +} \ No newline at end of file diff --git a/Application/FileConverterExtension/FileConverterExtension.cs b/Application/FileConverterExtension/FileConverterExtension.cs index 4bd42ee..cd10a47 100644 --- a/Application/FileConverterExtension/FileConverterExtension.cs +++ b/Application/FileConverterExtension/FileConverterExtension.cs @@ -16,6 +16,9 @@ namespace FileConverterExtension using SharpShell.Attributes; using SharpShell.SharpContextMenu; + /// + /// File converter context menu extension class. + /// [ComVisible(true), Guid("AF9B72B5-F4E4-44B0-A3D9-B55B748EFE90")] [COMServerAssociation(AssociationType.AllFiles)] public class FileConverterExtension : SharpContextMenu diff --git a/Application/FileConverterExtension/FileConverterExtension.csproj b/Application/FileConverterExtension/FileConverterExtension.csproj index 5ae715c..b325a0e 100644 --- a/Application/FileConverterExtension/FileConverterExtension.csproj +++ b/Application/FileConverterExtension/FileConverterExtension.csproj @@ -62,7 +62,9 @@ - + + true + True True @@ -83,11 +85,11 @@ - - \ No newline at end of file + diff --git a/Application/FileConverterExtension/PresetDefinition.cs b/Application/FileConverterExtension/PresetDefinition.cs index 5f6d9ae..823c5ec 100644 --- a/Application/FileConverterExtension/PresetDefinition.cs +++ b/Application/FileConverterExtension/PresetDefinition.cs @@ -4,9 +4,6 @@ namespace FileConverterExtension { public class PresetDefinition { - public bool Enabled; - public int ExtensionRefCount; - public PresetDefinition(string name) { this.Name = name; @@ -17,5 +14,17 @@ namespace FileConverterExtension get; private set; } + + public bool Enabled + { + get; + set; + } + + public int ExtensionRefCount + { + get; + set; + } } } \ No newline at end of file diff --git a/Application/FileConverterExtension/Settings.StyleCop b/Application/FileConverterExtension/Settings.StyleCop new file mode 100644 index 0000000..67f607a --- /dev/null +++ b/Application/FileConverterExtension/Settings.StyleCop @@ -0,0 +1,24 @@ + + + + + + + False + + + + + False + + + + + False + + + + + + + \ No newline at end of file diff --git a/Installer/Product.wxs b/Installer/Product.wxs index d8a36a9..067a21d 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -69,26 +69,26 @@ - + - + - + - + - + - + - +