Clean & stylecop

This commit is contained in:
Adrien Allard committed 2015-11-07 11:30:10 +01:00
1 parent 3da4e0ea84
commit bfa8fd7d4f
15 files changed
+161 -189

No files matched your search

@@ -215,18 +215,6 @@ namespace FileConverter
if (System.IO.File.Exists(conversionJob.OutputFilePath))
{
Diagnostics.Log("Success!");
if (this.debugMode)
{
Diagnostics.Log("Delete file {0}.", conversionJob.OutputFilePath);
try
{
//System.IO.File.Delete(conversionJob.OutputFilePath);
}
catch
{
}
}
}
else
{
@@ -1,15 +1,13 @@
// <copyright file="EncodingQualitySliderControl.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="EncodingQualitySliderControl.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.Controls
{
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
/// <summary>
/// Interaction logic for EncodingQualitySliderControl.xaml
/// Interaction logic for EncodingQualitySliderControl.
/// </summary>
public partial class EncodingQualitySliderControl : UserControl
{
@@ -31,7 +29,6 @@ namespace FileConverter.Controls
this.CoerceValue(EncodingQualitySliderControl.BitrateProperty);
Debug.Assert(this.slider != null);
this.slider.ValueChanged += this.Slider_ValueChanged;
}
@@ -59,8 +59,7 @@ namespace FileConverter.ConversionJobs
{
EncodingMode encodingMode = this.ConversionPreset.GetSettingsValue<EncodingMode>("Encoding");
string encoderArgs = string.Format("-acodec {0}", this.WAVEncodingToCodecArgument(encodingMode));
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"",
this.InputFilePath, this.OutputFilePath, encoderArgs);
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs);
}
break;
@@ -73,8 +72,7 @@ namespace FileConverter.ConversionJobs
switch (encodingMode)
{
case EncodingMode.Mp3VBR:
encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}",
this.MP3VBRBitrateToQualityIndex(encodingQuality));
encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}", this.MP3VBRBitrateToQualityIndex(encodingQuality));
break;
case EncodingMode.Mp3CBR:
@@ -85,8 +83,7 @@ namespace FileConverter.ConversionJobs
break;
}
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"",
this.InputFilePath, this.OutputFilePath, encoderArgs);
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs);
}
break;
@@ -94,10 +91,8 @@ namespace FileConverter.ConversionJobs
case OutputType.Ogg:
{
int encodingQuality = this.ConversionPreset.GetSettingsValue<int>("Bitrate");
string encoderArgs = string.Format("-codec:a libvorbis -qscale:a {0}",
this.OGGVBRBitrateToQualityIndex(encodingQuality));
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"",
this.InputFilePath, this.OutputFilePath, encoderArgs);
string encoderArgs = string.Format("-codec:a libvorbis -qscale:a {0}", this.OGGVBRBitrateToQualityIndex(encodingQuality));
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs);
}
break;
@@ -194,10 +189,10 @@ namespace FileConverter.ConversionJobs
}
/// <summary>
/// Convert bitrate in vorbis encoder quality index.
/// Convert bitrate in <c>vorbis</c> encoder quality index.
/// </summary>
/// <param name="bitrate">Wanted bitrate value.</param>
/// <returns>The vorbis encoder quality index assotiated to the given bitrate value.</returns>
/// <returns>The <c>vorbis</c> encoder quality index associated to the given bitrate value.</returns>
/// http://wiki.hydrogenaud.io/index.php?title=Recommended_Ogg_Vorbis
private int OGGVBRBitrateToQualityIndex(int bitrate)
{
@@ -247,10 +242,10 @@ namespace FileConverter.ConversionJobs
}
/// <summary>
/// Convert encoding mode setting to ffmpeg argument option.
/// Convert encoding mode setting to <c>ffmpeg</c> argument option.
/// </summary>
/// <param name="encoding">The encoding mode setting.</param>
/// <returns>Returns the ffmpeg argument corresponding to the given envoding mode.</returns>
/// <returns>Returns the <c>ffmpeg</c> argument corresponding to the given encoding mode.</returns>
/// https://trac.ffmpeg.org/wiki/audio%20types
private string WAVEncodingToCodecArgument(EncodingMode encoding)
{
@@ -1,4 +1,4 @@
// <copyright file="FileConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="ConversionPreset.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
@@ -22,7 +22,7 @@ namespace FileConverter
private InputPostConversionAction inputPostConversionAction;
private ConversionSettings settings = new ConversionSettings();
private string outputFileNameTemplate;
FileNameConverter outputFileNameConverter = new FileNameConverter();
private FileNameConverter outputFileNameConverter = new FileNameConverter();
public ConversionPreset()
{
@@ -68,7 +68,7 @@ namespace FileConverter
set
{
this.outputType = value;
this.InitializeDefaultSettings(outputType);
this.InitializeDefaultSettings(this.outputType);
this.OnPropertyChanged();
}
}
@@ -193,14 +193,6 @@ namespace FileConverter
}
}
public string this[string columnName]
{
get
{
return this.Validate(columnName);
}
}
public string Error
{
get
@@ -221,6 +213,14 @@ namespace FileConverter
}
}
public string this[string columnName]
{
get
{
return this.Validate(columnName);
}
}
public void OnDeserializationComplete()
{
for (int index = 0; index < this.InputTypes.Count; index++)
@@ -250,7 +250,7 @@ namespace FileConverter
public string GenerateOutputFilePath(string inputFilePath)
{
return (string)this.outputFileNameConverter.Convert(new object[] {inputFilePath, this.OutputType, this.OutputFileNameTemplate}, typeof (string), null, null);
return (string)this.outputFileNameConverter.Convert(new object[] { inputFilePath, this.OutputType, this.OutputFileNameTemplate }, typeof(string), null, null);
}
public void SetSettingsValue(string settingsKey, string value)
@@ -403,17 +403,14 @@ namespace FileConverter
if (this.Name.Contains(";"))
{
return "The preset name can't contains the character ';'.";
return "The preset name can't contains the character ';'.";
}
Application application = Application.Current as Application;
if (application?.Settings != null)
int? count = application?.Settings?.ConversionPresets?.Count(match => match?.name == this.Name);
if (count > 1)
{
int count = application.Settings.ConversionPresets.Count(match => match.name == this.Name);
if (count > 1)
{
return "The preset name is already used.";
}
return "The preset name is already used.";
}
}
@@ -1,12 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// <copyright file="ConversionSettingsOverride.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System.Collections;
using System.Collections.Generic;
public struct ConversionSettingsOverride : IConversionSettings
{
private string key;
@@ -18,16 +16,6 @@ namespace FileConverter
this.value = value;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
yield return new KeyValuePair<string, string>(this.key, this.value);
}
public int Count
{
get
@@ -36,6 +24,40 @@ namespace FileConverter
}
}
public IEnumerable<string> Keys
{
get
{
yield return this.key;
}
}
public IEnumerable<string> Values
{
get
{
yield return this.value;
}
}
public string this[string key]
{
get
{
if (key == this.key)
{
return this.value;
}
throw new KeyNotFoundException();
}
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
yield return new KeyValuePair<string, string>(this.key, this.value);
}
public bool ContainsKey(string key)
{
return key == this.key;
@@ -54,33 +76,9 @@ namespace FileConverter
return false;
}
public string this[string key]
IEnumerator IEnumerable.GetEnumerator()
{
get
{
if (key == this.key)
{
return this.value;
}
throw new KeyNotFoundException();
}
}
public IEnumerable<string> Keys
{
get
{
yield return this.key;
}
}
public IEnumerable<string> Values
{
get
{
yield return this.value;
}
return this.GetEnumerator();
}
}
}
@@ -15,6 +15,7 @@
<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/=OGGVBR/@EntryIndexedValue">OGGVBR</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>
+65 -66
View File
@@ -5,18 +5,17 @@ namespace FileConverter
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Windows;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using FileConverter.Annotations;
using Microsoft.Win32;
public class Settings : INotifyPropertyChanged, IDataErrorInfo
{
@@ -26,6 +25,29 @@ namespace FileConverter
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<ConversionPreset> ConversionPresets
{
get { return this.conversionPresets; }
set { this.conversionPresets = value; }
}
public string Error
{
get
{
for (int index = 0; index < this.ConversionPresets.Count; index++)
{
string error = this.ConversionPresets[index].Error;
if (!string.IsNullOrEmpty(error))
{
return error;
}
}
return string.Empty;
}
}
private static bool IsInAdmininstratorPrivileges
{
get
@@ -34,16 +56,45 @@ namespace FileConverter
}
}
public ObservableCollection<ConversionPreset> ConversionPresets
public string this[string columnName]
{
get { return this.conversionPresets; }
set { this.conversionPresets = value; }
get
{
return this.Error;
}
}
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
public static void ApplyTemporarySettings()
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
// Load temporary settings.
string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath();
if (!File.Exists(temporaryFilePath))
{
return;
}
ICollection<ConversionPreset> conversionPresets = new ObservableCollection<ConversionPreset>();
XmlHelpers.LoadFromFile("Settings", temporaryFilePath, ref conversionPresets);
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter");
if (registryKey == null)
{
MessageBox.Show("Can't apply settings in registry. (code 0x03)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// Compute the registry entries data from settings.
Dictionary<string, List<string>> registryEntries = ComputeRegistryEntriesFromConvertionPresets(conversionPresets);
bool succeed = Settings.ApplyRegistryModifications(registryEntries);
if (succeed)
{
// Copy temporary settings file to the real settings file.
string userFilePath = Settings.GetUserSettingsFilePath();
File.Copy(temporaryFilePath, userFilePath, true);
File.Delete(temporaryFilePath);
}
}
public ConversionPreset GetPresetFromName(string presetName)
@@ -118,39 +169,6 @@ namespace FileConverter
}
}
public static void ApplyTemporarySettings()
{
// Load temporary settings.
string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath();
if (!File.Exists(temporaryFilePath))
{
return;
}
ICollection<ConversionPreset> conversionPresets = new ObservableCollection<ConversionPreset>();
XmlHelpers.LoadFromFile("Settings", temporaryFilePath, ref conversionPresets);
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter");
if (registryKey == null)
{
MessageBox.Show("Can't apply settings in registry. (code 0x03)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// Compute the registry entries data from settings.
Dictionary<string, List<string>> registryEntries = ComputeRegistryEntriesFromConvertionPresets(conversionPresets);
bool succeed = Settings.ApplyRegistryModifications(registryEntries);
if (succeed)
{
// Copy temporary settings file to the real settings file.
string userFilePath = Settings.GetUserSettingsFilePath();
File.Copy(temporaryFilePath, userFilePath, true);
File.Delete(temporaryFilePath);
}
}
private static bool ApplyRegistryModifications(Dictionary<string, List<string>> registryEntries)
{
if (!Settings.IsInAdmininstratorPrivileges)
@@ -359,29 +377,10 @@ namespace FileConverter
}
}
public string this[string columnName]
[NotifyPropertyChangedInvocator]
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
get
{
return this.Error;
}
}
public string Error
{
get
{
for (int index = 0; index < this.ConversionPresets.Count; index++)
{
string error = this.ConversionPresets[index].Error;
if (!string.IsNullOrEmpty(error))
{
return error;
}
}
return string.Empty;
}
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
@@ -1,4 +1,4 @@
// <copyright file="EqualsConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="BoolInverterConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ValueConverters.Generic
{
@@ -1,17 +1,12 @@
// <copyright file="CollectionContainsElementToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace FileConverter.ValueConverters.Generic
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
public class CollectionContainsElementToBool : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
@@ -21,8 +16,8 @@ namespace FileConverter.ValueConverters.Generic
throw new ArgumentException("The values must contains the collection of elements and the researched element.");
}
// TODO: Make this converter generic.
//// TODO: Make this converter generic.
if (!(values[0] is ICollection<string>))
{
return false;
@@ -1,4 +1,4 @@
// <copyright file="ConversionSettingsTemplateSelector.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="ConversionSettingsTemplateSelector.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.Windows
{
@@ -5,7 +5,7 @@ namespace FileConverter.Windows
using System.Windows;
/// <summary>
/// Interaction logic for DiagnosticsWindow.xaml
/// Interaction logic for DiagnosticsWindow.
/// </summary>
public partial class DiagnosticsWindow : Window
{
@@ -1,22 +1,23 @@
// <copyright file="SettingsWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
// <copyright file="InputExtension.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System.ComponentModel;
using System.Runtime.CompilerServices;
using FileConverter.Annotations;
public class InputExtension : INotifyPropertyChanged
{
public string name;
public event PropertyChangedEventHandler PropertyChanged;
private string name;
public InputExtension(string name)
{
this.Name = name;
}
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get
@@ -1,24 +1,25 @@
// <copyright file="InputExtensionCategory.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using FileConverter.Annotations;
namespace FileConverter
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using FileConverter.Annotations;
public class InputExtensionCategory : INotifyPropertyChanged
{
private string name;
private List<InputExtension> inputExtensions = new List<InputExtension>();
public event PropertyChangedEventHandler PropertyChanged;
public InputExtensionCategory(string name)
{
this.Name = name;
}
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get
@@ -54,7 +54,7 @@ namespace FileConverter
private void SettingsWindow_Closed(object sender, System.EventArgs e)
{
settingsWindow.OnSettingsWindowHide -= this.SettingsWindow_Closed;
this.settingsWindow.OnSettingsWindowHide -= this.SettingsWindow_Closed;
this.Close();
}
@@ -2,19 +2,19 @@
namespace FileConverter
{
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Input;
using FileConverter.Annotations;
using Microsoft.Win32;
/// <summary>
/// Interaction logic for Settings.xaml
/// Interaction logic for Settings.
/// </summary>
public partial class SettingsWindow : Window, INotifyPropertyChanged
{
@@ -30,7 +30,7 @@ namespace FileConverter
Application application = Application.Current as Application;
this.settings = application.Settings;
this.PresetList.ItemsSource = settings.ConversionPresets;
this.PresetList.ItemsSource = this.settings.ConversionPresets;
OutputType[] outputTypes = new[]
{