2020-04-17 21:45:50 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : BlurayInfoViewModel.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : GUI view models.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// View model and code for the Blu-ray 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 16:34:20 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reactive;
|
|
|
|
|
using Aaru.Decoders.Bluray;
|
|
|
|
|
using Aaru.Decoders.SCSI.MMC;
|
|
|
|
|
using Avalonia.Controls;
|
2020-07-22 13:20:25 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-04-12 16:34:20 +01:00
|
|
|
using ReactiveUI;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed class BlurayInfoViewModel
|
2020-04-12 16:34:20 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
readonly byte[] _burstCuttingArea;
|
|
|
|
|
readonly byte[] _cartridgeStatus;
|
|
|
|
|
readonly byte[] _dds;
|
|
|
|
|
readonly byte[] _discInformation;
|
|
|
|
|
readonly byte[] _pac;
|
|
|
|
|
readonly byte[] _powResources;
|
|
|
|
|
readonly byte[] _rawDfl;
|
|
|
|
|
readonly byte[] _spareAreaInformation;
|
|
|
|
|
readonly byte[] _trackResources;
|
|
|
|
|
readonly Window _view;
|
|
|
|
|
|
|
|
|
|
public BlurayInfoViewModel([CanBeNull] byte[] blurayDiscInformation, [CanBeNull] byte[] blurayBurstCuttingArea,
|
|
|
|
|
[CanBeNull] byte[] blurayDds, [CanBeNull] byte[] blurayCartridgeStatus,
|
|
|
|
|
[CanBeNull] byte[] bluraySpareAreaInformation, [CanBeNull] byte[] blurayPowResources,
|
|
|
|
|
[CanBeNull] byte[] blurayTrackResources, [CanBeNull] byte[] blurayRawDfl,
|
|
|
|
|
[CanBeNull] byte[] blurayPac, Window view)
|
2020-04-12 16:34:20 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
_view = view;
|
|
|
|
|
_discInformation = blurayDiscInformation;
|
|
|
|
|
_burstCuttingArea = blurayBurstCuttingArea;
|
|
|
|
|
_dds = blurayDds;
|
|
|
|
|
_cartridgeStatus = blurayCartridgeStatus;
|
|
|
|
|
_spareAreaInformation = bluraySpareAreaInformation;
|
|
|
|
|
_powResources = blurayPowResources;
|
|
|
|
|
_trackResources = blurayTrackResources;
|
|
|
|
|
_rawDfl = blurayRawDfl;
|
|
|
|
|
_pac = blurayPac;
|
|
|
|
|
SaveBlurayDiscInformationCommand = ReactiveCommand.Create(ExecuteSaveBlurayDiscInformationCommand);
|
|
|
|
|
SaveBlurayBurstCuttingAreaCommand = ReactiveCommand.Create(ExecuteSaveBlurayBurstCuttingAreaCommand);
|
|
|
|
|
SaveBlurayDdsCommand = ReactiveCommand.Create(ExecuteSaveBlurayDdsCommand);
|
|
|
|
|
SaveBlurayCartridgeStatusCommand = ReactiveCommand.Create(ExecuteSaveBlurayCartridgeStatusCommand);
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
SaveBluraySpareAreaInformationCommand = ReactiveCommand.Create(ExecuteSaveBluraySpareAreaInformationCommand);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
SaveBlurayPowResourcesCommand = ReactiveCommand.Create(ExecuteSaveBlurayPowResourcesCommand);
|
|
|
|
|
SaveBlurayTrackResourcesCommand = ReactiveCommand.Create(ExecuteSaveBlurayTrackResourcesCommand);
|
|
|
|
|
SaveBlurayRawDflCommand = ReactiveCommand.Create(ExecuteSaveBlurayRawDflCommand);
|
|
|
|
|
SaveBlurayPacCommand = ReactiveCommand.Create(ExecuteSaveBlurayPacCommand);
|
|
|
|
|
|
|
|
|
|
if(blurayDiscInformation != null)
|
2020-04-12 16:34:20 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
SaveBlurayDiscInformationVisible = true;
|
|
|
|
|
BlurayDiscInformationText = DI.Prettify(blurayDiscInformation);
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blurayBurstCuttingArea != null)
|
|
|
|
|
{
|
|
|
|
|
SaveBlurayBurstCuttingAreaVisible = true;
|
|
|
|
|
BlurayBurstCuttingAreaText = BCA.Prettify(blurayBurstCuttingArea);
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blurayDds != null)
|
|
|
|
|
{
|
|
|
|
|
SaveBlurayDdsVisible = true;
|
|
|
|
|
BlurayDdsText = DDS.Prettify(blurayDds);
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blurayCartridgeStatus != null)
|
|
|
|
|
{
|
|
|
|
|
SaveBlurayCartridgeStatusVisible = true;
|
|
|
|
|
BlurayCartridgeStatusText = Cartridge.Prettify(blurayCartridgeStatus);
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(bluraySpareAreaInformation != null)
|
|
|
|
|
{
|
|
|
|
|
SaveBluraySpareAreaInformationVisible = true;
|
|
|
|
|
BluraySpareAreaInformationText = Spare.Prettify(bluraySpareAreaInformation);
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blurayPowResources != null)
|
|
|
|
|
{
|
|
|
|
|
SaveBlurayPowResourcesVisible = true;
|
|
|
|
|
BlurayPowResourcesText = DiscInformation.Prettify(blurayPowResources);
|
2020-04-12 16:34:20 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blurayTrackResources != null)
|
2020-04-12 16:34:20 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
SaveBlurayTrackResourcesVisible = true;
|
|
|
|
|
BlurayTrackResourcesText = DiscInformation.Prettify(blurayTrackResources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveBlurayRawDflVisible = blurayRawDfl != null;
|
|
|
|
|
SaveBlurayPacVisible = blurayPac != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string BlurayDiscInformationText { get; }
|
|
|
|
|
public string BlurayBurstCuttingAreaText { get; }
|
|
|
|
|
public string BlurayDdsText { get; }
|
|
|
|
|
public string BlurayCartridgeStatusText { get; }
|
|
|
|
|
public string BluraySpareAreaInformationText { get; }
|
|
|
|
|
public string BlurayPowResourcesText { get; }
|
|
|
|
|
public string BlurayTrackResourcesText { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayDiscInformationCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayBurstCuttingAreaCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayDdsCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayCartridgeStatusCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBluraySpareAreaInformationCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayPowResourcesCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayTrackResourcesCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayRawDflCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveBlurayPacCommand { get; }
|
|
|
|
|
public bool SaveBlurayDiscInformationVisible { get; }
|
|
|
|
|
public bool SaveBlurayBurstCuttingAreaVisible { get; }
|
|
|
|
|
public bool SaveBlurayDdsVisible { get; }
|
|
|
|
|
public bool SaveBlurayCartridgeStatusVisible { get; }
|
|
|
|
|
public bool SaveBluraySpareAreaInformationVisible { get; }
|
|
|
|
|
public bool SaveBlurayPowResourcesVisible { get; }
|
|
|
|
|
public bool SaveBlurayTrackResourcesVisible { get; }
|
|
|
|
|
public bool SaveBlurayRawDflVisible { get; }
|
|
|
|
|
public bool SaveBlurayPacVisible { get; }
|
|
|
|
|
|
|
|
|
|
async void SaveElement(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
dlgSaveBinary.Filters.Add(new FileDialogFilter
|
|
|
|
|
{
|
|
|
|
|
Extensions = new List<string>(new[]
|
2020-04-12 16:34:20 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
"*.bin"
|
|
|
|
|
}),
|
|
|
|
|
Name = "Binary"
|
|
|
|
|
});
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(result is null)
|
|
|
|
|
return;
|
2020-04-12 16:34:20 +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 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayDiscInformationCommand() => SaveElement(_discInformation);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayBurstCuttingAreaCommand() => SaveElement(_burstCuttingArea);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayDdsCommand() => SaveElement(_dds);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayCartridgeStatusCommand() => SaveElement(_cartridgeStatus);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBluraySpareAreaInformationCommand() => SaveElement(_spareAreaInformation);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayPowResourcesCommand() => SaveElement(_powResources);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayTrackResourcesCommand() => SaveElement(_trackResources);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayRawDflCommand() => SaveElement(_rawDfl);
|
2020-04-12 16:34:20 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
void ExecuteSaveBlurayPacCommand() => SaveElement(_pac);
|
2020-04-12 16:34:20 +01:00
|
|
|
}
|