mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General code cleanup and style refactor.
This commit is contained in:
@@ -30,8 +30,6 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -46,6 +44,8 @@ using Claunia.Encoding;
|
||||
using Claunia.RsrcFork;
|
||||
using Version = Resources.Version;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
public sealed partial class Ndif
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -118,17 +118,17 @@ public sealed partial class Ndif
|
||||
// Block chunks and headers
|
||||
_chunks = new Dictionary<ulong, BlockChunk>();
|
||||
|
||||
for(var i = 0; i < _header.chunks; i++)
|
||||
for(int i = 0; i < _header.chunks; i++)
|
||||
{
|
||||
// Obsolete read-only NDIF only prepended the header and then put the image without any kind of block references.
|
||||
// So let's falsify a block chunk
|
||||
var bChnk = new BlockChunk();
|
||||
var sector = new byte[4];
|
||||
Array.Copy(bcem, 128 + 0 + i * 12, sector, 1, 3);
|
||||
var bChnk = new BlockChunk();
|
||||
byte[] sector = new byte[4];
|
||||
Array.Copy(bcem, 128 + 0 + (i * 12), sector, 1, 3);
|
||||
bChnk.sector = BigEndianBitConverter.ToUInt32(sector, 0);
|
||||
bChnk.type = bcem[128 + 3 + i * 12];
|
||||
bChnk.offset = BigEndianBitConverter.ToUInt32(bcem, 128 + 4 + i * 12);
|
||||
bChnk.length = BigEndianBitConverter.ToUInt32(bcem, 128 + 8 + i * 12);
|
||||
bChnk.type = bcem[128 + 3 + (i * 12)];
|
||||
bChnk.offset = BigEndianBitConverter.ToUInt32(bcem, 128 + 4 + (i * 12));
|
||||
bChnk.length = BigEndianBitConverter.ToUInt32(bcem, 128 + 8 + (i * 12));
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].type = 0x{1:X2}", i, bChnk.type);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].sector = {1}", i, bChnk.sector);
|
||||
@@ -160,8 +160,7 @@ public sealed partial class Ndif
|
||||
|
||||
// TODO: Handle compressed chunks
|
||||
if(bChnk.type is > CHUNK_TYPE_COPY and < CHUNK_TYPE_KENCODE or > CHUNK_TYPE_ADC and < CHUNK_TYPE_STUFFIT
|
||||
or > CHUNK_TYPE_STUFFIT and < CHUNK_TYPE_END
|
||||
or 1)
|
||||
or > CHUNK_TYPE_STUFFIT and < CHUNK_TYPE_END or 1)
|
||||
{
|
||||
AaruConsole.ErrorWriteLine($"Unsupported chunk type 0x{bChnk.type:X8} found");
|
||||
|
||||
@@ -189,13 +188,13 @@ public sealed partial class Ndif
|
||||
}
|
||||
|
||||
_imageInfo.MediaType = _imageInfo.Sectors switch
|
||||
{
|
||||
1440 => MediaType.DOS_35_DS_DD_9,
|
||||
1600 => MediaType.AppleSonyDS,
|
||||
2880 => MediaType.DOS_35_HD,
|
||||
3360 => MediaType.DMF,
|
||||
_ => MediaType.GENERIC_HDD
|
||||
};
|
||||
{
|
||||
1440 => MediaType.DOS_35_DS_DD_9,
|
||||
1600 => MediaType.AppleSonyDS,
|
||||
2880 => MediaType.DOS_35_HD,
|
||||
3360 => MediaType.DMF,
|
||||
_ => MediaType.GENERIC_HDD
|
||||
};
|
||||
|
||||
if(rsrcFork.ContainsKey(0x76657273))
|
||||
{
|
||||
@@ -217,12 +216,12 @@ public sealed partial class Ndif
|
||||
release = $".{version.MinorVersion % 10}";
|
||||
|
||||
string dev = version.DevStage switch
|
||||
{
|
||||
Version.DevelopmentStage.Alpha => "a",
|
||||
Version.DevelopmentStage.Beta => "b",
|
||||
Version.DevelopmentStage.PreAlpha => "d",
|
||||
_ => null
|
||||
};
|
||||
{
|
||||
Version.DevelopmentStage.Alpha => "a",
|
||||
Version.DevelopmentStage.Beta => "b",
|
||||
Version.DevelopmentStage.PreAlpha => "d",
|
||||
_ => null
|
||||
};
|
||||
|
||||
if(dev == null &&
|
||||
version.PreReleaseVersion > 0)
|
||||
@@ -236,11 +235,11 @@ public sealed partial class Ndif
|
||||
_imageInfo.Comments = version.VersionMessage;
|
||||
|
||||
_imageInfo.Application = version.MajorVersion switch
|
||||
{
|
||||
3 => "ShrinkWrap™",
|
||||
6 => "DiskCopy",
|
||||
_ => _imageInfo.Application
|
||||
};
|
||||
{
|
||||
3 => "ShrinkWrap™",
|
||||
6 => "DiskCopy",
|
||||
_ => _imageInfo.Application
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +313,7 @@ public sealed partial class Ndif
|
||||
return ErrorNumber.NoError;
|
||||
|
||||
var currentChunk = new BlockChunk();
|
||||
var chunkFound = false;
|
||||
bool chunkFound = false;
|
||||
ulong chunkStartSector = 0;
|
||||
|
||||
foreach(KeyValuePair<ulong, BlockChunk> kvp in _chunks.Where(kvp => sectorAddress >= kvp.Key))
|
||||
@@ -336,7 +335,7 @@ public sealed partial class Ndif
|
||||
{
|
||||
if(!_chunkCache.TryGetValue(chunkStartSector, out byte[] data))
|
||||
{
|
||||
var cmpBuffer = new byte[currentChunk.length];
|
||||
byte[] cmpBuffer = new byte[currentChunk.length];
|
||||
_imageStream.Seek(currentChunk.offset, SeekOrigin.Begin);
|
||||
_imageStream.EnsureRead(cmpBuffer, 0, cmpBuffer.Length);
|
||||
int realSize;
|
||||
@@ -345,7 +344,7 @@ public sealed partial class Ndif
|
||||
{
|
||||
case CHUNK_TYPE_ADC:
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
byte[] tmpBuffer = new byte[_bufferSize];
|
||||
realSize = ADC.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
@@ -355,7 +354,7 @@ public sealed partial class Ndif
|
||||
|
||||
case CHUNK_TYPE_RLE:
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
byte[] tmpBuffer = new byte[_bufferSize];
|
||||
realSize = AppleRle.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
Reference in New Issue
Block a user