/// <summary> /// Constructs an object with decryptor options</br> /// If specified this constructor inits the database /// </summary> /// <param name="options"></param> public Decryptor(DecryptorOptions options) : this() { Options = options; if (options.UseDatabase) { Options.UseDatabase = InitDB(options.DatabasePath); } }
static void Main(string[] args) { Decryptor decryptor; DecryptorOptions decryptorOptions = new DecryptorOptions(); try { decryptorOptions = ParseCommandLineArgs(args); decryptor = new Decryptor(decryptorOptions); if (decryptorOptions.UsageMode == Mode.None) { Usage(); goto End; } else if (decryptorOptions.RemoveFilesAfterDecryption) { WriteToConsole("[ARGS] Removing files after decryption." + Environment.NewLine, ConsoleColor.Yellow); WriteToConsole("[ARGS] Press any key to continue or CTRL + C to break..." + Environment.NewLine, ConsoleColor.Yellow); Console.ReadKey(); } decryptor.InitDecryptor(ENCRYPTION_KEY); if (decryptorOptions.UsageMode == Mode.Folder) { decryptor.DecryptAll(decryptorOptions.InputPath, decryptorOptions.OutputPath); } else if (decryptorOptions.UsageMode == Mode.File) { decryptor.Decrypt(decryptorOptions.InputPath, decryptorOptions.OutputPath); } } catch (Exception e) { WriteToConsole("[START] Error occured: " + e.Message + Environment.NewLine, ConsoleColor.Red); Usage(); } End: WriteToConsole(Environment.NewLine + "Press any key to exit the program..."); Console.ReadKey(); }
public static DecryptorOptions ParseCommandLineArgs(string[] args) { var options = new DecryptorOptions(); int index = 0; int length = args.Length; foreach (string arg in args) { if (string.IsNullOrWhiteSpace(arg)) { index++; continue; } switch (arg.ToUpper()) { case "/D": // Directory Mode if (length - 1 > index && Directory.Exists(args[index + 1])) { options.InputPath = args[index + 1]; options.UsageMode = Mode.Folder; WriteToConsole("[ARGS] Changing mode to Folder decryption!", ConsoleColor.Yellow); } else { WriteToConsole("[ARGS] The directory path is missing..." + Environment.NewLine, ConsoleColor.Red); throw new FileNotFoundException("Directory path is missing or specified directory was not found!"); } break; case "/F": // File Mode if (length - 1 > index && File.Exists(args[index + 1])) { options.InputPath = args[index + 1]; if (length - 1 > index + 1 && !string.IsNullOrWhiteSpace(args[index + 2])) { if (File.Exists(args[index + 2])) { throw new IOException("File already exists: " + args[index + 2]); } options.OutputPath = args[index + 2]; } else { throw new FormatException("Output file path is missing..."); } options.UsageMode = Mode.File; WriteToConsole("[ARGS] Changing mode to Single decryption!", ConsoleColor.Yellow); } else { throw new FileNotFoundException("Input file is missing or not specified!"); } break; case "/DB": // Use Database options.UseDatabase = true; if (length - 1 > index && File.Exists(args[index + 1])) { options.DatabasePath = args[index + 1]; } break; case "/RM": // Remove encrypted files after decryption options.RemoveFilesAfterDecryption = true; break; case "/OUT": options.UseOutputFolder = true; if (args.Length - 1 > index) { options.OutputFolder = args[index + 1]; } break; } index++; } return(options); }