Use a block map in media scan in the GUI.

This commit is contained in:
2019-04-21 16:40:16 +01:00
parent b0efcddd25
commit 294ebe89dd
8 changed files with 97 additions and 41 deletions

View File

@@ -1677,6 +1677,7 @@
</e> </e>
<e p="ConsoleHandler.cs" t="Include" /> <e p="ConsoleHandler.cs" t="Include" />
<e p="Controls" t="Include"> <e p="Controls" t="Include">
<e p="BlockMap.cs" t="Include" />
<e p="ColoredGrid.cs" t="Include" /> <e p="ColoredGrid.cs" t="Include" />
<e p="SvgImageView.cs" t="Include" /> <e p="SvgImageView.cs" t="Include" />
</e> </e>

View File

@@ -103,16 +103,16 @@ namespace DiscImageChef.Core
/// </summary> /// </summary>
public delegate void ErrorMessageHandler(string text); public delegate void ErrorMessageHandler(string text);
public delegate void InitBlockMapHandler(ulong blocks, ulong blockSize, ulong blocksToRead);
/// <summary> /// <summary>
/// Updates lists of time taken on scanning the specified number of blocks /// Updates lists of time taken on scanning from the specified sector
/// </summary> /// </summary>
/// <param name="time">Time in milliseconds</param> /// <param name="duration">Time in milliseconds</param>
/// <param name="blocks">Number of blocks scanned</param> public delegate void ScanTimeHandler(ulong sector, double duration);
public delegate void ScanTimeHandler(double time, uint blocks);
/// <summary> /// <summary>
/// Specified a number of blocks could not be read on scan /// Specified a number of blocks could not be read on scan
/// </summary> /// </summary>
/// <param name="blocks">Number of blocks scanned</param> public delegate void ScanUnreadableHandler(ulong sector);
public delegate void ScanUnreadableHandler(uint blocks);
} }

View File

@@ -117,6 +117,7 @@ namespace DiscImageChef.Core.Devices.Scanning
{ {
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE); ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
@@ -149,13 +150,13 @@ namespace DiscImageChef.Core.Devices.Scanning
else if(duration >= 3) results.B += blocksToRead; else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead; else results.A += blocksToRead;
ScanTime?.Invoke(duration, blocksToRead); ScanTime?.Invoke(i, duration);
mhddLog.Write(i, duration); mhddLog.Write(i, duration);
ibgLog.Write(i, currentSpeed * 1024); ibgLog.Write(i, currentSpeed * 1024);
} }
else else
{ {
ScanUnreadable?.Invoke(blocksToRead); ScanUnreadable?.Invoke(i);
results.Errored += blocksToRead; results.Errored += blocksToRead;
for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b);
@@ -207,6 +208,7 @@ namespace DiscImageChef.Core.Devices.Scanning
} }
else else
{ {
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE); ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
@@ -245,13 +247,13 @@ namespace DiscImageChef.Core.Devices.Scanning
else if(duration >= 3) results.B += blocksToRead; else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead; else results.A += blocksToRead;
ScanTime?.Invoke(duration, blocksToRead); ScanTime?.Invoke(currentBlock, duration);
mhddLog.Write(currentBlock, duration); mhddLog.Write(currentBlock, duration);
ibgLog.Write(currentBlock, currentSpeed * 1024); ibgLog.Write(currentBlock, currentSpeed * 1024);
} }
else else
{ {
ScanUnreadable?.Invoke(blocksToRead); ScanUnreadable?.Invoke(currentBlock);
results.Errored += blocksToRead; results.Errored += blocksToRead;
results.UnreadableSectors.Add(currentBlock); results.UnreadableSectors.Add(currentBlock);
mhddLog.Write(currentBlock, duration < 500 ? 65535 : duration); mhddLog.Write(currentBlock, duration < 500 ? 65535 : duration);

View File

@@ -70,5 +70,6 @@ namespace DiscImageChef.Core.Devices.Scanning
public event PulseProgressHandler PulseProgress; public event PulseProgressHandler PulseProgress;
public event ScanTimeHandler ScanTime; public event ScanTimeHandler ScanTime;
public event ScanUnreadableHandler ScanUnreadable; public event ScanUnreadableHandler ScanUnreadable;
public event InitBlockMapHandler InitBlockMap;
} }
} }

View File

@@ -278,6 +278,7 @@ namespace DiscImageChef.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, currentProfile); ibgLog = new IbgLog(ibgLogPath, currentProfile);
DateTime timeSpeedStart = DateTime.UtcNow; DateTime timeSpeedStart = DateTime.UtcNow;
@@ -317,7 +318,7 @@ namespace DiscImageChef.Core.Devices.Scanning
else if(cmdDuration >= 3) results.B += blocksToRead; else if(cmdDuration >= 3) results.B += blocksToRead;
else results.A += blocksToRead; else results.A += blocksToRead;
ScanTime?.Invoke(cmdDuration, blocksToRead); ScanTime?.Invoke(i, cmdDuration);
mhddLog.Write(i, cmdDuration); mhddLog.Write(i, cmdDuration);
ibgLog.Write(i, currentSpeed * 1024); ibgLog.Write(i, currentSpeed * 1024);
} }
@@ -345,7 +346,7 @@ namespace DiscImageChef.Core.Devices.Scanning
} }
else else
{ {
ScanUnreadable?.Invoke(blocksToRead); ScanUnreadable?.Invoke(i);
results.Errored += blocksToRead; results.Errored += blocksToRead;
for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b);
@@ -379,6 +380,7 @@ namespace DiscImageChef.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
ibgLog = new IbgLog(ibgLogPath, currentProfile); ibgLog = new IbgLog(ibgLogPath, currentProfile);
DateTime timeSpeedStart = DateTime.UtcNow; DateTime timeSpeedStart = DateTime.UtcNow;
@@ -411,14 +413,14 @@ namespace DiscImageChef.Core.Devices.Scanning
else if(cmdDuration >= 3) results.B += blocksToRead; else if(cmdDuration >= 3) results.B += blocksToRead;
else results.A += blocksToRead; else results.A += blocksToRead;
ScanTime?.Invoke(cmdDuration, blocksToRead); ScanTime?.Invoke(i, cmdDuration);
mhddLog.Write(i, cmdDuration); mhddLog.Write(i, cmdDuration);
ibgLog.Write(i, currentSpeed * 1024); ibgLog.Write(i, currentSpeed * 1024);
} }
// TODO: Separate errors on kind of errors. // TODO: Separate errors on kind of errors.
else else
{ {
ScanUnreadable?.Invoke(blocksToRead); ScanUnreadable?.Invoke(i);
results.Errored += blocksToRead; results.Errored += blocksToRead;
for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b);

View File

@@ -147,6 +147,7 @@ namespace DiscImageChef.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead);
MhddLog mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); MhddLog mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
IbgLog ibgLog = new IbgLog(ibgLogPath, SD_PROFILE); IbgLog ibgLog = new IbgLog(ibgLogPath, SD_PROFILE);
@@ -180,13 +181,13 @@ namespace DiscImageChef.Core.Devices.Scanning
else if(duration >= 3) results.B += blocksToRead; else if(duration >= 3) results.B += blocksToRead;
else results.A += blocksToRead; else results.A += blocksToRead;
ScanTime?.Invoke(duration, blocksToRead); ScanTime?.Invoke(i, duration);
mhddLog.Write(i, duration); mhddLog.Write(i, duration);
ibgLog.Write(i, currentSpeed * 1024); ibgLog.Write(i, currentSpeed * 1024);
} }
else else
{ {
ScanUnreadable?.Invoke(blocksToRead); ScanUnreadable?.Invoke(i);
results.Errored += blocksToRead; results.Errored += blocksToRead;
for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b);

View File

@@ -31,9 +31,9 @@
// Copyright © 2011-2019 Natalia Portillo // Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
--> -->
<Form xmlns="http://schema.picoe.ca/eto.forms" Title="Media scan" ClientSize="600, 450" Padding="10"> <Form xmlns="http://schema.picoe.ca/eto.forms" xmlns:local="clr-namespace:DiscImageChef.Gui.Controls;assembly=DiscImageChef.Gui" Title="Media scan" ClientSize="600, 450" Padding="10">
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<TabControl Visible="False" ID="tabResults"> <TabControl Visible="True" ID="tabResults">
<TabPage Text="Log"> <TabPage Text="Log">
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" <StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"> VerticalContentAlignment="Stretch">
@@ -51,6 +51,9 @@
<Label ID="lblMinSpeed" Text="Slowest speed burst: 0 MiB/sec." Visible="False"/> <Label ID="lblMinSpeed" Text="Slowest speed burst: 0 MiB/sec." Visible="False"/>
</StackLayout> </StackLayout>
</TabPage> </TabPage>
<TabPage Text="Graph">
<local:BlockMap ID="blockMap"/>
</TabPage>
</TabControl> </TabControl>
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" <StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
ID="stkProgress" Visible="False"> ID="stkProgress" Visible="False">

View File

@@ -37,6 +37,8 @@ using DiscImageChef.Core;
using DiscImageChef.Core.Devices.Scanning; using DiscImageChef.Core.Devices.Scanning;
using DiscImageChef.Core.Media.Info; using DiscImageChef.Core.Media.Info;
using DiscImageChef.Devices; using DiscImageChef.Devices;
using DiscImageChef.Gui.Controls;
using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using Eto.Serialization.Xaml; using Eto.Serialization.Xaml;
using DeviceInfo = DiscImageChef.Core.Devices.Info.DeviceInfo; using DeviceInfo = DiscImageChef.Core.Devices.Info.DeviceInfo;
@@ -45,10 +47,16 @@ namespace DiscImageChef.Gui.Forms
{ {
public class frmMediaScan : Form public class frmMediaScan : Form
{ {
static readonly Color LightGreen = Color.FromRgb(0x00FF00);
static readonly Color Green = Color.FromRgb(0x006400);
static readonly Color DarkGreen = Color.FromRgb(0x003200);
static readonly Color Yellow = Color.FromRgb(0xFFA500);
static readonly Color Orange = Color.FromRgb(0xFF4500);
static readonly Color Red = Color.FromRgb(0x800000);
static Color LightRed = Color.FromRgb(0xFF0000);
ulong blocksToRead;
string devicePath; string devicePath;
ScanResults localResults; ScanResults localResults;
MediaScan scanner; MediaScan scanner;
public frmMediaScan(string devicePath, DeviceInfo deviceInfo, ScsiInfo scsiInfo = null) public frmMediaScan(string devicePath, DeviceInfo deviceInfo, ScsiInfo scsiInfo = null)
@@ -111,6 +119,7 @@ namespace DiscImageChef.Gui.Forms
scanner.InitProgress += InitProgress; scanner.InitProgress += InitProgress;
scanner.UpdateProgress += UpdateProgress; scanner.UpdateProgress += UpdateProgress;
scanner.EndProgress += EndProgress; scanner.EndProgress += EndProgress;
scanner.InitBlockMap += InitBlockMap;
ScanResults results = scanner.Scan(); ScanResults results = scanner.Scan();
@@ -152,6 +161,16 @@ namespace DiscImageChef.Gui.Forms
WorkFinished(); WorkFinished();
} }
void InitBlockMap(ulong blocks, ulong blocksize, ulong blockstoread)
{
Application.Instance.Invoke(() =>
{
blockMap.Sectors = blocks;
blockMap.SectorsToRead = (uint)blockstoread;
blocksToRead = blockstoread;
});
}
void WorkFinished() void WorkFinished()
{ {
Application.Instance.Invoke(() => Application.Instance.Invoke(() =>
@@ -221,25 +240,51 @@ namespace DiscImageChef.Gui.Forms
Application.Instance.Invoke(() => { lblProgress.Text = text; }); Application.Instance.Invoke(() => { lblProgress.Text = text; });
} }
void OnScanUnreadable(uint blocks) void OnScanUnreadable(ulong sector)
{ {
Application.Instance.Invoke(() => Application.Instance.Invoke(() =>
{ {
localResults.Errored += blocks; localResults.Errored += blocksToRead;
lblUnreadableSectors.Text = $"{localResults.Errored} sectors could not be read."; lblUnreadableSectors.Text = $"{localResults.Errored} sectors could not be read.";
blockMap.ColoredSectors.Add(new ColoredBlock(sector, LightGreen));
}); });
} }
void OnScanTime(double time, uint blocks) void OnScanTime(ulong sector, double duration)
{ {
Application.Instance.Invoke(() => Application.Instance.Invoke(() =>
{ {
if(time < 3) localResults.A += blocks; if(duration < 3)
else if(time >= 3 && time < 10) localResults.B += blocks; {
else if(time >= 10 && time < 50) localResults.C += blocks; localResults.A += blocksToRead;
else if(time >= 50 && time < 150) localResults.D += blocks; blockMap.ColoredSectors.Add(new ColoredBlock(sector, LightGreen));
else if(time >= 150 && time < 500) localResults.E += blocks; }
else if(time >= 500) localResults.F += blocks; else if(duration >= 3 && duration < 10)
{
localResults.B += blocksToRead;
blockMap.ColoredSectors.Add(new ColoredBlock(sector, Green));
}
else if(duration >= 10 && duration < 50)
{
localResults.C += blocksToRead;
blockMap.ColoredSectors.Add(new ColoredBlock(sector, DarkGreen));
}
else if(duration >= 50 && duration < 150)
{
localResults.D += blocksToRead;
blockMap.ColoredSectors.Add(new ColoredBlock(sector, Yellow));
}
else if(duration >= 150 && duration < 500)
{
localResults.E += blocksToRead;
blockMap.ColoredSectors.Add(new ColoredBlock(sector, Orange));
}
else if(duration >= 500)
{
localResults.F += blocksToRead;
blockMap.ColoredSectors.Add(new ColoredBlock(sector, Red));
}
lblA.Text = $"{localResults.A} sectors took less than 3 ms."; lblA.Text = $"{localResults.A} sectors took less than 3 ms.";
lblB.Text = $"{localResults.B} sectors took less than 10 ms but more than 3 ms."; lblB.Text = $"{localResults.B} sectors took less than 10 ms but more than 3 ms.";
lblC.Text = $"{localResults.C} sectors took less than 50 ms but more than 10 ms."; lblC.Text = $"{localResults.C} sectors took less than 50 ms but more than 10 ms.";
@@ -272,6 +317,7 @@ namespace DiscImageChef.Gui.Forms
Label lblProgress2; Label lblProgress2;
ProgressBar prgProgress2; ProgressBar prgProgress2;
TabControl tabResults; TabControl tabResults;
BlockMap blockMap;
#endregion #endregion
} }
} }