Migrate ata info from Eto.Forms to Avalonia.

This commit is contained in:
2020-04-12 13:44:42 +01:00
parent ec8ef12dae
commit 915491f329
9 changed files with 451 additions and 500 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -120,6 +120,12 @@
</TabItem.Header>
<ContentControl Content="{Binding ScsiInfo}" />
</TabItem>
<TabItem IsVisible="{Binding !!AtaInfo}">
<TabItem.Header>
<TextBlock Text="ATA / ATAPI" />
</TabItem.Header>
<ContentControl Content="{Binding AtaInfo}" />
</TabItem>
</TabControl>
<StackPanel Orientation="Horizontal" Spacing="5">
<Button Command="{Binding EntropyCommand}">

View File

@@ -87,7 +87,7 @@ namespace Aaru.Gui.Panels
tabPcmciaInfo.LoadData(devInfo.Cis);
tabInfos.Pages.Add(tabPcmciaInfo);
}
/*
if(devInfo.AtaIdentify != null ||
devInfo.AtapiIdentify != null)
{
@@ -96,7 +96,7 @@ namespace Aaru.Gui.Panels
tabInfos.Pages.Add(tabAtaInfo);
}
*/
/*
if(devInfo.ScsiInquiryData != null)
{

View File

@@ -0,0 +1,30 @@
<UserControl xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Aaru.Gui.Tabs.AtaInfoTab">
<Design.DataContext>
<vm:AtaInfoViewModel />
</Design.DataContext>
<StackPanel>
<TextBlock Text="{Binding AtaOrAtapiText}" />
<TextBox IsReadOnly="True" Text="{Binding AtaIdentifyText}" TextWrapping="Wrap" />
<CheckBox IsEnabled="False" IsChecked="{Binding AtaMcptChecked}" IsVisible="{Binding AtaMcptVisible}">
<TextBlock Text="Device is Media Card Pass Through" />
</CheckBox>
<TextBlock Text="{Binding AtaMcptText}" />
<CheckBox IsEnabled="False" IsChecked="{Binding AtaMcptWriteProtectionChecked}"
IsVisible="{Binding AtaMcptChecked}">
<TextBlock Text="Media card is write protected" />
</CheckBox>
<TextBlock Text="{Binding AtaMcptSpecificDataText}" />
<StackPanel Orientation="Horizontal">
<Button Command="{Binding SaveAtaBinaryCommand}">
<TextBlock Text="Save binary to file" />
</Button>
<Button Command="{Binding SaveAtaTextCommand}">
<TextBlock Text="Save text to file" />
</Button>
</StackPanel>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,12 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Aaru.Gui.Tabs
{
public class AtaInfoTab : UserControl
{
public AtaInfoTab() => InitializeComponent();
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
}

View File

@@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><!--
// /***************************************************************************
// The Disc Image Chef
// ============================================================================
//
// Filename : tabAtaInfo.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device information.
//
// ==[ Description ] ==========================================================
//
// Defines the structure for the ATA device information.
//
// ==[ 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-2020 Natalia Portillo
// ****************************************************************************/
-->
<TabPage Text="ATA/ATAPI" Visible="False" xmlns="http://schema.picoe.ca/eto.forms"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackLayout Orientation="Vertical">
<StackLayoutItem HorizontalAlignment="Center">
<Label ID="lblAtaIdentify" Text="ATA IDENTIFY DEVICE"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<TextArea ID="txtAtaIdentify" ReadOnly="True"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Left">
<StackLayout ID="stkAtaMcpt" Orientation="Vertical">
<CheckBox ID="chkAtaMcpt" Text="Device is Media Card Pass Through" Enabled="False"/>
<Label ID="lblAtaMcpt"/>
<CheckBox ID="chkAtaMcptWriteProtection" Text="Media card is write protected" Enabled="False"/>
<Label ID="lblAtaMcptSpecificData" Visible="False"/>
</StackLayout>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Right" VerticalAlignment="Bottom">
<StackLayout Orientation="Horizontal">
<Button ID="btnSaveAtaBinary" Text="Save binary to file" Click="OnBtnSaveAtaBinary"/>
<Button ID="btnSaveAtaText" Text="Save text to file" Click="OnBtnSaveAtaText"/>
</StackLayout>
</StackLayoutItem>
</StackLayout>
</TabPage>

View File

@@ -1,189 +0,0 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : tabAtaInfo.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device information.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements the ATA device information.
//
// --[ 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-2020 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using Aaru.Decoders.ATA;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace Aaru.Gui.Tabs
{
public class tabAtaInfo : TabPage
{
byte[] ata;
byte[] atapi;
public tabAtaInfo() => XamlReader.Load(this);
internal void LoadData(byte[] ataIdentify, byte[] atapiIdentify, AtaErrorRegistersChs? ataMcptError)
{
ata = ataIdentify;
atapi = atapiIdentify;
if(ataIdentify == null &&
atapiIdentify == null)
return;
Visible = true;
if(ataIdentify != null)
{
stkAtaMcpt.Visible = false;
chkAtaMcpt.Checked = ataMcptError.HasValue;
lblAtaMcpt.Visible = ataMcptError.HasValue;
lblAtaIdentify.Text = "ATA IDENTIFY DEVICE";
if(ataMcptError.HasValue)
{
switch(ataMcptError.Value.DeviceHead & 0x7)
{
case 0:
lblAtaMcpt.Text = "Device reports incorrect media card type";
break;
case 1:
lblAtaMcpt.Text = "Device contains a Secure Digital card";
break;
case 2:
lblAtaMcpt.Text = "Device contains a MultiMediaCard ";
break;
case 3:
lblAtaMcpt.Text = "Device contains a Secure Digital I/O card";
break;
case 4:
lblAtaMcpt.Text = "Device contains a Smart Media card";
break;
default:
lblAtaMcpt.Text =
$"Device contains unknown media card type {ataMcptError.Value.DeviceHead & 0x07}";
break;
}
chkAtaMcptWriteProtection.Checked = (ataMcptError.Value.DeviceHead & 0x08) == 0x08;
ushort specificData = (ushort)((ataMcptError.Value.CylinderHigh * 0x100) +
ataMcptError.Value.CylinderLow);
if(specificData != 0)
{
lblAtaMcptSpecificData.Visible = true;
lblAtaMcptSpecificData.Text = $"Card specific data: 0x{specificData:X4}";
}
}
Text = "ATA";
txtAtaIdentify.Text = Identify.Prettify(ata);
}
else
{
lblAtaIdentify.Text = "ATA PACKET IDENTIFY DEVICE";
stkAtaMcpt.Visible = false;
Text = "ATAPI";
txtAtaIdentify.Text = Identify.Prettify(atapi);
}
}
protected void OnBtnSaveAtaBinary(object sender, EventArgs e)
{
var dlgSaveBinary = new SaveFileDialog();
dlgSaveBinary.Filters.Add(new FileFilter
{
Extensions = new[]
{
"*.bin"
},
Name = "Binary"
});
DialogResult result = dlgSaveBinary.ShowDialog(this);
if(result != DialogResult.Ok)
return;
var saveFs = new FileStream(dlgSaveBinary.FileName, FileMode.Create);
if(ata != null)
saveFs.Write(ata, 0, ata.Length);
else if(atapi != null)
saveFs.Write(atapi, 0, atapi.Length);
saveFs.Close();
}
protected void OnBtnSaveAtaText(object sender, EventArgs e)
{
var dlgSaveText = new SaveFileDialog();
dlgSaveText.Filters.Add(new FileFilter
{
Extensions = new[]
{
"*.txt"
},
Name = "Text"
});
DialogResult result = dlgSaveText.ShowDialog(this);
if(result != DialogResult.Ok)
return;
var saveFs = new FileStream(dlgSaveText.FileName, FileMode.Create);
var saveSw = new StreamWriter(saveFs);
saveSw.Write(txtAtaIdentify.Text);
saveFs.Close();
}
#region XAML controls
#pragma warning disable 169
#pragma warning disable 649
Label lblAtaIdentify;
TextArea txtAtaIdentify;
Button btnSaveAtaBinary;
Button btnSaveAtaText;
StackLayout stkAtaMcpt;
CheckBox chkAtaMcpt;
Label lblAtaMcpt;
CheckBox chkAtaMcptWriteProtection;
Label lblAtaMcptSpecificData;
#pragma warning restore 169
#pragma warning restore 649
#endregion
}
}

View File

@@ -0,0 +1,146 @@
using System.Collections.Generic;
using System.IO;
using System.Reactive;
using Aaru.Decoders.ATA;
using Avalonia.Controls;
using ReactiveUI;
namespace Aaru.Gui.ViewModels
{
public class AtaInfoViewModel : ViewModelBase
{
readonly byte[] ata;
readonly byte[] atapi;
Window _view;
public AtaInfoViewModel(byte[] ataIdentify, byte[] atapiIdentify, AtaErrorRegistersChs? ataMcptError,
Window view)
{
SaveAtaBinaryCommand = ReactiveCommand.Create(ExecuteSaveAtaBinaryCommand);
SaveAtaTextCommand = ReactiveCommand.Create(ExecuteSaveAtaTextCommand);
ata = ataIdentify;
atapi = atapiIdentify;
if(ataIdentify == null &&
atapiIdentify == null)
return;
if(ataIdentify != null)
{
AtaMcptVisible = true;
AtaMcptChecked = ataMcptError.HasValue;
AtaOrAtapiText = "ATA IDENTIFY DEVICE";
if(ataMcptError.HasValue)
{
switch(ataMcptError.Value.DeviceHead & 0x7)
{
case 0:
AtaMcptText = "Device reports incorrect media card type";
break;
case 1:
AtaMcptText = "Device contains a Secure Digital card";
break;
case 2:
AtaMcptText = "Device contains a MultiMediaCard ";
break;
case 3:
AtaMcptText = "Device contains a Secure Digital I/O card";
break;
case 4:
AtaMcptText = "Device contains a Smart Media card";
break;
default:
AtaMcptText =
$"Device contains unknown media card type {ataMcptError.Value.DeviceHead & 0x07}";
break;
}
AtaMcptWriteProtectionChecked = (ataMcptError.Value.DeviceHead & 0x08) == 0x08;
ushort specificData = (ushort)((ataMcptError.Value.CylinderHigh * 0x100) +
ataMcptError.Value.CylinderLow);
AtaMcptSpecificDataText = $"Card specific data: 0x{specificData:X4}";
}
AtaIdentifyText = Identify.Prettify(ata);
}
else
{
AtaOrAtapiText = "ATA PACKET IDENTIFY DEVICE";
AtaIdentifyText = Identify.Prettify(atapi);
}
}
public string AtaIdentifyText { get; }
public string AtaMcptText { get; }
public string AtaMcptSpecificDataText { get; }
public bool AtaMcptChecked { get; }
public bool AtaMcptWriteProtectionChecked { get; }
public bool AtaMcptVisible { get; }
public ReactiveCommand<Unit, Unit> SaveAtaBinaryCommand { get; }
public ReactiveCommand<Unit, Unit> SaveAtaTextCommand { get; }
public string AtaOrAtapiText { get; }
protected async void ExecuteSaveAtaBinaryCommand()
{
var dlgSaveBinary = new SaveFileDialog();
dlgSaveBinary.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>(new[]
{
"*.bin"
}),
Name = "Binary"
});
string result = await dlgSaveBinary.ShowAsync(_view);
if(result is null)
return;
var saveFs = new FileStream(result, FileMode.Create);
if(ata != null)
saveFs.Write(ata, 0, ata.Length);
else if(atapi != null)
saveFs.Write(atapi, 0, atapi.Length);
saveFs.Close();
}
protected async void ExecuteSaveAtaTextCommand()
{
var dlgSaveText = new SaveFileDialog();
dlgSaveText.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>(new[]
{
"*.txt"
}),
Name = "Text"
});
string result = await dlgSaveText.ShowAsync(_view);
if(result is null)
return;
var saveFs = new FileStream(result, FileMode.Create);
var saveSw = new StreamWriter(saveFs);
saveSw.Write(AtaIdentifyText);
saveFs.Close();
}
}
}

View File

@@ -22,9 +22,9 @@ namespace Aaru.Gui.ViewModels
public class ImageInfoViewModel : ViewModelBase
{
readonly IMediaImage _imageFormat;
readonly Window _view;
IFilter _filter;
string _imagePath;
readonly Window _view;
public ImageInfoViewModel(string imagePath, IFilter filter, IMediaImage imageFormat, Window view)
@@ -189,7 +189,6 @@ namespace Aaru.Gui.ViewModels
scsiModeSense6, scsiModeSense10, null, _view)
};
/* TODO: tabAtaInfo
byte[] ataIdentify = null;
byte[] atapiIdentify = null;
@@ -201,10 +200,11 @@ namespace Aaru.Gui.ViewModels
imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATAPI_IDENTIFY))
atapiIdentify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);
var tabAtaInfo = new tabAtaInfo();
tabAtaInfo.LoadData(ataIdentify, atapiIdentify, null);
tabInfos.Pages.Add(tabAtaInfo);
*/
AtaInfo = new AtaInfoTab
{
DataContext = new AtaInfoViewModel(ataIdentify, atapiIdentify, null, _view)
};
/* TODO: tabCompactDiscInfo
byte[] toc = null;
TOC.CDTOC? decodedToc = null;
@@ -648,8 +648,8 @@ namespace Aaru.Gui.ViewModels
}
}
public ScsiInfoTab ScsiInfo { get; }
public ScsiInfoTab ScsiInfo { get; }
public AtaInfoTab AtaInfo { get; }
public Bitmap MediaLogo { get; }
public string ImagePathText { get; }
public string FilterText { get; }