コード例 #1
0
        public int Execute(string[] commandLineArguments)
        {
            options.Parse(commandLineArguments);

            if (StringOperators.IsNullOrWhiteSpace(signatureFilePath))
            {
                throw new OptionException("No signature file was specified", "new-file");
            }
            if (StringOperators.IsNullOrWhiteSpace(newFilePath))
            {
                throw new OptionException("No new file was specified", "new-file");
            }

            newFilePath       = Path.GetFullPath(newFilePath);
            signatureFilePath = Path.GetFullPath(signatureFilePath);

            var delta = new DeltaBuilder();

            foreach (var config in configuration)
            {
                config(delta);
            }

            if (!File.Exists(signatureFilePath))
            {
                throw new FileNotFoundException("File not found: " + signatureFilePath, signatureFilePath);
            }

            if (!File.Exists(newFilePath))
            {
                throw new FileNotFoundException("File not found: " + newFilePath, newFilePath);
            }

            if (StringOperators.IsNullOrWhiteSpace(deltaFilePath))
            {
                deltaFilePath = newFilePath + ".octodelta";
            }
            else
            {
                deltaFilePath = Path.GetFullPath(deltaFilePath);
                var directory = Path.GetDirectoryName(deltaFilePath);
                if (directory != null && !Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
            }

            using (var newFileStream = new FileStream(newFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var signatureStream = new FileStream(signatureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var deltaStream = new FileStream(deltaFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        delta.BuildDelta(newFileStream, new SignatureReader(signatureStream, delta.ProgressReporter), new AggregateCopyOperationsDecorator(new BinaryDeltaWriter(deltaStream)));
                    }

            return(0);
        }
コード例 #2
0
        void PrintCommandHelp(string executable, ICommand command, ICommandMetadata commandMetadata, string commandName)
        {
            //Console.ResetColor();
            Console.Write("Usage: ");
            //Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(executable + " " + commandName + (!StringOperators.IsNullOrWhiteSpace(commandMetadata.Usage) ? " " + commandMetadata.Usage : "") + " [<options>]");
            // Console.ResetColor();
            Console.WriteLine();
            command.GetHelp(Console.Out);

            Console.WriteLine();
        }
コード例 #3
0
        public int Execute(string[] commandLineArguments)
        {
            options.Parse(commandLineArguments);

            if (StringOperators.IsNullOrWhiteSpace(basisFilePath))
            {
                throw new OptionException("No basis file was specified", "basis-file");
            }
            if (StringOperators.IsNullOrWhiteSpace(deltaFilePath))
            {
                throw new OptionException("No delta file was specified", "delta-file");
            }
            if (StringOperators.IsNullOrWhiteSpace(newFilePath))
            {
                throw new OptionException("No new file was specified", "new-file");
            }

            basisFilePath = Path.GetFullPath(basisFilePath);
            deltaFilePath = Path.GetFullPath(deltaFilePath);
            newFilePath   = Path.GetFullPath(newFilePath);

            if (!File.Exists(basisFilePath))
            {
                throw new FileNotFoundException("File not found: " + basisFilePath, basisFilePath);
            }
            if (!File.Exists(deltaFilePath))
            {
                throw new FileNotFoundException("File not found: " + deltaFilePath, deltaFilePath);
            }

            var directory = Path.GetDirectoryName(newFilePath);

            if (directory != null && !Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var delta = new DeltaApplier
            {
                SkipHashCheck = skipHashCheck
            };

            using (var basisStream = new FileStream(basisFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var deltaStream = new FileStream(deltaFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var newFileStream = new FileStream(newFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                    {
                        delta.Apply(basisStream, new BinaryDeltaReader(deltaStream, progressReporter), newFileStream);
                    }

            return(0);
        }
コード例 #4
0
        public int Execute(string[] commandLineArguments)
        {
            options.Parse(commandLineArguments);

            if (StringOperators.IsNullOrWhiteSpace(basisFilePath))
            {
                throw new OptionException("No basis file was specified", "basis-file");
            }

            basisFilePath = Path.GetFullPath(basisFilePath);

            var signatureBuilder = new SignatureBuilder();

            foreach (var config in configuration)
            {
                config(signatureBuilder);
            }

            if (!File.Exists(basisFilePath))
            {
                throw new FileNotFoundException("File not found: " + basisFilePath, basisFilePath);
            }

            if (StringOperators.IsNullOrWhiteSpace(signatureFilePath))
            {
                signatureFilePath = basisFilePath + ".octosig";
            }
            else
            {
                signatureFilePath = Path.GetFullPath(signatureFilePath);
                var sigDirectory = Path.GetDirectoryName(signatureFilePath);
                if (sigDirectory != null && !Directory.Exists(sigDirectory))
                {
                    Directory.CreateDirectory(sigDirectory);
                }
            }

            using (var basisStream = new FileStream(basisFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var signatureStream = new FileStream(signatureFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    signatureBuilder.Build(basisStream, new SignatureWriter(signatureStream));
                }

            return(0);
        }
コード例 #5
0
        public int Execute(string[] commandLineArguments)
        {
            options.Parse(commandLineArguments);

            if (StringOperators.IsNullOrWhiteSpace(deltaFilePath))
            {
                throw new OptionException("No delta file was specified", "delta-file");
            }

            deltaFilePath = Path.GetFullPath(deltaFilePath);

            if (!File.Exists(deltaFilePath))
            {
                throw new FileNotFoundException("File not found: " + deltaFilePath, deltaFilePath);
            }

            using (var deltaStream = new FileStream(deltaFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var reader = new BinaryDeltaReader(deltaStream, new NullProgressReporter());

                reader.Apply(data =>
                {
                    if (data.Length > 20)
                    {
                        Console.WriteLine("Data: ({0} bytes): {1}...", data.Length,
                                          BitConverter.ToString(data.Take(20).ToArray()));
                    }
                    else
                    {
                        Console.WriteLine("Data: ({0} bytes): {1}", data.Length, BitConverter.ToString(data.ToArray()));
                    }
                },
                             (start, offset) => Console.WriteLine("Copy: {0:X} to {1:X}", start, offset));
            }

            return(0);
        }