mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Refactor Virtual98 and RayDIM.
This commit is contained in:
@@ -51,6 +51,7 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
MemoryStream disk;
|
||||
ImageInfo imageInfo;
|
||||
FileStream writingStream;
|
||||
|
||||
public RayDim()
|
||||
{
|
||||
@@ -312,49 +313,28 @@ namespace DiscImageChef.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct RayHdr
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
|
||||
public byte[] signature;
|
||||
public RayDiskTypes diskType;
|
||||
public byte cylinders;
|
||||
public byte sectorsPerTrack;
|
||||
public byte heads;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
enum RayDiskTypes : byte
|
||||
{
|
||||
Md2dd = 1,
|
||||
Md2hd = 2,
|
||||
Mf2dd = 3,
|
||||
Mf2hd = 4,
|
||||
Mf2ed = 5
|
||||
}
|
||||
|
||||
public IEnumerable<MediaTagType> SupportedMediaTags => new MediaTagType[] { };
|
||||
public IEnumerable<SectorTagType> SupportedSectorTags => new SectorTagType[] { };
|
||||
// TODO: Test with real hardware to see real supported media
|
||||
public IEnumerable<MediaType> SupportedMediaTypes =>
|
||||
new[]
|
||||
{
|
||||
MediaType.Apricot_35, MediaType.ATARI_35_DS_DD,
|
||||
MediaType.ATARI_35_DS_DD_11, MediaType.ATARI_35_SS_DD, MediaType.ATARI_35_SS_DD_11, MediaType.DMF,
|
||||
MediaType.DMF_82, MediaType.DOS_35_DS_DD_8, MediaType.DOS_35_DS_DD_9, MediaType.DOS_35_ED,
|
||||
MediaType.DOS_35_HD, MediaType.DOS_35_SS_DD_8, MediaType.DOS_35_SS_DD_9, MediaType.DOS_525_DS_DD_8,
|
||||
MediaType.DOS_525_DS_DD_9, MediaType.DOS_525_HD, MediaType.DOS_525_SS_DD_8, MediaType.DOS_525_SS_DD_9,
|
||||
MediaType.FDFORMAT_35_DD, MediaType.FDFORMAT_35_HD, MediaType.FDFORMAT_525_DD,
|
||||
MediaType.FDFORMAT_525_HD, MediaType.RX50, MediaType.XDF_35, MediaType.XDF_525
|
||||
MediaType.Apricot_35, MediaType.ATARI_35_DS_DD, MediaType.ATARI_35_DS_DD_11, MediaType.ATARI_35_SS_DD,
|
||||
MediaType.ATARI_35_SS_DD_11, MediaType.DMF, MediaType.DMF_82, MediaType.DOS_35_DS_DD_8,
|
||||
MediaType.DOS_35_DS_DD_9, MediaType.DOS_35_ED, MediaType.DOS_35_HD, MediaType.DOS_35_SS_DD_8,
|
||||
MediaType.DOS_35_SS_DD_9, MediaType.DOS_525_DS_DD_8, MediaType.DOS_525_DS_DD_9, MediaType.DOS_525_HD,
|
||||
MediaType.DOS_525_SS_DD_8, MediaType.DOS_525_SS_DD_9, MediaType.FDFORMAT_35_DD,
|
||||
MediaType.FDFORMAT_35_HD, MediaType.FDFORMAT_525_DD, MediaType.FDFORMAT_525_HD, MediaType.RX50,
|
||||
MediaType.XDF_35, MediaType.XDF_525
|
||||
};
|
||||
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
||||
new(string name, Type type, string description)[] { };
|
||||
public IEnumerable<string> KnownExtensions => new[] {".dim"};
|
||||
public bool IsWriting { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
FileStream writingStream;
|
||||
public bool IsWriting { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors, uint sectorSize)
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
||||
uint sectorSize)
|
||||
{
|
||||
if(sectorSize == 512)
|
||||
{
|
||||
@@ -362,7 +342,7 @@ namespace DiscImageChef.DiscImages
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sectors > (255 * 255 * 255))
|
||||
if(sectors > 255 * 255 * 255)
|
||||
{
|
||||
ErrorMessage = $"Too many sectors";
|
||||
return false;
|
||||
@@ -376,13 +356,13 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
(ushort cylinders, byte heads, ushort sectorsPerTrack, uint bytesPerSector, MediaEncoding encoding, bool
|
||||
variableSectorsPerTrack, MediaType type) geometry = Geometry.GetGeometry(mediaType);
|
||||
imageInfo = new ImageInfo
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
MediaType = mediaType,
|
||||
SectorSize = sectorSize,
|
||||
Sectors = sectors,
|
||||
Cylinders = geometry.cylinders,
|
||||
Heads = geometry.heads,
|
||||
MediaType = mediaType,
|
||||
SectorSize = sectorSize,
|
||||
Sectors = sectors,
|
||||
Cylinders = geometry.cylinders,
|
||||
Heads = geometry.heads,
|
||||
SectorsPerTrack = geometry.sectorsPerTrack
|
||||
};
|
||||
|
||||
@@ -424,7 +404,8 @@ namespace DiscImageChef.DiscImages
|
||||
return false;
|
||||
}
|
||||
|
||||
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
||||
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize),
|
||||
SeekOrigin.Begin);
|
||||
writingStream.Write(data, 0, data.Length);
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -451,7 +432,8 @@ namespace DiscImageChef.DiscImages
|
||||
return false;
|
||||
}
|
||||
|
||||
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
||||
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize),
|
||||
SeekOrigin.Begin);
|
||||
writingStream.Write(data, 0, data.Length);
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -517,5 +499,26 @@ namespace DiscImageChef.DiscImages
|
||||
imageInfo.Comments = metadata.Comments;
|
||||
return true;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct RayHdr
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
|
||||
public byte[] signature;
|
||||
public RayDiskTypes diskType;
|
||||
public byte cylinders;
|
||||
public byte sectorsPerTrack;
|
||||
public byte heads;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
enum RayDiskTypes : byte
|
||||
{
|
||||
Md2dd = 1,
|
||||
Md2hd = 2,
|
||||
Mf2dd = 3,
|
||||
Mf2hd = 4,
|
||||
Mf2ed = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,34 +46,35 @@ namespace DiscImageChef.DiscImages
|
||||
public class Virtual98 : IWritableImage
|
||||
{
|
||||
readonly byte[] signature = {0x56, 0x48, 0x44, 0x31, 0x2E, 0x30, 0x30, 0x00};
|
||||
ImageInfo imageInfo;
|
||||
IFilter nhdImageFilter;
|
||||
ImageInfo imageInfo;
|
||||
IFilter nhdImageFilter;
|
||||
|
||||
Virtual98Header v98Hdr;
|
||||
FileStream writingStream;
|
||||
|
||||
public Virtual98()
|
||||
{
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null,
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null,
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
@@ -81,7 +82,7 @@ namespace DiscImageChef.DiscImages
|
||||
public ImageInfo Info => imageInfo;
|
||||
|
||||
public string Name => "Virtual98 Disk Image";
|
||||
public Guid Id => new Guid("C0CDE13D-04D0-4913-8740-AFAA44D0A107");
|
||||
public Guid Id => new Guid("C0CDE13D-04D0-4913-8740-AFAA44D0A107");
|
||||
|
||||
public string Format => "Virtual98 disk image";
|
||||
|
||||
@@ -109,7 +110,8 @@ namespace DiscImageChef.DiscImages
|
||||
stream.Read(hdrB, 0, hdrB.Length);
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);
|
||||
v98Hdr = (Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
|
||||
v98Hdr =
|
||||
(Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
|
||||
handle.Free();
|
||||
|
||||
if(!v98Hdr.signature.SequenceEqual(signature)) return false;
|
||||
@@ -118,13 +120,13 @@ namespace DiscImageChef.DiscImages
|
||||
StringHandlers.CToString(v98Hdr.signature, shiftjis));
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.comment = \"{0}\"",
|
||||
StringHandlers.CToString(v98Hdr.comment, shiftjis));
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.padding = {0}", v98Hdr.padding);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.mbsize = {0}", v98Hdr.mbsize);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.padding = {0}", v98Hdr.padding);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.mbsize = {0}", v98Hdr.mbsize);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.sectorsize = {0}", v98Hdr.sectorsize);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.sectors = {0}", v98Hdr.sectors);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.surfaces = {0}", v98Hdr.surfaces);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.cylinders = {0}", v98Hdr.cylinders);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.totals = {0}", v98Hdr.totals);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.sectors = {0}", v98Hdr.sectors);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.surfaces = {0}", v98Hdr.surfaces);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.cylinders = {0}", v98Hdr.cylinders);
|
||||
DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.totals = {0}", v98Hdr.totals);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -144,22 +146,23 @@ namespace DiscImageChef.DiscImages
|
||||
stream.Read(hdrB, 0, hdrB.Length);
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);
|
||||
v98Hdr = (Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
|
||||
v98Hdr =
|
||||
(Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
|
||||
handle.Free();
|
||||
|
||||
imageInfo.MediaType = MediaType.GENERIC_HDD;
|
||||
|
||||
imageInfo.ImageSize = (ulong)(stream.Length - 0xDC);
|
||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||
imageInfo.ImageSize = (ulong)(stream.Length - 0xDC);
|
||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
||||
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
||||
imageInfo.Sectors = v98Hdr.totals;
|
||||
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
||||
imageInfo.SectorSize = v98Hdr.sectorsize;
|
||||
imageInfo.Cylinders = v98Hdr.cylinders;
|
||||
imageInfo.Heads = v98Hdr.surfaces;
|
||||
imageInfo.SectorsPerTrack = v98Hdr.sectors;
|
||||
imageInfo.Comments = StringHandlers.CToString(v98Hdr.comment, shiftjis);
|
||||
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
||||
imageInfo.Sectors = v98Hdr.totals;
|
||||
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
||||
imageInfo.SectorSize = v98Hdr.sectorsize;
|
||||
imageInfo.Cylinders = v98Hdr.cylinders;
|
||||
imageInfo.Heads = v98Hdr.surfaces;
|
||||
imageInfo.SectorsPerTrack = v98Hdr.sectors;
|
||||
imageInfo.Comments = StringHandlers.CToString(v98Hdr.comment, shiftjis);
|
||||
|
||||
nhdImageFilter = imageFilter;
|
||||
|
||||
@@ -273,7 +276,7 @@ namespace DiscImageChef.DiscImages
|
||||
}
|
||||
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
@@ -283,7 +286,7 @@ namespace DiscImageChef.DiscImages
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -293,32 +296,18 @@ namespace DiscImageChef.DiscImages
|
||||
return null;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct Virtual98Header
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] signature;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public byte[] comment;
|
||||
public uint padding;
|
||||
public ushort mbsize;
|
||||
public ushort sectorsize;
|
||||
public byte sectors;
|
||||
public byte surfaces;
|
||||
public ushort cylinders;
|
||||
public uint totals;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x44)] public byte[] padding2;
|
||||
}
|
||||
|
||||
public IEnumerable<MediaTagType> SupportedMediaTags => new MediaTagType[] { };
|
||||
public IEnumerable<MediaTagType> SupportedMediaTags => new MediaTagType[] { };
|
||||
public IEnumerable<SectorTagType> SupportedSectorTags => new SectorTagType[] { };
|
||||
public IEnumerable<MediaType> SupportedMediaTypes => new []{MediaType.GENERIC_HDD, MediaType.Unknown};
|
||||
public IEnumerable<MediaType> SupportedMediaTypes =>
|
||||
new[] {MediaType.GENERIC_HDD, MediaType.Unknown};
|
||||
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
||||
new (string name, Type type, string description)[] { };
|
||||
public IEnumerable<string> KnownExtensions => new[] {".v98"};
|
||||
public bool IsWriting { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
FileStream writingStream;
|
||||
public bool IsWriting { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors, uint sectorSize)
|
||||
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
||||
uint sectorSize)
|
||||
{
|
||||
if(sectorSize == 0)
|
||||
{
|
||||
@@ -460,9 +449,7 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
byte[] commentsBytes = null;
|
||||
if(!string.IsNullOrEmpty(imageInfo.Comments))
|
||||
{
|
||||
commentsBytes = Encoding.GetEncoding("shift_jis").GetBytes(imageInfo.Comments);
|
||||
}
|
||||
|
||||
v98Hdr = new Virtual98Header
|
||||
{
|
||||
@@ -479,7 +466,7 @@ namespace DiscImageChef.DiscImages
|
||||
if(commentsBytes != null)
|
||||
Array.Copy(commentsBytes, 0, v98Hdr.comment, 0,
|
||||
commentsBytes.Length >= 128 ? 128 : commentsBytes.Length);
|
||||
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf(v98Hdr)];
|
||||
IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(v98Hdr));
|
||||
Marshal.StructureToPtr(v98Hdr, hdrPtr, true);
|
||||
@@ -501,5 +488,23 @@ namespace DiscImageChef.DiscImages
|
||||
imageInfo.Comments = metadata.Comments;
|
||||
return true;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct Virtual98Header
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public byte[] signature;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
public byte[] comment;
|
||||
public uint padding;
|
||||
public ushort mbsize;
|
||||
public ushort sectorsize;
|
||||
public byte sectors;
|
||||
public byte surfaces;
|
||||
public ushort cylinders;
|
||||
public uint totals;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x44)]
|
||||
public byte[] padding2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user