Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        public static void Encrypt(EncryptOptions options, IOutputHandler outputHandler)
        {
            var helper = new EncryptCommandHelper();

            PerformCommand(options, outputHandler, "Encryption", () => helper.GenerateEncryptionFileList(options), helper.PerformEncryption);
            if (options.Prune)
            {
                helper.PruneEncryptedDirectory(options, outputHandler);
            }
        }
Ejemplo n.º 3
0
        public IList <EncryptOperation> GenerateEncryptionFileList(EncryptOptions options)
        {
            var fileNames = CreateFileList(options.SourceDir, options.IgnoreFilePath);
            var files     = EncryptOperationFactory.Build(options.SourceDir, fileNames, options.BinaryKey[0], options.Levels).ToList();

            if (!options.Force)
            {
                files = files.Where(x => IsSourceFileNewer(x.FileName, Path.Combine(options.DestinationDir, x.EncFileName))).ToList();
            }
            return(files);
        }
        public static IList <string> Validate(EncryptOptions options)
        {
            var retVal = new List <string>();

            if (options.Levels < 0 || options.Levels > 5)
            {
                retVal.Add("Directory level is outside valid range (0-5)");
            }

            retVal.AddRange(Validate(options as CommonOptions));
            return(retVal);
        }
        public static IList<string> Validate(EncryptOptions options)
        {
            var retVal = new List<string>();

            if (options.Levels < 0 || options.Levels > 5)
            {
                retVal.Add("Directory level is outside valid range (0-5)");
            }

            retVal.AddRange(Validate(options as CommonOptions));
            return retVal;
        }