mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Invert 'if' statement to reduce nesting.
This commit is contained in:
@@ -43,101 +43,99 @@ namespace DiscImageChef.Core.Logging
|
||||
|
||||
internal MhddLog(string outputFile, Device dev, ulong blocks, ulong blockSize, ulong blocksToRead)
|
||||
{
|
||||
if(dev != null && !string.IsNullOrEmpty(outputFile))
|
||||
if(dev == null || string.IsNullOrEmpty(outputFile)) return;
|
||||
|
||||
mhddFs = new FileStream(outputFile, FileMode.Create);
|
||||
|
||||
string device;
|
||||
string mode;
|
||||
string fw;
|
||||
string sn;
|
||||
string sectors;
|
||||
string sectorsize;
|
||||
string scanblocksize;
|
||||
string ver;
|
||||
|
||||
switch(dev.Type)
|
||||
{
|
||||
mhddFs = new FileStream(outputFile, FileMode.Create);
|
||||
|
||||
string device;
|
||||
string mode;
|
||||
string fw;
|
||||
string sn;
|
||||
string sectors;
|
||||
string sectorsize;
|
||||
string scanblocksize;
|
||||
string ver;
|
||||
|
||||
switch(dev.Type)
|
||||
{
|
||||
case DeviceType.ATA:
|
||||
case DeviceType.ATAPI:
|
||||
mode = "MODE: IDE";
|
||||
break;
|
||||
case DeviceType.SCSI:
|
||||
mode = "MODE: SCSI";
|
||||
break;
|
||||
case DeviceType.MMC:
|
||||
mode = "MODE: MMC";
|
||||
break;
|
||||
case DeviceType.NVMe:
|
||||
mode = "MODE: NVMe";
|
||||
break;
|
||||
case DeviceType.SecureDigital:
|
||||
mode = "MODE: SD";
|
||||
break;
|
||||
default:
|
||||
mode = "MODE: IDE";
|
||||
break;
|
||||
}
|
||||
|
||||
device = string.Format("DEVICE: {0} {1}", dev.Manufacturer, dev.Model);
|
||||
fw = string.Format("F/W: {0}", dev.Revision);
|
||||
sn = string.Format("S/N: {0}", dev.Serial);
|
||||
sectors = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTORS: {0:n0}", blocks);
|
||||
sectorsize = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTOR SIZE: {0:n0} bytes",
|
||||
blockSize);
|
||||
scanblocksize = string.Format(new System.Globalization.CultureInfo("en-US"),
|
||||
"SCAN BLOCK SIZE: {0:n0} sectors", blocksToRead);
|
||||
ver = "VER:2 ";
|
||||
|
||||
byte[] deviceBytes = Encoding.ASCII.GetBytes(device);
|
||||
byte[] modeBytes = Encoding.ASCII.GetBytes(mode);
|
||||
byte[] fwBytes = Encoding.ASCII.GetBytes(fw);
|
||||
byte[] snBytes = Encoding.ASCII.GetBytes(sn);
|
||||
byte[] sectorsBytes = Encoding.ASCII.GetBytes(sectors);
|
||||
byte[] sectorsizeBytes = Encoding.ASCII.GetBytes(sectorsize);
|
||||
byte[] scanblocksizeBytes = Encoding.ASCII.GetBytes(scanblocksize);
|
||||
byte[] verBytes = Encoding.ASCII.GetBytes(ver);
|
||||
|
||||
uint pointer = (uint)(deviceBytes.Length + modeBytes.Length + fwBytes.Length + snBytes.Length +
|
||||
sectorsBytes.Length + sectorsizeBytes.Length + scanblocksizeBytes.Length +
|
||||
verBytes.Length + 2 * 9 + // New lines
|
||||
4); // Pointer
|
||||
|
||||
byte[] newLine = new byte[2];
|
||||
newLine[0] = 0x0D;
|
||||
newLine[1] = 0x0A;
|
||||
|
||||
mhddFs.Write(BitConverter.GetBytes(pointer), 0, 4);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(verBytes, 0, verBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(modeBytes, 0, modeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(deviceBytes, 0, deviceBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(fwBytes, 0, fwBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(snBytes, 0, snBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(sectorsBytes, 0, sectorsBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(sectorsizeBytes, 0, sectorsizeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(scanblocksizeBytes, 0, scanblocksizeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
case DeviceType.ATA:
|
||||
case DeviceType.ATAPI:
|
||||
mode = "MODE: IDE";
|
||||
break;
|
||||
case DeviceType.SCSI:
|
||||
mode = "MODE: SCSI";
|
||||
break;
|
||||
case DeviceType.MMC:
|
||||
mode = "MODE: MMC";
|
||||
break;
|
||||
case DeviceType.NVMe:
|
||||
mode = "MODE: NVMe";
|
||||
break;
|
||||
case DeviceType.SecureDigital:
|
||||
mode = "MODE: SD";
|
||||
break;
|
||||
default:
|
||||
mode = "MODE: IDE";
|
||||
break;
|
||||
}
|
||||
|
||||
device = string.Format("DEVICE: {0} {1}", dev.Manufacturer, dev.Model);
|
||||
fw = string.Format("F/W: {0}", dev.Revision);
|
||||
sn = string.Format("S/N: {0}", dev.Serial);
|
||||
sectors = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTORS: {0:n0}", blocks);
|
||||
sectorsize = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTOR SIZE: {0:n0} bytes",
|
||||
blockSize);
|
||||
scanblocksize = string.Format(new System.Globalization.CultureInfo("en-US"),
|
||||
"SCAN BLOCK SIZE: {0:n0} sectors", blocksToRead);
|
||||
ver = "VER:2 ";
|
||||
|
||||
byte[] deviceBytes = Encoding.ASCII.GetBytes(device);
|
||||
byte[] modeBytes = Encoding.ASCII.GetBytes(mode);
|
||||
byte[] fwBytes = Encoding.ASCII.GetBytes(fw);
|
||||
byte[] snBytes = Encoding.ASCII.GetBytes(sn);
|
||||
byte[] sectorsBytes = Encoding.ASCII.GetBytes(sectors);
|
||||
byte[] sectorsizeBytes = Encoding.ASCII.GetBytes(sectorsize);
|
||||
byte[] scanblocksizeBytes = Encoding.ASCII.GetBytes(scanblocksize);
|
||||
byte[] verBytes = Encoding.ASCII.GetBytes(ver);
|
||||
|
||||
uint pointer = (uint)(deviceBytes.Length + modeBytes.Length + fwBytes.Length + snBytes.Length +
|
||||
sectorsBytes.Length + sectorsizeBytes.Length + scanblocksizeBytes.Length +
|
||||
verBytes.Length + 2 * 9 + // New lines
|
||||
4); // Pointer
|
||||
|
||||
byte[] newLine = new byte[2];
|
||||
newLine[0] = 0x0D;
|
||||
newLine[1] = 0x0A;
|
||||
|
||||
mhddFs.Write(BitConverter.GetBytes(pointer), 0, 4);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(verBytes, 0, verBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(modeBytes, 0, modeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(deviceBytes, 0, deviceBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(fwBytes, 0, fwBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(snBytes, 0, snBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(sectorsBytes, 0, sectorsBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(sectorsizeBytes, 0, sectorsizeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
mhddFs.Write(scanblocksizeBytes, 0, scanblocksizeBytes.Length);
|
||||
mhddFs.Write(newLine, 0, 2);
|
||||
}
|
||||
|
||||
internal void Write(ulong sector, double duration)
|
||||
{
|
||||
if(mhddFs != null)
|
||||
{
|
||||
byte[] sectorBytes = BitConverter.GetBytes(sector);
|
||||
byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000));
|
||||
if(mhddFs == null) return;
|
||||
|
||||
mhddFs.Write(sectorBytes, 0, 8);
|
||||
mhddFs.Write(durationBytes, 0, 8);
|
||||
}
|
||||
byte[] sectorBytes = BitConverter.GetBytes(sector);
|
||||
byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000));
|
||||
|
||||
mhddFs.Write(sectorBytes, 0, 8);
|
||||
mhddFs.Write(durationBytes, 0, 8);
|
||||
}
|
||||
|
||||
internal void Close()
|
||||
|
||||
Reference in New Issue
Block a user