public long PerformEncryption(CommonOptions options, IOutputHandler outputHandler, EncryptOperation o, byte[] key) { outputHandler.WriteVerbose("\t{0} => ", o.RelFileName); var result = FileEncrypter.EncryptFile(options.DestinationDir, o, key); if (result.HasResult) { outputHandler.WriteVerboseLine(o.EncFileName); return(result.Result.Item2); } outputHandler.WriteVerboseOrNormalLine("\t{0} => Failed to encrypt file! ({1})", "Failed to encrypt file! ({1})", o.RelFileName, result.ErrorMessage); return(0); }
private static void PerformCommand <T>(CommonOptions options, IOutputHandler outputHandler, string action, Func <IList <T> > fileList, Func <CommonOptions, IOutputHandler, T, byte[], long> operation) { outputHandler.Write("{0} started", action); var sw = Stopwatch.StartNew(); var files = fileList(); if (files == null || files.Count == 0) { outputHandler.WriteLine(" (no files found)"); return; } outputHandler.WriteVerboseOrNormalLine("", " ({0} files)", files.Count); var totalSize = files.Sum(o => operation(options, outputHandler, o, options.BinaryKey)); sw.Stop(); if (totalSize != 0) { if (options.Verbose) { var avgSpeed = "--"; var elapsedSecs = sw.ElapsedMilliseconds / 1000; totalSize = totalSize / (1024 * 1024); if (totalSize != 0 && elapsedSecs != 0) { avgSpeed = (totalSize / elapsedSecs).ToString(CultureInfo.InvariantCulture); } outputHandler.WriteVerboseLine("{0} of {1} files complete ({2}MB in {3:hh\\:mm\\:ss}, avg {4}MB/s)", action, files.Count, totalSize, sw.Elapsed, avgSpeed); } else { outputHandler.WriteLine("{0} of {1} files complete", action, files.Count); } } }