示例#1
0
        private void UpdateCache(Session s, BinaryReader r, DatFile.Mft mft, CustomEntry c)
        {
            using (var w = new BinaryWriter(r.BaseStream))
            {
                var entry = mft.entries[INDEX_ENTRIES];

                //write the data
                w.BaseStream.Position = mft.entries[c.index].offset;
                var size = c.WriteTo(w.BaseStream, s.compressor);

                if (size != c.entry.size)
                {
                    //rewrite the size of the entry
                    w.BaseStream.Position = entry.offset + (c.index + 1) * 24 + 8;
                    w.Write(size);

                    //note that although the data for this entry has changed, the crc hasn't due to how it's calculated

                    //calculate the crc of the main entry
                    r.BaseStream.Position = entry.offset;
                    var buffer = r.ReadBytes(entry.size);

                    var crc32 = new Crc32();

                    for (var i = 0; i < buffer.Length; i++)
                    {
                        if (i < 72 || i >= 96) //skip 3rd entry
                        {
                            crc32.Add(buffer[i]);
                        }
                    }

                    //rewrite the crc
                    w.BaseStream.Position = entry.offset + (INDEX_ENTRIES + 1) * 24 + 20;
                    w.Write(crc32.CRC);
                }
            }
        }