Beispiel #1
0
        void WriteDirectoryRecordSector(BinaryWriter writer, DirectoryRecordSector sector)
        {
            Assert.IsNotNull(writer, nameof(writer));
            Assert.IsNotNull(sector, nameof(sector));

            var spaceleft = DefaultSectorSize;

            foreach (var record in sector.Records)
            {
                var buffer = new Byte[record.GetSize()];
                WriteDirectoryRecord(buffer, 0, record);

                if (spaceleft < buffer.Length)
                {
                    writer.BaseStream.Position += spaceleft;
                    spaceleft = DefaultSectorSize;
                }

                writer.Write(buffer);
                spaceleft -= buffer.Length;
            }
        }
Beispiel #2
0
        Dictionary <DirectoryRecord, List <DirectoryRecord> > ReadDirectoryRecords(BasicVolumeDescriptor descriptor)
        {
            Assert.IsNotNull(descriptor, nameof(descriptor));

            var directorytree = new Dictionary <DirectoryRecord, List <DirectoryRecord> >();

            var workinglist = new Stack <DirectoryRecord>();

            workinglist.Push(descriptor.RootDirectory);

            while (workinglist.Count > 0)
            {
                var dir = workinglist.Pop();

                var children = ReadChildrenDirectoryRecords(dir);

                var sectorobj = new DirectoryRecordSector();
                sectorobj.Records.AddRange(children);

                SectorMap[dir.SectorNumber] = sectorobj;
                directorytree[dir]          = new List <DirectoryRecord>();

                foreach (var child in children.Skip(2))
                {
                    if ((child.Flags & DirectoryRecordFlags.Directory) == DirectoryRecordFlags.Directory)
                    {
                        workinglist.Push(child);
                    }
                    else
                    {
                        SectorMap[child.SectorNumber] = new FileSector(child, () => FileSectorReadFunc((Int32)child.SectorNumber, (Int32)child.DataLength));
                    }

                    directorytree[dir].Add(child);
                }
            }

            return(directorytree);
        }