diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8b0b175 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.cs] + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# Naming Conventions +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# New line preferences +csharp_new_line_before_open_brace = none +csharp_new_line_before_else = false +csharp_new_line_before_catch = false +csharp_new_line_before_finally = false + +# Wrapping preferences +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true + +# Switch case +csharp_indent_case_contents = true \ No newline at end of file diff --git a/Program.cs b/Program.cs index 32a5169..d0873c6 100644 --- a/Program.cs +++ b/Program.cs @@ -1,15 +1,19 @@ public class Program { static void Main(string[] args) { + Console.ForegroundColor = ConsoleColor.Red; if (args.Length == 0) { - Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please specify an option."); - Console.ResetColor(); - Console.WriteLine("Options are: checksum, countmd5, deletemd5, compareChecksums"); - } else { - switch(args[0]) { + PrintAvailableOptions(); + return; + } else if (args.Length > 1) { + Console.WriteLine("Too many options."); + return; + } + + Console.ForegroundColor = ConsoleColor.Green; + switch (args[0]) { case "checksum": - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting the checksum process."); Console.ResetColor(); @@ -17,10 +21,8 @@ Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Checksum process finished"); - Console.ResetColor(); break; case "countmd5": - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Counting md5 checksum files."); Console.ResetColor(); @@ -28,10 +30,8 @@ Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Finished counting all md5 checksum files."); - Console.ResetColor(); break; case "deletemd5": - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Deleting all md5 checksum files."); Console.ResetColor(); @@ -39,15 +39,38 @@ Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Deleted all md5 checksum files."); - Console.ResetColor(); break; case "compareChecksums": + Console.WriteLine("Comparing all md5 checksum files. If there is none, creating one."); + Console.ResetColor(); + Chksum.compareChecksums(); break; - default: + case "help": + PrintAvailableOptions(); + break; + default: + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Invalid option. Maybe you mistyped it?"); + PrintAvailableOptions(); break; - } } + } + static void PrintAvailableOptions() { + String[] options = { + "checksum", + "countmd5", + "deletemd5", + "compareChecksums", + "help" + }; + + Console.ResetColor(); + Console.WriteLine("usage: chksum [option]"); + Console.WriteLine("Here is a list of all available options:"); + foreach (String option in options) { + Console.WriteLine("\t" + option); + } } } \ No newline at end of file diff --git a/chksum.cs b/chksum.cs index fcb7bf5..06af796 100644 --- a/chksum.cs +++ b/chksum.cs @@ -20,10 +20,8 @@ public class Chksum { // } private static string CalculateMD5(string filename) { - using (var md5 = System.Security.Cryptography.MD5.Create()) - { - using (var stream = File.OpenRead(filename)) - { + using (var md5 = System.Security.Cryptography.MD5.Create()) { + using (var stream = File.OpenRead(filename)) { var hash = md5.ComputeHash(stream); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } @@ -110,5 +108,4 @@ public class Chksum { compareChecksums(); } } - } \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 0000000..d9be799 --- /dev/null +++ b/justfile @@ -0,0 +1,2 @@ +publish: + @dotnet publish --configuration Release chksum.csproj