From 3e98e8ffda1a55946fc345e3e931b9d3007531fa Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 22 Apr 2019 01:09:06 +0100 Subject: [PATCH] Draw a speed chart on media scan in GUI. --- DiscImageChef.Core/Delegates.cs | 4 +- DiscImageChef.Core/Devices/Scanning/ATA.cs | 8 +- .../Devices/Scanning/MediaScan.cs | 1 + DiscImageChef.Core/Devices/Scanning/SCSI.cs | 8 +- .../Devices/Scanning/SecureDigital.cs | 4 +- DiscImageChef.Gui/Forms/frmMediaScan.xeto | 3 + DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs | 100 +++++++++++++++++- 7 files changed, 121 insertions(+), 7 deletions(-) diff --git a/DiscImageChef.Core/Delegates.cs b/DiscImageChef.Core/Delegates.cs index 267c3c6ee..9749bcf0b 100644 --- a/DiscImageChef.Core/Delegates.cs +++ b/DiscImageChef.Core/Delegates.cs @@ -103,7 +103,7 @@ namespace DiscImageChef.Core /// public delegate void ErrorMessageHandler(string text); - public delegate void InitBlockMapHandler(ulong blocks, ulong blockSize, ulong blocksToRead); + public delegate void InitBlockMapHandler(ulong blocks, ulong blockSize, ulong blocksToRead, ushort currentProfile); /// /// Updates lists of time taken on scanning from the specified sector @@ -115,4 +115,6 @@ namespace DiscImageChef.Core /// Specified a number of blocks could not be read on scan /// public delegate void ScanUnreadableHandler(ulong sector); + + public delegate void ScanSpeedHandler(ulong sector, double currentSpeed); } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Scanning/ATA.cs b/DiscImageChef.Core/Devices/Scanning/ATA.cs index be614b818..27472b603 100644 --- a/DiscImageChef.Core/Devices/Scanning/ATA.cs +++ b/DiscImageChef.Core/Devices/Scanning/ATA.cs @@ -117,7 +117,7 @@ namespace DiscImageChef.Core.Devices.Scanning { UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); - InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead); + InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, ATA_PROFILE); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE); @@ -151,12 +151,14 @@ namespace DiscImageChef.Core.Devices.Scanning else results.A += blocksToRead; ScanTime?.Invoke(i, duration); + ScanSpeed?.Invoke(i, currentSpeed * 1024); mhddLog.Write(i, duration); ibgLog.Write(i, currentSpeed * 1024); } else { ScanUnreadable?.Invoke(i); + ScanSpeed?.Invoke(i, 0); results.Errored += blocksToRead; for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); @@ -208,7 +210,7 @@ namespace DiscImageChef.Core.Devices.Scanning } else { - InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead); + InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, ATA_PROFILE); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE); @@ -248,12 +250,14 @@ namespace DiscImageChef.Core.Devices.Scanning else results.A += blocksToRead; ScanTime?.Invoke(currentBlock, duration); + ScanSpeed?.Invoke(currentBlock, currentSpeed * 1024); mhddLog.Write(currentBlock, duration); ibgLog.Write(currentBlock, currentSpeed * 1024); } else { ScanUnreadable?.Invoke(currentBlock); + ScanSpeed?.Invoke(currentBlock, 0); results.Errored += blocksToRead; results.UnreadableSectors.Add(currentBlock); mhddLog.Write(currentBlock, duration < 500 ? 65535 : duration); diff --git a/DiscImageChef.Core/Devices/Scanning/MediaScan.cs b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs index a75c70b8d..2f9a343df 100644 --- a/DiscImageChef.Core/Devices/Scanning/MediaScan.cs +++ b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs @@ -71,5 +71,6 @@ namespace DiscImageChef.Core.Devices.Scanning public event ScanTimeHandler ScanTime; public event ScanUnreadableHandler ScanUnreadable; public event InitBlockMapHandler InitBlockMap; + public event ScanSpeedHandler ScanSpeed; } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Scanning/SCSI.cs b/DiscImageChef.Core/Devices/Scanning/SCSI.cs index 1b7dc0f5c..2767da9d9 100644 --- a/DiscImageChef.Core/Devices/Scanning/SCSI.cs +++ b/DiscImageChef.Core/Devices/Scanning/SCSI.cs @@ -278,7 +278,7 @@ namespace DiscImageChef.Core.Devices.Scanning UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); - InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead); + InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, currentProfile); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); ibgLog = new IbgLog(ibgLogPath, currentProfile); DateTime timeSpeedStart = DateTime.UtcNow; @@ -319,6 +319,7 @@ namespace DiscImageChef.Core.Devices.Scanning else results.A += blocksToRead; ScanTime?.Invoke(i, cmdDuration); + ScanSpeed?.Invoke(i, currentSpeed * 1024); mhddLog.Write(i, cmdDuration); ibgLog.Write(i, currentSpeed * 1024); } @@ -347,6 +348,7 @@ namespace DiscImageChef.Core.Devices.Scanning else { ScanUnreadable?.Invoke(i); + ScanSpeed?.Invoke(i, 0); results.Errored += blocksToRead; for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); @@ -380,7 +382,7 @@ namespace DiscImageChef.Core.Devices.Scanning UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); - InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead); + InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, currentProfile); mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); ibgLog = new IbgLog(ibgLogPath, currentProfile); DateTime timeSpeedStart = DateTime.UtcNow; @@ -414,6 +416,7 @@ namespace DiscImageChef.Core.Devices.Scanning else results.A += blocksToRead; ScanTime?.Invoke(i, cmdDuration); + ScanSpeed?.Invoke(i, currentSpeed * 1024); mhddLog.Write(i, cmdDuration); ibgLog.Write(i, currentSpeed * 1024); } @@ -421,6 +424,7 @@ namespace DiscImageChef.Core.Devices.Scanning else { ScanUnreadable?.Invoke(i); + ScanSpeed?.Invoke(i, 0); results.Errored += blocksToRead; for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); diff --git a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs index 905c25205..25c2f502f 100644 --- a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs @@ -147,7 +147,7 @@ namespace DiscImageChef.Core.Devices.Scanning UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time."); - InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead); + InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, SD_PROFILE); MhddLog mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead); IbgLog ibgLog = new IbgLog(ibgLogPath, SD_PROFILE); @@ -182,12 +182,14 @@ namespace DiscImageChef.Core.Devices.Scanning else results.A += blocksToRead; ScanTime?.Invoke(i, duration); + ScanSpeed?.Invoke(i, currentSpeed * 1024); mhddLog.Write(i, duration); ibgLog.Write(i, currentSpeed * 1024); } else { ScanUnreadable?.Invoke(i); + ScanSpeed?.Invoke(i, 0); results.Errored += blocksToRead; for(ulong b = i; b < i + blocksToRead; b++) results.UnreadableSectors.Add(b); diff --git a/DiscImageChef.Gui/Forms/frmMediaScan.xeto b/DiscImageChef.Gui/Forms/frmMediaScan.xeto index 34d0f5d79..c90447b27 100644 --- a/DiscImageChef.Gui/Forms/frmMediaScan.xeto +++ b/DiscImageChef.Gui/Forms/frmMediaScan.xeto @@ -54,6 +54,9 @@ + + + diff --git a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs index 78d0e6dec..b0c034453 100644 --- a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs +++ b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs @@ -66,6 +66,16 @@ namespace DiscImageChef.Gui.Forms this.devicePath = devicePath; btnStop.Visible = false; + + lineChart.AbsoluteMargins = true; + lineChart.MarginX = 5; + lineChart.MarginY = 5; + lineChart.DrawAxes = true; + lineChart.AxesColor = Colors.Black; + lineChart.ColorX = Colors.Gray; + lineChart.ColorY = Colors.Gray; + lineChart.BackgroundColor = Color.FromRgb(0x2974c1); + lineChart.LineColor = Colors.Yellow; } void OnBtnCancelClick(object sender, EventArgs e) @@ -120,6 +130,7 @@ namespace DiscImageChef.Gui.Forms scanner.UpdateProgress += UpdateProgress; scanner.EndProgress += EndProgress; scanner.InitBlockMap += InitBlockMap; + scanner.ScanSpeed += ScanSpeed; ScanResults results = scanner.Scan(); @@ -161,13 +172,99 @@ namespace DiscImageChef.Gui.Forms WorkFinished(); } - void InitBlockMap(ulong blocks, ulong blocksize, ulong blockstoread) + void ScanSpeed(ulong sector, double currentspeed) + { + Application.Instance.Invoke(() => + { + System.Console.WriteLine(lineChart.MaxY); + if(currentspeed > lineChart.MaxY) lineChart.MaxY = (float)(currentspeed + currentspeed / 10); + + lineChart.Values.Add(new PointF(sector, (float)currentspeed)); + }); + } + + void InitBlockMap(ulong blocks, ulong blocksize, ulong blockstoread, ushort currentProfile) { Application.Instance.Invoke(() => { blockMap.Sectors = blocks; blockMap.SectorsToRead = (uint)blockstoread; blocksToRead = blockstoread; + lineChart.MinX = 0; + lineChart.MinY = 0; + switch(currentProfile) + { + case 0x0005: // CD and DDCD + case 0x0008: + case 0x0009: + case 0x000A: + case 0x0020: + case 0x0021: + case 0x0022: + if(blocks <= 360000) lineChart.MaxX = 360000; + else if(blocks <= 405000) lineChart.MaxX = 405000; + else if(blocks <= 445500) lineChart.MaxX = 445500; + else lineChart.MaxX = blocks; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 150 * 4; + lineChart.MaxY = lineChart.StepsY * 13.5f; + break; + case 0x0010: // DVD SL + case 0x0011: + case 0x0012: + case 0x0013: + case 0x0014: + case 0x0018: + case 0x001A: + case 0x001B: + lineChart.MaxX = 2298496; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 1352.5f; + lineChart.MaxY = lineChart.StepsY * 30; + break; + case 0x0015: // DVD DL + case 0x0016: + case 0x0017: + case 0x002A: + case 0x002B: + lineChart.MaxX = 4173824; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 1352.5f; + lineChart.MaxY = lineChart.StepsY * 30; + break; + case 0x0041: + case 0x0042: + case 0x0043: + case 0x0040: // BD + if(blocks <= 12219392) lineChart.MaxX = 12219392; + else if(blocks <= 24438784) lineChart.MaxX = 24438784; + else if(blocks <= 48878592) lineChart.MaxX = 48878592; + else if(blocks <= 62500864) lineChart.MaxX = 62500864; + else lineChart.MaxX = blocks; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 4394.5f; + lineChart.MaxY = lineChart.StepsY * 20; + break; + case 0x0050: // HD DVD + case 0x0051: + case 0x0052: + case 0x0053: + case 0x0058: + case 0x005A: + if(blocks <= 7361599) lineChart.MaxX = 7361599; + else if(blocks <= 16305407) lineChart.MaxX = 16305407; + else lineChart.MaxX = blocks; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 4394.5f; + lineChart.MaxY = lineChart.StepsY * 20; + break; + default: + lineChart.MaxX = blocks; + lineChart.StepsX = lineChart.MaxX / 10f; + lineChart.StepsY = 625f; + lineChart.MaxY = lineChart.StepsY; + break; + } }); } @@ -318,6 +415,7 @@ namespace DiscImageChef.Gui.Forms ProgressBar prgProgress2; TabControl tabResults; BlockMap blockMap; + LineChart lineChart; #endregion } } \ No newline at end of file