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)); } }
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); }
private static void CheckFile(LocalArch localArch, ArchOptions archOptions) { localArch.Check(archOptions.SourceFilename, archOptions.Password, archOptions.BufferSize); }
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); }
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); } }