2020-04-17 21:45:50 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : DvdInfoViewModel.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : GUI view models.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// View model and code for the DVD information tab.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2020-04-17 21:45:50 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
namespace Aaru.Gui.ViewModels.Tabs;
|
|
|
|
|
|
2020-04-12 15:04:48 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reactive;
|
2022-03-26 16:52:00 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-04-12 15:04:48 +01:00
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.Decoders.DVD;
|
|
|
|
|
using Avalonia.Controls;
|
2020-07-22 13:20:25 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-04-12 15:04:48 +01:00
|
|
|
using ReactiveUI;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed class DvdInfoViewModel
|
2020-04-12 15:04:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
readonly byte[] _dvdAacs;
|
|
|
|
|
readonly byte[] _dvdBca;
|
|
|
|
|
readonly byte[] _dvdCmi;
|
|
|
|
|
readonly byte[] _dvdDmi;
|
|
|
|
|
readonly byte[] _dvdPfi;
|
|
|
|
|
readonly byte[] _hddvdCopyrightInformation;
|
|
|
|
|
readonly Window _view;
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
public DvdInfoViewModel(MediaType mediaType, [CanBeNull] byte[] pfi, [CanBeNull] byte[] dmi, [CanBeNull] byte[] cmi,
|
|
|
|
|
[CanBeNull] byte[] hdCopyrightInformation, [CanBeNull] byte[] bca, [CanBeNull] byte[] aacs,
|
2022-03-06 13:29:38 +00:00
|
|
|
PFI.PhysicalFormatInformation? decodedPfi, Window view)
|
2020-04-12 15:04:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
_dvdPfi = pfi;
|
|
|
|
|
_dvdDmi = dmi;
|
|
|
|
|
_dvdCmi = cmi;
|
|
|
|
|
_hddvdCopyrightInformation = hdCopyrightInformation;
|
|
|
|
|
_dvdBca = bca;
|
|
|
|
|
_dvdAacs = aacs;
|
|
|
|
|
_view = view;
|
|
|
|
|
SaveDvdPfiCommand = ReactiveCommand.Create(ExecuteSaveDvdPfiCommand);
|
|
|
|
|
SaveDvdDmiCommand = ReactiveCommand.Create(ExecuteSaveDvdDmiCommand);
|
|
|
|
|
SaveDvdCmiCommand = ReactiveCommand.Create(ExecuteSaveDvdCmiCommand);
|
|
|
|
|
SaveHdDvdCmiCommand = ReactiveCommand.Create(ExecuteSaveHdDvdCmiCommand);
|
|
|
|
|
SaveDvdBcaCommand = ReactiveCommand.Create(ExecuteSaveDvdBcaCommand);
|
|
|
|
|
SaveDvdAacsCommand = ReactiveCommand.Create(ExecuteSaveDvdAacsCommand);
|
|
|
|
|
|
|
|
|
|
/* TODO: Pass back
|
|
|
|
|
switch(mediaType)
|
2020-04-12 15:04:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
case MediaType.HDDVDROM:
|
|
|
|
|
case MediaType.HDDVDRAM:
|
|
|
|
|
case MediaType.HDDVDR:
|
|
|
|
|
case MediaType.HDDVDRW:
|
|
|
|
|
case MediaType.HDDVDRDL:
|
|
|
|
|
case MediaType.HDDVDRWDL:
|
|
|
|
|
Text = "HD DVD";
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Text = "DVD";
|
|
|
|
|
|
|
|
|
|
break;
|
2020-04-12 15:04:48 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
*/
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(decodedPfi.HasValue)
|
|
|
|
|
DvdPfiText = PFI.Prettify(decodedPfi);
|
|
|
|
|
|
|
|
|
|
if(cmi != null)
|
|
|
|
|
DvdCmiText = CSS_CPRM.PrettifyLeadInCopyright(cmi);
|
|
|
|
|
|
|
|
|
|
SaveDvdPfiVisible = pfi != null;
|
|
|
|
|
SaveDvdDmiVisible = dmi != null;
|
|
|
|
|
SaveDvdCmiVisible = cmi != null;
|
|
|
|
|
SaveHdDvdCmiVisible = hdCopyrightInformation != null;
|
|
|
|
|
SaveDvdBcaVisible = bca != null;
|
|
|
|
|
SaveDvdAacsVisible = aacs != null;
|
|
|
|
|
}
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
public ReactiveCommand<Unit, Task> SaveDvdPfiCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveDvdDmiCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveDvdCmiCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveHdDvdCmiCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveDvdBcaCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveDvdAacsCommand { get; }
|
2022-03-06 13:29:38 +00:00
|
|
|
public string DvdPfiText { get; }
|
|
|
|
|
public string DvdCmiText { get; }
|
|
|
|
|
public bool SaveDvdPfiVisible { get; }
|
|
|
|
|
public bool SaveDvdDmiVisible { get; }
|
|
|
|
|
public bool SaveDvdCmiVisible { get; }
|
|
|
|
|
public bool SaveHdDvdCmiVisible { get; }
|
|
|
|
|
public bool SaveDvdBcaVisible { get; }
|
|
|
|
|
public bool SaveDvdAacsVisible { get; }
|
|
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task SaveElement(byte[] data)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
|
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
Extensions = new List<string>(new[]
|
2020-04-12 15:04:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
"*.bin"
|
|
|
|
|
}),
|
|
|
|
|
Name = "Binary"
|
|
|
|
|
});
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(result is null)
|
|
|
|
|
return;
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(data, 0, data.Length);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveDvdPfiCommand() => await SaveElement(_dvdPfi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveDvdDmiCommand() => await SaveElement(_dvdDmi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveDvdCmiCommand() => await SaveElement(_dvdCmi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveHdDvdCmiCommand() => await SaveElement(_hddvdCopyrightInformation);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveDvdBcaCommand() => await SaveElement(_dvdBca);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveDvdAacsCommand() => await SaveElement(_dvdAacs);
|
2020-04-12 15:04:48 +01:00
|
|
|
}
|