Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Directory"/> class
        /// from an array of bytes.
        /// </summary>
        /// <param name="buffer">Array of bytes containing the directory information</param>
        /// <param name="diskFormatType">Disk Format to use when interpreting the Array of bytes</param>
        public Directory(byte[] buffer, DiskFormatType diskFormatType)
        {
            this.FormatType = diskFormatType;
            this.entries    = new List <DirectoryEntry>();
            int offset = 0;

            switch (diskFormatType)
            {
            case DiskFormatType.DragonDosFormat:
                List <byte[]> entries = new List <byte[]>();

                while (offset < buffer.Length)
                {
                    if ((buffer[offset] & 0x08) == 0x08)
                    {
                        break;
                    }

                    entries.Add(buffer.Subset(offset, 0x19));
                    offset += 19;
                    if ((offset + 6) % 100 == 0)
                    {
                        offset += 6;
                    }
                }

                byte[][] blocks = entries.ToArray();

                foreach (byte[] block in blocks)
                {
                    DirectoryEntry entry = new DirectoryEntry(block, this.FormatType);
                    this.entries.Add(entry);
                    if (entry.NextDirectoryEntry != 0)
                    {
                        entry.PutDragonDosExtBytes(blocks[entry.NextDirectoryEntry]);
                    }
                }

                break;

            case DiskFormatType.OS9Format:
            case DiskFormatType.RSDOSFormat:
                while (offset < buffer.Length)
                {
                    this.entries.Add(new DirectoryEntry(buffer.Subset(offset, 32), this.FormatType));
                    offset += 32;
                }

                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryEntry"/> class
        /// from an Array of bytes.
        /// </summary>
        /// <param name="directoryEntryBytes">Array of bytes containing directory entry information</param>
        /// <param name="diskFormatType">Type of Disk Format</param>
        public DirectoryEntry(byte[] directoryEntryBytes, DiskFormatType diskFormatType)
        {
            this.FormatType = diskFormatType;

            string filename, ext;

            switch (diskFormatType)
            {
            case DiskFormatType.OS9Format:
                if (directoryEntryBytes[0] == 0x00)
                {
                    this.Deleted  = true;
                    this.Filename = "?" + Util.GetString(directoryEntryBytes.Subset(1, 29));
                }
                else
                {
                    this.Deleted  = false;
                    this.Filename = Util.GetString(directoryEntryBytes.Subset(0, 29));
                }

                this.LSN         = Util.Int24(directoryEntryBytes.Subset(29, 3));
                this.SegmentList = new FileSegment[48];
                break;

            case DiskFormatType.DragonDosFormat:
                this.AttrByte  = directoryEntryBytes[0];
                this.Deleted   = (directoryEntryBytes[0] & 0x80) == 0x80;
                this.Protected = (directoryEntryBytes[0] & 0x02) == 0x02;

                filename      = Util.GetString(directoryEntryBytes.Subset(1, 8));
                ext           = Util.GetString(directoryEntryBytes.Subset(9, 3));
                this.Filename = string.Format("{0}.{1}", filename, ext);
                this.SectorAllocationBlocks = new SectorAllocationBlock[11];

                for (int i = 0; i < 4; i++)
                {
                    this.SectorAllocationBlocks[i] = new SectorAllocationBlock(directoryEntryBytes.Subset(12 + (i * 3), 3));
                }

                if ((directoryEntryBytes[0] & 0x20) == 0x20)
                {
                    this.NextDirectoryEntry = directoryEntryBytes[0x18];
                }
                else
                {
                    this.BytesUsedInLastSector = directoryEntryBytes[0x18];
                }

                int size = 0;
                for (int i = 0; i < 11; i++)
                {
                    if (this.SectorAllocationBlocks[i].Sectors != 0)
                    {
                        size += this.SectorAllocationBlocks[i].Sectors * 256;
                    }
                }

                this.Size = (uint)size;

                if (this.BytesUsedInLastSector != 0)
                {
                    size -= 0x100 - this.BytesUsedInLastSector;
                }

                break;

            case DiskFormatType.RSDOSFormat:
                if (directoryEntryBytes[0] == 0x00)
                {
                    this.Deleted = true;
                    filename     = "?" + Util.GetString(directoryEntryBytes.Subset(1, 8)).Trim();
                }
                else
                {
                    Deleted  = false;
                    filename = Util.GetString(directoryEntryBytes.Subset(0, 8)).Trim();
                }

                ext                     = Util.GetString(directoryEntryBytes.Subset(8, 3)).Trim();
                this.Filename           = string.Format("{0}.{1}", filename, ext);
                this.FileType           = directoryEntryBytes[0x0b];
                this.AsciiFlag          = directoryEntryBytes[0x0c];
                this.FirstGranule       = directoryEntryBytes[0x0d];
                this.LastSectorBytesMSB = directoryEntryBytes[0x0e];
                this.LastSectorBytesLSB = directoryEntryBytes[0x0f];
                break;
            }
        }