protected virtual void LoadFromStream(Stream stream) { var secSize = 128 << (SectorSizeCode & 3); var cylSize = GetSectorMap(0, 0).Length *secSize * 2; var cylCount = (int)(stream.Length / cylSize); if ((stream.Length % cylSize) > 0L) { cylCount += 1; } m_diskImage.SetPhysics(cylCount, 2); for (var c = 0; c < m_diskImage.CylynderCount; c++) { for (var h = 0; h < m_diskImage.SideCount; h++) { var sectorList = new List <Sector>(); var il = GetSectorMap(c, h); for (var s = 0; s < il.Length; s++) { var sector = new SimpleSector( c, h, il[s], SectorSizeCode & 3, new byte[secSize]); stream.Read(sector.Data, 0, sector.Data.Length); sector.SetAdCrc(true); sector.SetDataCrc(true); sectorList.Add(sector); } m_diskImage .GetTrackImage(c, h) .AssignSectors(sectorList); } } m_diskImage.ModifyFlag = ModifyFlag.None; }
private void loadFromStream(Stream stream) { var crc = CrcUdi.InitValue; var hdr = new byte[16]; stream.Seek(0, SeekOrigin.Begin); stream.Read(hdr, 0, hdr.Length); crc = CrcUdi.Update(crc, hdr, 0, hdr.Length); if (Encoding.ASCII.GetString(hdr, 0, 4) != "UDI!") // check "UDI!" { Locator.Resolve <IUserMessage>() .Error("UDI loader\n\nUnknown *.UDI file identifier!"); return; } var size = hdr[4] | hdr[5] << 8 | hdr[6] << 16 | hdr[7] << 24; if (stream.Length != (size + 4)) { Locator.Resolve <IUserMessage>() .Error("UDI loader\n\nCorrupt *.UDI file!"); return; } if (hdr[8] != 0) { Locator.Resolve <IUserMessage>() .Error("UDI loader\n\nUnsupported *.UDI format version!"); return; } var cylCount = hdr[9] + 1; var sideCount = hdr[0x0A] + 1; var hdr2len = hdr[0x0C] | hdr[0x0D] << 8 | hdr[0x0E] << 16 | hdr[0x0F] << 24; _diskImage.SetPhysics(cylCount, sideCount); if (hdr2len > 0) { byte[] hdr2 = new byte[hdr2len]; stream.Read(hdr2, 0, hdr2len); crc = CrcUdi.Update(crc, hdr2, 0, hdr2.Length); } // f.Seek(16 + hdr2len, SeekOrigin.Begin); for (var cyl = 0; cyl < cylCount; cyl++) { for (var side = 0; side < sideCount; side++) { stream.Read(hdr, 0, 3); crc = CrcUdi.Update(crc, hdr, 0, 3); var trackType = hdr[0]; var trackSize = hdr[1] | hdr[2] << 8; var image = new byte[2][]; image[0] = new byte[trackSize]; image[1] = new byte[trackSize / 8 + (((trackSize & 7) != 0) ? 1 : 0)]; stream.Read(image[0], 0, image[0].Length); crc = CrcUdi.Update(crc, image[0], 0, image[0].Length); stream.Read(image[1], 0, image[1].Length); crc = CrcUdi.Update(crc, image[1], 0, image[1].Length); _diskImage.GetTrackImage(cyl, side) .AssignImage(image[0], image[1]); } } // check CRC stream.Read(hdr, 0, 4); var stampCrc = (UInt32)(hdr[0] | hdr[1] << 8 | hdr[2] << 16 | hdr[3] << 24); if (stampCrc != crc) { Locator.Resolve <IUserMessage>() .Warning( "UDI loader\n\nCRC ERROR:\nStamp: {0:X8}\nReal: {1:X8}", stampCrc, crc); } }