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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-05-01 04:17:32 +01:00
|
|
|
// Copyright © 2011-2024 Natalia Portillo
|
2020-04-17 21:45:50 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2024-05-02 00:50:34 +01:00
|
|
|
using System.Collections.Generic;
|
2020-04-12 15:04:48 +01:00
|
|
|
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.Decoders.DVD;
|
2022-11-19 21:10:41 +00:00
|
|
|
using Aaru.Localization;
|
2020-04-12 15:04:48 +01:00
|
|
|
using Avalonia.Controls;
|
2024-05-02 00:50:34 +01:00
|
|
|
using Avalonia.Platform.Storage;
|
2020-07-22 13:20:25 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-04-12 15:04:48 +01:00
|
|
|
using ReactiveUI;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Gui.ViewModels.Tabs;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2023-10-05 01:05:23 +01:00
|
|
|
public DvdInfoViewModel([CanBeNull] byte[] pfi, [CanBeNull] byte[] dmi, [CanBeNull] byte[] cmi,
|
2022-03-07 07:36:44 +00:00
|
|
|
[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
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedPfi.HasValue) DvdPfiText = PFI.Prettify(decodedPfi);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(cmi != null) DvdCmiText = CSS_CPRM.PrettifyLeadInCopyright(cmi);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
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-11-16 21:40:54 +00:00
|
|
|
|
2022-11-19 21:10:41 +00:00
|
|
|
public string SaveDvdPfiLabel => UI.ButtonLabel_Save_Physical_Format_Information;
|
|
|
|
|
public string SaveDvdDmiLabel => UI.ButtonLabel_Save_Disc_Manufacturer_Information;
|
|
|
|
|
public string SaveDvdCmiLabel => UI.ButtonLabel_Save_Copyright_Management_Information;
|
|
|
|
|
public string SaveHdDvdCmiLabel => UI.ButtonLabel_Save_Copyright_Management_Information;
|
|
|
|
|
public string SaveDvdBcaLabel => UI.ButtonLabel_Save_Burst_Cutting_Area;
|
|
|
|
|
public string SaveDvdAacsLabel => UI.ButtonLabel_Save_AACS_Information;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task SaveElement(byte[] data)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-02 00:50:34 +01:00
|
|
|
IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-02 00:50:34 +01:00
|
|
|
FileTypeChoices = new List<FilePickerFileType>
|
|
|
|
|
{
|
|
|
|
|
FilePickerFileTypes.Binary
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2024-05-02 00:50:34 +01:00
|
|
|
var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create);
|
2022-03-06 13:29:38 +00:00
|
|
|
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
|
|
|
}
|