REFACTOR: All refactor in DiscImageChef.Decoders.

This commit is contained in:
2017-12-22 02:04:18 +00:00
parent 7f829422a8
commit 49144eeb01
148 changed files with 2606 additions and 1939 deletions

View File

@@ -32,11 +32,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
namespace DiscImageChef.Decoders.PCMCIA
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class CIS
{
// TODO: Handle links? Or are they removed in lower layers of the operating system drivers?
@@ -47,9 +51,7 @@ namespace DiscImageChef.Decoders.PCMCIA
while(position < data.Length)
{
Tuple tuple = new Tuple();
tuple.Code = (TupleCodes)data[position];
Tuple tuple = new Tuple {Code = (TupleCodes)data[position]};
if(tuple.Code == TupleCodes.CISTPL_NULL) continue;
@@ -75,28 +77,27 @@ namespace DiscImageChef.Decoders.PCMCIA
if(tuple.Code != TupleCodes.CISTPL_DEVICEGEO && tuple.Code != TupleCodes.CISTPL_DEVICEGEO_A) return null;
if(tuple.Data == null) return null;
return DecodeDeviceGeometryTuple(tuple.Data);
return tuple.Data == null ? null : DecodeDeviceGeometryTuple(tuple.Data);
}
public static DeviceGeometryTuple DecodeDeviceGeometryTuple(byte[] data)
{
if(data == null) return null;
if((data.Length - 2) % 6 != 0) return null;
if((data?.Length - 2) % 6 != 0) return null;
DeviceGeometryTuple tuple = new DeviceGeometryTuple();
List<DeviceGeometry> geometries = new List<DeviceGeometry>();
for(int position = 2; position < data.Length; position += 6)
{
DeviceGeometry geometry = new DeviceGeometry();
geometry.CardInterface = data[position];
geometry.EraseBlockSize = data[position + 1];
geometry.ReadBlockSize = data[position + 2];
geometry.WriteBlockSize = data[position + 3];
geometry.Partitions = data[position + 4];
geometry.Interleaving = data[position + 5];
DeviceGeometry geometry = new DeviceGeometry
{
CardInterface = data[position],
EraseBlockSize = data[position + 1],
ReadBlockSize = data[position + 2],
WriteBlockSize = data[position + 3],
Partitions = data[position + 4],
Interleaving = data[position + 5]
};
geometries.Add(geometry);
}
@@ -145,13 +146,9 @@ namespace DiscImageChef.Decoders.PCMCIA
public static ManufacturerIdentificationTuple DecodeManufacturerIdentificationTuple(Tuple tuple)
{
if(tuple == null) return null;
if(tuple?.Code != TupleCodes.CISTPL_MANFID) return null;
if(tuple.Code != TupleCodes.CISTPL_MANFID) return null;
if(tuple.Data == null) return null;
return DecodeManufacturerIdentificationTuple(tuple.Data);
return tuple.Data == null ? null : DecodeManufacturerIdentificationTuple(tuple.Data);
}
public static ManufacturerIdentificationTuple DecodeManufacturerIdentificationTuple(byte[] data)
@@ -160,20 +157,18 @@ namespace DiscImageChef.Decoders.PCMCIA
if(data.Length < 6) return null;
ManufacturerIdentificationTuple tuple = new ManufacturerIdentificationTuple();
tuple.Code = (TupleCodes)data[0];
tuple.Link = data[1];
tuple.ManufacturerID = BitConverter.ToUInt16(data, 2);
tuple.CardID = BitConverter.ToUInt16(data, 4);
return tuple;
return new ManufacturerIdentificationTuple
{
Code = (TupleCodes)data[0],
Link = data[1],
ManufacturerID = BitConverter.ToUInt16(data, 2),
CardID = BitConverter.ToUInt16(data, 4)
};
}
public static string PrettifyManufacturerIdentificationTuple(ManufacturerIdentificationTuple tuple)
{
if(tuple == null) return null;
if(tuple.Code != TupleCodes.CISTPL_MANFID) return null;
if(tuple?.Code != TupleCodes.CISTPL_MANFID) return null;
StringBuilder sb = new StringBuilder();
sb.AppendLine("PCMCIA Manufacturer Identification Tuple:");
@@ -195,13 +190,9 @@ namespace DiscImageChef.Decoders.PCMCIA
public static Level1VersionTuple DecodeLevel1VersionTuple(Tuple tuple)
{
if(tuple == null) return null;
if(tuple?.Code != TupleCodes.CISTPL_VERS_1) return null;
if(tuple.Code != TupleCodes.CISTPL_VERS_1) return null;
if(tuple.Data == null) return null;
return DecodeLevel1VersionTuple(tuple.Data);
return tuple.Data == null ? null : DecodeLevel1VersionTuple(tuple.Data);
}
public static Level1VersionTuple DecodeLevel1VersionTuple(byte[] data)
@@ -215,11 +206,13 @@ namespace DiscImageChef.Decoders.PCMCIA
bool firstString = false;
bool secondString = false;
Level1VersionTuple tuple = new Level1VersionTuple();
tuple.Code = (TupleCodes)data[0];
tuple.Link = data[1];
tuple.MajorVersion = data[2];
tuple.MinorVersion = data[3];
Level1VersionTuple tuple = new Level1VersionTuple
{
Code = (TupleCodes)data[0],
Link = data[1],
MajorVersion = data[2],
MinorVersion = data[3]
};
for(int position = 4; position < data.Length; position++)
{
@@ -259,9 +252,7 @@ namespace DiscImageChef.Decoders.PCMCIA
public static string PrettifyLevel1VersionTuple(Level1VersionTuple tuple)
{
if(tuple == null) return null;
if(tuple.Code != TupleCodes.CISTPL_VERS_1) return null;
if(tuple?.Code != TupleCodes.CISTPL_VERS_1) return null;
StringBuilder sb = new StringBuilder();
sb.AppendLine("PCMCIA Level 1 Version / Product Information Tuple:");