public void PruneEncryptedDirectory(EncryptOptions options, IOutputHandler outputHandler) { outputHandler.WriteVerboseLine(); outputHandler.WriteVerbose("Pruning files"); int count = 0; var fileNames = CreateFileList(options.SourceDir, options.IgnoreFilePath); var validFiles = EncryptOperationFactory.Build(options.SourceDir, fileNames, options.BinaryKey[0], options.Levels).Select(x => x.EncFileName); var validHashes = new HashSet <string>(validFiles.Select(Path.GetFileName)); foreach (var file in _fileSource.GetFilesRecursive(options.DestinationDir)) { var fileName = Path.GetFileName(file); if (!string.IsNullOrWhiteSpace(fileName) && !validHashes.Contains(fileName)) { if (count == 0) { outputHandler.WriteVerboseLine(); } outputHandler.WriteVerboseLine("\t{0}", fileName); File.Delete(file); count++; } } outputHandler.WriteVerboseLine(count == 0 ? " (no files found)" : "Pruned " + count + " files"); }
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); }
public static long PerformDecryption(CommonOptions options, IOutputHandler outputHandler, string file, byte[] key) { outputHandler.WriteVerbose("{0} => ", file.Replace(options.SourceDir, "").TrimStart(new[] { Path.DirectorySeparatorChar })); var result = FileEncrypter.DecryptFile(options.DestinationDir, file, key); if (result.HasResult) { outputHandler.WriteVerboseLine(result.Result.Item1.Replace(options.DestinationDir, "").TrimStart(new[] { Path.DirectorySeparatorChar })); return(result.Result.Item2); } outputHandler.WriteLine("Failed to decrypt file! ({0})", result.ErrorMessage); return(0); }