mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Invert 'if' statement to reduce nesting.
This commit is contained in:
@@ -43,93 +43,90 @@ namespace DiscImageChef.Core.Logging
|
||||
|
||||
public DumpLog(string outputFile, Device dev)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(outputFile))
|
||||
if(string.IsNullOrEmpty(outputFile)) return;
|
||||
|
||||
logSw = new StreamWriter(outputFile, true);
|
||||
|
||||
logSw.WriteLine("Start logging at {0}", DateTime.Now);
|
||||
|
||||
Interop.PlatformID platId = Interop.DetectOS.GetRealPlatformID();
|
||||
string platVer = Interop.DetectOS.GetVersion();
|
||||
Type monoRunType = Type.GetType("Mono.Runtime");
|
||||
|
||||
logSw.WriteLine("################# System information #################");
|
||||
logSw.WriteLine("{0} {1} ({2}-bit)", Interop.DetectOS.GetPlatformName(platId, platVer), platVer,
|
||||
Environment.Is64BitOperatingSystem ? 64 : 32);
|
||||
if(monoRunType != null)
|
||||
{
|
||||
logSw = new StreamWriter(outputFile, true);
|
||||
|
||||
logSw.WriteLine("Start logging at {0}", DateTime.Now);
|
||||
|
||||
Interop.PlatformID platId = Interop.DetectOS.GetRealPlatformID();
|
||||
string platVer = Interop.DetectOS.GetVersion();
|
||||
Type monoRunType = Type.GetType("Mono.Runtime");
|
||||
|
||||
logSw.WriteLine("################# System information #################");
|
||||
logSw.WriteLine("{0} {1} ({2}-bit)", Interop.DetectOS.GetPlatformName(platId, platVer), platVer,
|
||||
Environment.Is64BitOperatingSystem ? 64 : 32);
|
||||
if(monoRunType != null)
|
||||
{
|
||||
string monoVer = "unknown version";
|
||||
MethodInfo monoDisplayName =
|
||||
monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null);
|
||||
logSw.WriteLine("Mono {0}", monoVer);
|
||||
}
|
||||
else logSw.WriteLine(".NET Framework {0}", Environment.Version);
|
||||
logSw.WriteLine();
|
||||
|
||||
logSw.WriteLine("################# Program information ################");
|
||||
logSw.WriteLine("DiscImageChef {0} running in {1}-bit", Version.GetVersion(),
|
||||
Environment.Is64BitProcess ? 64 : 32);
|
||||
#if DEBUG
|
||||
logSw.WriteLine("DEBUG version");
|
||||
#endif
|
||||
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
|
||||
logSw.WriteLine();
|
||||
|
||||
logSw.WriteLine("################# Device information #################");
|
||||
logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer);
|
||||
logSw.WriteLine("Model: {0}", dev.Model);
|
||||
logSw.WriteLine("Firmware revision: {0}", dev.Revision);
|
||||
logSw.WriteLine("Serial number: {0}", dev.Serial);
|
||||
logSw.WriteLine("Removable device: {0}", dev.IsRemovable);
|
||||
logSw.WriteLine("Device type: {0}", dev.Type);
|
||||
logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash);
|
||||
logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia);
|
||||
logSw.WriteLine("USB device: {0}", dev.IsUsb);
|
||||
if(dev.IsUsb)
|
||||
{
|
||||
logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString);
|
||||
logSw.WriteLine("USB product: {0}", dev.UsbProductString);
|
||||
logSw.WriteLine("USB serial: {0}", dev.UsbSerialString);
|
||||
logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId);
|
||||
logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId);
|
||||
}
|
||||
logSw.WriteLine("FireWire device: {0}", dev.IsFireWire);
|
||||
if(dev.IsFireWire)
|
||||
{
|
||||
logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName);
|
||||
logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName);
|
||||
logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid);
|
||||
logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor);
|
||||
logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel);
|
||||
}
|
||||
logSw.WriteLine();
|
||||
logSw.WriteLine("######################################################");
|
||||
|
||||
logSw.WriteLine();
|
||||
logSw.WriteLine("################ Dumping progress log ################");
|
||||
logSw.Flush();
|
||||
string monoVer = "unknown version";
|
||||
MethodInfo monoDisplayName =
|
||||
monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null);
|
||||
logSw.WriteLine("Mono {0}", monoVer);
|
||||
}
|
||||
else logSw.WriteLine(".NET Framework {0}", Environment.Version);
|
||||
logSw.WriteLine();
|
||||
|
||||
logSw.WriteLine("################# Program information ################");
|
||||
logSw.WriteLine("DiscImageChef {0} running in {1}-bit", Version.GetVersion(),
|
||||
Environment.Is64BitProcess ? 64 : 32);
|
||||
#if DEBUG
|
||||
logSw.WriteLine("DEBUG version");
|
||||
#endif
|
||||
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
|
||||
logSw.WriteLine();
|
||||
|
||||
logSw.WriteLine("################# Device information #################");
|
||||
logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer);
|
||||
logSw.WriteLine("Model: {0}", dev.Model);
|
||||
logSw.WriteLine("Firmware revision: {0}", dev.Revision);
|
||||
logSw.WriteLine("Serial number: {0}", dev.Serial);
|
||||
logSw.WriteLine("Removable device: {0}", dev.IsRemovable);
|
||||
logSw.WriteLine("Device type: {0}", dev.Type);
|
||||
logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash);
|
||||
logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia);
|
||||
logSw.WriteLine("USB device: {0}", dev.IsUsb);
|
||||
if(dev.IsUsb)
|
||||
{
|
||||
logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString);
|
||||
logSw.WriteLine("USB product: {0}", dev.UsbProductString);
|
||||
logSw.WriteLine("USB serial: {0}", dev.UsbSerialString);
|
||||
logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId);
|
||||
logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId);
|
||||
}
|
||||
logSw.WriteLine("FireWire device: {0}", dev.IsFireWire);
|
||||
if(dev.IsFireWire)
|
||||
{
|
||||
logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName);
|
||||
logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName);
|
||||
logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid);
|
||||
logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor);
|
||||
logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel);
|
||||
}
|
||||
logSw.WriteLine();
|
||||
logSw.WriteLine("######################################################");
|
||||
|
||||
logSw.WriteLine();
|
||||
logSw.WriteLine("################ Dumping progress log ################");
|
||||
logSw.Flush();
|
||||
}
|
||||
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
if(logSw != null)
|
||||
{
|
||||
string text = string.Format(format, args);
|
||||
logSw.WriteLine("{0:s} {1}", DateTime.Now, text);
|
||||
logSw.Flush();
|
||||
}
|
||||
if(logSw == null) return;
|
||||
|
||||
string text = string.Format(format, args);
|
||||
logSw.WriteLine("{0:s} {1}", DateTime.Now, text);
|
||||
logSw.Flush();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if(logSw != null)
|
||||
{
|
||||
logSw.WriteLine("######################################################");
|
||||
logSw.WriteLine("End logging at {0}", DateTime.Now);
|
||||
logSw.Close();
|
||||
}
|
||||
if(logSw == null) return;
|
||||
|
||||
logSw.WriteLine("######################################################");
|
||||
logSw.WriteLine("End logging at {0}", DateTime.Now);
|
||||
logSw.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,237 +56,233 @@ namespace DiscImageChef.Core.Logging
|
||||
|
||||
internal IbgLog(string outputFile, ushort currentProfile)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(outputFile))
|
||||
{
|
||||
ibgFs = new FileStream(outputFile, FileMode.Create);
|
||||
ibgSb = new StringBuilder();
|
||||
ibgDatePoint = DateTime.Now;
|
||||
ibgCulture = new CultureInfo("en-US");
|
||||
ibgStartSet = false;
|
||||
ibgMaxSpeed = 0;
|
||||
ibgIntSpeed = 0;
|
||||
ibgSnaps = 0;
|
||||
ibgIntSector = 0;
|
||||
if(string.IsNullOrEmpty(outputFile)) return;
|
||||
|
||||
switch(currentProfile)
|
||||
{
|
||||
case 0x0001:
|
||||
ibgMediaType = "HDD";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0005:
|
||||
ibgMediaType = "CD-MO";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0008:
|
||||
ibgMediaType = "CD-ROM";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0009:
|
||||
ibgMediaType = "CD-R";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x000A:
|
||||
ibgMediaType = "CD-RW";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0010:
|
||||
ibgMediaType = "DVD-ROM";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0011:
|
||||
ibgMediaType = "DVD-R";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0012:
|
||||
ibgMediaType = "DVD-RAM";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0013:
|
||||
case 0x0014:
|
||||
ibgMediaType = "DVD-RW";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0015:
|
||||
case 0x0016:
|
||||
ibgMediaType = "DVD-R DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0017:
|
||||
ibgMediaType = "DVD-RW DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0018:
|
||||
ibgMediaType = "DVD-Download";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x001A:
|
||||
ibgMediaType = "DVD+RW";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x001B:
|
||||
ibgMediaType = "DVD+R";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0020:
|
||||
ibgMediaType = "DDCD-ROM";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0021:
|
||||
ibgMediaType = "DDCD-R";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0022:
|
||||
ibgMediaType = "DDCD-RW";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x002A:
|
||||
ibgMediaType = "DVD+RW DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x002B:
|
||||
ibgMediaType = "DVD+R DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0040:
|
||||
ibgMediaType = "BD-ROM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0041:
|
||||
case 0x0042:
|
||||
ibgMediaType = "BD-R";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0043:
|
||||
ibgMediaType = "BD-RE";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0050:
|
||||
ibgMediaType = "HD DVD-ROM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0051:
|
||||
ibgMediaType = "HD DVD-R";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0052:
|
||||
ibgMediaType = "HD DVD-RAM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0053:
|
||||
ibgMediaType = "HD DVD-RW";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0058:
|
||||
ibgMediaType = "HD DVD-R DL";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x005A:
|
||||
ibgMediaType = "HD DVD-RW DL";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
default:
|
||||
ibgMediaType = "Unknown";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
}
|
||||
ibgFs = new FileStream(outputFile, FileMode.Create);
|
||||
ibgSb = new StringBuilder();
|
||||
ibgDatePoint = DateTime.Now;
|
||||
ibgCulture = new CultureInfo("en-US");
|
||||
ibgStartSet = false;
|
||||
ibgMaxSpeed = 0;
|
||||
ibgIntSpeed = 0;
|
||||
ibgSnaps = 0;
|
||||
ibgIntSector = 0;
|
||||
|
||||
switch(currentProfile)
|
||||
{
|
||||
case 0x0001:
|
||||
ibgMediaType = "HDD";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0005:
|
||||
ibgMediaType = "CD-MO";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0008:
|
||||
ibgMediaType = "CD-ROM";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0009:
|
||||
ibgMediaType = "CD-R";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x000A:
|
||||
ibgMediaType = "CD-RW";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0010:
|
||||
ibgMediaType = "DVD-ROM";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0011:
|
||||
ibgMediaType = "DVD-R";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0012:
|
||||
ibgMediaType = "DVD-RAM";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0013:
|
||||
case 0x0014:
|
||||
ibgMediaType = "DVD-RW";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0015:
|
||||
case 0x0016:
|
||||
ibgMediaType = "DVD-R DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0017:
|
||||
ibgMediaType = "DVD-RW DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0018:
|
||||
ibgMediaType = "DVD-Download";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x001A:
|
||||
ibgMediaType = "DVD+RW";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x001B:
|
||||
ibgMediaType = "DVD+R";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0020:
|
||||
ibgMediaType = "DDCD-ROM";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0021:
|
||||
ibgMediaType = "DDCD-R";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x0022:
|
||||
ibgMediaType = "DDCD-RW";
|
||||
ibgDivider = 150;
|
||||
break;
|
||||
case 0x002A:
|
||||
ibgMediaType = "DVD+RW DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x002B:
|
||||
ibgMediaType = "DVD+R DL";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
case 0x0040:
|
||||
ibgMediaType = "BD-ROM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0041:
|
||||
case 0x0042:
|
||||
ibgMediaType = "BD-R";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0043:
|
||||
ibgMediaType = "BD-RE";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0050:
|
||||
ibgMediaType = "HD DVD-ROM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0051:
|
||||
ibgMediaType = "HD DVD-R";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0052:
|
||||
ibgMediaType = "HD DVD-RAM";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0053:
|
||||
ibgMediaType = "HD DVD-RW";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x0058:
|
||||
ibgMediaType = "HD DVD-R DL";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
case 0x005A:
|
||||
ibgMediaType = "HD DVD-RW DL";
|
||||
ibgDivider = 4500;
|
||||
break;
|
||||
default:
|
||||
ibgMediaType = "Unknown";
|
||||
ibgDivider = 1353;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal void Write(ulong sector, double currentSpeed)
|
||||
{
|
||||
if(ibgFs != null)
|
||||
if(ibgFs == null) return;
|
||||
|
||||
ibgIntSpeed += currentSpeed;
|
||||
ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds);
|
||||
ibgSnaps++;
|
||||
|
||||
if(ibgSampleRate < 100) return;
|
||||
|
||||
if(ibgIntSpeed > 0 && !ibgStartSet)
|
||||
{
|
||||
ibgIntSpeed += currentSpeed;
|
||||
ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds);
|
||||
ibgSnaps++;
|
||||
|
||||
if(ibgSampleRate >= 100)
|
||||
{
|
||||
if(ibgIntSpeed > 0 && !ibgStartSet)
|
||||
{
|
||||
ibgStartSpeed = ibgIntSpeed / ibgSnaps / ibgDivider;
|
||||
ibgStartSet = true;
|
||||
}
|
||||
|
||||
ibgSb.AppendFormat("{0:0.00},{1},{2:0},0", ibgIntSpeed / ibgSnaps / ibgDivider, ibgIntSector,
|
||||
ibgSampleRate).AppendLine();
|
||||
if(ibgIntSpeed / ibgSnaps / ibgDivider > ibgMaxSpeed) ibgMaxSpeed = ibgIntSpeed / ibgDivider;
|
||||
|
||||
ibgDatePoint = DateTime.Now;
|
||||
ibgIntSpeed = 0;
|
||||
ibgSampleRate = 0;
|
||||
ibgSnaps = 0;
|
||||
ibgIntSector = sector;
|
||||
}
|
||||
ibgStartSpeed = ibgIntSpeed / ibgSnaps / ibgDivider;
|
||||
ibgStartSet = true;
|
||||
}
|
||||
|
||||
ibgSb.AppendFormat("{0:0.00},{1},{2:0},0", ibgIntSpeed / ibgSnaps / ibgDivider, ibgIntSector,
|
||||
ibgSampleRate).AppendLine();
|
||||
if(ibgIntSpeed / ibgSnaps / ibgDivider > ibgMaxSpeed) ibgMaxSpeed = ibgIntSpeed / ibgDivider;
|
||||
|
||||
ibgDatePoint = DateTime.Now;
|
||||
ibgIntSpeed = 0;
|
||||
ibgSampleRate = 0;
|
||||
ibgSnaps = 0;
|
||||
ibgIntSector = sector;
|
||||
}
|
||||
|
||||
internal void Close(Device dev, ulong blocks, ulong blockSize, double totalSeconds, double currentSpeed,
|
||||
double averageSpeed, string devicePath)
|
||||
{
|
||||
if(ibgFs != null)
|
||||
{
|
||||
StringBuilder ibgHeader = new StringBuilder();
|
||||
string ibgBusType;
|
||||
if(ibgFs == null) return;
|
||||
|
||||
if(dev.IsUsb) ibgBusType = "USB";
|
||||
else if(dev.IsFireWire) ibgBusType = "FireWire";
|
||||
else ibgBusType = dev.Type.ToString();
|
||||
StringBuilder ibgHeader = new StringBuilder();
|
||||
string ibgBusType;
|
||||
|
||||
ibgHeader.AppendLine("IBGD");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("[START_CONFIGURATION]");
|
||||
ibgHeader.AppendLine("IBGD_VERSION=2");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("DATE={0}", DateTime.Now).AppendLine();
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("SAMPLE_RATE={0}", 100).AppendLine();
|
||||
if(dev.IsUsb) ibgBusType = "USB";
|
||||
else if(dev.IsFireWire) ibgBusType = "FireWire";
|
||||
else ibgBusType = dev.Type.ToString();
|
||||
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE=[0:0:0] {0} {1} ({2}) ({3})", dev.Manufacturer, dev.Model, devicePath,
|
||||
ibgBusType).AppendLine();
|
||||
ibgHeader.AppendLine("DEVICE_ADDRESS=0:0:0");
|
||||
ibgHeader.AppendFormat("DEVICE_MAKEMODEL={0} {1}", dev.Manufacturer, dev.Model).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_FIRMWAREVERSION={0}", dev.Revision).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_DRIVELETTER={0}", devicePath).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_BUSTYPE={0}", ibgBusType).AppendLine();
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("IBGD");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("[START_CONFIGURATION]");
|
||||
ibgHeader.AppendLine("IBGD_VERSION=2");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("DATE={0}", DateTime.Now).AppendLine();
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("SAMPLE_RATE={0}", 100).AppendLine();
|
||||
|
||||
ibgHeader.AppendFormat("MEDIA_TYPE={0}", ibgMediaType).AppendLine();
|
||||
ibgHeader.AppendLine("MEDIA_BOOKTYPE=Unknown");
|
||||
ibgHeader.AppendLine("MEDIA_ID=N/A");
|
||||
ibgHeader.AppendLine("MEDIA_TRACKPATH=PTP");
|
||||
ibgHeader.AppendLine("MEDIA_SPEEDS=N/A");
|
||||
ibgHeader.AppendFormat("MEDIA_CAPACITY={0}", blocks).AppendLine();
|
||||
ibgHeader.AppendLine("MEDIA_LAYER_BREAK=0");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("DATA_IMAGEFILE=/dev/null");
|
||||
ibgHeader.AppendFormat("DATA_SECTORS={0}", blocks).AppendLine();
|
||||
ibgHeader.AppendFormat("DATA_TYPE=MODE1/{0}", blockSize).AppendLine();
|
||||
ibgHeader.AppendLine("DATA_VOLUMEIDENTIFIER=");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_START={0:0.00}", ibgStartSpeed).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_END={0:0.00}", currentSpeed / ibgDivider).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_AVERAGE={0:0.00}", averageSpeed / ibgDivider)
|
||||
.AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_MAX={0:0.00}", ibgMaxSpeed).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_TIME_TAKEN={0:0}", Math.Floor(totalSeconds)).AppendLine();
|
||||
ibgHeader.AppendLine("[END_CONFIGURATION]");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("HRPC=True");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("[START_VERIFY_GRAPH_VALUES]");
|
||||
ibgHeader.Append(ibgSb.ToString());
|
||||
ibgHeader.AppendLine("[END_VERIFY_GRAPH_VALUES]");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE=[0:0:0] {0} {1} ({2}) ({3})", dev.Manufacturer, dev.Model, devicePath,
|
||||
ibgBusType).AppendLine();
|
||||
ibgHeader.AppendLine("DEVICE_ADDRESS=0:0:0");
|
||||
ibgHeader.AppendFormat("DEVICE_MAKEMODEL={0} {1}", dev.Manufacturer, dev.Model).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_FIRMWAREVERSION={0}", dev.Revision).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_DRIVELETTER={0}", devicePath).AppendLine();
|
||||
ibgHeader.AppendFormat("DEVICE_BUSTYPE={0}", ibgBusType).AppendLine();
|
||||
ibgHeader.AppendLine();
|
||||
|
||||
StreamWriter sr = new StreamWriter(ibgFs);
|
||||
sr.Write(ibgHeader);
|
||||
sr.Close();
|
||||
ibgFs.Close();
|
||||
}
|
||||
ibgHeader.AppendFormat("MEDIA_TYPE={0}", ibgMediaType).AppendLine();
|
||||
ibgHeader.AppendLine("MEDIA_BOOKTYPE=Unknown");
|
||||
ibgHeader.AppendLine("MEDIA_ID=N/A");
|
||||
ibgHeader.AppendLine("MEDIA_TRACKPATH=PTP");
|
||||
ibgHeader.AppendLine("MEDIA_SPEEDS=N/A");
|
||||
ibgHeader.AppendFormat("MEDIA_CAPACITY={0}", blocks).AppendLine();
|
||||
ibgHeader.AppendLine("MEDIA_LAYER_BREAK=0");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("DATA_IMAGEFILE=/dev/null");
|
||||
ibgHeader.AppendFormat("DATA_SECTORS={0}", blocks).AppendLine();
|
||||
ibgHeader.AppendFormat("DATA_TYPE=MODE1/{0}", blockSize).AppendLine();
|
||||
ibgHeader.AppendLine("DATA_VOLUMEIDENTIFIER=");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_START={0:0.00}", ibgStartSpeed).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_END={0:0.00}", currentSpeed / ibgDivider).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_AVERAGE={0:0.00}", averageSpeed / ibgDivider)
|
||||
.AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_MAX={0:0.00}", ibgMaxSpeed).AppendLine();
|
||||
ibgHeader.AppendFormat(ibgCulture, "VERIFY_TIME_TAKEN={0:0}", Math.Floor(totalSeconds)).AppendLine();
|
||||
ibgHeader.AppendLine("[END_CONFIGURATION]");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("HRPC=True");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.AppendLine("[START_VERIFY_GRAPH_VALUES]");
|
||||
ibgHeader.Append(ibgSb.ToString());
|
||||
ibgHeader.AppendLine("[END_VERIFY_GRAPH_VALUES]");
|
||||
ibgHeader.AppendLine();
|
||||
ibgHeader.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
|
||||
|
||||
StreamWriter sr = new StreamWriter(ibgFs);
|
||||
sr.Write(ibgHeader);
|
||||
sr.Close();
|
||||
ibgFs.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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