CSPspEmu.Hle.Formats.IsoFile.ProcessDirectoryRecord C# (CSharp) Method

ProcessDirectoryRecord() protected method

protected ProcessDirectoryRecord ( IsoNode ParentIsoNode ) : void
ParentIsoNode IsoNode
return void
        protected void ProcessDirectoryRecord(IsoNode ParentIsoNode)
        {
            var DirectoryStart  = ParentIsoNode.DirectoryRecord.Extent * SectorSize;
            var DirectoryLength = ParentIsoNode.DirectoryRecord.Size;
            var DirectoryStream = this.Stream.SliceWithLength(DirectoryStart, DirectoryLength);

            while (!DirectoryStream.Eof())
            {
                //writefln("%08X : %08X : %08X", directoryStream.position, directoryStart, directoryLength);
                byte DirectoryRecordSize;
                DirectoryRecordSize = (byte)DirectoryStream.ReadByte();

                // Even if a directory spans multiple sectors, the directory entries are not permitted to cross the sector boundary (unlike the path table).
                // Where there is not enough space to record an entire directory entry at the end of a sector, that sector is zero-padded and the next
                // consecutive sector is used.
                if (DirectoryRecordSize == 0)
                {
                    DirectoryStream.Position = MathUtils.NextAligned(DirectoryStream.Position, SectorSize);
                    //Console.WriteLine("AlignedTo: {0:X}", DirectoryStream.Position);
                    continue;
                }

                DirectoryStream.Position = DirectoryStream.Position - 1;

                //Console.WriteLine("[{0}:{1:X}-{2:X}]", DirectoryRecordSize, DirectoryStream.Position, DirectoryStream.Position + DirectoryRecordSize);

                byte[] DirectoryRecordBytes = new byte[DirectoryRecordSize];
                DirectoryStream.Read(DirectoryRecordBytes, 0, DirectoryRecordSize);
                var DirectoryRecord = StructUtils.BytesToStruct<DirectoryRecord>(DirectoryRecordBytes);

                string name = Encoding.UTF8.GetString(DirectoryRecordBytes.Slice(sizeof(DirectoryRecord), DirectoryRecord.NameLength));

                //Console.WriteLine("{0}", name); Console.ReadKey();

                if (name == "\x00" || name == "\x01") continue;

                //writefln("   %s", name);

                var childIsoNode = new IsoNode(this, DirectoryRecord, name, ParentIsoNode);
                ParentIsoNode._Childs.Add(childIsoNode);
                ParentIsoNode._childsByName[childIsoNode.Name] = childIsoNode;
                ParentIsoNode._childsByNameUpperCase[childIsoNode.Name.ToUpper()] = childIsoNode;
            }

            foreach (var child in ParentIsoNode._Childs)
            {
                if (child.IsDirectory) ProcessDirectoryRecord(child);
            }
        }