mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
🐛Implement Apple RLE algorithm, fix #120, thanks to David Ryskalczyk.
This commit is contained in:
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -85,6 +85,7 @@
|
|||||||
<e p="packages.config" t="Include" />
|
<e p="packages.config" t="Include" />
|
||||||
</e>
|
</e>
|
||||||
<e p="DiscImageChef.Compression" t="IncludeRecursive">
|
<e p="DiscImageChef.Compression" t="IncludeRecursive">
|
||||||
|
<e p="AppleRle.cs" t="Include" />
|
||||||
<e p="DiscImageChef.Compression.csproj" t="IncludeRecursive" />
|
<e p="DiscImageChef.Compression.csproj" t="IncludeRecursive" />
|
||||||
<e p="Properties" t="Include">
|
<e p="Properties" t="Include">
|
||||||
<e p="AssemblyInfo.cs" t="Include" />
|
<e p="AssemblyInfo.cs" t="Include" />
|
||||||
|
|||||||
112
DiscImageChef.Compression/AppleRle.cs
Normal file
112
DiscImageChef.Compression/AppleRle.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : TeleDiskLzh.cs
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : Compression algorithms.
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Decompress Apple variant of RLE.
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2011-2018 Natalia Portillo
|
||||||
|
// Copyright © 2018 David Ryskalczyk
|
||||||
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Compression
|
||||||
|
{
|
||||||
|
public class AppleRle
|
||||||
|
{
|
||||||
|
const uint DART_CHUNK = 20960;
|
||||||
|
|
||||||
|
readonly Stream inStream;
|
||||||
|
int count;
|
||||||
|
bool nextA; // true if A, false if B
|
||||||
|
|
||||||
|
byte repeatedbyteA, repeatedbyteB;
|
||||||
|
bool repeatMode; // true if we're repeating, false if we're just copying
|
||||||
|
|
||||||
|
public AppleRle(Stream stream)
|
||||||
|
{
|
||||||
|
inStream = stream;
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reset()
|
||||||
|
{
|
||||||
|
repeatedbyteA = repeatedbyteB = 0;
|
||||||
|
count = 0;
|
||||||
|
nextA = true;
|
||||||
|
repeatMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ProduceByte()
|
||||||
|
{
|
||||||
|
if(repeatMode && count > 0)
|
||||||
|
{
|
||||||
|
count--;
|
||||||
|
if(nextA)
|
||||||
|
{
|
||||||
|
nextA = false;
|
||||||
|
return repeatedbyteA;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextA = true;
|
||||||
|
return repeatedbyteB;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!repeatMode && count > 0)
|
||||||
|
{
|
||||||
|
count--;
|
||||||
|
return inStream.ReadByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inStream.Position == inStream.Length) return -1;
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
byte b1 = (byte)inStream.ReadByte();
|
||||||
|
byte b2 = (byte)inStream.ReadByte();
|
||||||
|
short s = (short)((b1 << 8) | b2);
|
||||||
|
|
||||||
|
if(s == 0 || s >= DART_CHUNK || s <= -DART_CHUNK) continue;
|
||||||
|
|
||||||
|
if(s < 0)
|
||||||
|
{
|
||||||
|
repeatMode = true;
|
||||||
|
repeatedbyteA = (byte)inStream.ReadByte();
|
||||||
|
repeatedbyteB = (byte)inStream.ReadByte();
|
||||||
|
count = -s * 2 - 1;
|
||||||
|
nextA = false;
|
||||||
|
return repeatedbyteA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(s <= 0) continue;
|
||||||
|
|
||||||
|
repeatMode = false;
|
||||||
|
count = s * 2 - 1;
|
||||||
|
return inStream.ReadByte();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AppleRle.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TeleDiskLzh.cs" />
|
<Compile Include="TeleDiskLzh.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ using System.Text;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Claunia.RsrcFork;
|
using Claunia.RsrcFork;
|
||||||
using DiscImageChef.CommonTypes;
|
using DiscImageChef.CommonTypes;
|
||||||
|
using DiscImageChef.Compression;
|
||||||
using DiscImageChef.Console;
|
using DiscImageChef.Console;
|
||||||
using DiscImageChef.Filters;
|
using DiscImageChef.Filters;
|
||||||
using Version = Resources.Version;
|
using Version = Resources.Version;
|
||||||
@@ -47,11 +48,11 @@ namespace DiscImageChef.DiscImages
|
|||||||
public class Dart : IMediaImage
|
public class Dart : IMediaImage
|
||||||
{
|
{
|
||||||
// Disk types
|
// Disk types
|
||||||
const byte DISK_MAC = 1;
|
const byte DISK_MAC = 1;
|
||||||
const byte DISK_LISA = 2;
|
const byte DISK_LISA = 2;
|
||||||
const byte DISK_APPLE2 = 3;
|
const byte DISK_APPLE2 = 3;
|
||||||
const byte DISK_MAC_HD = 16;
|
const byte DISK_MAC_HD = 16;
|
||||||
const byte DISK_DOS = 17;
|
const byte DISK_DOS = 17;
|
||||||
const byte DISK_DOS_HD = 18;
|
const byte DISK_DOS_HD = 18;
|
||||||
|
|
||||||
// Compression types
|
// Compression types
|
||||||
@@ -63,61 +64,61 @@ namespace DiscImageChef.DiscImages
|
|||||||
const byte COMPRESS_NONE = 2;
|
const byte COMPRESS_NONE = 2;
|
||||||
|
|
||||||
// Valid sizes
|
// Valid sizes
|
||||||
const short SIZE_LISA = 400;
|
const short SIZE_LISA = 400;
|
||||||
const short SIZE_MAC_SS = 400;
|
const short SIZE_MAC_SS = 400;
|
||||||
const short SIZE_MAC = 800;
|
const short SIZE_MAC = 800;
|
||||||
const short SIZE_MAC_HD = 1440;
|
const short SIZE_MAC_HD = 1440;
|
||||||
const short SIZE_APPLE2 = 800;
|
const short SIZE_APPLE2 = 800;
|
||||||
const short SIZE_DOS = 720;
|
const short SIZE_DOS = 720;
|
||||||
const short SIZE_DOS_HD = 1440;
|
const short SIZE_DOS_HD = 1440;
|
||||||
|
|
||||||
// bLength array sizes
|
// bLength array sizes
|
||||||
const int BLOCK_ARRAY_LEN_LOW = 40;
|
const int BLOCK_ARRAY_LEN_LOW = 40;
|
||||||
const int BLOCK_ARRAY_LEN_HIGH = 72;
|
const int BLOCK_ARRAY_LEN_HIGH = 72;
|
||||||
|
|
||||||
const int SECTORS_PER_BLOCK = 40;
|
const int SECTORS_PER_BLOCK = 40;
|
||||||
const int SECTOR_SIZE = 512;
|
const int SECTOR_SIZE = 512;
|
||||||
const int TAG_SECTOR_SIZE = 12;
|
const int TAG_SECTOR_SIZE = 12;
|
||||||
const int DATA_SIZE = SECTORS_PER_BLOCK * SECTOR_SIZE;
|
const int DATA_SIZE = SECTORS_PER_BLOCK * SECTOR_SIZE;
|
||||||
const int TAG_SIZE = SECTORS_PER_BLOCK * TAG_SECTOR_SIZE;
|
const int TAG_SIZE = SECTORS_PER_BLOCK * TAG_SECTOR_SIZE;
|
||||||
const int BUFFER_SIZE = SECTORS_PER_BLOCK * SECTOR_SIZE + SECTORS_PER_BLOCK * TAG_SECTOR_SIZE;
|
const int BUFFER_SIZE = SECTORS_PER_BLOCK * SECTOR_SIZE + SECTORS_PER_BLOCK * TAG_SECTOR_SIZE;
|
||||||
|
|
||||||
// DART images are at most 1474560 bytes, so let's cache the whole
|
// DART images are at most 1474560 bytes, so let's cache the whole
|
||||||
byte[] dataCache;
|
byte[] dataCache;
|
||||||
uint dataChecksum;
|
uint dataChecksum;
|
||||||
ImageInfo imageInfo;
|
ImageInfo imageInfo;
|
||||||
byte[] tagCache;
|
byte[] tagCache;
|
||||||
uint tagChecksum;
|
uint tagChecksum;
|
||||||
|
|
||||||
public Dart()
|
public Dart()
|
||||||
{
|
{
|
||||||
imageInfo = new ImageInfo
|
imageInfo = new ImageInfo
|
||||||
{
|
{
|
||||||
ReadableSectorTags = new List<SectorTagType>(),
|
ReadableSectorTags = new List<SectorTagType>(),
|
||||||
ReadableMediaTags = new List<MediaTagType>(),
|
ReadableMediaTags = new List<MediaTagType>(),
|
||||||
HasPartitions = false,
|
HasPartitions = false,
|
||||||
HasSessions = false,
|
HasSessions = false,
|
||||||
Version = null,
|
Version = null,
|
||||||
Application = null,
|
Application = null,
|
||||||
ApplicationVersion = null,
|
ApplicationVersion = null,
|
||||||
Creator = null,
|
Creator = null,
|
||||||
Comments = null,
|
Comments = null,
|
||||||
MediaManufacturer = null,
|
MediaManufacturer = null,
|
||||||
MediaModel = null,
|
MediaModel = null,
|
||||||
MediaSerialNumber = null,
|
MediaSerialNumber = null,
|
||||||
MediaBarcode = null,
|
MediaBarcode = null,
|
||||||
MediaPartNumber = null,
|
MediaPartNumber = null,
|
||||||
MediaSequence = 0,
|
MediaSequence = 0,
|
||||||
LastMediaSequence = 0,
|
LastMediaSequence = 0,
|
||||||
DriveManufacturer = null,
|
DriveManufacturer = null,
|
||||||
DriveModel = null,
|
DriveModel = null,
|
||||||
DriveSerialNumber = null,
|
DriveSerialNumber = null,
|
||||||
DriveFirmwareRevision = null
|
DriveFirmwareRevision = null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "Apple Disk Archival/Retrieval Tool";
|
public string Name => "Apple Disk Archival/Retrieval Tool";
|
||||||
public Guid Id => new Guid("B3E06BF8-F98D-4F9B-BBE2-342C373BAF3E");
|
public Guid Id => new Guid("B3E06BF8-F98D-4F9B-BBE2-342C373BAF3E");
|
||||||
public ImageInfo Info => imageInfo;
|
public ImageInfo Info => imageInfo;
|
||||||
|
|
||||||
public string Format => "Apple Disk Archival/Retrieval Tool";
|
public string Format => "Apple Disk Archival/Retrieval Tool";
|
||||||
@@ -235,11 +236,11 @@ namespace DiscImageChef.DiscImages
|
|||||||
short[] bLength;
|
short[] bLength;
|
||||||
|
|
||||||
if(header.srcType == DISK_MAC_HD || header.srcType == DISK_DOS_HD)
|
if(header.srcType == DISK_MAC_HD || header.srcType == DISK_DOS_HD)
|
||||||
bLength = new short[BLOCK_ARRAY_LEN_HIGH];
|
bLength = new short[BLOCK_ARRAY_LEN_HIGH];
|
||||||
else bLength = new short[BLOCK_ARRAY_LEN_LOW];
|
else bLength = new short[BLOCK_ARRAY_LEN_LOW];
|
||||||
|
|
||||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||||
|
|
||||||
for(int i = 0; i < bLength.Length; i++)
|
for(int i = 0; i < bLength.Length; i++)
|
||||||
{
|
{
|
||||||
byte[] tmpShort = new byte[2];
|
byte[] tmpShort = new byte[2];
|
||||||
@@ -248,7 +249,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
MemoryStream dataMs = new MemoryStream();
|
MemoryStream dataMs = new MemoryStream();
|
||||||
MemoryStream tagMs = new MemoryStream();
|
MemoryStream tagMs = new MemoryStream();
|
||||||
|
|
||||||
foreach(short l in bLength)
|
foreach(short l in bLength)
|
||||||
if(l != 0)
|
if(l != 0)
|
||||||
@@ -267,12 +268,18 @@ namespace DiscImageChef.DiscImages
|
|||||||
{
|
{
|
||||||
temp = new byte[l * 2];
|
temp = new byte[l * 2];
|
||||||
stream.Read(temp, 0, temp.Length);
|
stream.Read(temp, 0, temp.Length);
|
||||||
throw new ImageNotSupportedException("Compressed images not yet supported");
|
AppleRle rle = new AppleRle(new MemoryStream(temp));
|
||||||
|
buffer = new byte[BUFFER_SIZE];
|
||||||
|
for(int i = 0; i < BUFFER_SIZE; i++) buffer[i] = (byte)rle.ProduceByte();
|
||||||
|
dataMs.Write(buffer, 0, DATA_SIZE);
|
||||||
|
tagMs.Write(buffer, DATA_SIZE, TAG_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp = new byte[l];
|
||||||
|
stream.Read(temp, 0, temp.Length);
|
||||||
|
throw new ImageNotSupportedException("LZH Compressed images not yet supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
temp = new byte[l];
|
|
||||||
stream.Read(temp, 0, temp.Length);
|
|
||||||
throw new ImageNotSupportedException("Compressed images not yet supported");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,12 +307,12 @@ namespace DiscImageChef.DiscImages
|
|||||||
Version version = new Version(vers);
|
Version version = new Version(vers);
|
||||||
|
|
||||||
string release = null;
|
string release = null;
|
||||||
string dev = null;
|
string dev = null;
|
||||||
string pre = null;
|
string pre = null;
|
||||||
|
|
||||||
string major = $"{version.MajorVersion}";
|
string major = $"{version.MajorVersion}";
|
||||||
string minor = $".{version.MinorVersion / 10}";
|
string minor = $".{version.MinorVersion / 10}";
|
||||||
if(version.MinorVersion % 10 > 0) release = $".{version.MinorVersion % 10}";
|
if(version.MinorVersion % 10 > 0) release = $".{version.MinorVersion % 10}";
|
||||||
switch(version.DevStage)
|
switch(version.DevStage)
|
||||||
{
|
{
|
||||||
case Version.DevelopmentStage.Alpha:
|
case Version.DevelopmentStage.Alpha:
|
||||||
@@ -324,8 +331,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
if(dev != null) pre = $"{version.PreReleaseVersion}";
|
if(dev != null) pre = $"{version.PreReleaseVersion}";
|
||||||
|
|
||||||
imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
|
imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
|
||||||
imageInfo.Application = version.VersionString;
|
imageInfo.Application = version.VersionString;
|
||||||
imageInfo.Comments = version.VersionMessage;
|
imageInfo.Comments = version.VersionMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,15 +346,15 @@ namespace DiscImageChef.DiscImages
|
|||||||
Encoding.GetEncoding("macintosh"));
|
Encoding.GetEncoding("macintosh"));
|
||||||
const string DART_REGEX =
|
const string DART_REGEX =
|
||||||
@"(?<version>\S+), tag checksum=\$(?<tagchk>[0123456789ABCDEF]{8}), data checksum=\$(?<datachk>[0123456789ABCDEF]{8})$";
|
@"(?<version>\S+), tag checksum=\$(?<tagchk>[0123456789ABCDEF]{8}), data checksum=\$(?<datachk>[0123456789ABCDEF]{8})$";
|
||||||
Regex dArtEx = new Regex(DART_REGEX);
|
Regex dArtEx = new Regex(DART_REGEX);
|
||||||
Match dArtMatch = dArtEx.Match(dArt);
|
Match dArtMatch = dArtEx.Match(dArt);
|
||||||
|
|
||||||
if(dArtMatch.Success)
|
if(dArtMatch.Success)
|
||||||
{
|
{
|
||||||
imageInfo.Application = "DART";
|
imageInfo.Application = "DART";
|
||||||
imageInfo.ApplicationVersion = dArtMatch.Groups["version"].Value;
|
imageInfo.ApplicationVersion = dArtMatch.Groups["version"].Value;
|
||||||
dataChecksum = Convert.ToUInt32(dArtMatch.Groups["datachk"].Value, 16);
|
dataChecksum = Convert.ToUInt32(dArtMatch.Groups["datachk"].Value, 16);
|
||||||
tagChecksum = Convert.ToUInt32(dArtMatch.Groups["tagchk"].Value, 16);
|
tagChecksum = Convert.ToUInt32(dArtMatch.Groups["tagchk"].Value, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,12 +366,13 @@ namespace DiscImageChef.DiscImages
|
|||||||
if(cksmRsrc?.ContainsId(1) == true)
|
if(cksmRsrc?.ContainsId(1) == true)
|
||||||
{
|
{
|
||||||
byte[] tagChk = cksmRsrc.GetResource(1);
|
byte[] tagChk = cksmRsrc.GetResource(1);
|
||||||
tagChecksum = BigEndianBitConverter.ToUInt32(tagChk, 0);
|
tagChecksum = BigEndianBitConverter.ToUInt32(tagChk, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cksmRsrc?.ContainsId(2) == true)
|
if(cksmRsrc?.ContainsId(2) == true)
|
||||||
{
|
{
|
||||||
byte[] dataChk = cksmRsrc.GetResource(1);
|
byte[] dataChk = cksmRsrc.GetResource(1);
|
||||||
dataChecksum = BigEndianBitConverter.ToUInt32(dataChk, 0);
|
dataChecksum = BigEndianBitConverter.ToUInt32(dataChk, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,40 +382,40 @@ namespace DiscImageChef.DiscImages
|
|||||||
DicConsole.DebugWriteLine("DART plugin", "Image application = {0} version {1}", imageInfo.Application,
|
DicConsole.DebugWriteLine("DART plugin", "Image application = {0} version {1}", imageInfo.Application,
|
||||||
imageInfo.ApplicationVersion);
|
imageInfo.ApplicationVersion);
|
||||||
|
|
||||||
imageInfo.Sectors = (ulong)(header.srcSize * 2);
|
imageInfo.Sectors = (ulong)(header.srcSize * 2);
|
||||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||||
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
||||||
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
||||||
imageInfo.SectorSize = SECTOR_SIZE;
|
imageInfo.SectorSize = SECTOR_SIZE;
|
||||||
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
||||||
imageInfo.ImageSize = imageInfo.Sectors * SECTOR_SIZE;
|
imageInfo.ImageSize = imageInfo.Sectors * SECTOR_SIZE;
|
||||||
imageInfo.Version = header.srcCmp == COMPRESS_NONE ? "1.4" : "1.5";
|
imageInfo.Version = header.srcCmp == COMPRESS_NONE ? "1.4" : "1.5";
|
||||||
|
|
||||||
switch(header.srcSize)
|
switch(header.srcSize)
|
||||||
{
|
{
|
||||||
case SIZE_MAC_SS:
|
case SIZE_MAC_SS:
|
||||||
imageInfo.Cylinders = 80;
|
imageInfo.Cylinders = 80;
|
||||||
imageInfo.Heads = 1;
|
imageInfo.Heads = 1;
|
||||||
imageInfo.SectorsPerTrack = 10;
|
imageInfo.SectorsPerTrack = 10;
|
||||||
imageInfo.MediaType = MediaType.AppleSonySS;
|
imageInfo.MediaType = MediaType.AppleSonySS;
|
||||||
break;
|
break;
|
||||||
case SIZE_MAC:
|
case SIZE_MAC:
|
||||||
imageInfo.Cylinders = 80;
|
imageInfo.Cylinders = 80;
|
||||||
imageInfo.Heads = 2;
|
imageInfo.Heads = 2;
|
||||||
imageInfo.SectorsPerTrack = 10;
|
imageInfo.SectorsPerTrack = 10;
|
||||||
imageInfo.MediaType = MediaType.AppleSonyDS;
|
imageInfo.MediaType = MediaType.AppleSonyDS;
|
||||||
break;
|
break;
|
||||||
case SIZE_DOS:
|
case SIZE_DOS:
|
||||||
imageInfo.Cylinders = 80;
|
imageInfo.Cylinders = 80;
|
||||||
imageInfo.Heads = 2;
|
imageInfo.Heads = 2;
|
||||||
imageInfo.SectorsPerTrack = 9;
|
imageInfo.SectorsPerTrack = 9;
|
||||||
imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
||||||
break;
|
break;
|
||||||
case SIZE_MAC_HD:
|
case SIZE_MAC_HD:
|
||||||
imageInfo.Cylinders = 80;
|
imageInfo.Cylinders = 80;
|
||||||
imageInfo.Heads = 2;
|
imageInfo.Heads = 2;
|
||||||
imageInfo.SectorsPerTrack = 18;
|
imageInfo.SectorsPerTrack = 18;
|
||||||
imageInfo.MediaType = MediaType.DOS_35_HD;
|
imageInfo.MediaType = MediaType.DOS_35_HD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,8 +481,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
if(sectorAddress + length > imageInfo.Sectors)
|
if(sectorAddress + length > imageInfo.Sectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||||
|
|
||||||
byte[] data = ReadSectors(sectorAddress, length);
|
byte[] data = ReadSectors(sectorAddress, length);
|
||||||
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
||||||
byte[] buffer = new byte[data.Length + tags.Length];
|
byte[] buffer = new byte[data.Length + tags.Length];
|
||||||
|
|
||||||
for(uint i = 0; i < length; i++)
|
for(uint i = 0; i < length; i++)
|
||||||
@@ -482,7 +490,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
Array.Copy(data, i * imageInfo.SectorSize, buffer, i * (imageInfo.SectorSize + TAG_SECTOR_SIZE),
|
Array.Copy(data, i * imageInfo.SectorSize, buffer, i * (imageInfo.SectorSize + TAG_SECTOR_SIZE),
|
||||||
imageInfo.SectorSize);
|
imageInfo.SectorSize);
|
||||||
Array.Copy(tags, i * TAG_SECTOR_SIZE, buffer,
|
Array.Copy(tags, i * TAG_SECTOR_SIZE, buffer,
|
||||||
i * (imageInfo.SectorSize + TAG_SECTOR_SIZE) + imageInfo.SectorSize, TAG_SECTOR_SIZE);
|
i * (imageInfo.SectorSize + TAG_SECTOR_SIZE) + imageInfo.SectorSize, TAG_SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
@@ -544,7 +552,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
@@ -554,7 +562,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||||
}
|
}
|
||||||
@@ -567,8 +575,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
struct DartHeader
|
struct DartHeader
|
||||||
{
|
{
|
||||||
public byte srcCmp;
|
public byte srcCmp;
|
||||||
public byte srcType;
|
public byte srcType;
|
||||||
public short srcSize;
|
public short srcSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Claunia.RsrcFork;
|
using Claunia.RsrcFork;
|
||||||
using DiscImageChef.CommonTypes;
|
using DiscImageChef.CommonTypes;
|
||||||
|
using DiscImageChef.Compression;
|
||||||
using DiscImageChef.Console;
|
using DiscImageChef.Console;
|
||||||
using DiscImageChef.Filters;
|
using DiscImageChef.Filters;
|
||||||
using SharpCompress.Compressors.ADC;
|
using SharpCompress.Compressors.ADC;
|
||||||
@@ -236,8 +237,6 @@ namespace DiscImageChef.DiscImages
|
|||||||
case CHUNK_TYPE_KENCODE:
|
case CHUNK_TYPE_KENCODE:
|
||||||
throw new
|
throw new
|
||||||
ImageNotSupportedException("Chunks compressed with KenCode are not yet supported.");
|
ImageNotSupportedException("Chunks compressed with KenCode are not yet supported.");
|
||||||
case CHUNK_TYPE_RLE:
|
|
||||||
throw new ImageNotSupportedException("Chunks compressed with RLE are not yet supported.");
|
|
||||||
case CHUNK_TYPE_LZH:
|
case CHUNK_TYPE_LZH:
|
||||||
throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported.");
|
throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported.");
|
||||||
case CHUNK_TYPE_STUFFIT:
|
case CHUNK_TYPE_STUFFIT:
|
||||||
@@ -411,15 +410,41 @@ namespace DiscImageChef.DiscImages
|
|||||||
imageStream.Seek(currentChunk.offset, SeekOrigin.Begin);
|
imageStream.Seek(currentChunk.offset, SeekOrigin.Begin);
|
||||||
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
|
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
|
||||||
MemoryStream cmpMs = new MemoryStream(cmpBuffer);
|
MemoryStream cmpMs = new MemoryStream(cmpBuffer);
|
||||||
Stream decStream;
|
int realSize = 0;
|
||||||
|
|
||||||
if(currentChunk.type == CHUNK_TYPE_ADC) decStream = new ADCStream(cmpMs);
|
switch(currentChunk.type)
|
||||||
else throw new ImageNotSupportedException($"Unsupported chunk type 0x{currentChunk.type:X8} found");
|
{
|
||||||
|
case CHUNK_TYPE_ADC:
|
||||||
|
{
|
||||||
|
Stream decStream = new ADCStream(cmpMs);
|
||||||
|
byte[] tmpBuffer = new byte[buffersize];
|
||||||
|
realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
|
||||||
|
buffer = new byte[realSize];
|
||||||
|
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CHUNK_TYPE_RLE:
|
||||||
|
{
|
||||||
|
byte[] tmpBuffer = new byte[buffersize];
|
||||||
|
realSize = 0;
|
||||||
|
AppleRle rle = new AppleRle(cmpMs);
|
||||||
|
for(int i = 0; i < buffersize; i++)
|
||||||
|
{
|
||||||
|
int b = rle.ProduceByte();
|
||||||
|
if(b == -1) break;
|
||||||
|
|
||||||
byte[] tmpBuffer = new byte[buffersize];
|
tmpBuffer[i] = (byte)b;
|
||||||
int realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
|
realSize++;
|
||||||
buffer = new byte[realSize];
|
}
|
||||||
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
|
||||||
|
buffer = new byte[realSize];
|
||||||
|
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new
|
||||||
|
ImageNotSupportedException($"Unsupported chunk type 0x{currentChunk.type:X8} found");
|
||||||
|
}
|
||||||
|
|
||||||
if(currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
|
if(currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ using Claunia.PropertyList;
|
|||||||
using Claunia.RsrcFork;
|
using Claunia.RsrcFork;
|
||||||
using DiscImageChef.Checksums;
|
using DiscImageChef.Checksums;
|
||||||
using DiscImageChef.CommonTypes;
|
using DiscImageChef.CommonTypes;
|
||||||
|
using DiscImageChef.Compression;
|
||||||
using DiscImageChef.Console;
|
using DiscImageChef.Console;
|
||||||
using DiscImageChef.Filters;
|
using DiscImageChef.Filters;
|
||||||
using Ionic.Zlib;
|
using Ionic.Zlib;
|
||||||
@@ -507,8 +508,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
byte[] cmpBuffer = new byte[currentChunk.length];
|
byte[] cmpBuffer = new byte[currentChunk.length];
|
||||||
imageStream.Seek((long)currentChunk.offset, SeekOrigin.Begin);
|
imageStream.Seek((long)currentChunk.offset, SeekOrigin.Begin);
|
||||||
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
|
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
|
||||||
MemoryStream cmpMs = new MemoryStream(cmpBuffer);
|
MemoryStream cmpMs = new MemoryStream(cmpBuffer);
|
||||||
Stream decStream;
|
Stream decStream = null;
|
||||||
|
|
||||||
switch(currentChunk.type)
|
switch(currentChunk.type)
|
||||||
{
|
{
|
||||||
@@ -521,6 +522,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
case CHUNK_TYPE_BZIP:
|
case CHUNK_TYPE_BZIP:
|
||||||
decStream = new BZip2Stream(cmpMs, SharpCompress.Compressors.CompressionMode.Decompress);
|
decStream = new BZip2Stream(cmpMs, SharpCompress.Compressors.CompressionMode.Decompress);
|
||||||
break;
|
break;
|
||||||
|
case CHUNK_TYPE_RLE: break;
|
||||||
default:
|
default:
|
||||||
throw new
|
throw new
|
||||||
ImageNotSupportedException($"Unsupported chunk type 0x{currentChunk.type:X8} found");
|
ImageNotSupportedException($"Unsupported chunk type 0x{currentChunk.type:X8} found");
|
||||||
@@ -530,19 +532,44 @@ namespace DiscImageChef.DiscImages
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
byte[] tmpBuffer = new byte[buffersize];
|
byte[] tmpBuffer;
|
||||||
int realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
|
int realSize;
|
||||||
buffer = new byte[realSize];
|
switch(currentChunk.type)
|
||||||
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
|
||||||
|
|
||||||
if(currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
|
|
||||||
{
|
{
|
||||||
chunkCache.Clear();
|
case CHUNK_TYPE_ADC:
|
||||||
currentChunkCacheSize = 0;
|
case CHUNK_TYPE_ZLIB:
|
||||||
}
|
case CHUNK_TYPE_BZIP:
|
||||||
|
tmpBuffer = new byte[buffersize];
|
||||||
|
realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
|
||||||
|
buffer = new byte[realSize];
|
||||||
|
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||||
|
|
||||||
chunkCache.Add(chunkStartSector, buffer);
|
if(currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
|
||||||
currentChunkCacheSize += (uint)realSize;
|
{
|
||||||
|
chunkCache.Clear();
|
||||||
|
currentChunkCacheSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkCache.Add(chunkStartSector, buffer);
|
||||||
|
currentChunkCacheSize += (uint)realSize;
|
||||||
|
break;
|
||||||
|
case CHUNK_TYPE_RLE:
|
||||||
|
tmpBuffer = new byte[buffersize];
|
||||||
|
realSize = 0;
|
||||||
|
AppleRle rle = new AppleRle(cmpMs);
|
||||||
|
for(int i = 0; i < buffersize; i++)
|
||||||
|
{
|
||||||
|
int b = rle.ProduceByte();
|
||||||
|
if(b == -1) break;
|
||||||
|
|
||||||
|
tmpBuffer[i] = (byte)b;
|
||||||
|
realSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = new byte[realSize];
|
||||||
|
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
}
|
}
|
||||||
catch(ZlibException)
|
catch(ZlibException)
|
||||||
|
|||||||
Reference in New Issue
Block a user