mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Migrate image sidecar window from Eto.Forms to Avalonia.
This commit is contained in:
7
.idea/.idea.Aaru/.idea/contentModel.xml
generated
7
.idea/.idea.Aaru/.idea/contentModel.xml
generated
@@ -1219,12 +1219,8 @@
|
|||||||
<e p="SvgImageView.cs" t="Include" />
|
<e p="SvgImageView.cs" t="Include" />
|
||||||
</e>
|
</e>
|
||||||
<e p="Forms" t="Include">
|
<e p="Forms" t="Include">
|
||||||
<e p="frmDecodeMediaTags.xeto" t="Include" />
|
|
||||||
<e p="frmDecodeMediaTags.xeto.cs" t="Include" />
|
|
||||||
<e p="frmDump.xeto" t="Include" />
|
<e p="frmDump.xeto" t="Include" />
|
||||||
<e p="frmDump.xeto.cs" t="Include" />
|
<e p="frmDump.xeto.cs" t="Include" />
|
||||||
<e p="frmImageSidecar.xeto" t="Include" />
|
|
||||||
<e p="frmImageSidecar.xeto.cs" t="Include" />
|
|
||||||
<e p="frmMain.xeto" t="Include" />
|
<e p="frmMain.xeto" t="Include" />
|
||||||
<e p="frmMain.xeto.cs" t="Include" />
|
<e p="frmMain.xeto.cs" t="Include" />
|
||||||
<e p="frmMediaScan.xeto" t="Include" />
|
<e p="frmMediaScan.xeto" t="Include" />
|
||||||
@@ -1305,6 +1301,7 @@
|
|||||||
<e p="ImageConvertViewModel.cs" t="Include" />
|
<e p="ImageConvertViewModel.cs" t="Include" />
|
||||||
<e p="ImageEntropyViewModel.cs" t="Include" />
|
<e p="ImageEntropyViewModel.cs" t="Include" />
|
||||||
<e p="ImageInfoViewModel.cs" t="Include" />
|
<e p="ImageInfoViewModel.cs" t="Include" />
|
||||||
|
<e p="ImageSidecarViewModel.cs" t="Include" />
|
||||||
<e p="ImageVerifyViewModel.cs" t="Include" />
|
<e p="ImageVerifyViewModel.cs" t="Include" />
|
||||||
<e p="LicenseDialogViewModel.cs" t="Include" />
|
<e p="LicenseDialogViewModel.cs" t="Include" />
|
||||||
<e p="MainWindowViewModel.cs" t="Include" />
|
<e p="MainWindowViewModel.cs" t="Include" />
|
||||||
@@ -1334,6 +1331,8 @@
|
|||||||
<e p="ImageConvertWindow.xaml.cs" t="Include" />
|
<e p="ImageConvertWindow.xaml.cs" t="Include" />
|
||||||
<e p="ImageEntropyWindow.xaml" t="Include" />
|
<e p="ImageEntropyWindow.xaml" t="Include" />
|
||||||
<e p="ImageEntropyWindow.xaml.cs" t="Include" />
|
<e p="ImageEntropyWindow.xaml.cs" t="Include" />
|
||||||
|
<e p="ImageSidecarWindow.xaml" t="Include" />
|
||||||
|
<e p="ImageSidecarWindow.xaml.cs" t="Include" />
|
||||||
<e p="ImageVerifyWindow.xaml" t="Include" />
|
<e p="ImageVerifyWindow.xaml" t="Include" />
|
||||||
<e p="ImageVerifyWindow.xaml.cs" t="Include" />
|
<e p="ImageVerifyWindow.xaml.cs" t="Include" />
|
||||||
<e p="LicenseDialog.xaml" t="Include" />
|
<e p="LicenseDialog.xaml" t="Include" />
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><!--
|
|
||||||
// /***************************************************************************
|
|
||||||
// The Disc Image Chef
|
|
||||||
// ============================================================================
|
|
||||||
//
|
|
||||||
// Filename : frmImageSidecar.xeto
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// Component : Image sidecar creation window.
|
|
||||||
//
|
|
||||||
// ==[ Description ] ==========================================================
|
|
||||||
//
|
|
||||||
// Defines the structure for the image sidecar creation 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" Title="Create metadata sidecar" ClientSize="800, 600" Padding="10">
|
|
||||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
|
||||||
<Label Text="Destination file"/>
|
|
||||||
<StackLayout Orientation="Horizontal" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
|
||||||
<StackLayoutItem Expand="True">
|
|
||||||
<TextBox ID="txtDestination" ReadOnly="True"/>
|
|
||||||
</StackLayoutItem>
|
|
||||||
<Button ID="btnDestination" Text="Choose..." Click="OnBtnDestinationClick"/>
|
|
||||||
</StackLayout>
|
|
||||||
<StackLayout Orientation="Vertical" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
|
|
||||||
ID="stkProgress" Visible="False">
|
|
||||||
<StackLayoutItem HorizontalAlignment="Center" Expand="True">
|
|
||||||
<Label ID="lblStatus" Visible="False"/>
|
|
||||||
</StackLayoutItem>
|
|
||||||
<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" Visible="False" Click="OnBtnStop"/>
|
|
||||||
</StackLayout>
|
|
||||||
</StackLayoutItem>
|
|
||||||
</StackLayout>
|
|
||||||
</Form>
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
// /***************************************************************************
|
|
||||||
// Aaru Data Preservation Suite
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : frmImageSidecar.xeto.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// Component : Image sidecar creation window.
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Implements creating image metadata sidecar.
|
|
||||||
//
|
|
||||||
// --[ 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 System.Threading;
|
|
||||||
using System.Xml.Serialization;
|
|
||||||
using Aaru.CommonTypes.Interfaces;
|
|
||||||
using Aaru.Console;
|
|
||||||
using Aaru.Core;
|
|
||||||
using Claunia.Encoding;
|
|
||||||
using Eto.Forms;
|
|
||||||
using Eto.Serialization.Xaml;
|
|
||||||
using Schemas;
|
|
||||||
|
|
||||||
namespace Aaru.Gui.Forms
|
|
||||||
{
|
|
||||||
public class frmImageSidecar : Form
|
|
||||||
{
|
|
||||||
readonly Encoding encoding;
|
|
||||||
readonly Guid filterId;
|
|
||||||
readonly string imageSource;
|
|
||||||
readonly IMediaImage inputFormat;
|
|
||||||
|
|
||||||
Sidecar sidecarClass;
|
|
||||||
|
|
||||||
public frmImageSidecar(IMediaImage inputFormat, string imageSource, Guid filterId, Encoding encoding)
|
|
||||||
{
|
|
||||||
this.inputFormat = inputFormat;
|
|
||||||
this.imageSource = imageSource;
|
|
||||||
this.filterId = filterId;
|
|
||||||
this.encoding = encoding;
|
|
||||||
XamlReader.Load(this);
|
|
||||||
|
|
||||||
txtDestination.Text = Path.Combine(Path.GetDirectoryName(imageSource) ?? "",
|
|
||||||
Path.GetFileNameWithoutExtension(imageSource) + ".cicm.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnBtnStart(object sender, EventArgs e) => new Thread(DoWork).Start();
|
|
||||||
|
|
||||||
void DoWork()
|
|
||||||
{
|
|
||||||
// Prepare UI
|
|
||||||
Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
btnClose.Visible = false;
|
|
||||||
btnStart.Visible = false;
|
|
||||||
btnStop.Visible = true;
|
|
||||||
btnStop.Enabled = true;
|
|
||||||
stkProgress.Visible = true;
|
|
||||||
btnDestination.Visible = false;
|
|
||||||
lblStatus.Visible = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
sidecarClass = new Sidecar(inputFormat, imageSource, filterId, encoding);
|
|
||||||
sidecarClass.UpdateStatusEvent += UpdateStatus;
|
|
||||||
sidecarClass.InitProgressEvent += InitProgress;
|
|
||||||
sidecarClass.UpdateProgressEvent += UpdateProgress;
|
|
||||||
sidecarClass.EndProgressEvent += EndProgress;
|
|
||||||
sidecarClass.InitProgressEvent2 += InitProgress2;
|
|
||||||
sidecarClass.UpdateProgressEvent2 += UpdateProgress2;
|
|
||||||
sidecarClass.EndProgressEvent2 += EndProgress2;
|
|
||||||
CICMMetadataType sidecar = sidecarClass.Create();
|
|
||||||
|
|
||||||
AaruConsole.WriteLine("Writing metadata sidecar");
|
|
||||||
|
|
||||||
var xmlFs = new FileStream(txtDestination.Text, FileMode.Create);
|
|
||||||
|
|
||||||
var xmlSer = new XmlSerializer(typeof(CICMMetadataType));
|
|
||||||
xmlSer.Serialize(xmlFs, sidecar);
|
|
||||||
xmlFs.Close();
|
|
||||||
|
|
||||||
Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
btnClose.Visible = true;
|
|
||||||
btnStop.Visible = false;
|
|
||||||
stkProgress.Visible = false;
|
|
||||||
lblStatus.Visible = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
Statistics.AddCommand("create-sidecar");
|
|
||||||
}
|
|
||||||
|
|
||||||
void EndProgress2() => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
stkProgress2.Visible = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
void UpdateProgress2(string text, long current, long maximum) => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
lblProgress2.Text = text;
|
|
||||||
prgProgress2.Indeterminate = false;
|
|
||||||
prgProgress2.MinValue = 0;
|
|
||||||
|
|
||||||
if(maximum > int.MaxValue)
|
|
||||||
{
|
|
||||||
prgProgress2.MaxValue = (int)(maximum / int.MaxValue);
|
|
||||||
prgProgress2.Value = (int)(current / int.MaxValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prgProgress2.MaxValue = (int)maximum;
|
|
||||||
prgProgress2.Value = (int)current;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
void InitProgress2() => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
stkProgress2.Visible = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
void EndProgress() => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
stkProgress1.Visible = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
void UpdateProgress(string text, long current, long maximum) => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
lblProgress.Text = text;
|
|
||||||
prgProgress.Indeterminate = false;
|
|
||||||
prgProgress.MinValue = 0;
|
|
||||||
|
|
||||||
if(maximum > int.MaxValue)
|
|
||||||
{
|
|
||||||
prgProgress.MaxValue = (int)(maximum / int.MaxValue);
|
|
||||||
prgProgress.Value = (int)(current / int.MaxValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prgProgress.MaxValue = (int)maximum;
|
|
||||||
prgProgress.Value = (int)current;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
void InitProgress() => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
stkProgress1.Visible = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
void UpdateStatus(string text) => Application.Instance.Invoke(() =>
|
|
||||||
{
|
|
||||||
lblStatus.Text = text;
|
|
||||||
});
|
|
||||||
|
|
||||||
protected void OnBtnClose(object sender, EventArgs e) => Close();
|
|
||||||
|
|
||||||
protected void OnBtnStop(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
lblProgress.Text = "Aborting...";
|
|
||||||
btnStop.Enabled = false;
|
|
||||||
sidecarClass.Abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnBtnDestinationClick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var dlgDestination = new SaveFileDialog
|
|
||||||
{
|
|
||||||
Title = "Choose destination file"
|
|
||||||
};
|
|
||||||
|
|
||||||
dlgDestination.Filters.Add(new FileFilter("CICM XML metadata", "*.xml"));
|
|
||||||
|
|
||||||
DialogResult result = dlgDestination.ShowDialog(this);
|
|
||||||
|
|
||||||
if(result != DialogResult.Ok)
|
|
||||||
{
|
|
||||||
txtDestination.Text = "";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(string.IsNullOrEmpty(Path.GetExtension(dlgDestination.FileName)))
|
|
||||||
dlgDestination.FileName += ".xml";
|
|
||||||
|
|
||||||
txtDestination.Text = dlgDestination.FileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region XAML IDs
|
|
||||||
TextBox txtDestination;
|
|
||||||
Button btnDestination;
|
|
||||||
StackLayout stkProgress;
|
|
||||||
StackLayout stkProgress1;
|
|
||||||
Label lblProgress;
|
|
||||||
ProgressBar prgProgress;
|
|
||||||
StackLayout stkProgress2;
|
|
||||||
Label lblProgress2;
|
|
||||||
ProgressBar prgProgress2;
|
|
||||||
Button btnStart;
|
|
||||||
Button btnClose;
|
|
||||||
Button btnStop;
|
|
||||||
Label lblStatus;
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,14 +27,15 @@ namespace Aaru.Gui.ViewModels
|
|||||||
{
|
{
|
||||||
public class ImageInfoViewModel : ViewModelBase
|
public class ImageInfoViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
readonly IFilter _filter;
|
||||||
readonly IMediaImage _imageFormat;
|
readonly IMediaImage _imageFormat;
|
||||||
readonly string _imagePath;
|
readonly string _imagePath;
|
||||||
readonly Window _view;
|
readonly Window _view;
|
||||||
DecodeMediaTagsWindow _decodeMediaTagsWindow;
|
DecodeMediaTagsWindow _decodeMediaTagsWindow;
|
||||||
IFilter _filter;
|
|
||||||
ImageChecksumWindow _imageChecksumWindow;
|
ImageChecksumWindow _imageChecksumWindow;
|
||||||
ImageConvertWindow _imageConvertWindow;
|
ImageConvertWindow _imageConvertWindow;
|
||||||
ImageEntropyWindow _imageEntropyWindow;
|
ImageEntropyWindow _imageEntropyWindow;
|
||||||
|
ImageSidecarWindow _imageSidecarWindow;
|
||||||
ImageVerifyWindow _imageVerifyWindow;
|
ImageVerifyWindow _imageVerifyWindow;
|
||||||
ViewSectorWindow _viewSectorWindow;
|
ViewSectorWindow _viewSectorWindow;
|
||||||
|
|
||||||
@@ -789,24 +790,25 @@ namespace Aaru.Gui.ViewModels
|
|||||||
|
|
||||||
protected void ExecuteCreateSidecarCommand()
|
protected void ExecuteCreateSidecarCommand()
|
||||||
{
|
{
|
||||||
/* TODO: frmImageSidecar
|
if(_imageSidecarWindow != null)
|
||||||
if(frmImageSidecar != null)
|
|
||||||
{
|
{
|
||||||
frmImageSidecar.Show();
|
_imageSidecarWindow.Show();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Pass thru chosen default encoding
|
_imageSidecarWindow = new ImageSidecarWindow();
|
||||||
frmImageSidecar = new frmImageSidecar(imageFormat, imagePath, filter.Id, null);
|
|
||||||
|
|
||||||
frmImageSidecar.Closed += (s, ea) =>
|
// TODO: Pass thru chosen default encoding
|
||||||
|
_imageSidecarWindow.DataContext =
|
||||||
|
new ImageSidecarViewModel(_imageFormat, _imagePath, _filter.Id, null, _imageSidecarWindow);
|
||||||
|
|
||||||
|
_imageSidecarWindow.Closed += (sender, args) =>
|
||||||
{
|
{
|
||||||
frmImageSidecar = null;
|
_imageSidecarWindow = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
frmImageSidecar.Show();
|
_imageSidecarWindow.Show();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ExecuteViewSectorsCommand()
|
protected void ExecuteViewSectorsCommand()
|
||||||
|
|||||||
316
Aaru.Gui/ViewModels/ImageSidecarViewModel.cs
Normal file
316
Aaru.Gui/ViewModels/ImageSidecarViewModel.cs
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reactive;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
using Aaru.CommonTypes.Interfaces;
|
||||||
|
using Aaru.Console;
|
||||||
|
using Aaru.Core;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using ReactiveUI;
|
||||||
|
using Schemas;
|
||||||
|
|
||||||
|
namespace Aaru.Gui.ViewModels
|
||||||
|
{
|
||||||
|
public class ImageSidecarViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
readonly Encoding _encoding;
|
||||||
|
readonly Guid _filterId;
|
||||||
|
readonly string _imageSource;
|
||||||
|
readonly IMediaImage _inputFormat;
|
||||||
|
readonly Window _view;
|
||||||
|
bool _closeVisible;
|
||||||
|
bool _destinationEnabled;
|
||||||
|
string _destinationText;
|
||||||
|
bool _progress1Visible;
|
||||||
|
bool _progress2Indeterminate;
|
||||||
|
double _progress2MaxValue;
|
||||||
|
string _progress2Text;
|
||||||
|
double _progress2Value;
|
||||||
|
bool _progress2Visible;
|
||||||
|
bool _progressIndeterminate;
|
||||||
|
double _progressMaxValue;
|
||||||
|
string _progressText;
|
||||||
|
double _progressValue;
|
||||||
|
bool _progressVisible;
|
||||||
|
Sidecar _sidecarClass;
|
||||||
|
bool _startVisible;
|
||||||
|
string _statusText;
|
||||||
|
bool _statusVisible;
|
||||||
|
bool _stopEnabled;
|
||||||
|
bool _stopVisible;
|
||||||
|
|
||||||
|
public ImageSidecarViewModel(IMediaImage inputFormat, string imageSource, Guid filterId, Encoding encoding,
|
||||||
|
Window view)
|
||||||
|
{
|
||||||
|
_view = view;
|
||||||
|
_inputFormat = inputFormat;
|
||||||
|
_imageSource = imageSource;
|
||||||
|
_filterId = filterId;
|
||||||
|
_encoding = encoding;
|
||||||
|
|
||||||
|
DestinationText = Path.Combine(Path.GetDirectoryName(imageSource) ?? "",
|
||||||
|
Path.GetFileNameWithoutExtension(imageSource) + ".cicm.xml");
|
||||||
|
|
||||||
|
DestinationEnabled = true;
|
||||||
|
StartVisible = true;
|
||||||
|
CloseVisible = true;
|
||||||
|
DestinationCommand = ReactiveCommand.Create(ExecuteDestinationCommand);
|
||||||
|
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
|
||||||
|
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||||
|
StopCommand = ReactiveCommand.Create(ExecuteStopCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Title { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> DestinationCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> StopCommand { get; }
|
||||||
|
|
||||||
|
public bool ProgressIndeterminate
|
||||||
|
{
|
||||||
|
get => _progressIndeterminate;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressIndeterminate, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ProgressVisible
|
||||||
|
{
|
||||||
|
get => _progressVisible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Progress1Visible
|
||||||
|
{
|
||||||
|
get => _progress1Visible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress1Visible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Progress2Visible
|
||||||
|
{
|
||||||
|
get => _progress2Visible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Progress2Indeterminate
|
||||||
|
{
|
||||||
|
get => _progress2Indeterminate;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress2Indeterminate, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double ProgressMaxValue
|
||||||
|
{
|
||||||
|
get => _progressMaxValue;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressMaxValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Progress2MaxValue
|
||||||
|
{
|
||||||
|
get => _progress2MaxValue;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress2MaxValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ProgressText
|
||||||
|
{
|
||||||
|
get => _progressText;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressText, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double ProgressValue
|
||||||
|
{
|
||||||
|
get => _progressValue;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Progress2Value
|
||||||
|
{
|
||||||
|
get => _progress2Value;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress2Value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Progress2Text
|
||||||
|
{
|
||||||
|
get => _progress2Text;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progress2Text, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DestinationText
|
||||||
|
{
|
||||||
|
get => _destinationText;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _destinationText, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DestinationEnabled
|
||||||
|
{
|
||||||
|
get => _destinationEnabled;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _destinationEnabled, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string StatusText
|
||||||
|
{
|
||||||
|
get => _statusText;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _statusText, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StatusVisible
|
||||||
|
{
|
||||||
|
get => _statusVisible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _statusVisible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StartVisible
|
||||||
|
{
|
||||||
|
get => _startVisible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _startVisible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CloseVisible
|
||||||
|
{
|
||||||
|
get => _closeVisible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _closeVisible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StopEnabled
|
||||||
|
{
|
||||||
|
get => _stopEnabled;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _stopEnabled, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StopVisible
|
||||||
|
{
|
||||||
|
get => _stopVisible;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _stopVisible, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExecuteStartCommand() => new Thread(DoWork).Start();
|
||||||
|
|
||||||
|
async void DoWork()
|
||||||
|
{
|
||||||
|
// Prepare UI
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
CloseVisible = false;
|
||||||
|
StartVisible = false;
|
||||||
|
StopVisible = true;
|
||||||
|
StopEnabled = true;
|
||||||
|
ProgressVisible = true;
|
||||||
|
DestinationEnabled = false;
|
||||||
|
StatusVisible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
_sidecarClass = new Sidecar(_inputFormat, _imageSource, _filterId, _encoding);
|
||||||
|
_sidecarClass.UpdateStatusEvent += UpdateStatus;
|
||||||
|
_sidecarClass.InitProgressEvent += InitProgress;
|
||||||
|
_sidecarClass.UpdateProgressEvent += UpdateProgress;
|
||||||
|
_sidecarClass.EndProgressEvent += EndProgress;
|
||||||
|
_sidecarClass.InitProgressEvent2 += InitProgress2;
|
||||||
|
_sidecarClass.UpdateProgressEvent2 += UpdateProgress2;
|
||||||
|
_sidecarClass.EndProgressEvent2 += EndProgress2;
|
||||||
|
CICMMetadataType sidecar = _sidecarClass.Create();
|
||||||
|
|
||||||
|
AaruConsole.WriteLine("Writing metadata sidecar");
|
||||||
|
|
||||||
|
var xmlFs = new FileStream(DestinationText, FileMode.Create);
|
||||||
|
|
||||||
|
var xmlSer = new XmlSerializer(typeof(CICMMetadataType));
|
||||||
|
xmlSer.Serialize(xmlFs, sidecar);
|
||||||
|
xmlFs.Close();
|
||||||
|
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
CloseVisible = true;
|
||||||
|
StopVisible = false;
|
||||||
|
ProgressVisible = false;
|
||||||
|
StatusVisible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Statistics.AddCommand("create-sidecar");
|
||||||
|
}
|
||||||
|
|
||||||
|
async void EndProgress2() => await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Progress2Visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void UpdateProgress2(string text, long current, long maximum) =>
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Progress2Text = text;
|
||||||
|
Progress2Indeterminate = false;
|
||||||
|
|
||||||
|
Progress2MaxValue = maximum;
|
||||||
|
Progress2Value = current;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void InitProgress2() => await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Progress2Visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void EndProgress() => await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Progress1Visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void UpdateProgress(string text, long current, long maximum) =>
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
ProgressText = text;
|
||||||
|
ProgressIndeterminate = false;
|
||||||
|
|
||||||
|
ProgressMaxValue = maximum;
|
||||||
|
ProgressValue = current;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void InitProgress() => await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Progress1Visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
async void UpdateStatus(string text) => await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
StatusText = text;
|
||||||
|
});
|
||||||
|
|
||||||
|
void ExecuteCloseCommand() => _view.Close();
|
||||||
|
|
||||||
|
void ExecuteStopCommand()
|
||||||
|
{
|
||||||
|
ProgressText = "Aborting...";
|
||||||
|
StopEnabled = false;
|
||||||
|
_sidecarClass.Abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
async void ExecuteDestinationCommand()
|
||||||
|
{
|
||||||
|
var dlgDestination = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Title = "Choose destination file"
|
||||||
|
};
|
||||||
|
|
||||||
|
dlgDestination.Filters.Add(new FileDialogFilter
|
||||||
|
{
|
||||||
|
Name = "CICM XML metadata", Extensions = new List<string>(new[]
|
||||||
|
{
|
||||||
|
"*.xml"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
string result = await dlgDestination.ShowAsync(_view);
|
||||||
|
|
||||||
|
if(result is null)
|
||||||
|
{
|
||||||
|
DestinationText = "";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(Path.GetExtension(result)))
|
||||||
|
result += ".xml";
|
||||||
|
|
||||||
|
DestinationText = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
Aaru.Gui/Views/ImageSidecarWindow.xaml
Normal file
76
Aaru.Gui/Views/ImageSidecarWindow.xaml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<!--
|
||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ============================================================================
|
||||||
|
//
|
||||||
|
// Filename : dlgEncodings.xeto
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : Encodings dialog.
|
||||||
|
//
|
||||||
|
// ==[ Description ] ==========================================================
|
||||||
|
//
|
||||||
|
// Defines the structure for the encodings list dialog.
|
||||||
|
//
|
||||||
|
// ==[ 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
|
||||||
|
// ****************************************************************************/
|
||||||
|
-->
|
||||||
|
<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" Width="480" Height="320" x:Class="Aaru.Gui.Views.ImageSidecarWindow"
|
||||||
|
Icon="/Assets/aaru-logo.png" CanResize="False" Title="{Binding Title}">
|
||||||
|
<Design.DataContext>
|
||||||
|
<vm:ImageSidecarViewModel />
|
||||||
|
</Design.DataContext>
|
||||||
|
<StackPanel Orientation="Vertical">
|
||||||
|
<TextBlock Text="Destination file" />
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBox Text="{Binding DestinationText}" IsReadOnly="True" />
|
||||||
|
<Button Command="{Binding DestinationCommand}" IsEnabled="{Binding DestinationEnabled}">
|
||||||
|
<TextBlock Text="Choose..." />
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Vertical" IsVisible="{Binding ProgressVisible}">
|
||||||
|
<TextBlock Text="{Binding StatusText}" IsVisible="{Binding StatusVisible}" />
|
||||||
|
<StackPanel Orientation="Vertical" IsVisible="{Binding Progress1Visible}">
|
||||||
|
<TextBlock Text="{Binding ProgressText}" />
|
||||||
|
<ProgressBar Maximum="{Binding ProgressMaxValue}" Value="{Binding ProgressValue}"
|
||||||
|
IsIndeterminate="{Binding ProgressIndeterminate}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Vertical" IsVisible="{Binding Progress2Visible}">
|
||||||
|
<TextBlock Text="{Binding Progress2Text}" />
|
||||||
|
<ProgressBar Maximum="{Binding Progress2MaxValue}" Value="{Binding Progress2Value}"
|
||||||
|
IsIndeterminate="{Binding Progress2Indeterminate}" />
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<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}" IsEnabled="{Binding StopEnabled}" IsVisible="{Binding StopVisible}">
|
||||||
|
<TextBlock Text="Stop" />
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Window>
|
||||||
19
Aaru.Gui/Views/ImageSidecarWindow.xaml.cs
Normal file
19
Aaru.Gui/Views/ImageSidecarWindow.xaml.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace Aaru.Gui.Views
|
||||||
|
{
|
||||||
|
public class ImageSidecarWindow : Window
|
||||||
|
{
|
||||||
|
public ImageSidecarWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
#if DEBUG
|
||||||
|
this.AttachDevTools();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user