Convert if to switch statement.

This commit is contained in:
2022-11-13 19:38:02 +00:00
parent d7577c9880
commit 02d6222ae9
13 changed files with 752 additions and 410 deletions

View File

@@ -3741,15 +3741,27 @@ public static class Features
else if(ftr.DVDPRead &&
ftr.DVDPWrite)
sb.Append("Drive can read and write DVD+MRW");
else if(ftr.Write &&
ftr.DVDPRead)
sb.Append("Drive and read DVD+MRW and read and write CD-MRW");
else if(ftr.Write)
sb.Append("Drive can read and write CD-MRW");
else if(ftr.DVDPRead)
sb.Append("Drive can read CD-MRW and DVD+MRW");
else
sb.Append("Drive can read CD-MRW");
switch(ftr.Write)
{
case true when ftr.DVDPRead:
sb.Append("Drive and read DVD+MRW and read and write CD-MRW");
break;
case true:
sb.Append("Drive can read and write CD-MRW");
break;
default:
{
if(ftr.DVDPRead)
sb.Append("Drive can read CD-MRW and DVD+MRW");
else
sb.Append("Drive can read CD-MRW");
break;
}
}
if(ftr.Current)
sb.AppendLine(" (current)");
@@ -3968,14 +3980,21 @@ public static class Features
Feature_002E ftr = feature.Value;
var sb = new StringBuilder();
if(ftr.SAO &&
!ftr.RAW)
sb.AppendLine("Drive can write CDs in Session at Once Mode:");
else if(!ftr.SAO &&
ftr.RAW)
sb.AppendLine("Drive can write CDs in raw Mode:");
else
sb.AppendLine("Drive can write CDs in Session at Once and in Raw Modes:");
switch(ftr.SAO)
{
case true when !ftr.RAW:
sb.AppendLine("Drive can write CDs in Session at Once Mode:");
break;
case false when ftr.RAW:
sb.AppendLine("Drive can write CDs in raw Mode:");
break;
default:
sb.AppendLine("Drive can write CDs in Session at Once and in Raw Modes:");
break;
}
if(ftr.RAW &&
ftr.RAWMS)
@@ -4270,7 +4289,8 @@ public static class Features
}
public static string Prettify_0042(Feature_0042? feature) =>
!feature.HasValue ? null : "Drive is able to detect and report defective writable unit and behave accordingly\n";
!feature.HasValue ? null
: "Drive is able to detect and report defective writable unit and behave accordingly\n";
public static string Prettify_0050(Feature_0050? feature)
{
@@ -4280,15 +4300,26 @@ public static class Features
Feature_0050 ftr = feature.Value;
var sb = new StringBuilder();
if(ftr.HDDVDR &&
ftr.HDDVDRAM)
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW, HD DVD-R and HD DVD-RAM");
else if(ftr.HDDVDR)
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-R");
else if(ftr.HDDVDRAM)
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-RAM");
else
sb.Append("Drive can read HD DVD-ROM and HD DVD-RW");
switch(ftr.HDDVDR)
{
case true when ftr.HDDVDRAM:
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW, HD DVD-R and HD DVD-RAM");
break;
case true:
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-R");
break;
default:
{
if(ftr.HDDVDRAM)
sb.Append("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-RAM");
else
sb.Append("Drive can read HD DVD-ROM and HD DVD-RW");
break;
}
}
if(ftr.Current)
sb.AppendLine(" (current)");
@@ -4306,15 +4337,26 @@ public static class Features
Feature_0051 ftr = feature.Value;
var sb = new StringBuilder();
if(ftr.HDDVDR &&
ftr.HDDVDRAM)
sb.Append("Drive can write HD DVD-RW, HD DVD-R and HD DVD-RAM");
else if(ftr.HDDVDR)
sb.Append("Drive can write HD DVD-RW and HD DVD-R");
else if(ftr.HDDVDRAM)
sb.Append("Drive can write HD DVD-RW and HD DVD-RAM");
else
sb.Append("Drive can write HD DVD-RW");
switch(ftr.HDDVDR)
{
case true when ftr.HDDVDRAM:
sb.Append("Drive can write HD DVD-RW, HD DVD-R and HD DVD-RAM");
break;
case true:
sb.Append("Drive can write HD DVD-RW and HD DVD-R");
break;
default:
{
if(ftr.HDDVDRAM)
sb.Append("Drive can write HD DVD-RW and HD DVD-RAM");
else
sb.Append("Drive can write HD DVD-RW");
break;
}
}
if(ftr.Current)
sb.AppendLine(" (current)");

View File

@@ -163,16 +163,25 @@ public static partial class Modes
if(page.POFM)
sb.AppendLine("\tPartition parameters will not be applied until a FORMAT MEDIUM command is received");
if(!page.CLEAR &&
!page.ADDP)
sb.AppendLine("\tDevice may erase any or all partitions on MODE SELECT for partitioning");
else if(page.CLEAR &&
!page.ADDP)
sb.AppendLine("\tDevice shall erase all partitions on MODE SELECT for partitioning");
else if(!page.CLEAR)
sb.AppendLine("\tDevice shall not erase any partition on MODE SELECT for partitioning");
else
sb.AppendLine("\tDevice shall erase all partitions differing on size on MODE SELECT for partitioning");
switch(page.CLEAR)
{
case false when !page.ADDP:
sb.AppendLine("\tDevice may erase any or all partitions on MODE SELECT for partitioning");
break;
case true when !page.ADDP:
sb.AppendLine("\tDevice shall erase all partitions on MODE SELECT for partitioning");
break;
case false:
sb.AppendLine("\tDevice shall not erase any partition on MODE SELECT for partitioning");
break;
default:
sb.AppendLine("\tDevice shall erase all partitions differing on size on MODE SELECT for partitioning");
break;
}
string measure;

View File

@@ -187,14 +187,19 @@ public static partial class Modes
sb.AppendLine("\tDrive contains a changer that can report the exact contents of the slots");
if(page.CurrentWriteSpeedSelected > 0)
{
if(page.RotationControlSelected == 0)
sb.AppendFormat("\tDrive's current writing speed is {0} Kbyte/sec. in CLV mode",
page.CurrentWriteSpeedSelected).AppendLine();
else if(page.RotationControlSelected == 1)
sb.AppendFormat("\tDrive's current writing speed is {0} Kbyte/sec. in pure CAV mode",
page.CurrentWriteSpeedSelected).AppendLine();
}
switch(page.RotationControlSelected)
{
case 0:
sb.AppendFormat("\tDrive's current writing speed is {0} Kbyte/sec. in CLV mode",
page.CurrentWriteSpeedSelected).AppendLine();
break;
case 1:
sb.AppendFormat("\tDrive's current writing speed is {0} Kbyte/sec. in pure CAV mode",
page.CurrentWriteSpeedSelected).AppendLine();
break;
}
else
{
if(page.MaxWriteSpeed > 0)
@@ -208,12 +213,19 @@ public static partial class Modes
if(page.WriteSpeedPerformanceDescriptors != null)
foreach(ModePage_2A_WriteDescriptor descriptor in page.WriteSpeedPerformanceDescriptors.Where(descriptor =>
descriptor.WriteSpeed > 0))
if(descriptor.RotationControl == 0)
sb.AppendFormat("\tDrive supports writing at {0} Kbyte/sec. in CLV mode", descriptor.WriteSpeed).
AppendLine();
else if(descriptor.RotationControl == 1)
sb.AppendFormat("\tDrive supports writing at is {0} Kbyte/sec. in pure CAV mode",
descriptor.WriteSpeed).AppendLine();
switch(descriptor.RotationControl)
{
case 0:
sb.AppendFormat("\tDrive supports writing at {0} Kbyte/sec. in CLV mode",
descriptor.WriteSpeed).AppendLine();
break;
case 1:
sb.AppendFormat("\tDrive supports writing at is {0} Kbyte/sec. in pure CAV mode",
descriptor.WriteSpeed).AppendLine();
break;
}
if(page.TestWrite)
sb.AppendLine("\tDrive supports test writing");

View File

@@ -200,36 +200,43 @@ public static partial class Modes
offset += pg.PageResponse.Length;
}
else
{
if(isSubpage && offset + 3 < modeResponse.Length)
switch(isSubpage)
{
pg.PageResponse = new byte[(modeResponse[offset + 2] << 8) + modeResponse[offset + 3] + 4];
int copyLen = pg.PageResponse.Length;
case true when offset + 3 < modeResponse.Length:
{
pg.PageResponse = new byte[(modeResponse[offset + 2] << 8) + modeResponse[offset + 3] + 4];
int copyLen = pg.PageResponse.Length;
if(pg.PageResponse.Length + offset > modeResponse.Length)
copyLen = modeResponse.Length - offset;
if(pg.PageResponse.Length + offset > modeResponse.Length)
copyLen = modeResponse.Length - offset;
Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
pg.Page = (byte)(modeResponse[offset] & 0x3F);
pg.Subpage = modeResponse[offset + 1];
offset += pg.PageResponse.Length;
Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
pg.Page = (byte)(modeResponse[offset] & 0x3F);
pg.Subpage = modeResponse[offset + 1];
offset += pg.PageResponse.Length;
break;
}
case true when offset + 1 < modeResponse.Length:
{
pg.PageResponse = new byte[modeResponse[offset + 1] + 2];
int copyLen = pg.PageResponse.Length;
if(pg.PageResponse.Length + offset > modeResponse.Length)
copyLen = modeResponse.Length - offset;
Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
pg.Page = (byte)(modeResponse[offset] & 0x3F);
pg.Subpage = 0;
offset += pg.PageResponse.Length;
break;
}
default:
offset = modeResponse.Length;
break;
}
else if(isSubpage && offset + 1 < modeResponse.Length)
{
pg.PageResponse = new byte[modeResponse[offset + 1] + 2];
int copyLen = pg.PageResponse.Length;
if(pg.PageResponse.Length + offset > modeResponse.Length)
copyLen = modeResponse.Length - offset;
Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
pg.Page = (byte)(modeResponse[offset] & 0x3F);
pg.Subpage = 0;
offset += pg.PageResponse.Length;
}
else
offset = modeResponse.Length;
}
listpages.Add(pg);
}