mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Migrate image entropy window from Eto.Forms to Avalonia.
This commit is contained in:
6
.idea/.idea.Aaru/.idea/contentModel.xml
generated
6
.idea/.idea.Aaru/.idea/contentModel.xml
generated
@@ -1225,8 +1225,6 @@
|
||||
<e p="frmDump.xeto.cs" t="Include" />
|
||||
<e p="frmImageConvert.xeto" t="Include" />
|
||||
<e p="frmImageConvert.xeto.cs" t="Include" />
|
||||
<e p="frmImageEntropy.xeto" t="Include" />
|
||||
<e p="frmImageEntropy.xeto.cs" t="Include" />
|
||||
<e p="frmImageSidecar.xeto" t="Include" />
|
||||
<e p="frmImageSidecar.xeto.cs" t="Include" />
|
||||
<e p="frmImageVerify.xeto" t="Include" />
|
||||
@@ -1258,6 +1256,7 @@
|
||||
<e p="PluginModel.cs" t="Include" />
|
||||
<e p="RootModel.cs" t="Include" />
|
||||
<e p="ScsiPageModel.cs" t="Include" />
|
||||
<e p="TrackEntropyModel.cs" t="Include" />
|
||||
</e>
|
||||
<e p="Panels" t="Include">
|
||||
<e p="ImageInfoPanel.xaml" t="Include" />
|
||||
@@ -1305,6 +1304,7 @@
|
||||
<e p="DvdWritableInfoViewModel.cs" t="Include" />
|
||||
<e p="EncodingsDialogViewModel.cs" t="Include" />
|
||||
<e p="ImageChecksumViewModel.cs" t="Include" />
|
||||
<e p="ImageEntropyViewModel.cs" t="Include" />
|
||||
<e p="ImageInfoViewModel.cs" t="Include" />
|
||||
<e p="LicenseDialogViewModel.cs" t="Include" />
|
||||
<e p="MainWindowViewModel.cs" t="Include" />
|
||||
@@ -1327,6 +1327,8 @@
|
||||
<e p="EncodingsDialog.xaml.cs" t="Include" />
|
||||
<e p="ImageChecksumWindow.xaml" t="Include" />
|
||||
<e p="ImageChecksumWindow.xaml.cs" t="Include" />
|
||||
<e p="ImageEntropyWindow.xaml" t="Include" />
|
||||
<e p="ImageEntropyWindow.xaml.cs" t="Include" />
|
||||
<e p="LicenseDialog.xaml" t="Include" />
|
||||
<e p="LicenseDialog.xaml.cs" t="Include" />
|
||||
<e p="MainWindow.xaml" t="Include" />
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!--
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ============================================================================
|
||||
//
|
||||
// Filename : frmImageEntropy.xeto
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Image entropy calculation window.
|
||||
//
|
||||
// ==[ Description ] ==========================================================
|
||||
//
|
||||
// Defines the structure for the image entroy calculation 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-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
-->
|
||||
<Form xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Calculate entropy" ClientSize="600, 450" Padding="10">
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
ID="stkOptions">
|
||||
<CheckBox Text="Calculates how many sectors are duplicated (have same exact data in user area)."
|
||||
ID="chkDuplicatedSectors" Checked="True"/>
|
||||
<CheckBox Text="Calculates entropy for each track separately." ID="chkSeparatedTracks" Checked="True"
|
||||
Visible="False"/>
|
||||
<CheckBox Text="Calculates entropy for the whole disc." ID="chkWholeDisc" Checked="True" Visible="False"/>
|
||||
</StackLayout>
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
ID="stkResults" Visible="False">
|
||||
<Label ID="lblMediaEntropy"/>
|
||||
<Label ID="lblMediaUniqueSectors"/>
|
||||
<GroupBox Text="Track entropy" ID="grpTrackEntropy">
|
||||
<TreeGridView ID="treeTrackEntropy"/>
|
||||
</GroupBox>
|
||||
</StackLayout>
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
ID="stkProgress" Visible="False">
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
ID="stkProgress1" Visible="False">
|
||||
<StackLayoutItem HorizontalAlignment="Center" Expand="True">
|
||||
<Label ID="lblProgress"/>
|
||||
</StackLayoutItem>
|
||||
<StackLayoutItem HorizontalAlignment="Center" Expand="True">
|
||||
<ProgressBar ID="prgProgress"/>
|
||||
</StackLayoutItem>
|
||||
</StackLayout>
|
||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
||||
ID="stkProgress2" Visible="False">
|
||||
<StackLayoutItem HorizontalAlignment="Center" Expand="True">
|
||||
<Label ID="lblProgress2"/>
|
||||
</StackLayoutItem>
|
||||
<StackLayoutItem HorizontalAlignment="Center" Expand="True">
|
||||
<ProgressBar ID="prgProgress2"/>
|
||||
</StackLayoutItem>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
<StackLayoutItem HorizontalAlignment="Right" Expand="True">
|
||||
<StackLayout Orientation="Horizontal" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom">
|
||||
<Button ID="btnStart" Text="Start" Click="OnBtnStart"/>
|
||||
<Button ID="btnClose" Text="Close" Click="OnBtnClose"/>
|
||||
<Button ID="btnStop" Text="Stop" Enabled="False" Visible="False" Click="OnBtnStop"/>
|
||||
</StackLayout>
|
||||
</StackLayoutItem>
|
||||
</StackLayout>
|
||||
</Form>
|
||||
@@ -1,244 +0,0 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : frmImageEntropy.xeto.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Image entropy calculation window.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Implements calculating media image entropy.
|
||||
//
|
||||
// --[ 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.Threading;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
using Aaru.Core;
|
||||
using Eto.Forms;
|
||||
using Eto.Serialization.Xaml;
|
||||
|
||||
namespace Aaru.Gui.Forms
|
||||
{
|
||||
public class frmImageEntropy : Form
|
||||
{
|
||||
readonly IMediaImage inputFormat;
|
||||
EntropyResults entropy;
|
||||
EntropyResults[] tracksEntropy;
|
||||
|
||||
public frmImageEntropy(IMediaImage inputFormat)
|
||||
{
|
||||
this.inputFormat = inputFormat;
|
||||
XamlReader.Load(this);
|
||||
|
||||
var inputOptical = inputFormat as IOpticalMediaImage;
|
||||
|
||||
if(inputOptical?.Tracks != null &&
|
||||
inputOptical?.Tracks.Count > 0)
|
||||
{
|
||||
chkSeparatedTracks.Visible = true;
|
||||
chkWholeDisc.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
chkSeparatedTracks.Checked = false;
|
||||
chkWholeDisc.Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnBtnStart(object sender, EventArgs e)
|
||||
{
|
||||
var entropyCalculator = new Entropy(false, false, inputFormat);
|
||||
entropyCalculator.InitProgressEvent += InitProgress;
|
||||
entropyCalculator.InitProgress2Event += InitProgress2;
|
||||
entropyCalculator.UpdateProgressEvent += UpdateProgress;
|
||||
entropyCalculator.UpdateProgress2Event += UpdateProgress2;
|
||||
entropyCalculator.EndProgressEvent += EndProgress;
|
||||
entropyCalculator.EndProgress2Event += EndProgress2;
|
||||
chkDuplicatedSectors.Enabled = false;
|
||||
chkSeparatedTracks.Enabled = false;
|
||||
chkWholeDisc.Enabled = false;
|
||||
btnClose.Visible = false;
|
||||
btnStart.Visible = false;
|
||||
btnStop.Visible = false;
|
||||
stkProgress.Visible = true;
|
||||
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
if(chkSeparatedTracks.Checked == true)
|
||||
{
|
||||
tracksEntropy = entropyCalculator.CalculateTracksEntropy(chkDuplicatedSectors.Checked == true);
|
||||
|
||||
foreach(EntropyResults trackEntropy in tracksEntropy)
|
||||
{
|
||||
AaruConsole.WriteLine("Entropy for track {0} is {1:F4}.", trackEntropy.Track,
|
||||
trackEntropy.Entropy);
|
||||
|
||||
if(trackEntropy.UniqueSectors != null)
|
||||
AaruConsole.WriteLine("Track {0} has {1} unique sectors ({2:P3})", trackEntropy.Track,
|
||||
trackEntropy.UniqueSectors,
|
||||
(double)trackEntropy.UniqueSectors / (double)trackEntropy.Sectors);
|
||||
}
|
||||
}
|
||||
|
||||
if(chkWholeDisc.Checked != true)
|
||||
return;
|
||||
|
||||
entropy = entropyCalculator.CalculateMediaEntropy(chkDuplicatedSectors.Checked == true);
|
||||
|
||||
Application.Instance.Invoke(Finish);
|
||||
});
|
||||
|
||||
Statistics.AddCommand("entropy");
|
||||
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
void Finish()
|
||||
{
|
||||
stkOptions.Visible = false;
|
||||
btnClose.Visible = true;
|
||||
stkProgress.Visible = false;
|
||||
stkResults.Visible = true;
|
||||
|
||||
if(chkSeparatedTracks.Checked == true)
|
||||
{
|
||||
var entropyList = new TreeGridItemCollection();
|
||||
|
||||
treeTrackEntropy.Columns.Add(new GridColumn
|
||||
{
|
||||
HeaderText = "Track", DataCell = new TextBoxCell(0)
|
||||
});
|
||||
|
||||
treeTrackEntropy.Columns.Add(new GridColumn
|
||||
{
|
||||
HeaderText = "Entropy", DataCell = new TextBoxCell(1)
|
||||
});
|
||||
|
||||
if(chkDuplicatedSectors.Checked == true)
|
||||
treeTrackEntropy.Columns.Add(new GridColumn
|
||||
{
|
||||
HeaderText = "Unique sectors", DataCell = new TextBoxCell(2)
|
||||
});
|
||||
|
||||
treeTrackEntropy.AllowMultipleSelection = false;
|
||||
treeTrackEntropy.ShowHeader = true;
|
||||
treeTrackEntropy.DataStore = entropyList;
|
||||
|
||||
foreach(EntropyResults trackEntropy in tracksEntropy)
|
||||
entropyList.Add(new TreeGridItem
|
||||
{
|
||||
Values = new object[]
|
||||
{
|
||||
trackEntropy.Track, trackEntropy.Entropy,
|
||||
$"{trackEntropy.UniqueSectors} ({(double)trackEntropy.UniqueSectors / (double)trackEntropy.Sectors:P3})"
|
||||
}
|
||||
});
|
||||
|
||||
grpTrackEntropy.Visible = true;
|
||||
}
|
||||
|
||||
if(chkWholeDisc.Checked != true)
|
||||
return;
|
||||
|
||||
lblMediaEntropy.Text = $"Entropy for disk is {entropy.Entropy:F4}.";
|
||||
lblMediaEntropy.Visible = true;
|
||||
|
||||
if(entropy.UniqueSectors == null)
|
||||
return;
|
||||
|
||||
lblMediaUniqueSectors.Text =
|
||||
$"Disk has {entropy.UniqueSectors} unique sectors ({(double)entropy.UniqueSectors / (double)entropy.Sectors:P3})";
|
||||
|
||||
lblMediaUniqueSectors.Visible = true;
|
||||
}
|
||||
|
||||
protected void OnBtnClose(object sender, EventArgs e) => Close();
|
||||
|
||||
protected void OnBtnStop(object sender, EventArgs e) => throw new NotImplementedException();
|
||||
|
||||
void InitProgress() => stkProgress1.Visible = true;
|
||||
|
||||
void EndProgress() => stkProgress1.Visible = false;
|
||||
|
||||
void InitProgress2() => stkProgress2.Visible = true;
|
||||
|
||||
void EndProgress2() => stkProgress2.Visible = false;
|
||||
|
||||
void UpdateProgress(string text, long current, long maximum) =>
|
||||
UpdateProgress(text, current, maximum, lblProgress, prgProgress);
|
||||
|
||||
void UpdateProgress2(string text, long current, long maximum) =>
|
||||
UpdateProgress(text, current, maximum, lblProgress2, prgProgress2);
|
||||
|
||||
void UpdateProgress(string text, long current, long maximum, Label label, ProgressBar progressBar) =>
|
||||
Application.Instance.Invoke(() =>
|
||||
{
|
||||
label.Text = text;
|
||||
|
||||
if(maximum == 0)
|
||||
{
|
||||
progressBar.Indeterminate = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(progressBar.Indeterminate)
|
||||
progressBar.Indeterminate = false;
|
||||
|
||||
if(maximum > int.MaxValue ||
|
||||
current > int.MaxValue)
|
||||
{
|
||||
progressBar.MaxValue = (int)(maximum / int.MaxValue);
|
||||
progressBar.Value = (int)(current / int.MaxValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.MaxValue = (int)maximum;
|
||||
progressBar.Value = (int)current;
|
||||
}
|
||||
});
|
||||
|
||||
#region XAML IDs
|
||||
StackLayout stkOptions;
|
||||
CheckBox chkDuplicatedSectors;
|
||||
CheckBox chkSeparatedTracks;
|
||||
CheckBox chkWholeDisc;
|
||||
StackLayout stkResults;
|
||||
Label lblMediaEntropy;
|
||||
Label lblMediaUniqueSectors;
|
||||
GroupBox grpTrackEntropy;
|
||||
TreeGridView treeTrackEntropy;
|
||||
StackLayout stkProgress;
|
||||
StackLayout stkProgress1;
|
||||
Label lblProgress;
|
||||
ProgressBar prgProgress;
|
||||
StackLayout stkProgress2;
|
||||
Label lblProgress2;
|
||||
ProgressBar prgProgress2;
|
||||
Button btnStart;
|
||||
Button btnClose;
|
||||
Button btnStop;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
9
Aaru.Gui/Models/TrackEntropyModel.cs
Normal file
9
Aaru.Gui/Models/TrackEntropyModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Aaru.Gui.Models
|
||||
{
|
||||
public class TrackEntropyModel
|
||||
{
|
||||
public string Track { get; set; }
|
||||
public string Entropy { get; set; }
|
||||
public string UniqueSectors { get; set; }
|
||||
}
|
||||
}
|
||||
385
Aaru.Gui/ViewModels/ImageEntropyViewModel.cs
Normal file
385
Aaru.Gui/ViewModels/ImageEntropyViewModel.cs
Normal file
@@ -0,0 +1,385 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Reactive;
|
||||
using System.Threading;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
using Aaru.Core;
|
||||
using Aaru.Gui.Models;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Aaru.Gui.ViewModels
|
||||
{
|
||||
public class ImageEntropyViewModel : ViewModelBase
|
||||
{
|
||||
readonly IMediaImage _inputFormat;
|
||||
bool _closeVisible;
|
||||
bool _duplicatedSectorsChecked;
|
||||
bool _duplicatedSectorsEnabled;
|
||||
EntropyResults _entropy;
|
||||
string _mediaEntropyText;
|
||||
bool _mediaEntropyVisible;
|
||||
string _mediaUniqueSectorsText;
|
||||
bool _mediaUniqueSectorsVisible;
|
||||
bool _optionsVisible;
|
||||
bool _progress1Visible;
|
||||
bool _progress2Indeterminate;
|
||||
double _progress2Max;
|
||||
string _progress2Text;
|
||||
double _progress2Value;
|
||||
bool _progress2Visible;
|
||||
bool _progressIndeterminate;
|
||||
double _progressMax;
|
||||
string _progressText;
|
||||
double _progressValue;
|
||||
bool _progressVisible;
|
||||
bool _resultsVisible;
|
||||
bool _separatedTracksChecked;
|
||||
bool _separatedTracksEnabled;
|
||||
bool _separatedTracksVisible;
|
||||
bool _startVisible;
|
||||
bool _stopVisible;
|
||||
EntropyResults[] _tracksEntropy;
|
||||
readonly Window _view;
|
||||
bool _wholeDiscChecked;
|
||||
bool _wholeDiscEnabled;
|
||||
bool _wholeDiscVisible;
|
||||
|
||||
public ImageEntropyViewModel(IMediaImage inputFormat, Window view)
|
||||
{
|
||||
_inputFormat = inputFormat;
|
||||
_view = view;
|
||||
TrackEntropy = new ObservableCollection<TrackEntropyModel>();
|
||||
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
|
||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
StopCommand = ReactiveCommand.Create(ExecuteStopCommand);
|
||||
OptionsVisible = true;
|
||||
DuplicatedSectorsChecked = true;
|
||||
SeparatedTracksChecked = true;
|
||||
WholeDiscChecked = true;
|
||||
StartVisible = true;
|
||||
|
||||
var inputOptical = inputFormat as IOpticalMediaImage;
|
||||
|
||||
if(inputOptical?.Tracks.Count > 0)
|
||||
{
|
||||
SeparatedTracksVisible = true;
|
||||
WholeDiscVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SeparatedTracksChecked = false;
|
||||
WholeDiscChecked = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SeparatedTracksVisible
|
||||
{
|
||||
get => _separatedTracksVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _separatedTracksVisible, value);
|
||||
}
|
||||
|
||||
public bool WholeDiscVisible
|
||||
{
|
||||
get => _wholeDiscVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _wholeDiscVisible, value);
|
||||
}
|
||||
|
||||
public bool SeparatedTracksChecked
|
||||
{
|
||||
get => _separatedTracksChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _separatedTracksChecked, value);
|
||||
}
|
||||
|
||||
public bool WholeDiscChecked
|
||||
{
|
||||
get => _wholeDiscChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _wholeDiscChecked, value);
|
||||
}
|
||||
|
||||
public bool DuplicatedSectorsEnabled
|
||||
{
|
||||
get => _duplicatedSectorsEnabled;
|
||||
set => this.RaiseAndSetIfChanged(ref _duplicatedSectorsEnabled, value);
|
||||
}
|
||||
|
||||
public bool SeparatedTracksEnabled
|
||||
{
|
||||
get => _separatedTracksEnabled;
|
||||
set => this.RaiseAndSetIfChanged(ref _separatedTracksEnabled, value);
|
||||
}
|
||||
|
||||
public bool WholeDiscEnabled
|
||||
{
|
||||
get => _wholeDiscEnabled;
|
||||
set => this.RaiseAndSetIfChanged(ref _wholeDiscEnabled, value);
|
||||
}
|
||||
|
||||
public bool CloseVisible
|
||||
{
|
||||
get => _closeVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _closeVisible, value);
|
||||
}
|
||||
|
||||
public bool StartVisible
|
||||
{
|
||||
get => _startVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _startVisible, value);
|
||||
}
|
||||
|
||||
public bool StopVisible
|
||||
{
|
||||
get => _stopVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _stopVisible, value);
|
||||
}
|
||||
|
||||
public bool ProgressVisible
|
||||
{
|
||||
get => _progressVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
|
||||
}
|
||||
|
||||
public bool DuplicatedSectorsChecked
|
||||
{
|
||||
get => _duplicatedSectorsChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _duplicatedSectorsChecked, value);
|
||||
}
|
||||
|
||||
public bool OptionsVisible
|
||||
{
|
||||
get => _optionsVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _optionsVisible, value);
|
||||
}
|
||||
|
||||
public bool ResultsVisible
|
||||
{
|
||||
get => _resultsVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _resultsVisible, value);
|
||||
}
|
||||
|
||||
public string MediaEntropyText
|
||||
{
|
||||
get => _mediaEntropyText;
|
||||
set => this.RaiseAndSetIfChanged(ref _mediaEntropyText, value);
|
||||
}
|
||||
|
||||
public bool MediaEntropyVisible
|
||||
{
|
||||
get => _mediaEntropyVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _mediaEntropyVisible, value);
|
||||
}
|
||||
|
||||
public string MediaUniqueSectorsText
|
||||
{
|
||||
get => _mediaUniqueSectorsText;
|
||||
set => this.RaiseAndSetIfChanged(ref _mediaUniqueSectorsText, value);
|
||||
}
|
||||
|
||||
public bool MediaUniqueSectorsVisible
|
||||
{
|
||||
get => _mediaUniqueSectorsVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _mediaUniqueSectorsVisible, value);
|
||||
}
|
||||
|
||||
public bool Progress1Visible
|
||||
{
|
||||
get => _progress1Visible;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress1Visible, value);
|
||||
}
|
||||
|
||||
public bool Progress2Visible
|
||||
{
|
||||
get => _progress2Visible;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
|
||||
}
|
||||
|
||||
public string ProgressText
|
||||
{
|
||||
get => _progressText;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressText, value);
|
||||
}
|
||||
|
||||
public bool ProgressIndeterminate
|
||||
{
|
||||
get => _progressIndeterminate;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressIndeterminate, value);
|
||||
}
|
||||
|
||||
public double ProgressMax
|
||||
{
|
||||
get => _progressMax;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressMax, value);
|
||||
}
|
||||
|
||||
public double ProgressValue
|
||||
{
|
||||
get => _progressValue;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
|
||||
}
|
||||
|
||||
public string Progress2Text
|
||||
{
|
||||
get => _progress2Text;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Text, value);
|
||||
}
|
||||
|
||||
public bool Progress2Indeterminate
|
||||
{
|
||||
get => _progress2Indeterminate;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Indeterminate, value);
|
||||
}
|
||||
|
||||
public double Progress2Max
|
||||
{
|
||||
get => _progress2Max;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Max, value);
|
||||
}
|
||||
|
||||
public double Progress2Value
|
||||
{
|
||||
get => _progress2Value;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Value, value);
|
||||
}
|
||||
|
||||
public string Title => "Calculating entropy";
|
||||
public ObservableCollection<TrackEntropyModel> TrackEntropy { get; }
|
||||
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> StopCommand { get; }
|
||||
|
||||
void ExecuteStartCommand()
|
||||
{
|
||||
var entropyCalculator = new Entropy(false, false, _inputFormat);
|
||||
entropyCalculator.InitProgressEvent += InitProgress;
|
||||
entropyCalculator.InitProgress2Event += InitProgress2;
|
||||
entropyCalculator.UpdateProgressEvent += UpdateProgress;
|
||||
entropyCalculator.UpdateProgress2Event += UpdateProgress2;
|
||||
entropyCalculator.EndProgressEvent += EndProgress;
|
||||
entropyCalculator.EndProgress2Event += EndProgress2;
|
||||
DuplicatedSectorsEnabled = false;
|
||||
SeparatedTracksEnabled = false;
|
||||
WholeDiscEnabled = false;
|
||||
CloseVisible = false;
|
||||
StartVisible = false;
|
||||
StopVisible = false;
|
||||
ProgressVisible = true;
|
||||
|
||||
var thread = new Thread(async () =>
|
||||
{
|
||||
if(SeparatedTracksChecked)
|
||||
{
|
||||
_tracksEntropy = entropyCalculator.CalculateTracksEntropy(DuplicatedSectorsChecked);
|
||||
|
||||
foreach(EntropyResults trackEntropy in _tracksEntropy)
|
||||
{
|
||||
AaruConsole.WriteLine("Entropy for track {0} is {1:F4}.", trackEntropy.Track,
|
||||
trackEntropy.Entropy);
|
||||
|
||||
if(trackEntropy.UniqueSectors != null)
|
||||
AaruConsole.WriteLine("Track {0} has {1} unique sectors ({2:P3})", trackEntropy.Track,
|
||||
trackEntropy.UniqueSectors,
|
||||
(double)trackEntropy.UniqueSectors / (double)trackEntropy.Sectors);
|
||||
}
|
||||
}
|
||||
|
||||
if(WholeDiscChecked != true)
|
||||
return;
|
||||
|
||||
_entropy = entropyCalculator.CalculateMediaEntropy(DuplicatedSectorsChecked);
|
||||
|
||||
await Dispatcher.UIThread.InvokeAsync(Finish);
|
||||
});
|
||||
|
||||
Statistics.AddCommand("entropy");
|
||||
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
void Finish()
|
||||
{
|
||||
OptionsVisible = false;
|
||||
CloseVisible = true;
|
||||
ProgressVisible = false;
|
||||
ResultsVisible = true;
|
||||
|
||||
if(SeparatedTracksChecked)
|
||||
{
|
||||
foreach(EntropyResults trackEntropy in _tracksEntropy)
|
||||
TrackEntropy.Add(new TrackEntropyModel
|
||||
{
|
||||
Track = trackEntropy.Track.ToString(),
|
||||
Entropy = trackEntropy.Entropy.ToString(CultureInfo.CurrentUICulture),
|
||||
UniqueSectors =
|
||||
$"{trackEntropy.UniqueSectors} ({(double)(trackEntropy.UniqueSectors ?? 0) / (double)trackEntropy.Sectors:P3})"
|
||||
});
|
||||
}
|
||||
|
||||
if(WholeDiscChecked != true)
|
||||
return;
|
||||
|
||||
MediaEntropyText = $"Entropy for disk is {_entropy.Entropy:F4}.";
|
||||
MediaEntropyVisible = true;
|
||||
|
||||
if(_entropy.UniqueSectors == null)
|
||||
return;
|
||||
|
||||
MediaUniqueSectorsText =
|
||||
$"Disk has {_entropy.UniqueSectors} unique sectors ({(double)_entropy.UniqueSectors / (double)_entropy.Sectors:P3})";
|
||||
|
||||
MediaUniqueSectorsVisible = true;
|
||||
}
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
|
||||
void ExecuteStopCommand() => throw new NotImplementedException();
|
||||
|
||||
void InitProgress() => Progress1Visible = true;
|
||||
|
||||
void EndProgress() => Progress1Visible = false;
|
||||
|
||||
void InitProgress2() => Progress2Visible = true;
|
||||
|
||||
void EndProgress2() => Progress2Visible = false;
|
||||
|
||||
async void UpdateProgress(string text, long current, long maximum) =>
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
ProgressText = text;
|
||||
|
||||
if(maximum == 0)
|
||||
{
|
||||
ProgressIndeterminate = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(ProgressIndeterminate)
|
||||
ProgressIndeterminate = false;
|
||||
|
||||
ProgressMax = maximum;
|
||||
ProgressValue = current;
|
||||
});
|
||||
|
||||
async void UpdateProgress2(string text, long current, long maximum) =>
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
Progress2Text = text;
|
||||
|
||||
if(maximum == 0)
|
||||
{
|
||||
Progress2Indeterminate = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(Progress2Indeterminate)
|
||||
Progress2Indeterminate = false;
|
||||
|
||||
Progress2Max = maximum;
|
||||
Progress2Value = current;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,9 @@ namespace Aaru.Gui.ViewModels
|
||||
readonly IMediaImage _imageFormat;
|
||||
readonly Window _view;
|
||||
IFilter _filter;
|
||||
|
||||
ImageChecksumWindow _imageChecksumWindow;
|
||||
string _imagePath;
|
||||
ImageChecksumWindow _imageChecksumWindow;
|
||||
ImageEntropyWindow _imageEntropyWindow;
|
||||
string _imagePath;
|
||||
|
||||
public ImageInfoViewModel(string imagePath, IFilter filter, IMediaImage imageFormat, Window view)
|
||||
|
||||
@@ -705,23 +705,22 @@ namespace Aaru.Gui.ViewModels
|
||||
|
||||
protected void ExecuteEntropyCommand()
|
||||
{
|
||||
/* TODO: frmImageEntropy
|
||||
if(frmImageEntropy != null)
|
||||
if(_imageEntropyWindow != null)
|
||||
{
|
||||
frmImageEntropy.Show();
|
||||
_imageEntropyWindow.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
frmImageEntropy = new frmImageEntropy(imageFormat);
|
||||
_imageEntropyWindow = new ImageEntropyWindow();
|
||||
_imageEntropyWindow.DataContext = new ImageEntropyViewModel(_imageFormat, _imageEntropyWindow);
|
||||
|
||||
frmImageEntropy.Closed += (s, ea) =>
|
||||
_imageEntropyWindow.Closed += (sender, args) =>
|
||||
{
|
||||
frmImageEntropy = null;
|
||||
_imageEntropyWindow = null;
|
||||
};
|
||||
|
||||
frmImageEntropy.Show();
|
||||
*/
|
||||
_imageEntropyWindow.Show();
|
||||
}
|
||||
|
||||
protected void ExecuteVerifyCommand()
|
||||
|
||||
58
Aaru.Gui/Views/ImageEntropyWindow.xaml
Normal file
58
Aaru.Gui/Views/ImageEntropyWindow.xaml
Normal file
@@ -0,0 +1,58 @@
|
||||
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450" x:Class="Aaru.Gui.Views.ImageEntropyWindow" Icon="/Assets/aaru-logo.png"
|
||||
Title="{Binding Title}">
|
||||
<Design.DataContext>
|
||||
<vm:ImageEntropyViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<StackPanel IsVisible="{Binding OptionsVisible}" Orientation="Vertical">
|
||||
<CheckBox IsEnabled="{Binding DuplicatedSectorsEnabled}" IsChecked="{Binding DuplicatedSectorsChecked}">
|
||||
<TextBlock Text="Calculates how many sectors are duplicated (have same exact data in user area)." />
|
||||
</CheckBox>
|
||||
<CheckBox IsEnabled="{Binding SeparatedTracksEnabled}" IsChecked="{Binding SeparatedTracksChecked}"
|
||||
IsVisible="{Binding SeparatedTracksVisible}">
|
||||
<TextBlock Text="Calculates entropy for each track separately." />
|
||||
</CheckBox>
|
||||
<CheckBox IsEnabled="{Binding WholeDiscEnabled}" IsChecked="{Binding WholeDiscChecked}"
|
||||
IsVisible="{Binding WholeDiscVisible}">
|
||||
<TextBlock Text="Calculates entropy for the whole disc." />
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" IsVisible="{Binding ResultsVisible}">
|
||||
<TextBlock Text="{Binding MediaEntropyText}" IsVisible="{Binding MediaEntropyVisible}" />
|
||||
<TextBlock Text="{Binding MediaUniqueSectorsText}" IsVisible="{Binding MediaUniqueSectorsVisible}" />
|
||||
<TextBlock Text="Track entropy" IsVisible="{Binding SeparatedTracksEnabled}" />
|
||||
<DataGrid IsVisible="{Binding SeparatedTracksEnabled}" Items="{Binding TrackEntropy}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Track" Binding="{Binding Track}" />
|
||||
<DataGridTextColumn Header="Entropy" Binding="{Binding Entropy}" />
|
||||
<DataGridTextColumn Header="Unique sectors" Binding="{Binding UniqueSectors}" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" IsVisible="{Binding ProgressVisible}">
|
||||
<StackPanel Orientation="Vertical" IsVisible="{Binding Progress1Visible}">
|
||||
<TextBlock Text="{Binding ProgressText}" />
|
||||
<ProgressBar Maximum="{Binding ProgressMax}" Value="{Binding ProgressValue}"
|
||||
IsIndeterminate="{Binding ProgressIndeterminate}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" IsVisible="{Binding Progress2Visible}">
|
||||
<TextBlock Text="{Binding Progress2Text}" />
|
||||
<ProgressBar Maximum="{Binding Progress2Max}" Value="{Binding Progress2Value}"
|
||||
IsIndeterminate="{Binding Progress2Indeterminate}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Button Command="{Binding StartCommand}" IsVisible="{Binding StartVisible}">
|
||||
<TextBlock Text="Start" />
|
||||
</Button>
|
||||
<Button Command="{Binding CloseCommand}" IsVisible="{Binding CloseVisible}">
|
||||
<TextBlock Text="Close" />
|
||||
</Button>
|
||||
<Button Command="{Binding StopCommand}" IsVisible="{Binding StopVisible}">
|
||||
<TextBlock Text="Stop" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
27
Aaru.Gui/Views/ImageEntropyWindow.xaml.cs
Normal file
27
Aaru.Gui/Views/ImageEntropyWindow.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.ComponentModel;
|
||||
using Aaru.Gui.ViewModels;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Aaru.Gui.Views
|
||||
{
|
||||
public class ImageEntropyWindow : Window
|
||||
{
|
||||
public ImageEntropyWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
(DataContext as ImageChecksumViewModel)?.ExecuteStopCommand();
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user