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-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 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;
|
2022-03-26 16:52:00 +00:00
|
|
|
using System.Threading.Tasks;
|
2025-08-20 21:19:43 +01:00
|
|
|
using System.Windows.Input;
|
2020-04-12 15:04:48 +01:00
|
|
|
using Aaru.Decoders.DVD;
|
|
|
|
|
using Avalonia.Controls;
|
2024-05-02 00:50:34 +01:00
|
|
|
using Avalonia.Platform.Storage;
|
2025-08-20 21:19:43 +01:00
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2020-07-22 13:20:25 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-04-12 15:04:48 +01:00
|
|
|
|
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;
|
2025-08-20 21:19:43 +01:00
|
|
|
SaveDvdPfiCommand = new AsyncRelayCommand(SaveDvdPfiAsync);
|
|
|
|
|
SaveDvdDmiCommand = new AsyncRelayCommand(SaveDvdDmiAsync);
|
|
|
|
|
SaveDvdCmiCommand = new AsyncRelayCommand(SaveDvdCmiAsync);
|
|
|
|
|
SaveHdDvdCmiCommand = new AsyncRelayCommand(SaveHdDvdCmiAsync);
|
|
|
|
|
SaveDvdBcaCommand = new AsyncRelayCommand(SaveDvdBcaAsync);
|
|
|
|
|
SaveDvdAacsCommand = new AsyncRelayCommand(SaveDvdAacsAsync);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
public ICommand SaveDvdPfiCommand { get; }
|
|
|
|
|
public ICommand SaveDvdDmiCommand { get; }
|
|
|
|
|
public ICommand SaveDvdCmiCommand { get; }
|
|
|
|
|
public ICommand SaveHdDvdCmiCommand { get; }
|
|
|
|
|
public ICommand SaveDvdBcaCommand { get; }
|
|
|
|
|
public ICommand SaveDvdAacsCommand { get; }
|
|
|
|
|
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
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
async Task SaveElementAsync(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
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveDvdPfiAsync() => SaveElementAsync(_dvdPfi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveDvdDmiAsync() => SaveElementAsync(_dvdDmi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveDvdCmiAsync() => SaveElementAsync(_dvdCmi);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveHdDvdCmiAsync() => SaveElementAsync(_hddvdCopyrightInformation);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveDvdBcaAsync() => SaveElementAsync(_dvdBca);
|
2020-04-12 15:04:48 +01:00
|
|
|
|
2025-08-20 21:19:43 +01:00
|
|
|
Task SaveDvdAacsAsync() => SaveElementAsync(_dvdAacs);
|
2020-04-12 15:04:48 +01:00
|
|
|
}
|