Exemple #1
0
        public XDeltaPatch(byte[] source, byte[] target)
        {
            OriginalFilesize = source.Length;
            PatchedFilesize  = target.Length;

            // TODO: Change this ASAP when I compile the DLLs for XDelta, replace this executable call with a library link, which
            // will be a thousand times faster, specially on PCs with old HDDs.

            var targetFilename = Path.GetTempFileName();
            var sourceFilename = Path.GetTempFileName();
            var patchFilename  = Path.GetTempFileName();

            {
                using var targetFile = File.OpenWrite(targetFilename);
                targetFile.Write(target, 0, target.Length);
                using var sourceFile = File.OpenWrite(sourceFilename);
                sourceFile.Write(source, 0, source.Length);
            }

            XDelta.CreatePatch(targetFilename, sourceFilename, patchFilename);

            using var patchFile = File.OpenRead(patchFilename);
            Data = new byte[patchFile.Length];
            patchFile.Read(Data, 0, (int)patchFile.Length);
        }
Exemple #2
0
        public byte[] Apply(byte[] source)
        {
            // TODO: Change this ASAP when I compile the DLLs for XDelta, replace this executable call with a library link, which
            // will be a thousand times faster, specially on PCs with old HDDs.

            var patchFilename  = Path.GetTempFileName();
            var sourceFilename = Path.GetTempFileName();
            var resultFilename = Path.GetTempFileName();

            {
                using var patchFile = File.OpenWrite(patchFilename);
                patchFile.Write(Data, 0, Data.Length);
                using var sourceFile = File.OpenWrite(sourceFilename);
                sourceFile.Write(source, 0, source.Length);
            }


            XDelta.ApplyPatch(patchFilename, sourceFilename, resultFilename);

            using var resultFile = File.OpenRead(resultFilename);
            byte[] resultData = new byte[resultFile.Length];
            resultFile.Read(resultData, 0, (int)resultFile.Length);
            return(resultData);
        }