Migrate image sector viewer from Eto.Forms to Avalonia.

This commit is contained in:
2020-04-13 23:54:35 +01:00
parent 9eb7ef6d3c
commit fb8ea8b72d
7 changed files with 374 additions and 355 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -355,6 +355,9 @@
<Compile Update="Tabs\ScsiInfoTab.xaml.cs"> <Compile Update="Tabs\ScsiInfoTab.xaml.cs">
<DependentUpon>ScsiInfoTab.xaml</DependentUpon> <DependentUpon>ScsiInfoTab.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\ViewSectorWindow.xaml.cs">
<DependentUpon>ViewSectorWindow.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.xaml" /> <UpToDateCheckInput Remove="Views\MainWindow.xaml" />

View File

@@ -1,85 +0,0 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : frmPrintHex.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Form to show hexadecimal dumps of sectors.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements hexadecimal sector viewer.
//
// --[ 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 Aaru.CommonTypes.Interfaces;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace Aaru.Gui.Forms
{
// TODO: Decode long sector components
// TODO: Panel with string representation of contents
public class frmPrintHex : Form
{
const int HEX_COLUMNS = 32;
readonly IMediaImage inputFormat;
public frmPrintHex(IMediaImage inputFormat)
{
this.inputFormat = inputFormat;
XamlReader.Load(this);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
inputFormat.ReadSectorLong(0);
chkLongSector.Checked = true;
}
catch
{
chkLongSector.Visible = false;
}
lblSectors.Text = $"of {inputFormat.Info.Sectors}";
nmuSector.Value = 0;
OnNmuSectorValueChanged(nmuSector, e);
}
void OnNmuSectorValueChanged(object sender, EventArgs e) => txtPrintHex.Text =
PrintHex.
ByteArrayToHexArrayString(chkLongSector.Checked == true ? inputFormat.ReadSectorLong((ulong)nmuSector.Value) : inputFormat.ReadSector((ulong)nmuSector.Value),
HEX_COLUMNS);
#region XAML IDs
Label lblSector;
NumericStepper nmuSector;
Label lblSectors;
CheckBox chkLongSector;
TextArea txtPrintHex;
#endregion
}
}

View File

@@ -28,13 +28,14 @@ namespace Aaru.Gui.ViewModels
public class ImageInfoViewModel : ViewModelBase public class ImageInfoViewModel : ViewModelBase
{ {
readonly IMediaImage _imageFormat; readonly IMediaImage _imageFormat;
readonly string _imagePath;
readonly Window _view; readonly Window _view;
IFilter _filter; IFilter _filter;
ImageChecksumWindow _imageChecksumWindow; ImageChecksumWindow _imageChecksumWindow;
ImageConvertWindow _imageConvertWindow; ImageConvertWindow _imageConvertWindow;
ImageEntropyWindow _imageEntropyWindow; ImageEntropyWindow _imageEntropyWindow;
readonly string _imagePath;
ImageVerifyWindow _imageVerifyWindow; ImageVerifyWindow _imageVerifyWindow;
ViewSectorWindow _viewSectorWindow;
public ImageInfoViewModel(string imagePath, IFilter filter, IMediaImage imageFormat, Window view) public ImageInfoViewModel(string imagePath, IFilter filter, IMediaImage imageFormat, Window view)
@@ -809,23 +810,22 @@ namespace Aaru.Gui.ViewModels
protected void ExecuteViewSectorsCommand() protected void ExecuteViewSectorsCommand()
{ {
/* TODO: frmPrintHex if(_viewSectorWindow != null)
if(frmPrintHex != null)
{ {
frmPrintHex.Show(); _viewSectorWindow.Show();
return; return;
} }
frmPrintHex = new frmPrintHex(imageFormat); _viewSectorWindow = new ViewSectorWindow
frmPrintHex.Closed += (s, ea) =>
{ {
frmPrintHex = null; DataContext = new ViewSectorViewModel(_imageFormat)
}; };
frmPrintHex.Show(); _viewSectorWindow.Closed += (sender, args) =>
*/ {
_viewSectorWindow = null;
};
} }
protected void ExecuteDecodeMediaTagCommand() protected void ExecuteDecodeMediaTagCommand()

View File

@@ -0,0 +1,71 @@
using Aaru.CommonTypes.Interfaces;
using ReactiveUI;
namespace Aaru.Gui.ViewModels
{
public class ViewSectorViewModel : ViewModelBase
{
const int HEX_COLUMNS = 32;
readonly IMediaImage inputFormat;
bool _longSectorChecked;
bool _longSectorVisible;
string _printHexText;
double _sectorNumber;
string _title;
string _totalSectorsText;
public ViewSectorViewModel(IMediaImage inputFormat)
{
this.inputFormat = inputFormat;
try
{
inputFormat.ReadSectorLong(0);
LongSectorChecked = true;
}
catch
{
LongSectorVisible = false;
}
TotalSectorsText = $"of {inputFormat.Info.Sectors}";
SectorNumber = 0;
}
public string Title
{
get => _title;
set => this.RaiseAndSetIfChanged(ref _title, value);
}
public double SectorNumber
{
get => _sectorNumber;
set
{
this.RaiseAndSetIfChanged(ref _sectorNumber, value);
PrintHexText =
PrintHex.
ByteArrayToHexArrayString(LongSectorChecked ? inputFormat.ReadSectorLong((ulong)SectorNumber) : inputFormat.ReadSector((ulong)SectorNumber),
HEX_COLUMNS);
}
}
public string TotalSectorsText { get; }
public bool LongSectorChecked
{
get => _longSectorChecked;
set => this.RaiseAndSetIfChanged(ref _longSectorChecked, value);
}
public bool LongSectorVisible { get; }
public string PrintHexText
{
get => _printHexText;
set => this.RaiseAndSetIfChanged(ref _printHexText, value);
}
}
}

View File

@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?><!-- <!--
// /*************************************************************************** // /***************************************************************************
// The Disc Image Chef // The Disc Image Chef
// ============================================================================ // ============================================================================
// //
// Filename : frmPrintHex.xeto // Filename : dlgEncodings.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com> // Author(s) : Natalia Portillo <claunia@claunia.com>
// //
// Component : Form to show hexadecimal dumps of sectors. // Component : Encodings dialog.
// //
// ==[ Description ] ========================================================== // ==[ Description ] ==========================================================
// //
// Defines the structure for the print hex GUI window. // Defines the structure for the encodings list dialog.
// //
// ==[ License ] ============================================================== // ==[ License ] ==============================================================
// //
@@ -31,16 +31,23 @@
// Copyright © 2011-2020 Natalia Portillo // Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
--> -->
<Form xmlns="http://schema.picoe.ca/eto.forms" Title="Sector viewer" ClientSize="600, 450" Padding="10"> <Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
<StackLayout Orientation="Horizontal" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
<Label Text="Sector" ID="lblSector"/> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800"
<NumericStepper ID="nmuSector" ValueChanged="OnNmuSectorValueChanged"/> d:DesignHeight="450" Width="480" Height="320" x:Class="Aaru.Gui.Views.ViewSectorWindow"
<Label Text="of XXXXX" ID="lblSectors"/> Icon="/Assets/aaru-logo.png" CanResize="False" Title="{Binding Title}">
</StackLayout> <Design.DataContext>
<CheckBox ID="chkLongSector" Text="Show long sector"/> <vm:ViewSectorViewModel />
<StackLayoutItem Expand="True"> </Design.DataContext>
<TextArea ID="txtPrintHex"/> <StackPanel Orientation="Vertical">
</StackLayoutItem> <StackPanel Orientation="Horizontal">
</StackLayout> <TextBlock Text="Sector" /> <NumericUpDown Value="{Binding SectorNumber}" />
</Form> <TextBlock Text="{Binding TotalSectorsText}" />
</StackPanel>
<CheckBox IsChecked="{Binding LongSectorChecked}" IsVisible="{Binding LongSectorVisible}">
<TextBlock Text="Show long sector" />
</CheckBox>
<TextBox IsReadOnly="True" Text="{Binding PrintHexText}" />
</StackPanel>
</Window>

View File

@@ -0,0 +1,19 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Aaru.Gui.Views
{
public class ViewSectorWindow : Window
{
public ViewSectorWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
}