Exemple #1
0
        public static void Main(string[] args)
        {
            DisplayHeader();
            Stopwatch stw = new Stopwatch();

            stw.Start();

            if (args == null || args.Length < 2)
            {
                DisplayHelp();
            }
            else
            {
                string action = args[0].ToLower();

                switch (action)
                {
                case ACTION_SPLIT:
                    if (args.Length < 4)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath    = args[2];
                        string destPath      = SuffixPath(args[3]);
                        int    splitSizeInMb = 1024;
                        int.TryParse(args[1], out splitSizeInMb);
                        Splitter.Split(splitSizeInMb, sourcePath, destPath);
                    }
                    break;

                case ACTION_ASSEMBLE:
                    if (args.Length < 3)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath = args[1];
                        string destPath   = SuffixPath(args[2]);
                        Splitter.Assemble(sourcePath, destPath);
                    }
                    break;

                case ACTION_CRYPT:
                    if (args.Length < 4)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath = args[2];
                        string destPath   = args[3];
                        SetEncryptionKey(args[1]);
                        DisplayInfo(action, sourcePath, destPath);
                        if (Directory.Exists(sourcePath))
                        {
                            sourcePath = SuffixPath(sourcePath);
                        }
                        Crypter.Crypt(sourcePath, destPath);
                    }
                    break;

                case ACTION_DECRYPT:
                    if (args.Length < 4)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath = args[2];
                        string destPath   = SuffixPath(args[3]);
                        SetEncryptionKey(args[1]);
                        DisplayInfo(action, sourcePath, destPath);
                        Crypter.Decrypt(sourcePath, destPath);
                    }
                    break;

                case ACTION_LIST:
                    if (args.Length < 3)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath = args[2];
                        string destPath   = null;
                        if (args.Length == 4)
                        {
                            destPath = args[3];
                        }
                        SetEncryptionKey(args[1]);
                        DisplayInfo(action, sourcePath, destPath);
                        Crypter.List(sourcePath, destPath);
                    }
                    break;

                case ACTION_LISTALL:
                    if (args.Length < 3)
                    {
                        DisplayHelp();
                    }
                    else
                    {
                        string sourcePath = args[2];
                        string destPath   = null;
                        if (args.Length == 4)
                        {
                            destPath = args[3];
                        }
                        SetEncryptionKey(args[1]);
                        DisplayInfo(action, sourcePath, destPath);
                        Crypter.ListAll(sourcePath, destPath);
                    }
                    break;

                default:
                    DisplayHelp();
                    break;
                }
            }

            stw.Stop();
            DisplayFinish(stw.Elapsed);
            Console.ReadLine();
        }