示例#1
0
        static ArgumetsParseResults ParseArguments(string[] args)
        {
            ArgumetsParseResults results = new ArgumetsParseResults();

            results.Paths   = new List <string>();
            results.DoPause = true;
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("/help"))
                {
                    Console.WriteLine("/help\t\tthis help");
                    Console.WriteLine("/p <password>\t\tPassword");
                    Console.WriteLine("/iv <iv>\t\tInitialization vector");
                    Console.WriteLine("/out <path>\t\tOutput folder");
                    Console.WriteLine("/nosuspend\t\tApplication will exit immidiately");
                    Console.WriteLine("<...paths...>\t\tAll arguments without /<modifier> will be considered as input files and directories.");
                }
                else if (args[i].Equals("/nosuspend"))
                {
                    results.DoPause = false;
                }
                else if (args[i].Equals("/p"))
                {
                    i++;
                    results.Password = args[i];
                }
                else if (args[i].Equals("/iv"))
                {
                    i++;
                    results.Iv = args[i];
                }
                else if (args[i].Equals("/out"))
                {
                    i++;
                    results.OutputDirectory = args[i];
                }
                else
                {
                    results.Paths.Add(args[i]);
                }
            }

            return(results);
        }
示例#2
0
        static int Main(string[] args)
        {
            ConsoleLogger consoleLogger = new ConsoleLogger();
            LogReporter   reporter      = new LogReporter(consoleLogger);


            ArgumetsParseResults argParse = ParseArguments(args);
            string password = String.Empty, iv = String.Empty;

            if (argParse.Password == null)
            {
                password = RetreivePassword();
            }
            else
            {
                password = argParse.Password;
            }

            if (argParse.Iv == null)
            {
                iv = RetreiveIv();
            }
            else
            {
                iv = argParse.Iv;
            }

            IList <FileInfo> files;

            if (argParse.Paths != null && argParse.Paths.Count > 0)
            {
                files = GetFiles(argParse.Paths);
            }
            else
            {
                files = GetFilesFromConsole();
            }

            DirectoryInfo outputDir;

            if (argParse.OutputDirectory != null && !String.IsNullOrEmpty(argParse.OutputDirectory))
            {
                outputDir = new DirectoryInfo(argParse.OutputDirectory);
            }
            else
            {
                outputDir = new DirectoryInfo(Environment.CurrentDirectory);
            }

            CipherBoxProcessor processer = new CipherBoxProcessor(password, iv, outputDir, consoleLogger);

            processer.Logger   = consoleLogger;
            processer.Reporter = reporter;

            int errorCount = 0;
            int totalCount = 0;

            foreach (var file in files)
            {
                totalCount++;
                try
                {
                    processer.ProcessFile(file);
                }
                catch (Exception)
                {
                    errorCount++;
                }
            }

            Console.WriteLine("TOTAL: " + totalCount);
            Console.WriteLine("ERRORS: " + errorCount);

            Console.WriteLine("Finished");

            if (argParse.DoPause)
            {
                Console.ReadKey();
            }

            return(errorCount);
        }