示例#1
0
        public static DecryptorOptions GetAppSettingsOptions()
        {
            DecryptorOptions options = new DecryptorOptions();

            try
            {
                var appSettings = ConfigurationManager.AppSettings;
                options.InputPath    = appSettings["InputPath"] ?? "";
                options.DatabasePath = appSettings["DatabasePath"] ?? "";
                options.OutputPath   = appSettings["OutputPath"] ?? "";

                bool.TryParse(appSettings["CreateTranscript"], out bool _createTranscript);
                options.CreateTranscript = _createTranscript;

                bool.TryParse(appSettings["RemoveFolderAfterDecryption"], out bool _removeFolderAfterDecryption);
                options.RemoveFolderAfterDecryption = _removeFolderAfterDecryption;
            }
            catch (ConfigurationErrorsException)
            {
                Console.WriteLine("Error reading app settings");
            }

            return(options);
        }
示例#2
0
        public static DecryptorOptions ParseCommandLineArgs(string[] args)
        {
            DecryptorOptions 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 "/F":     // All Folders Mode
                    if (length - 1 > index)
                    {
                        options.InputPath = args[index + 1];
                        WriteToConsole("Start to decrypt all courses...", ConsoleColor.Yellow);
                    }
                    else
                    {
                        WriteToConsole("The directory path is missing..." + Environment.NewLine,
                                       ConsoleColor.Red);
                        throw new FileNotFoundException(
                                  "Directory path is missing or specified directory was not found!");
                    }
                    break;

                case "/DB":     // Use Database
                    options.UseDatabase = true;

                    if (length - 1 > index)
                    {
                        options.DatabasePath = args[index + 1];
                    }
                    break;

                case "/RM":     // Remove encrypted folder(s) after decryption
                    options.RemoveFolderAfterDecryption = true;
                    break;

                case "/OUT":     // Output Folder Path
                    options.UseOutputFolder = true;

                    if (args.Length - 1 > index)
                    {
                        options.OutputPath = args[index + 1];
                    }
                    break;

                case "/TRANS":     // Create Transcript If course supportted
                    options.CreateTranscript = true;
                    break;

                case "/HELP":     // Open command explaination
                    options.UsageCommand = true;
                    break;
                }

                index++;
            }

            return(options);
        }