REFACTOR: Replace if statement with null-propagating code.

This commit is contained in:
2017-12-21 17:45:39 +00:00
parent 3053d22b91
commit a895700757
42 changed files with 91 additions and 172 deletions

View File

@@ -124,11 +124,9 @@ namespace DiscImageChef.Core.Logging
public void Close()
{
if(logSw == null) return;
logSw.WriteLine("######################################################");
logSw.WriteLine("End logging at {0}", DateTime.Now);
logSw.Close();
logSw?.WriteLine("######################################################");
logSw?.WriteLine("End logging at {0}", DateTime.Now);
logSw?.Close();
}
}
}

View File

@@ -68,11 +68,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_00_SFF? DecodeModePage_00_SFF(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x00) return null;
if((pageResponse?[0] & 0x3F) != 0x00) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -113,11 +113,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_01? DecodeModePage_01(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x01) return null;
if((pageResponse?[0] & 0x3F) != 0x01) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -69,11 +69,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_01_MMC? DecodeModePage_01_MMC(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x01) return null;
if((pageResponse?[0] & 0x3F) != 0x01) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -97,11 +97,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_02? DecodeModePage_02(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x02) return null;
if((pageResponse?[0] & 0x3F) != 0x02) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -105,11 +105,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_03? DecodeModePage_03(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x03) return null;
if((pageResponse?[0] & 0x3F) != 0x03) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -88,11 +88,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_04? DecodeModePage_04(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x04) return null;
if((pageResponse?[0] & 0x3F) != 0x04) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -153,11 +153,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_05? DecodeModePage_05(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x05) return null;
if((pageResponse?[0] & 0x3F) != 0x05) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -56,11 +56,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_06? DecodeModePage_06(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x06) return null;
if((pageResponse?[0] & 0x3F) != 0x06) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -80,11 +80,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_07? DecodeModePage_07(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x07) return null;
if((pageResponse?[0] & 0x3F) != 0x07) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -60,11 +60,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_07_MMC? DecodeModePage_07_MMC(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x07) return null;
if((pageResponse?[0] & 0x3F) != 0x07) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -136,11 +136,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_08? DecodeModePage_08(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x08) return null;
if((pageResponse?[0] & 0x3F) != 0x08) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -161,11 +161,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_0A? DecodeModePage_0A(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x0A) return null;
if((pageResponse?[0] & 0x3F) != 0x0A) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -56,11 +56,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_0B? DecodeModePage_0B(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x0B) return null;
if((pageResponse?[0] & 0x3F) != 0x0B) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -64,11 +64,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_0D? DecodeModePage_0D(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x0D) return null;
if((pageResponse?[0] & 0x3F) != 0x0D) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -104,11 +104,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_0E? DecodeModePage_0E(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x0E) return null;
if((pageResponse?[0] & 0x3F) != 0x0E) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -76,11 +76,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_0F? DecodeModePage_0F(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x0F) return null;
if((pageResponse?[0] & 0x3F) != 0x0F) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -72,11 +72,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_10? DecodeModePage_10(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x10) return null;
if((pageResponse?[0] & 0x3F) != 0x10) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -162,11 +162,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_10_SSC? DecodeModePage_10_SSC(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x10) return null;
if((pageResponse?[0] & 0x3F) != 0x10) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -128,11 +128,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_11? DecodeModePage_11(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x11) return null;
if((pageResponse?[0] & 0x3F) != 0x11) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -101,11 +101,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_1A? DecodeModePage_1A(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x1A) return null;
if((pageResponse?[0] & 0x3F) != 0x1A) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -72,11 +72,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_1B? DecodeModePage_1B(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x1B) return null;
if((pageResponse?[0] & 0x3F) != 0x1B) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -94,11 +94,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_1C? DecodeModePage_1C(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x1C) return null;
if((pageResponse?[0] & 0x3F) != 0x1C) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -64,11 +64,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_1C_SFF? DecodeModePage_1C_SFF(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x1C) return null;
if((pageResponse?[0] & 0x3F) != 0x1C) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -50,11 +50,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_1D? DecodeModePage_1D(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x1D) return null;
if((pageResponse?[0] & 0x3F) != 0x1D) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -55,11 +55,9 @@ namespace DiscImageChef.Decoders.SCSI
public static Certance_ModePage_21? DecodeCertanceModePage_21(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x21) return null;
if((pageResponse?[0] & 0x3F) != 0x21) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -58,11 +58,9 @@ namespace DiscImageChef.Decoders.SCSI
public static Certance_ModePage_22? DecodeCertanceModePage_22(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x22) return null;
if((pageResponse?[0] & 0x3F) != 0x22) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -51,11 +51,9 @@ namespace DiscImageChef.Decoders.SCSI
public static IBM_ModePage_24? DecodeIBMModePage_24(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x24) return null;
if((pageResponse?[0] & 0x3F) != 0x24) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -186,11 +186,9 @@ namespace DiscImageChef.Decoders.SCSI
public static ModePage_2A? DecodeModePage_2A(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x2A) return null;
if((pageResponse?[0] & 0x3F) != 0x2A) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -58,11 +58,9 @@ namespace DiscImageChef.Decoders.SCSI
public static IBM_ModePage_2F? DecodeIBMModePage_2F(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x2F) return null;
if((pageResponse?[0] & 0x3F) != 0x2F) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -46,11 +46,9 @@ namespace DiscImageChef.Decoders.SCSI
public static bool IsAppleModePage_30(byte[] pageResponse)
{
if(pageResponse == null) return false;
if((pageResponse?[0] & 0x40) == 0x40) return false;
if((pageResponse[0] & 0x40) == 0x40) return false;
if((pageResponse[0] & 0x3F) != 0x30) return false;
if((pageResponse?[0] & 0x3F) != 0x30) return false;
if(pageResponse[1] + 2 != pageResponse.Length) return false;

View File

@@ -50,11 +50,9 @@ namespace DiscImageChef.Decoders.SCSI
public static HP_ModePage_3B? DecodeHPModePage_3B(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3B) return null;
if((pageResponse?[0] & 0x3F) != 0x3B) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -60,11 +60,9 @@ namespace DiscImageChef.Decoders.SCSI
public static HP_ModePage_3C? DecodeHPModePage_3C(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3C) return null;
if((pageResponse?[0] & 0x3F) != 0x3C) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -48,11 +48,9 @@ namespace DiscImageChef.Decoders.SCSI
public static HP_ModePage_3D? DecodeHPModePage_3D(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3D) return null;
if((pageResponse?[0] & 0x3F) != 0x3D) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -48,11 +48,9 @@ namespace DiscImageChef.Decoders.SCSI
public static IBM_ModePage_3D? DecodeIBMModePage_3D(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3D) return null;
if((pageResponse?[0] & 0x3F) != 0x3D) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -84,11 +84,9 @@ namespace DiscImageChef.Decoders.SCSI
public static Fujitsu_ModePage_3E? DecodeFujitsuModePage_3E(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3E) return null;
if((pageResponse?[0] & 0x3F) != 0x3E) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -49,11 +49,9 @@ namespace DiscImageChef.Decoders.SCSI
public static HP_ModePage_3E? DecodeHPModePage_3E(byte[] pageResponse)
{
if(pageResponse == null) return null;
if((pageResponse?[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x40) == 0x40) return null;
if((pageResponse[0] & 0x3F) != 0x3E) return null;
if((pageResponse?[0] & 0x3F) != 0x3E) return null;
if(pageResponse[1] + 2 != pageResponse.Length) return null;

View File

@@ -359,14 +359,12 @@ namespace DiscImageChef.DiscImages
if(rsrcFork.ContainsKey(0x434B534D))
{
Resource cksmRsrc = rsrcFork.GetResource(0x434B534D);
if(cksmRsrc != null)
{
if(cksmRsrc.ContainsId(1))
if(cksmRsrc?.ContainsId(1) == true)
{
byte[] tagChk = cksmRsrc.GetResource(1);
tagChecksum = BigEndianBitConverter.ToUInt32(tagChk, 0);
}
if(cksmRsrc.ContainsId(2))
if(cksmRsrc?.ContainsId(2) == true)
{
byte[] dataChk = cksmRsrc.GetResource(1);
dataChecksum = BigEndianBitConverter.ToUInt32(dataChk, 0);
@@ -374,7 +372,6 @@ namespace DiscImageChef.DiscImages
}
}
}
}
catch(InvalidCastException) { }
DicConsole.DebugWriteLine("DART plugin", "Image application = {0} version {1}", ImageInfo.ImageApplication,

View File

@@ -212,10 +212,9 @@ namespace DiscImageChef.Filters
public override string GetFilename()
{
if(basePath == null) return null;
if(basePath.EndsWith(".bz2", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".bz2", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 4);
if(basePath.EndsWith(".bzip2", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".bzip2", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 6);
return basePath;

View File

@@ -221,10 +221,9 @@ namespace DiscImageChef.Filters
public override string GetFilename()
{
if(basePath == null) return null;
if(basePath.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
if(basePath.EndsWith(".gzip", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".gzip", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 5);
return basePath;

View File

@@ -195,10 +195,9 @@ namespace DiscImageChef.Filters
public override string GetFilename()
{
if(basePath == null) return null;
if(basePath.EndsWith(".lz", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".lz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
if(basePath.EndsWith(".lzip", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".lzip", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 5);
return basePath;

View File

@@ -237,10 +237,9 @@ namespace DiscImageChef.Filters
public override string GetFilename()
{
if(basePath == null) return null;
if(basePath.EndsWith(".xz", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".xz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
if(basePath.EndsWith(".xzip", StringComparison.InvariantCultureIgnoreCase))
if(basePath?.EndsWith(".xzip", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 5);
return basePath;