mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement media scan on GUI.
This commit is contained in:
2
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
2
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -1636,6 +1636,8 @@
|
||||
<e p="frmImageVerify.xeto.cs" t="Include" />
|
||||
<e p="frmMain.xeto" t="Include" />
|
||||
<e p="frmMain.xeto.cs" t="Include" />
|
||||
<e p="frmMediaScan.xeto" t="Include" />
|
||||
<e p="frmMediaScan.xeto.cs" t="Include" />
|
||||
<e p="frmPrintHex.xeto" t="Include" />
|
||||
<e p="frmPrintHex.xeto.cs" t="Include" />
|
||||
</e>
|
||||
|
||||
60
DiscImageChef.Gui/Forms/frmMediaScan.xeto
Normal file
60
DiscImageChef.Gui/Forms/frmMediaScan.xeto
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!--
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ============================================================================
|
||||
//
|
||||
// Filename : frmMediaScan.xeto
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Media surface scan window.
|
||||
//
|
||||
// ==[ Description ] ==========================================================
|
||||
//
|
||||
// Defines the structure for the media scan GUI window.
|
||||
//
|
||||
// ==[ License ] ==============================================================
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ============================================================================
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
-->
|
||||
<Form xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Media scan" ClientSize="600, 450" Padding="10">
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
||||
<Label ID="lblTotalTime" Text="Took a total of {0} seconds ({1} processing commands)."/>
|
||||
<Label ID="lblAvgSpeed" Text="Average speed: {0:F3} MiB/sec."/>
|
||||
<Label ID="lblMaxSpeed" Text="Fastest speed burst: {0:F3} MiB/sec."/>
|
||||
<Label ID="lblMinSpeed" Text="Slowest speed burst: {0:F3} MiB/sec."/>
|
||||
<Label ID="lblA" Text="{0} sectors took less than 3 ms."/>
|
||||
<Label ID="lblB" Text="{0} sectors took less than 10 ms but more than 3 ms."/>
|
||||
<Label ID="lblC" Text="{0} sectors took less than 50 ms but more than 10 ms."/>
|
||||
<Label ID="lblD" Text="{0} sectors took less than 150 ms but more than 50 ms."/>
|
||||
<Label ID="lblE" Text="{0} sectors took less than 500 ms but more than 150 ms."/>
|
||||
<Label ID="lblF" Text="{0} sectors took more than 500 ms."/>
|
||||
<Label ID="lblUnreadableSectors" Text="{0} sectors could not be read."/>
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<StackLayoutItem HorizontalAlignment="Right">
|
||||
<Button ID="btnCancel" Click="OnBtnCancelClick" Text="Cancel"/>
|
||||
</StackLayoutItem>
|
||||
<StackLayoutItem HorizontalAlignment="Right">
|
||||
<Button ID="btnStop" Click="OnBtnStopClick" Text="Stop"/>
|
||||
</StackLayoutItem>
|
||||
<StackLayoutItem HorizontalAlignment="Right">
|
||||
<Button ID="btnScan" Click="OnBtnScanClick" Text="Scan"/>
|
||||
</StackLayoutItem>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</Form>
|
||||
171
DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs
Normal file
171
DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : frmMediaScan.xeto.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Media surface scan window.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Implements media scan GUI window.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.Core;
|
||||
using DiscImageChef.Core.Devices.Scanning;
|
||||
using DiscImageChef.Core.Media.Info;
|
||||
using DiscImageChef.Devices;
|
||||
using Eto.Forms;
|
||||
using Eto.Serialization.Xaml;
|
||||
using DeviceInfo = DiscImageChef.Core.Devices.Info.DeviceInfo;
|
||||
|
||||
namespace DiscImageChef.Gui.Forms
|
||||
{
|
||||
public class frmMediaScan : Form
|
||||
{
|
||||
string devicePath;
|
||||
|
||||
public frmMediaScan(string devicePath, DeviceInfo deviceInfo, ScsiInfo scsiInfo = null)
|
||||
{
|
||||
MediaType mediaType;
|
||||
XamlReader.Load(this);
|
||||
|
||||
this.devicePath = devicePath;
|
||||
btnStop.Visible = false;
|
||||
}
|
||||
|
||||
void OnBtnCancelClick(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void OnBtnStopClick(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: Stop
|
||||
}
|
||||
|
||||
// TODO: Allow to save MHDD and ImgBurn log files
|
||||
void OnBtnScanClick(object sender, EventArgs e)
|
||||
{
|
||||
btnStop.Visible = true;
|
||||
btnScan.Visible = false;
|
||||
btnCancel.Visible = false;
|
||||
|
||||
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
|
||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||
|
||||
Device dev = new Device(devicePath);
|
||||
|
||||
if(dev.Error)
|
||||
{
|
||||
MessageBox.Show($"Error {dev.LastError} opening device.", MessageBoxType.Error);
|
||||
btnStop.Visible = false;
|
||||
btnScan.Visible = true;
|
||||
btnCancel.Visible = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Statistics.AddDevice(dev);
|
||||
|
||||
ScanResults results;
|
||||
|
||||
switch(dev.Type)
|
||||
{
|
||||
case DeviceType.ATA:
|
||||
results = Ata.Scan(null, null, devicePath, dev);
|
||||
break;
|
||||
case DeviceType.MMC:
|
||||
case DeviceType.SecureDigital:
|
||||
results = SecureDigital.Scan(null, null, devicePath, dev);
|
||||
break;
|
||||
case DeviceType.NVMe:
|
||||
results = Nvme.Scan(null, null, devicePath, dev);
|
||||
break;
|
||||
case DeviceType.ATAPI:
|
||||
case DeviceType.SCSI:
|
||||
results = Scsi.Scan(null, null, devicePath, dev);
|
||||
break;
|
||||
default: throw new NotSupportedException("Unknown device type.");
|
||||
}
|
||||
|
||||
lblTotalTime.Text = lblTotalTime.Text =
|
||||
$"Took a total of {results.TotalTime} seconds ({results.ProcessingTime} processing commands).";
|
||||
lblAvgSpeed.Text = $"Average speed: {results.AvgSpeed:F3} MiB/sec.";
|
||||
lblMaxSpeed.Text = $"Fastest speed burst: {results.MaxSpeed:F3} MiB/sec.";
|
||||
lblMinSpeed.Text = $"Slowest speed burst: {results.MinSpeed:F3} MiB/sec.";
|
||||
lblA.Text = $"{results.A} sectors took less than 3 ms.";
|
||||
lblB.Text = $"{results.B} sectors took less than 10 ms but more than 3 ms.";
|
||||
lblC.Text = $"{results.C} sectors took less than 50 ms but more than 10 ms.";
|
||||
lblD.Text = $"{results.D} sectors took less than 150 ms but more than 50 ms.";
|
||||
lblE.Text = $"{results.E} sectors took less than 500 ms but more than 150 ms.";
|
||||
lblF.Text = $"{results.F} sectors took more than 500 ms.";
|
||||
lblUnreadableSectors.Text = $"{results.UnreadableSectors.Count} sectors could not be read.";
|
||||
|
||||
// TODO: Show list of unreadable sectors
|
||||
/*
|
||||
if(results.UnreadableSectors.Count > 0)
|
||||
foreach(ulong bad in results.UnreadableSectors)
|
||||
string.Format("Sector {0} could not be read", bad);
|
||||
*/
|
||||
|
||||
// TODO: Show results
|
||||
/*
|
||||
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
|
||||
if(results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue)
|
||||
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
|
||||
string.Format("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)",
|
||||
results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000);
|
||||
*/
|
||||
|
||||
Statistics.AddMediaScan((long)results.A, (long)results.B, (long)results.C, (long)results.D, (long)results.E,
|
||||
(long)results.F, (long)results.Blocks, (long)results.Errored,
|
||||
(long)(results.Blocks - results.Errored));
|
||||
Statistics.AddCommand("media-scan");
|
||||
|
||||
dev.Close();
|
||||
|
||||
btnStop.Visible = false;
|
||||
btnScan.Visible = true;
|
||||
btnCancel.Visible = true;
|
||||
}
|
||||
|
||||
#region XAML IDs
|
||||
Label lblTotalTime;
|
||||
Label lblAvgSpeed;
|
||||
Label lblMaxSpeed;
|
||||
Label lblMinSpeed;
|
||||
Label lblA;
|
||||
Label lblB;
|
||||
Label lblC;
|
||||
Label lblD;
|
||||
Label lblE;
|
||||
Label lblF;
|
||||
Label lblUnreadableSectors;
|
||||
Button btnCancel;
|
||||
Button btnStop;
|
||||
Button btnScan;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -106,5 +106,8 @@
|
||||
<StackLayoutItem HorizontalAlignment="Left" VerticalAlignment="Bottom">
|
||||
<Button Click="OnBtnDumpClick" ID="btnDump" Text="Dump media to image"/>
|
||||
</StackLayoutItem>
|
||||
<StackLayoutItem HorizontalAlignment="Left" VerticalAlignment="Bottom">
|
||||
<Button Click="OnBtnScanClick" ID="btnScan" Text="Scan media surface"/>
|
||||
</StackLayoutItem>
|
||||
</StackLayout>
|
||||
</Panel>
|
||||
@@ -232,6 +232,22 @@ namespace DiscImageChef.Gui.Panels
|
||||
dumpForm.Show();
|
||||
}
|
||||
|
||||
protected void OnBtnScanClick(object sender, EventArgs e)
|
||||
{
|
||||
if(scsiInfo.MediaType == MediaType.GDR || scsiInfo.MediaType == MediaType.GDROM)
|
||||
{
|
||||
MessageBox.Show("GD-ROM scan support is not yet implemented.", MessageBoxType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if((scsiInfo.MediaType == MediaType.XGD || scsiInfo.MediaType == MediaType.XGD2 ||
|
||||
scsiInfo.MediaType == MediaType.XGD3))
|
||||
MessageBox.Show("Scanning Xbox discs is not yet supported.", MessageBoxType.Error);
|
||||
|
||||
frmMediaScan scanForm = new frmMediaScan(devicePath, scsiInfo.DeviceInfo, scsiInfo);
|
||||
scanForm.Show();
|
||||
}
|
||||
|
||||
#region XAML controls
|
||||
#pragma warning disable 169
|
||||
#pragma warning disable 649
|
||||
@@ -280,6 +296,7 @@ namespace DiscImageChef.Gui.Panels
|
||||
Button btnDump;
|
||||
ImageView imgMediaLogo;
|
||||
SvgImageView svgMediaLogo;
|
||||
Button btnScan;
|
||||
#pragma warning restore 169
|
||||
#pragma warning restore 649
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user