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(); }
public ContainerEntry(Dat dat, IdxEntry idxEntry) { this.dat = dat; this.idxEntry = idxEntry; }
public void Remove(IdxEntry entry) { this.entries.Remove(entry); this.IsDirty = true; }
public void Add(IdxEntry entry) { this.entries.Add(entry); this.IsDirty = true; }