Ejemplo n.º 1
0
        private static void BuildMasterPatch(string esm, ILookup <string, string> knownEsmVersions)
        {
            var fixPath = Path.Combine(OutDir, Path.ChangeExtension(esm, ".pat"));

            if (File.Exists(fixPath))
            {
                return;
            }

            var ttwESM   = Path.Combine(_dirTTWMain, esm);
            var ttwBytes = File.ReadAllBytes(ttwESM);
            var ttwChk   = new FileValidation(ttwBytes);

            var altVersions = knownEsmVersions[esm].ToList();

            var patches =
                altVersions.Select(dataESM =>
            {
                var dataBytes = File.ReadAllBytes(dataESM);
                byte[] patchBytes;

                using (var msPatch = new MemoryStream())
                {
                    MakeDiff.Create(dataBytes, ttwBytes, Diff.SIG_LZDIFF41, msPatch);
                    patchBytes = msPatch.ToArray();
                }

                return(new PatchInfo
                {
                    Metadata = new FileValidation(dataESM),
                    Data = patchBytes
                });
            })
                .AsParallel()
                .ToArray();

            var patchDict = new PatchDict(altVersions.Count);

            patchDict.Add(esm, new Patch(ttwChk, patches));

            using (var fixStream = File.OpenWrite(fixPath))
                patchDict.WriteAll(fixStream);
        }
Ejemplo n.º 2
0
        static unsafe byte[] GetDiff(string diffPath, long convertSignature = -1, bool moveToUsed = false)
        {
            if (File.Exists(diffPath))
            {
                try
                {
                    var diffBytes = File.ReadAllBytes(diffPath);
                    if (convertSignature > 0)
                        fixed(byte *pBz2 = diffBytes)
                        return(MakeDiff.ConvertPatch(pBz2, diffBytes.Length, Diff.SIG_BSDIFF40, convertSignature));

                    return(diffBytes);
                }
                finally
                {
                    if (moveToUsed)
                    {
                        File.Move(diffPath, Path.ChangeExtension(diffPath, ".used"));
                    }
                }
            }

            return(null);
        }