Commandline args && New features
chksum can now take arguments to execute diffrent functions functions include checksumming, counting all checksums, deleting all checksums
This commit is contained in:
parent
2a8bf7e8fe
commit
454717431f
51
Program.cs
51
Program.cs
@ -1,15 +1,50 @@
|
|||||||
public class Program {
|
public class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Console.WriteLine("Starting the checksum process.");
|
|
||||||
Console.ResetColor();
|
|
||||||
|
|
||||||
Chksum.doTheThing();
|
if (args.Length == 0) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("Please specify an option.");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.WriteLine("Options are: checksum, countmd5, deletemd5");
|
||||||
|
} else {
|
||||||
|
switch(args[0]) {
|
||||||
|
case "checksum":
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("Starting the checksum process.");
|
||||||
|
Console.ResetColor();
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Chksum.doTheThing();
|
||||||
Console.WriteLine("Checksum process finished");
|
|
||||||
Console.ResetColor();
|
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();
|
||||||
|
|
||||||
|
Chksum.countAllMd5Checksums();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
Chksum.deleteAllMd5Checksums();
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("Deleted all md5 checksum files.");
|
||||||
|
Console.ResetColor();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
25
chksum.cs
25
chksum.cs
@ -48,9 +48,32 @@ public class Chksum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTotalFileCount() {
|
private static int getTotalFileCount() {
|
||||||
int totalFileCount = Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories).Length;
|
int totalFileCount = Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories).Length;
|
||||||
return totalFileCount - 1; // Remove the program from the totalFileCount
|
return totalFileCount - 1; // Remove the program from the totalFileCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void countAllMd5Checksums() {
|
||||||
|
int totalMD5FileCount = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.md5", SearchOption.AllDirectories).Length;
|
||||||
|
Console.WriteLine("There are " + totalMD5FileCount + " md5 checksums");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteAllMd5Checksums() {
|
||||||
|
foreach (var directory in Directory.GetDirectories(Directory.GetCurrentDirectory())) {
|
||||||
|
Directory.SetCurrentDirectory(directory); // Set new root
|
||||||
|
if (getFileCount() >= 1) {
|
||||||
|
DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||||
|
FileInfo[] files = dir.GetFiles();
|
||||||
|
foreach (FileInfo file in files) {
|
||||||
|
string fileName = file.Name;
|
||||||
|
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
||||||
|
string checksumFile = Directory.GetCurrentDirectory() + "/" + fileNameWithoutExtension + ".md5";
|
||||||
|
File.Delete(checksumFile);
|
||||||
|
Console.WriteLine("Deleted " + checksumFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deleteAllMd5Checksums();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user