From f6f90d6fcc439a950e2d5b32922157ed34326ab8 Mon Sep 17 00:00:00 2001 From: Andres Garcia Alves Date: Fri, 30 Jun 2023 13:59:16 -0300 Subject: [PATCH] fixed miscellaneous Warnings & Messages --- .editorconfig | 79 +++++++++++++++++++ .../Entities/NamingProcessedEventArgs.cs | 2 - Renamer.Engine/Entities/NamingRequest.cs | 2 - .../Entities/RenameEngineValidator.cs | 7 +- Renamer.Engine/Entities/RenameSettings.cs | 9 ++- .../Entities/RenameSettingsFactory.cs | 22 +++--- Renamer.Engine/GlobalSuppressions.cs | 6 ++ Renamer.Engine/Helpers/ExtensionMethods.cs | 10 +-- .../NamingPatterns/ByPatternNaming.cs | 8 +- .../NamingPatterns/BySimpleMatchNaming.cs | 8 +- .../NamingPatterns/InvertedCaseNaming.cs | 9 +-- .../NamingPatterns/LowerCaseNaming.cs | 8 +- .../NamingPatterns/PositionalAppendNaming.cs | 8 +- .../NamingPatterns/PositionalReplaceNaming.cs | 8 +- .../NamingPatterns/RemoveTildesNaming.cs | 8 +- .../NamingPatterns/SentenceCaseNaming.cs | 8 +- .../NamingPatterns/TitleCaseNaming.cs | 8 +- .../NamingPatterns/UpperCaseNaming.cs | 8 +- Renamer.Engine/PhysicalRenamer/IRenamer.cs | 4 +- Renamer.Engine/PhysicalRenamer/Renamer.cs | 6 +- Renamer.Engine/RenameEngine.cs | 27 ++++--- Renamer.Engine/Renamer.Engine.csproj | 4 + Renamer.Front/AboutBox.cs | 32 ++++---- Renamer.Front/MainForm.cs | 54 ++++++------- Renamer.sln | 9 ++- 25 files changed, 195 insertions(+), 159 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6faf6e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,79 @@ +[*.cs] + +# IDE1006: Naming Styles +dotnet_diagnostic.IDE1006.severity = none +csharp_indent_labels = no_change +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +indent_size = 4 +end_of_line = crlf +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent diff --git a/Renamer.Engine/Entities/NamingProcessedEventArgs.cs b/Renamer.Engine/Entities/NamingProcessedEventArgs.cs index e52fddf..dbf2899 100644 --- a/Renamer.Engine/Entities/NamingProcessedEventArgs.cs +++ b/Renamer.Engine/Entities/NamingProcessedEventArgs.cs @@ -8,8 +8,6 @@ public class NamingProcessedEventArgs : EventArgs public NamingResult NamingResult { get; set; } public int Progress { get; set; } - public NamingProcessedEventArgs() { } - public NamingProcessedEventArgs(Operation operation, NamingResult namingResult, int progress) { this.Operation = operation; diff --git a/Renamer.Engine/Entities/NamingRequest.cs b/Renamer.Engine/Entities/NamingRequest.cs index 6e1111b..cc0cacb 100644 --- a/Renamer.Engine/Entities/NamingRequest.cs +++ b/Renamer.Engine/Entities/NamingRequest.cs @@ -5,8 +5,6 @@ public class NamingRequest public ObjectType ObjectType { get; } public string CurrentName { get; } - public NamingRequest() { } - public NamingRequest(ObjectType objectType, string currentName) { this.ObjectType = objectType; diff --git a/Renamer.Engine/Entities/RenameEngineValidator.cs b/Renamer.Engine/Entities/RenameEngineValidator.cs index c63e2b0..3b2b0b8 100644 --- a/Renamer.Engine/Entities/RenameEngineValidator.cs +++ b/Renamer.Engine/Entities/RenameEngineValidator.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -using Renamer.Engine.Helpers; +using Renamer.Engine.Helpers; namespace Renamer.Engine.Entities { @@ -39,7 +36,7 @@ public void Validate() case RenameType.Unknown: throw new ArgumentException("No rename method selected."); } } - catch (Exception ex) { throw ex; } + catch (Exception) { throw; } } private void ValidateBySimpleMatch() diff --git a/Renamer.Engine/Entities/RenameSettings.cs b/Renamer.Engine/Entities/RenameSettings.cs index a305bff..7fd29cf 100644 --- a/Renamer.Engine/Entities/RenameSettings.cs +++ b/Renamer.Engine/Entities/RenameSettings.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -namespace Renamer.Engine.Entities +namespace Renamer.Engine.Entities { public class RenameSettings { @@ -9,6 +6,10 @@ public class RenameSettings public List Parameters { get; } public bool IncludeExtension { get; } + public RenameSettings(RenameType renameType) : this(renameType, new List(), default) + { + } + public RenameSettings(RenameType renameType, List parameters, bool includeExtension = false) { // if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } diff --git a/Renamer.Engine/Entities/RenameSettingsFactory.cs b/Renamer.Engine/Entities/RenameSettingsFactory.cs index 867c439..157ce1e 100644 --- a/Renamer.Engine/Entities/RenameSettingsFactory.cs +++ b/Renamer.Engine/Entities/RenameSettingsFactory.cs @@ -6,67 +6,67 @@ public class RenameSettingsFactory { public static RenameSettings SentenceCase(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.SentenceCase, parameters, includeExtension); } public static RenameSettings TitleCase(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.TitleCase, parameters, includeExtension); } public static RenameSettings UpperCase(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.UpperCase, parameters, includeExtension); } public static RenameSettings LowerCase(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.LowerCase, parameters, includeExtension); } public static RenameSettings InvertedCase(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.InvertedCase, parameters, includeExtension); } public static RenameSettings RemoveTildes(bool includeExtension) { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.RemoveTildes, parameters, includeExtension); } public static RenameSettings BySimpleMatch(string matchSearch, string matchRemplacement, bool includeExtension) { - List parameters = new List() { matchSearch, matchRemplacement }; + var parameters = new List() { matchSearch, matchRemplacement }; return new RenameSettings(RenameType.BySimpleMatch, parameters, includeExtension); } public static RenameSettings ByPattern(string beginnigText, string startIndex, string increment, string numericPad, bool includeExtension) { - List parameters = new List() { beginnigText, startIndex, increment, numericPad }; + var parameters = new List() { beginnigText, startIndex, increment, numericPad }; return new RenameSettings(RenameType.ByPattern, parameters, includeExtension); } public static RenameSettings PositionalReplace(string positionalReplaceIndex, string positionalReplaceText, bool includeExtension) { - List parameters = new List() { positionalReplaceIndex, positionalReplaceText }; + var parameters = new List() { positionalReplaceIndex, positionalReplaceText }; return new RenameSettings(RenameType.PositionalReplace, parameters, includeExtension); } public static RenameSettings PositionalAppend(string positionalAppendIndex, string positionalAppendText, bool includeExtension) { - List parameters = new List() { positionalAppendIndex, positionalAppendText }; + var parameters = new List() { positionalAppendIndex, positionalAppendText }; return new RenameSettings(RenameType.PositionalAppend, parameters, includeExtension); } public static RenameSettings Unknown() { - List parameters = new List(); + var parameters = new List(); return new RenameSettings(RenameType.Unknown, parameters, false); } } diff --git a/Renamer.Engine/GlobalSuppressions.cs b/Renamer.Engine/GlobalSuppressions.cs index 9597248..a11d12c 100644 --- a/Renamer.Engine/GlobalSuppressions.cs +++ b/Renamer.Engine/GlobalSuppressions.cs @@ -6,3 +6,9 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Style", "IDE0016:Use 'throw' expression", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.Entities.RenameSettings.#ctor(Renamer.Engine.RenameType,System.Collections.Generic.List{System.String},System.Boolean)")] +[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.Helpers.ExtensionMethods.Truncate(System.String,System.Int32)~System.String")] +[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.NamingPatterns.PositionalAppendNaming.Process(Renamer.Engine.ObjectType,System.String)~System.String")] +[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.NamingPatterns.PositionalReplaceNaming.Process(Renamer.Engine.ObjectType,System.String)~System.String")] +[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.NamingPatterns.SentenceCaseNaming.Process(Renamer.Engine.ObjectType,System.String)~System.String")] +[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.NamingPatterns.TitleCaseNaming.Process(Renamer.Engine.ObjectType,System.String)~System.String")] +[assembly: SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "", Scope = "member", Target = "~M:Renamer.Engine.RenameEngine.GetNamingPattern(Renamer.Engine.PhysicalRenamer.IRenamer,Renamer.Engine.Entities.RenameSettings)~Renamer.Engine.NamingPatterns.BaseNaming")] diff --git a/Renamer.Engine/Helpers/ExtensionMethods.cs b/Renamer.Engine/Helpers/ExtensionMethods.cs index 887a8cd..cd2e0a9 100644 --- a/Renamer.Engine/Helpers/ExtensionMethods.cs +++ b/Renamer.Engine/Helpers/ExtensionMethods.cs @@ -1,6 +1,4 @@ -using System; - -namespace Renamer.Engine.Helpers +namespace Renamer.Engine.Helpers { internal static class ExtensionMethods { @@ -34,9 +32,9 @@ public static bool IsNumeric(this string text, bool zeroIsValid) /// Returns true if the text is a valid filename, otherwise false. public static bool IsValidFileName(this string text) { - if (text.Contains("\\") || text.Contains("/") || text.Contains(":") || - text.Contains("*") || text.Contains("?") || text.Contains("\"") || - text.Contains("<") || text.Contains(">") || text.Contains("|")) + if (text.Contains('\\') || text.Contains('/') || text.Contains(':') || + text.Contains('*') || text.Contains('?') || text.Contains('"') || + text.Contains('<') || text.Contains('>') || text.Contains('|')) return false; return true; diff --git a/Renamer.Engine/NamingPatterns/ByPatternNaming.cs b/Renamer.Engine/NamingPatterns/ByPatternNaming.cs index 63dc542..182d8ad 100644 --- a/Renamer.Engine/NamingPatterns/ByPatternNaming.cs +++ b/Renamer.Engine/NamingPatterns/ByPatternNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -55,7 +51,7 @@ protected override string Process(ObjectType objectType, string currentName) // increase currentIndex for next time currentIndex += increment; - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/BySimpleMatchNaming.cs b/Renamer.Engine/NamingPatterns/BySimpleMatchNaming.cs index 2269ff5..8dbc1ac 100644 --- a/Renamer.Engine/NamingPatterns/BySimpleMatchNaming.cs +++ b/Renamer.Engine/NamingPatterns/BySimpleMatchNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -44,7 +40,7 @@ protected override string Process(ObjectType objectType, string currentName) str += Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/InvertedCaseNaming.cs b/Renamer.Engine/NamingPatterns/InvertedCaseNaming.cs index 7b9a2f8..39cf2cc 100644 --- a/Renamer.Engine/NamingPatterns/InvertedCaseNaming.cs +++ b/Renamer.Engine/NamingPatterns/InvertedCaseNaming.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; -using System.Text; -using System.Threading.Tasks; +using System.Text; using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; @@ -35,7 +32,7 @@ protected override string Process(ObjectType objectType, string currentName) { string str; char[] characters; - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); if (base.RenameSettings.IncludeExtension && Path.GetExtension(currentName) != String.Empty) { @@ -62,7 +59,7 @@ protected override string Process(ObjectType objectType, string currentName) str = sb.ToString() + Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/LowerCaseNaming.cs b/Renamer.Engine/NamingPatterns/LowerCaseNaming.cs index ea60268..5fac311 100644 --- a/Renamer.Engine/NamingPatterns/LowerCaseNaming.cs +++ b/Renamer.Engine/NamingPatterns/LowerCaseNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -46,7 +42,7 @@ protected override string Process(ObjectType objectType, string currentName) str += Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/PositionalAppendNaming.cs b/Renamer.Engine/NamingPatterns/PositionalAppendNaming.cs index 07a049f..b54ab42 100644 --- a/Renamer.Engine/NamingPatterns/PositionalAppendNaming.cs +++ b/Renamer.Engine/NamingPatterns/PositionalAppendNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -61,7 +57,7 @@ protected override string Process(ObjectType objectType, string currentName) } } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/PositionalReplaceNaming.cs b/Renamer.Engine/NamingPatterns/PositionalReplaceNaming.cs index df8272c..a251697 100644 --- a/Renamer.Engine/NamingPatterns/PositionalReplaceNaming.cs +++ b/Renamer.Engine/NamingPatterns/PositionalReplaceNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -61,7 +57,7 @@ protected override string Process(ObjectType objectType, string currentName) } } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/RemoveTildesNaming.cs b/Renamer.Engine/NamingPatterns/RemoveTildesNaming.cs index 42021a1..33d7ab4 100644 --- a/Renamer.Engine/NamingPatterns/RemoveTildesNaming.cs +++ b/Renamer.Engine/NamingPatterns/RemoveTildesNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -48,7 +44,7 @@ protected override string Process(ObjectType objectType, string currentName) str += Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/SentenceCaseNaming.cs b/Renamer.Engine/NamingPatterns/SentenceCaseNaming.cs index 55ad637..fb4acd2 100644 --- a/Renamer.Engine/NamingPatterns/SentenceCaseNaming.cs +++ b/Renamer.Engine/NamingPatterns/SentenceCaseNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -52,7 +48,7 @@ protected override string Process(ObjectType objectType, string currentName) str = firstChar.ToUpper() + remainingChars.ToLower(); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/TitleCaseNaming.cs b/Renamer.Engine/NamingPatterns/TitleCaseNaming.cs index 0d120de..59e7df9 100644 --- a/Renamer.Engine/NamingPatterns/TitleCaseNaming.cs +++ b/Renamer.Engine/NamingPatterns/TitleCaseNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -67,7 +63,7 @@ protected override string Process(ObjectType objectType, string currentName) str += Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/NamingPatterns/UpperCaseNaming.cs b/Renamer.Engine/NamingPatterns/UpperCaseNaming.cs index d49d99c..3eb6b0c 100644 --- a/Renamer.Engine/NamingPatterns/UpperCaseNaming.cs +++ b/Renamer.Engine/NamingPatterns/UpperCaseNaming.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.PhysicalRenamer; namespace Renamer.Engine.NamingPatterns @@ -46,7 +42,7 @@ protected override string Process(ObjectType objectType, string currentName) str += Path.GetExtension(currentName); } - string basePath = Path.GetDirectoryName(currentName); + string basePath = Path.GetDirectoryName(currentName) ?? ""; return Path.Combine(basePath, str); } } diff --git a/Renamer.Engine/PhysicalRenamer/IRenamer.cs b/Renamer.Engine/PhysicalRenamer/IRenamer.cs index 4e882d6..989b478 100644 --- a/Renamer.Engine/PhysicalRenamer/IRenamer.cs +++ b/Renamer.Engine/PhysicalRenamer/IRenamer.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace Renamer.Engine.PhysicalRenamer +namespace Renamer.Engine.PhysicalRenamer { public interface IRenamer { diff --git a/Renamer.Engine/PhysicalRenamer/Renamer.cs b/Renamer.Engine/PhysicalRenamer/Renamer.cs index b46be29..7dbd0c8 100644 --- a/Renamer.Engine/PhysicalRenamer/Renamer.cs +++ b/Renamer.Engine/PhysicalRenamer/Renamer.cs @@ -17,13 +17,13 @@ public Task Rename(ObjectType objectType, string currentName, string newNa { try { - bool validation = this.Validations(objectType, currentName, newName); + bool validation = Validations(objectType, currentName, newName); if (!validation) { return Task.FromResult(false); } // actual rename if (objectType == ObjectType.File) { - FileInfo fi = new FileInfo(currentName); + var fi = new FileInfo(currentName); fi.MoveTo(newName); } else if (objectType == ObjectType.Directory) @@ -38,7 +38,7 @@ public Task Rename(ObjectType objectType, string currentName, string newNa catch (Exception) { return Task.FromResult(false); } } - private bool Validations(ObjectType objectType, string currentName, string newName) + private static bool Validations(ObjectType objectType, string currentName, string newName) { if (objectType == ObjectType.Unknown) { return false; } // throw new ArgumentException($"Unknown object type to rename."); diff --git a/Renamer.Engine/RenameEngine.cs b/Renamer.Engine/RenameEngine.cs index dda0663..938ce36 100644 --- a/Renamer.Engine/RenameEngine.cs +++ b/Renamer.Engine/RenameEngine.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Renamer.Engine.Entities; +using Renamer.Engine.Entities; using Renamer.Engine.NamingPatterns; using Renamer.Engine.PhysicalRenamer; @@ -11,16 +6,22 @@ namespace Renamer.Engine { public class RenameEngine { - private readonly RenameSettings renameSettings = null; - private readonly IRenamer renamer = null; + private readonly RenameSettings renameSettings; + private readonly IRenamer renamer; - public event EventHandler NamingProcessed; + public event EventHandler? NamingProcessed; public delegate void NamingProcessedEventHandler(object sender, NamingProcessedEventArgs e); - public RenameEngine(RenameSettings renameSettings) + public RenameEngine(RenameSettings renameSettings) : this(renameSettings, null) + { + } + + public RenameEngine(RenameSettings renameSettings, EventHandler? namingProcessed) { this.renameSettings = renameSettings; this.renamer = new PhysicalRenamer.Renamer(); + + this.NamingProcessed += namingProcessed; } /// @@ -45,7 +46,7 @@ public List Preview(List namingRequests) return namingResults; } - catch (Exception ex) { throw ex; } + catch (Exception) { throw; } } /// @@ -75,7 +76,7 @@ public async Task> Rename(List namingRequests) return namingResults; } - catch (Exception ex) { throw ex; } + catch (Exception) { throw; } } /// @@ -106,7 +107,7 @@ public async Task> Undo(List prevNamingResults) return namingResults; } - catch (Exception ex) { throw ex; } + catch (Exception) { throw; } } protected virtual void OnNamingProcessed(NamingProcessedEventArgs e) diff --git a/Renamer.Engine/Renamer.Engine.csproj b/Renamer.Engine/Renamer.Engine.csproj index 9805666..f7cf226 100644 --- a/Renamer.Engine/Renamer.Engine.csproj +++ b/Renamer.Engine/Renamer.Engine.csproj @@ -15,4 +15,8 @@ 3.1.0.0 + + + + diff --git a/Renamer.Front/AboutBox.cs b/Renamer.Front/AboutBox.cs index b27af5c..ae386fb 100644 --- a/Renamer.Front/AboutBox.cs +++ b/Renamer.Front/AboutBox.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Windows.Forms; +using System.Reflection; namespace Renamer.Front { @@ -13,16 +9,16 @@ public AboutBox() InitializeComponent(); this.Text = String.Format("About"); - this.labelProductName.Text = this.AssemblyProduct; - this.labelVersion.Text = String.Format("Version {0}", this.AssemblyVersion); - this.labelCopyright.Text = this.AssemblyCopyright; - this.labelCompanyName.Text = this.AssemblyCompany; - this.textBoxDescription.Text = this.AssemblyDescription; + this.labelProductName.Text = AssemblyProduct; + this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion); + this.labelCopyright.Text = AssemblyCopyright; + this.labelCompanyName.Text = AssemblyCompany; + this.textBoxDescription.Text = AssemblyDescription; } #region Assembly Attribute Accessors - public string AssemblyTitle + public static string AssemblyTitle { get { @@ -35,19 +31,19 @@ public string AssemblyTitle return titleAttribute.Title; } } - return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); + return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location); } } - public string AssemblyVersion + public static string AssemblyVersion { get { - return Assembly.GetExecutingAssembly().GetName().Version.ToString(); + return Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? ""; } } - public string AssemblyDescription + public static string AssemblyDescription { get { @@ -60,7 +56,7 @@ public string AssemblyDescription } } - public string AssemblyProduct + public static string AssemblyProduct { get { @@ -73,7 +69,7 @@ public string AssemblyProduct } } - public string AssemblyCopyright + public static string AssemblyCopyright { get { @@ -86,7 +82,7 @@ public string AssemblyCopyright } } - public string AssemblyCompany + public static string AssemblyCompany { get { diff --git a/Renamer.Front/MainForm.cs b/Renamer.Front/MainForm.cs index 2f6e5e1..d597193 100644 --- a/Renamer.Front/MainForm.cs +++ b/Renamer.Front/MainForm.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Text; using Renamer.Engine; using Renamer.Engine.Entities; @@ -18,8 +12,8 @@ public partial class MainForm : Form private Enums.SortType sortType = Enums.SortType.Ascending; private Enums.SortColumn sortColumn = Enums.SortColumn.FirstColumn; - private StringBuilder sbActivityLogs = new StringBuilder(); - private List namingResults = new List(); + private readonly StringBuilder sbActivityLogs = new(); + private List namingResults = new(); public MainForm() { @@ -82,6 +76,7 @@ private async void menuBtnUndo_Click(object sender, EventArgs e) private void menuBtnQuickAccess_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { + if (e.ClickedItem == null) { return; } Cursor = Cursors.WaitCursor; // retrieve full path of selected quick-access folder @@ -124,17 +119,19 @@ private void menuBtnAbout_Click(object sender, EventArgs e) #region TreeView & ListView events - private void treeViewFolderPick_BeforeExpand(object sender, TreeViewCancelEventArgs e) + private void treeViewFolderPick_BeforeExpand(object? sender, TreeViewCancelEventArgs e) { + if (e.Node == null) { return; } this.fullPath = Path.GetFullPath(e.Node.FullPath); - + this.statusStripLabelPath.Text = this.fullPath; this.LoadSubDirectories(this.fullPath); this.LoadFiles(this.fullPath); } - private void treeViewFolderPick_BeforeSelect(object sender, TreeViewCancelEventArgs e) + private void treeViewFolderPick_BeforeSelect(object? sender, TreeViewCancelEventArgs e) { + if (e.Node == null) { return; } this.fullPath = Path.GetFullPath(e.Node.FullPath); this.statusStripLabelPath.Text = this.fullPath; @@ -210,7 +207,7 @@ private void btnAddTree_Click(object sender, EventArgs e) { if (this.treeViewFolderPick.SelectedNode == null) { return; } - DirectoryInfo dirInfo = new DirectoryInfo(this.fullPath); + var dirInfo = new DirectoryInfo(this.fullPath); FileInfo[] filesInfo = dirInfo.GetFiles("*.*", SearchOption.AllDirectories); foreach (var fileInfo in filesInfo) @@ -241,14 +238,14 @@ private void listViewSelectedItems_KeyUp(object sender, KeyEventArgs e) private void radBySimpleMatch_CheckedChanged(object sender, EventArgs e) { - bool status = (sender as RadioButton).Checked; + bool status = ((RadioButton)sender).Checked; this.txtMatchSearch.Enabled = status; this.txtMatchReplacement.Enabled = status; } private void radByPattern_CheckedChanged(object sender, EventArgs e) { - bool status = (sender as RadioButton).Checked; + bool status = ((RadioButton)sender).Checked; this.txtBeginnigText.Enabled = status; this.txtStartIndex.Enabled = status; this.txtIncrement.Enabled = status; @@ -257,14 +254,14 @@ private void radByPattern_CheckedChanged(object sender, EventArgs e) private void radPositionalReplace_CheckedChanged(object sender, EventArgs e) { - bool status = (sender as RadioButton).Checked; + bool status = ((RadioButton)sender).Checked; this.txtPositionalReplaceIndex.Enabled = status; this.txtPositionalReplaceText.Enabled = status; } private void radPositionalAppend_CheckedChanged(object sender, EventArgs e) { - bool status = (sender as RadioButton).Checked; + bool status = ((RadioButton)sender).Checked; this.txtPositionalAppendIndex.Enabled = status; this.txtPositionalAppendText.Enabled = status; } @@ -291,7 +288,7 @@ private void btnClearActivityLogs_Click(object sender, EventArgs e) #region Renamer.Engine generated events - private void RenameEngine_NamingProcessed(object sender, NamingProcessedEventArgs e) + private void RenameEngine_NamingProcessed(object? sender, NamingProcessedEventArgs e) { try { @@ -312,7 +309,7 @@ private void RenameEngine_NamingProcessed(object sender, NamingProcessedEventArg Application.DoEvents(); } - catch (Exception ex) { throw ex; } + catch (Exception) { throw; } } #endregion @@ -440,14 +437,13 @@ private void PreviewWork() { try { - var renameSettings = this.BuildRenameSettings(); - var renameEngine = new RenameEngine(renameSettings); - // get NamingRequest items var listViewItems = ListViewHelper.GetCollectionItems(this.listViewSelectedItems.Items); var namingRequests = listViewItems.Select(a => new NamingRequest((ObjectType)a.Tag, a.Text)).ToList(); // send the files/directories to calculate rename changes + var renameSettings = this.BuildRenameSettings(); + var renameEngine = new RenameEngine(renameSettings); var namingResults = renameEngine.Preview(namingRequests); // refresh UI @@ -466,8 +462,7 @@ private async Task RenameWorkAsync() { var renameSettings = this.BuildRenameSettings(); - var renameEngine = new RenameEngine(renameSettings); - renameEngine.NamingProcessed += RenameEngine_NamingProcessed; + var renameEngine = new RenameEngine(renameSettings, RenameEngine_NamingProcessed); LogHelper.LogHeader(renameSettings); @@ -483,7 +478,7 @@ private async Task RenameWorkAsync() } catch (Exception ex) { - LogHelper.LogException(ex); throw ex; + LogHelper.LogException(ex); throw; } finally { @@ -498,10 +493,9 @@ private async Task UndoWorkAsync() { try { - var renameSettings = new RenameSettings(RenameType.Unknown, default, default); - - var renameEngine = new RenameEngine(renameSettings); - renameEngine.NamingProcessed += RenameEngine_NamingProcessed; + var renameSettings = new RenameSettings(RenameType.Unknown); // , new List(), default + + var renameEngine = new RenameEngine(renameSettings, RenameEngine_NamingProcessed); LogHelper.LogHeader(renameSettings); @@ -513,7 +507,7 @@ private async Task UndoWorkAsync() } catch (Exception ex) { - LogHelper.LogException(ex); throw ex; + LogHelper.LogException(ex); throw; } finally { diff --git a/Renamer.sln b/Renamer.sln index 344286d..6de1048 100644 --- a/Renamer.sln +++ b/Renamer.sln @@ -5,9 +5,14 @@ VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renamer.Front", "Renamer.Front\Renamer.Front.csproj", "{150E811C-2F2F-4FCD-B8DA-A66A03F34615}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renamer.Engine", "Renamer.Engine\Renamer.Engine.csproj", "{EE724D2B-3359-4189-8A7B-2E7B8C165B20}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renamer.Engine", "Renamer.Engine\Renamer.Engine.csproj", "{EE724D2B-3359-4189-8A7B-2E7B8C165B20}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renamer.Engine.UnitTest", "Renamer.Engine.UnitTest\Renamer.Engine.UnitTest.csproj", "{D70EB75F-654A-4294-9823-040A90060CCD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renamer.Engine.UnitTest", "Renamer.Engine.UnitTest\Renamer.Engine.UnitTest.csproj", "{D70EB75F-654A-4294-9823-040A90060CCD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C605DBC7-7F97-431E-9562-5C9B9DD59013}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution