Example #1
0
        private static void CreateAssetPatch(Settings settings, IBSA original, Fo3File originalRecord, Fo3File resultRecord, RecordAction recordAction)
        {
            string patchName;
            string patchFile;

            // @todo: memory stream and name with md5
            using (var patchStream = new MemoryStream())
            {
                // @todo: lock
                byte[] originalRecordBytes;
                if (original != null)
                {
                    lock (original)
                    {
                        originalRecordBytes = originalRecord.GetData(original.Reader);
                    }
                }
                else
                {
                    originalRecordBytes = originalRecord.GetData();
                }
                var referenceBytes = resultRecord.GetData();
                BsDiff.Create(originalRecordBytes, referenceBytes, patchStream);

                patchStream.Seek(0, SeekOrigin.Begin);
                patchName = new Guid(MD5.Create().ComputeHash(patchStream)).ToString();
                recordAction.PatchName = patchName;
                patchFile = string.Format("{0}\\{1}.patch", settings.GetTempFolder("Patches"), patchName);

                try
                {
                    using (var fileStream = new FileStream(patchFile, FileMode.CreateNew))
                    {
                        patchStream.Seek(0, SeekOrigin.Begin);
                        patchStream.CopyTo(fileStream);
                    }
                }
                catch (IOException exc)
                {
                    // ignored
                }
            }
        }