Code cleanup.

This commit is contained in:
2018-06-22 08:08:38 +01:00
parent 82f474c7e3
commit 88da8fc019
581 changed files with 22423 additions and 20839 deletions

View File

@@ -55,11 +55,11 @@ namespace DiscImageChef.Core.Devices.Scanning
public static ScanResults Scan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev)
{
ScanResults results = new ScanResults();
bool aborted;
bool sense;
bool aborted;
bool sense;
results.Blocks = 0;
const ushort ATA_PROFILE = 0x0001;
const uint TIMEOUT = 5;
const uint TIMEOUT = 5;
sense = dev.AtaIdentify(out byte[] cmdBuf, out _);
if(!sense && Identify.Decode(cmdBuf).HasValue)
@@ -73,6 +73,7 @@ namespace DiscImageChef.Core.Devices.Scanning
DicConsole.ErrorWriteLine(ataReader.ErrorMessage);
return results;
}
// Check block sizes
if(ataReader.GetBlockSize())
{
@@ -88,46 +89,46 @@ namespace DiscImageChef.Core.Devices.Scanning
return results;
}
uint blocksToRead = ataReader.BlocksToRead;
ushort cylinders = ataReader.Cylinders;
byte heads = ataReader.Heads;
byte sectors = ataReader.Sectors;
uint blocksToRead = ataReader.BlocksToRead;
ushort cylinders = ataReader.Cylinders;
byte heads = ataReader.Heads;
byte sectors = ataReader.Sectors;
results.A = 0; // <3ms
results.B = 0; // >=3ms, <10ms
results.C = 0; // >=10ms, <50ms
results.D = 0; // >=50ms, <150ms
results.E = 0; // >=150ms, <500ms
results.F = 0; // >=500ms
results.A = 0; // <3ms
results.B = 0; // >=3ms, <10ms
results.C = 0; // >=10ms, <50ms
results.D = 0; // >=50ms, <150ms
results.E = 0; // >=150ms, <500ms
results.F = 0; // >=500ms
results.Errored = 0;
DateTime start;
DateTime end;
results.ProcessingTime = 0;
double currentSpeed = 0;
results.MaxSpeed = double.MinValue;
results.MinSpeed = double.MaxValue;
results.MaxSpeed = double.MinValue;
results.MinSpeed = double.MaxValue;
results.UnreadableSectors = new List<ulong>();
results.SeekMax = double.MinValue;
results.SeekMin = double.MaxValue;
results.SeekTotal = 0;
results.SeekMax = double.MinValue;
results.SeekMin = double.MaxValue;
results.SeekTotal = 0;
const int SEEK_TIMES = 1000;
double seekCur;
Random rnd = new Random();
aborted = false;
aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
MhddLog mhddLog;
IbgLog ibgLog;
double duration;
IbgLog ibgLog;
double duration;
if(ataReader.IsLba)
{
DicConsole.WriteLine("Reading {0} sectors at a time.", blocksToRead);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
start = DateTime.UtcNow;
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
@@ -136,10 +137,10 @@ namespace DiscImageChef.Core.Devices.Scanning
if(results.Blocks - i < blocksToRead) blocksToRead = (byte)(results.Blocks - i);
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(currentSpeed > results.MaxSpeed && currentSpeed != 0) results.MaxSpeed = currentSpeed;
if(currentSpeed < results.MinSpeed && currentSpeed != 0) results.MinSpeed = currentSpeed;
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
DicConsole.Write("\rReading sector {0} of {1} ({2:F3} MiB/sec.)", i, results.Blocks,
currentSpeed);
@@ -148,12 +149,12 @@ namespace DiscImageChef.Core.Devices.Scanning
if(!error)
{
if(duration >= 500) results.F += blocksToRead;
if(duration >= 500) results.F += blocksToRead;
else if(duration >= 150) results.E += blocksToRead;
else if(duration >= 50) results.D += blocksToRead;
else if(duration >= 10) results.C += blocksToRead;
else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead;
else if(duration >= 50) results.D += blocksToRead;
else if(duration >= 10) results.C += blocksToRead;
else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead;
mhddLog.Write(i, duration);
ibgLog.Write(i, currentSpeed * 1024);
@@ -168,7 +169,8 @@ namespace DiscImageChef.Core.Devices.Scanning
ibgLog.Write(i, 0);
}
double newSpeed = (double)blockSize * blocksToRead / 1048576 / (duration / 1000);
double newSpeed =
(double)blockSize * blocksToRead / 1048576 / (duration / 1000);
if(!double.IsInfinity(newSpeed)) currentSpeed = newSpeed;
}
@@ -176,7 +178,8 @@ namespace DiscImageChef.Core.Devices.Scanning
DicConsole.WriteLine();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
blockSize * (double)(results.Blocks + 1) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
if(ataReader.CanSeekLba)
@@ -190,10 +193,10 @@ namespace DiscImageChef.Core.Devices.Scanning
ataReader.Seek(seekPos, out seekCur);
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(seekCur > results.SeekMax && seekCur != 0) results.SeekMax = seekCur;
if(seekCur < results.SeekMin && seekCur != 0) results.SeekMin = seekCur;
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
results.SeekTotal += seekCur;
GC.Collect();
@@ -202,11 +205,11 @@ namespace DiscImageChef.Core.Devices.Scanning
else
{
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
ulong currentBlock = 0;
results.Blocks = (ulong)(cylinders * heads * sectors);
start = DateTime.UtcNow;
start = DateTime.UtcNow;
for(ushort cy = 0; cy < cylinders; cy++)
{
for(byte hd = 0; hd < heads; hd++)
@@ -215,12 +218,12 @@ namespace DiscImageChef.Core.Devices.Scanning
{
if(aborted) break;
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(currentSpeed > results.MaxSpeed && currentSpeed != 0)
results.MaxSpeed = currentSpeed;
if(currentSpeed < results.MinSpeed && currentSpeed != 0)
results.MinSpeed = currentSpeed;
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
DicConsole.Write("\rReading cylinder {0} head {1} sector {2} ({3:F3} MiB/sec.)", cy, hd,
sc, currentSpeed);
@@ -229,12 +232,12 @@ namespace DiscImageChef.Core.Devices.Scanning
if(!error)
{
if(duration >= 500) results.F += blocksToRead;
if(duration >= 500) results.F += blocksToRead;
else if(duration >= 150) results.E += blocksToRead;
else if(duration >= 50) results.D += blocksToRead;
else if(duration >= 10) results.C += blocksToRead;
else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead;
else if(duration >= 50) results.D += blocksToRead;
else if(duration >= 10) results.C += blocksToRead;
else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead;
mhddLog.Write(currentBlock, duration);
ibgLog.Write(currentBlock, currentSpeed * 1024);
@@ -248,7 +251,8 @@ namespace DiscImageChef.Core.Devices.Scanning
ibgLog.Write(currentBlock, 0);
}
double newSpeed = blockSize / (double)1048576 / (duration / 1000);
double newSpeed =
blockSize / (double)1048576 / (duration / 1000);
if(!double.IsInfinity(newSpeed)) currentSpeed = newSpeed;
currentBlock++;
@@ -260,7 +264,8 @@ namespace DiscImageChef.Core.Devices.Scanning
DicConsole.WriteLine();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
blockSize * (double)(results.Blocks + 1) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
if(ataReader.CanSeek)
@@ -269,18 +274,18 @@ namespace DiscImageChef.Core.Devices.Scanning
if(aborted) break;
ushort seekCy = (ushort)rnd.Next(cylinders);
byte seekHd = (byte)rnd.Next(heads);
byte seekSc = (byte)rnd.Next(sectors);
byte seekHd = (byte)rnd.Next(heads);
byte seekSc = (byte)rnd.Next(sectors);
DicConsole.Write("\rSeeking to cylinder {0}, head {1}, sector {2}...\t\t", seekCy, seekHd,
seekSc);
ataReader.SeekChs(seekCy, seekHd, seekSc, out seekCur);
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(seekCur > results.SeekMax && seekCur != 0) results.SeekMax = seekCur;
if(seekCur < results.SeekMin && seekCur != 0) results.SeekMin = seekCur;
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
results.SeekTotal += seekCur;
GC.Collect();
@@ -290,9 +295,9 @@ namespace DiscImageChef.Core.Devices.Scanning
DicConsole.WriteLine();
results.ProcessingTime /= 1000;
results.TotalTime = (end - start).TotalSeconds;
results.AvgSpeed = blockSize * (double)(results.Blocks + 1) / 1048576 / results.ProcessingTime;
results.SeekTimes = SEEK_TIMES;
results.TotalTime = (end - start).TotalSeconds;
results.AvgSpeed = blockSize * (double)(results.Blocks + 1) / 1048576 / results.ProcessingTime;
results.SeekTimes = SEEK_TIMES;
return results;
}