mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General cleanup and refactor.
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
/// <summary>Implements reading CopyQM disk images</summary>
|
||||
public sealed partial class CopyQm : IMediaImage, IVerifiableImage
|
||||
{
|
||||
|
||||
@@ -30,12 +30,12 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -47,10 +47,10 @@ public sealed partial class CopyQm
|
||||
if(stream.Length < 133)
|
||||
return false;
|
||||
|
||||
byte[] hdr = new byte[133];
|
||||
var hdr = new byte[133];
|
||||
stream.Read(hdr, 0, 133);
|
||||
|
||||
ushort magic = BitConverter.ToUInt16(hdr, 0);
|
||||
var magic = BitConverter.ToUInt16(hdr, 0);
|
||||
|
||||
return magic == COPYQM_MAGIC && hdr[0x02] == COPYQM_MARK && 133 + hdr[0x6F] < stream.Length;
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Schemas;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -44,7 +44,7 @@ public sealed partial class CopyQm
|
||||
/// <inheritdoc />
|
||||
public string Name => "Sydex CopyQM";
|
||||
/// <inheritdoc />
|
||||
public Guid Id => new Guid("147E927D-3A92-4E0C-82CD-142F5A4FA76D");
|
||||
public Guid Id => new("147E927D-3A92-4E0C-82CD-142F5A4FA76D");
|
||||
/// <inheritdoc />
|
||||
public string Format => "Sydex CopyQM";
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aaru.CommonTypes;
|
||||
@@ -38,8 +40,6 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
using Aaru.Helpers;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -48,7 +48,7 @@ public sealed partial class CopyQm
|
||||
Stream stream = imageFilter.GetDataForkStream();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
byte[] hdr = new byte[133];
|
||||
var hdr = new byte[133];
|
||||
|
||||
stream.Read(hdr, 0, 133);
|
||||
_header = Marshal.ByteArrayToStructureLittleEndian<Header>(hdr);
|
||||
@@ -83,7 +83,7 @@ public sealed partial class CopyQm
|
||||
AaruConsole.DebugWriteLine("CopyQM plugin", "header.skew = {0}", _header.skew);
|
||||
AaruConsole.DebugWriteLine("CopyQM plugin", "header.drive = {0}", _header.drive);
|
||||
|
||||
byte[] cmt = new byte[_header.commentLength];
|
||||
var cmt = new byte[_header.commentLength];
|
||||
stream.Read(cmt, 0, _header.commentLength);
|
||||
_imageInfo.Comments = StringHandlers.CToString(cmt);
|
||||
_decodedImage = new MemoryStream();
|
||||
@@ -92,20 +92,20 @@ public sealed partial class CopyQm
|
||||
|
||||
while(stream.Position + 2 < stream.Length)
|
||||
{
|
||||
byte[] runLengthBytes = new byte[2];
|
||||
var runLengthBytes = new byte[2];
|
||||
|
||||
if(stream.Read(runLengthBytes, 0, 2) != 2)
|
||||
break;
|
||||
|
||||
short runLength = BitConverter.ToInt16(runLengthBytes, 0);
|
||||
var runLength = BitConverter.ToInt16(runLengthBytes, 0);
|
||||
|
||||
if(runLength < 0)
|
||||
{
|
||||
byte repeatedByte = (byte)stream.ReadByte();
|
||||
byte[] repeatedArray = new byte[runLength * -1];
|
||||
var repeatedByte = (byte)stream.ReadByte();
|
||||
var repeatedArray = new byte[runLength * -1];
|
||||
ArrayHelpers.ArrayFill(repeatedArray, repeatedByte);
|
||||
|
||||
for(int i = 0; i < runLength * -1; i++)
|
||||
for(var i = 0; i < runLength * -1; i++)
|
||||
{
|
||||
_decodedImage.WriteByte(repeatedByte);
|
||||
|
||||
@@ -115,31 +115,30 @@ public sealed partial class CopyQm
|
||||
}
|
||||
else if(runLength > 0)
|
||||
{
|
||||
byte[] nonRepeated = new byte[runLength];
|
||||
var nonRepeated = new byte[runLength];
|
||||
stream.Read(nonRepeated, 0, runLength);
|
||||
_decodedImage.Write(nonRepeated, 0, runLength);
|
||||
|
||||
foreach(byte c in nonRepeated)
|
||||
_calculatedDataCrc =
|
||||
_copyQmCrcTable[(c ^ _calculatedDataCrc) & 0x3F] ^ (_calculatedDataCrc >> 8);
|
||||
_calculatedDataCrc = _copyQmCrcTable[(c ^ _calculatedDataCrc) & 0x3F] ^ (_calculatedDataCrc >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
// In case there is omitted data
|
||||
long sectors = _header.sectorsPerTrack * _header.heads * _header.totalCylinders;
|
||||
|
||||
long fillingLen = (sectors * _header.sectorSize) - _decodedImage.Length;
|
||||
long fillingLen = sectors * _header.sectorSize - _decodedImage.Length;
|
||||
|
||||
if(fillingLen > 0)
|
||||
{
|
||||
byte[] filling = new byte[fillingLen];
|
||||
var filling = new byte[fillingLen];
|
||||
ArrayHelpers.ArrayFill(filling, (byte)0xF6);
|
||||
_decodedImage.Write(filling, 0, filling.Length);
|
||||
}
|
||||
|
||||
int sum = 0;
|
||||
var sum = 0;
|
||||
|
||||
for(int i = 0; i < hdr.Length - 1; i++)
|
||||
for(var i = 0; i < hdr.Length - 1; i++)
|
||||
sum += hdr[i];
|
||||
|
||||
_headerChecksumOk = ((-1 * sum) & 0xFF) == _header.headerChecksum;
|
||||
@@ -159,8 +158,8 @@ public sealed partial class CopyQm
|
||||
_imageInfo.SectorSize = _header.sectorSize;
|
||||
|
||||
_imageInfo.MediaType = Geometry.GetMediaType((_header.totalCylinders, (byte)_header.heads,
|
||||
_header.sectorsPerTrack, _header.sectorSize,
|
||||
MediaEncoding.MFM, false));
|
||||
_header.sectorsPerTrack, _header.sectorSize, MediaEncoding.MFM,
|
||||
false));
|
||||
|
||||
switch(_imageInfo.MediaType)
|
||||
{
|
||||
@@ -196,8 +195,7 @@ public sealed partial class CopyQm
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
@@ -212,8 +210,7 @@ public sealed partial class CopyQm
|
||||
|
||||
buffer = new byte[length * _imageInfo.SectorSize];
|
||||
|
||||
Array.Copy(_decodedDisk, (int)sectorAddress * _imageInfo.SectorSize, buffer, 0,
|
||||
length * _imageInfo.SectorSize);
|
||||
Array.Copy(_decodedDisk, (int)sectorAddress * _imageInfo.SectorSize, buffer, 0, length * _imageInfo.SectorSize);
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
public sealed partial class CopyQm
|
||||
{
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user