示例#1
0
        private void Add(string internalPath, byte[] uncompressed, DateTime fileTime)
        {
            var file   = Regex.Match(internalPath, "[^\\\\]+$").Value;
            var folder = internalPath.Substring(0, internalPath.Length - file.Length);

            foreach (var entry in this.entries.Keys.Where(entry => entry.Folder == folder && entry.File == file).ToArray())
            {
                this.Remove(entry);
            }

            var compressed     = Compression.Compress(uncompressed);
            var sizeCompressed = compressed.Length < uncompressed.Length ? compressed.Length : 0;

            var offset = (long)Dat.BlockSize;

            foreach (var entry in this.idx.Entries.OrderBy(entry => entry.Offset))
            {
                if (offset + (sizeCompressed == 0 ? uncompressed.Length : sizeCompressed) < entry.Offset)
                {
                    break;
                }

                offset = (entry.Offset + (entry.SizeCompressed == 0 ? entry.SizeUncompressed : entry.SizeCompressed) + Dat.BlockSize - 1)
                         / Dat.BlockSize
                         * Dat.BlockSize;
            }

            var idxEntry = new IdxEntry(
                folder,
                file,
                offset,
                uncompressed.Length,
                sizeCompressed,
                new SHA1Managed().ComputeHash(uncompressed).Take(8).ToArray(),
                fileTime,
                uncompressed.Take(8).ToArray()
                );

            this.dat.Write(offset, sizeCompressed == 0 ? uncompressed : compressed);
            this.idx.Add(idxEntry);
            this.entries.Add(new ContainerEntry(this.dat, idxEntry), idxEntry);
            this.Trim();
        }
示例#2
0
 public ContainerEntry(Dat dat, IdxEntry idxEntry)
 {
     this.dat      = dat;
     this.idxEntry = idxEntry;
 }
示例#3
0
 public void Remove(IdxEntry entry)
 {
     this.entries.Remove(entry);
     this.IsDirty = true;
 }
示例#4
0
 public void Add(IdxEntry entry)
 {
     this.entries.Add(entry);
     this.IsDirty = true;
 }