This commit is contained in:
Adrien Allard 2015-08-22 15:50:19 +02:00
parent 82be95fb43
commit 5db9c09cff
22 changed files with 207 additions and 160 deletions

View File

@ -1,7 +1,5 @@
// <copyright file="ConversionJob_FFMPEG.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
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);

View File

@ -0,0 +1,10 @@
// <copyright file="ConversionSettings.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System.Collections.Generic;
public class ConversionSettings : Dictionary<string, string>, IConversionSettings
{
}
}

View File

@ -0,0 +1,10 @@
// <copyright file="IConversionSettings.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System.Collections.Generic;
public interface IConversionSettings : IReadOnlyDictionary<string, string>
{
}
}

View File

@ -1,12 +0,0 @@
using System.Collections.Generic;
namespace FileConverter
{
public interface IConversionSettings : IReadOnlyDictionary<string, string>
{
}
public class ConversionSettings : Dictionary<string, string>, IConversionSettings
{
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="Mode.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="EncodingMode.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{

View File

@ -78,10 +78,11 @@
</Compile>
<Compile Include="ConversionJobs\ConversionJobFactory.cs" />
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
<Compile Include="ConversionSettings.cs" />
<Compile Include="ConversionPreset\ConversionSettings.cs" />
<Compile Include="EncodingMode.cs" />
<Compile Include="ConversionPreset\IConversionSettings.cs" />
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
<Compile Include="ConversionPreset.cs" />
<Compile Include="ConversionPreset\ConversionPreset.cs" />
<Compile Include="ValueConverters\BitrateToString.cs" />
<Compile Include="ValueConverters\Generic\BoolToVisibility.cs" />
<Compile Include="ValueConverters\ConversionSettingsToString.cs" />
@ -130,9 +131,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="OutputType.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\Annotations.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
@ -166,11 +170,11 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@ -14,6 +14,8 @@
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">// &lt;copyright file="$FILENAME$" company="AAllard"&gt;License: http://www.gnu.org/licenses/gpl.html GPL version 3.&lt;/copyright&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CBR/@EntryIndexedValue">CBR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VBR/@EntryIndexedValue">VBR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=MethodPropertyEvent/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>

View File

@ -1,4 +1,4 @@
// <copyright file="InputTypesToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="BitrateToString.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ValueConverters
{

View File

@ -1,4 +1,4 @@
// <copyright file="InputTypesToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="ConversionSettingsToString.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ValueConverters
{

View File

@ -1,6 +1,5 @@
// <copyright file="EqualsConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ValueConverters.Generic
{
using System;

View File

@ -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)
{

View File

@ -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<OutputType>(referenceTypeName,out referenceType))
if (!Enum.TryParse<OutputType>(referenceTypeName, out referenceType))
{
return "Hidden";
}
return outputType == referenceType ? "Visible" : "Hidden";

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// <copyright file="Version.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{

View File

@ -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;
// <copyright file="DiagnosticsWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.Windows
{
using System.Windows;
/// <summary>
/// Interaction logic for DiagnosticsWindow.xaml
/// </summary>
@ -21,7 +11,7 @@ namespace FileConverter.Windows
{
public DiagnosticsWindow()
{
InitializeComponent();
this.InitializeComponent();
}
}
}

View File

@ -11,8 +11,6 @@ namespace FileConverter
public partial class MainWindow : Window, INotifyPropertyChanged
{
private bool verboseMode;
private DiagnosticsWindow diagnosticsWindow;
private SettingsWindow settingsWindow;

View File

@ -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;
// <copyright file="XmlHelpers.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
using FileConverter;
public class XmlHelpers
namespace FileConverter
{
public static void LoadFromFile<T>(string root, string path, ref ICollection<T> 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<T>(string root, string path, ref ICollection<T> collection)
{
throw new ArgumentNullException("path");
}
XmlRootAttribute xmlRoot = new XmlRootAttribute
{
ElementName = root
};
XmlSerializer serializer = new XmlSerializer(typeof(List<T>), 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<T> elements = (List<T>)serializer.Deserialize(xmlReader);
foreach (T element in elements)
throw new ArgumentNullException("path");
}
XmlRootAttribute xmlRoot = new XmlRootAttribute
{
ElementName = root
};
XmlSerializer serializer = new XmlSerializer(typeof(List<T>), 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<T> elements = (List<T>)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<T>(string root, string path, ICollection<T> objectsToSerialize)
{
if (string.IsNullOrEmpty(path))
{
return;
}
List<T> list = new List<T>();
list.AddRange(objectsToSerialize);
XmlRootAttribute xmlRoot = new XmlRootAttribute
{
ElementName = root
};
XmlSerializer serializer = new XmlSerializer(typeof(List<T>), 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<T>(string root, string path, ICollection<T> 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<T> list = new List<T>();
list.AddRange(objectsToSerialize);
XmlRootAttribute xmlRoot = new XmlRootAttribute
{
ElementName = root
};
XmlSerializer serializer = new XmlSerializer(typeof(List<T>), 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);
}
}
}
}
}

View File

@ -16,6 +16,9 @@ namespace FileConverterExtension
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;
/// <summary>
/// File converter context menu extension class.
/// </summary>
[ComVisible(true), Guid("AF9B72B5-F4E4-44B0-A3D9-B55B748EFE90")]
[COMServerAssociation(AssociationType.AllFiles)]
public class FileConverterExtension : SharpContextMenu

View File

@ -62,7 +62,9 @@
<ItemGroup>
<Compile Include="FileConverterExtension.cs" />
<Compile Include="PresetDefinition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -83,11 +85,11 @@
<None Include="Resources\ApplicationIcon-16x16.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@ -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;
}
}
}

View File

@ -0,0 +1,24 @@
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="ElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EnumerationItemsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>

View File

@ -69,26 +69,26 @@
<!-- Registry entries -->
<Component Id="RegistryEntries" Guid="{C3EF3D67-0206-4DBD-B2EA-78FF2E290093}">
<RegistryKey Root="HKCU" Key="Software\FileConverter" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter">
<RegistryValue Name="Path" Type="string" Value="[INSTALLFOLDER]FileConverter.exe"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\ape" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\ape">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Mp3;To Flac;To Wav"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\flac" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\flac">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Mp3;To Wav"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\mp3" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\mp3">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\ogg" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\ogg">
<RegistryValue Name="Presets" Type="string" Value="To Mp3;To Wav"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\wav" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\wav">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Mp3;To Flac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\wma" Action="createAndRemoveOnUninstall">
<RegistryKey Root="HKCU" Key="Software\FileConverter\wma">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Mp3;To Wav"/>
</RegistryKey>
</Component>