Ejemplo n.º 1
0
        public void Apply(Stream basisFileStream, IDeltaReader delta, Stream outputStream)
        {
            delta.Apply(
                writeData: (data) => outputStream.Write(data, 0, data.Length),
                copy: (startPosition, length) =>
            {
                basisFileStream.Seek(startPosition, SeekOrigin.Begin);

                var buffer = new byte[4 * 1024 * 1024];
                int read;
                long soFar = 0;
                while ((read = basisFileStream.Read(buffer, 0, (int)Math.Min(length - soFar, buffer.Length))) > 0)
                {
                    soFar += read;
                    outputStream.Write(buffer, 0, read);
                }
            });

            if (!SkipHashCheck)
            {
                outputStream.Seek(0, SeekOrigin.Begin);

                var sourceFileHash = delta.ExpectedHash;
                var algorithm      = delta.HashAlgorithm;

                var actualHash = algorithm.ComputeHash(outputStream);

                if (!BinaryComparer.CompareArray(sourceFileHash, actualHash))
                {
                    throw new UsageException("Verification of the patched file failed. The SHA1 hash of the patch result file, and the file that was used as input for the delta, do not match. This can happen if the basis file changed since the signatures were calculated.");
                }
            }
        }
Ejemplo n.º 2
0
        public void Apply(Stream basisFileStream, IDeltaReader delta, Stream outputStream)
        {
            delta.Apply(
                writeData: (data) => outputStream.Write(data, 0, data.Length),
                copy: (startPosition, length) =>
                {
                    basisFileStream.Seek(startPosition, SeekOrigin.Begin);

                    var buffer = new byte[4*1024*1024];
                    int read;
                    do
                    {
                        read = basisFileStream.Read(buffer, 0, buffer.Length);

                        outputStream.Write(buffer, 0, read);
                    } while (read > 0);
                });

            if (!SkipHashCheck)
            {
                outputStream.Seek(0, SeekOrigin.Begin);

                var sourceFileHash = delta.ExpectedHash;
                var algorithm = delta.HashAlgorithm;

                var actualHash = algorithm.ComputeHash(outputStream);

                if (!StructuralComparisons.StructuralEqualityComparer.Equals(sourceFileHash, actualHash))
                    throw new UsageException("Verification of the patched file failed. The SHA1 hash of the patch result file, and the file that was used as input for the delta, do not match. This can happen if the basis file changed since the signatures were calculated.");
            }
        }
Ejemplo n.º 3
0
        public void Apply(Stream basisFileStream, IDeltaReader delta, Stream outputStream)
        {
            var buffer = new byte[readBufferSize];

            delta.Apply(
                writeData: (data) => outputStream.Write(data, 0, data.Length),
                copy: (startPosition, length) =>
            {
                basisFileStream.Seek(startPosition, SeekOrigin.Begin);

                int read;
                long soFar = 0;
                while ((read = basisFileStream.Read(buffer, 0, (int)Math.Min(length - soFar, buffer.Length))) > 0)
                {
                    soFar += read;
                    outputStream.Write(buffer, 0, read);
                }
            });

            if (!SkipHashCheck)
            {
                if (!HashCheck(delta, outputStream))
                {
                    throw new InvalidDataException(
                              $"Verification of the patched file failed. The {delta.HashAlgorithm.Name} hash of the patch result file, and the file that was used as input for the delta, do not match. This can happen if the basis file changed since the signatures were calculated.");
                }
            }
        }
Ejemplo n.º 4
0
        public void Apply(Stream basisFileStream, IDeltaReader delta, Stream outputStream, IProgressReporter progressReporter)
        {
            delta.Apply(
                writeData: (data, len) => outputStream.Write(data, 0, len),
                copy: (startPosition, length, buffer) =>
            {
                basisFileStream.Seek(startPosition, SeekOrigin.Begin);

                int read;
                long soFar = 0;
                while ((read = basisFileStream.Read(buffer, 0, (int)Math.Min(length - soFar, buffer.Length))) > 0)
                {
                    soFar += read;
                    outputStream.Write(buffer, 0, read);
                }
            });

            if (delta.FileSize != outputStream.Length)
            {
                throw new UsageException("Verification of the patched file failed. The hash of the patch result file, and the file that was used as input for the delta, do not match. This can happen if the basis file changed since the signatures were calculated.");
            }

            if (!SkipHashCheck)
            {
                outputStream.Seek(0, SeekOrigin.Begin);

                var sourceFileHash = delta.ExpectedHash;
                var algorithm      = delta.HashAlgorithm;
                var actualHash     = algorithm.ComputeHash(outputStream, progressReporter);
//                var actualHash2 = algorithm.ComputeHash(outputStream);

                if (!Enumerable.SequenceEqual(sourceFileHash, actualHash))
                {
                    throw new UsageException("Verification of the patched file failed. The hash of the patch result file, and the file that was used as input for the delta, do not match. This can happen if the basis file changed since the signatures were calculated.");
                }
            }
        }