internal void AddLeftSiblingTree(CompoundDocumentItem e, List <CompoundDocumentItem> dirs) { if (e.LeftSibling > 0) { var c = dirs[e.LeftSibling]; if (c.Parent != null) { c.Parent = e.Parent; c.Parent.Children.Insert(e.Parent.Children.IndexOf(e), c); e._handled = true; AddLeftSiblingTree(c, dirs); } } }
private void ReadDirectory(List <byte[]> sectors, int index, List <CompoundDocumentItem> l) { var br = new BinaryReader(new MemoryStream(sectors[index])); while (br.BaseStream.Position < br.BaseStream.Length) { var e = new CompoundDocumentItem(); e.Read(br); if (e.ObjectType != 0) { l.Add(e); } } }
public CompoundDocumentFile() { RootItem = new CompoundDocumentItem() { Name = "<Root>", Children = new List <CompoundDocumentItem>(), ObjectType = 5 }; minorVersion = 0x3E; majorVersion = 3; sectorShif = 9; minSectorShift = 6; _sectorSize = 1 << sectorShif; _miniSectorSize = 1 << minSectorShift; _sectorSizeInt = _sectorSize / 4; }
private void GetStorageAndStreams(StoragePart storage, CompoundDocumentItem parent) { foreach (var item in parent.Children) { if (item.ObjectType == 1) //Substorage { var part = new StoragePart(); storage.SubStorage.Add(item.Name, part); GetStorageAndStreams(part, item); } else if (item.ObjectType == 2) //Stream { storage.DataStreams.Add(item.Name, item.Stream); } } }
private void ReadDirectory(List <byte[]> sectors, int index, List <CompoundDocumentItem> l) { using (var ms = RecyclableMemory.GetStream(sectors[index])) { var br = new BinaryReader(ms); while (ms.Position < ms.Length) { var e = new CompoundDocumentItem(); e.Read(br); if (e.ObjectType != 0) { l.Add(e); } } } }
private void WriteDir(BinaryWriter bw, CompoundDocumentItem entity) { bw.Seek(_currentDirSectorPos, SeekOrigin.Begin); entity.Write(bw); _currentDirSectorPos += 128; if (_currentDirSectorPos % _sectorSize == 0) { if (_currentDirSectorPos == _sectorSize * 3) { _currentDirSectorPos = _sectorSize * 4; } WritePosition(bw, _currentDirSectorPos / _sectorSize - 1, ref _prevDirFATSectorPos); if (_currentDirSectorPos == _sectorSize * 4) { _prevDirFATSectorPos = (int)_sectorSize + 12; //Ref sector 3 in fat sector } } }
private void WriteStorageAndStreams(StoragePart storage, CompoundDocumentItem parent) { foreach (var item in storage.SubStorage) { var c = new CompoundDocumentItem() { Name = item.Key, ObjectType = 1, Stream = null, StreamSize = 0, Parent = parent }; parent.Children.Add(c); WriteStorageAndStreams(item.Value, c); } foreach (var item in storage.DataStreams) { var c = new CompoundDocumentItem() { Name = item.Key, ObjectType = 2, Stream = item.Value, StreamSize = (item.Value == null ? 0 : item.Value.Length), Parent = parent }; parent.Children.Add(c); } }
private void CreateFATStreams(CompoundDocumentItem item, BinaryWriter bw, BinaryWriter bwMini, DocWriteInfo dwi) { if (item.ObjectType != 5) //Root, we must have the miniStream first. { if (item.StreamSize > 0) { item.StreamSize = item.Stream.Length; if (item.StreamSize < _miniStreamCutoffSize) { item.StartingSectorLocation = WriteStream(bwMini, dwi.miniFAT, item.Stream, miniFATSectorSize); } else { item.StartingSectorLocation = WriteStream(bw, dwi.FAT, item.Stream, FATSectorSizeV3); } } } foreach (var c in item.Children) { CreateFATStreams(c, bw, bwMini, dwi); } }
private int AddChildren(CompoundDocumentItem item, List <CompoundDocumentItem> l) { var childId = -1; item.ColorFlag = 1; //Always Black-No matter here, we just add nodes as a b-tree if (item.Children.Count > 0) { foreach (var c in item.Children) { InitItem(c); } item.Children.Sort(); childId = SetSiblings(l.Count, item.Children, 0, item.Children.Count - 1, -1); l.AddRange(item.Children); foreach (var c in item.Children) { c.ChildID = AddChildren(c, l); } } return(childId); }
private void InitItem(CompoundDocumentItem item) { item.LeftSibling = -1; item.RightSibling = -1; item._handled = false; }