示例#1
0
 private static void SetEncryption(ArchOptions archOptions, string value)
 {
     var parts = value.Split(':');
     if (2 != parts.Length)
     {
         throw new ArgumentException(value);
     }
     string method = parts[0];
     OptionValidators.ValidateContains("method", method, Enum.GetNames(typeof(ZipEncryptionMethod)));
     string password = parts[1];
     if (string.IsNullOrEmpty(password))
     {
         throw new ArgumentException("Invalid password.");
     }
     archOptions.EncryptionMethod =  (ZipEncryptionMethod)Enum.Parse(typeof(ZipEncryptionMethod), parts[0]);
     archOptions.Password = password;
 }
示例#2
0
        private static void Archive(ArchOptions archOptions)
        {
            if (false == File.Exists(archOptions.SourceFilename))
            {
                throw new FileNotFoundException("Archive source was not found", archOptions.SourceFilename);
            }

            var localArch = new LocalArch();
            var stopwatch = new Stopwatch();
            if (archOptions.MeasureTime)
            {
                stopwatch.Start();
            }

            ArchiveFile(localArch, archOptions);

            if (archOptions.MeasureTime)
            {
                stopwatch.Stop();
                Console.WriteLine(string.Format("Archive took {0} minutes ({1} seconds)",
                    stopwatch.Elapsed.TotalMinutes, stopwatch.Elapsed.TotalSeconds));
            }
        }
示例#3
0
 private static void SetCustomParameter(ArchOptions archOptions, string value)
 {
     var parts = value.Split('=');
     if (2 != parts.Length)
     {
         throw new ArgumentException(value);
     }
     archOptions.CustomParameters[parts[0]] = parts[1];
 }
示例#4
0
 private static void SetDecompress(ArchOptions archOptions, string password)
 {
     archOptions.Decompress = true;
     archOptions.Password = password;
 }
示例#5
0
 private static ArchOptions ParseArgs(string[] args)
 {
     var archOptions = new ArchOptions();
     archOptions.SourceFilename = args[0];
     OptionValidators.ValidatePath("source filename", archOptions.SourceFilename);
     Program.ArchOptionDescriptorSet.Apply(archOptions, args.Skip(1));
     return archOptions;
 }
示例#6
0
 private static void DecompressFile(LocalArch localArch, ArchOptions archOptions, FileMode fileMode)
 {
     if ((false == string.IsNullOrEmpty(archOptions.OutputFilename)) &&
         (false == Directory.Exists(archOptions.OutputFilename)))
     {
         throw new DirectoryNotFoundException(archOptions.OutputFilename);
     }
     localArch.Decompress(archOptions.SourceFilename, archOptions.OutputFilename, fileMode,
         archOptions.Password, archOptions.BufferSize, archOptions.PreallocationPercent);
 }
示例#7
0
 private static void CompressFile(LocalArch localArch, ArchOptions archOptions, FileMode fileMode)
 {
     string targetFilename = archOptions.OutputFilename;
     string extension = archOptions.ArchiveFormat.GetExtension();
     if (string.IsNullOrEmpty(targetFilename))
     {
         targetFilename = Path.ChangeExtension(Path.GetFileName(archOptions.SourceFilename), extension);
     }
     else if (Directory.Exists(targetFilename))
     {
         targetFilename = Path.Combine(targetFilename, Path.ChangeExtension(
             Path.GetFileName(archOptions.SourceFilename), extension));
     }
     localArch.Compress(archOptions.SourceFilename, targetFilename, fileMode,
         archOptions.ArchiveFormat, archOptions.CompressionMethod, archOptions.CompressionLevel,
         archOptions.EncryptionMethod, archOptions.Password, archOptions.BufferSize,
         archOptions.PreallocationPercent, archOptions.Check, archOptions.CustomParameters);
 }
示例#8
0
 private static void CheckFile(LocalArch localArch, ArchOptions archOptions)
 {
     localArch.Check(archOptions.SourceFilename, archOptions.Password, archOptions.BufferSize);
 }
示例#9
0
        private static void ArchiveFile(LocalArch localArch, ArchOptions archOptions)
        {
            FileMode fileMode = FileMode.Create;
            if (false == archOptions.Overwrite)
            {
                fileMode = FileMode.CreateNew;
            }

            if (archOptions.Decompress)
            {
                if (archOptions.Check)
                {
                    CheckFile(localArch, archOptions);
                }
                else
                {
                    DecompressFile(localArch, archOptions, fileMode);
                }
            }
            else
            {
                CompressFile(localArch, archOptions, fileMode);
            }
        }