Files
Aaru/Aaru.Gui/ViewModels/Tabs/DvdWritableInfoViewModel.cs

291 lines
13 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : DvdWritableInfoViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the writable 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
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
2025-08-20 21:19:43 +01:00
using System.Windows.Input;
using Aaru.Decoders.DVD;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
2025-08-20 21:19:43 +01:00
using CommunityToolkit.Mvvm.Input;
namespace Aaru.Gui.ViewModels.Tabs;
2022-03-06 13:29:38 +00:00
public sealed class DvdWritableInfoViewModel
{
2022-03-06 13:29:38 +00:00
readonly byte[] _dvdLastBorderOutRmd;
readonly byte[] _dvdPlusAdip;
readonly byte[] _dvdPlusDcb;
readonly byte[] _dvdPreRecordedInfo;
readonly byte[] _dvdRamCartridgeStatus;
readonly byte[] _dvdRamDds;
readonly byte[] _dvdRamSpareArea;
readonly byte[] _dvdrDlJumpIntervalSize;
readonly byte[] _dvdrDlManualLayerJumpStartLba;
readonly byte[] _dvdrDlMiddleZoneStart;
readonly byte[] _dvdrDlRemapAnchorPoint;
readonly byte[] _dvdrLayerCapacity;
readonly byte[] _dvdrMediaIdentifier;
readonly byte[] _dvdrPhysicalInformation;
readonly byte[] _hddvdrLastRmd;
readonly byte[] _hddvdrMediumStatus;
readonly Window _view;
2023-10-05 01:05:23 +01:00
public DvdWritableInfoViewModel(byte[] dds, byte[] cartridgeStatus, byte[] spareArea, byte[] lastBorderOutRmd,
byte[] preRecordedInfo, byte[] mediaIdentifier, byte[] physicalInformation,
byte[] mediumStatus, byte[] hdLastRmd, byte[] layerCapacity, byte[] middleZoneStart,
byte[] jumpIntervalSize, byte[] manualLayerJumpStartLba, byte[] remapAnchorPoint,
byte[] adip, byte[] dcb, Window view)
{
2022-03-06 13:29:38 +00:00
_view = view;
2025-08-20 21:19:43 +01:00
SaveDvdRamDdsCommand = new AsyncRelayCommand(SaveDvdRamDdsAsync);
SaveDvdRamCartridgeStatusCommand = new AsyncRelayCommand(SaveDvdRamCartridgeStatusAsync);
2022-03-06 13:29:38 +00:00
2025-08-20 21:19:43 +01:00
SaveDvdRamSpareAreaInformationCommand = new AsyncRelayCommand(SaveDvdRamSpareAreaInformationAsync);
2022-03-06 13:29:38 +00:00
2025-08-20 21:19:43 +01:00
SaveLastBorderOutRmdCommand = new AsyncRelayCommand(SaveLastBorderOutRmdAsync);
SaveDvdPreRecordedInfoCommand = new AsyncRelayCommand(SaveDvdPreRecordedInfoAsync);
SaveDvdrMediaIdentifierCommand = new AsyncRelayCommand(SaveDvdrMediaIdentifierAsync);
SaveDvdrPhysicalInformationCommand = new AsyncRelayCommand(SaveDvdrPhysicalInformationAsync);
SaveHddvdrMediumStatusCommand = new AsyncRelayCommand(SaveHddvdrMediumStatusAsync);
SaveHddvdrLastRmdCommand = new AsyncRelayCommand(SaveHddvdrLastRmdAsync);
SaveDvdrLayerCapacityCommand = new AsyncRelayCommand(SaveDvdrLayerCapacityAsync);
SaveDvdrDlMiddleZoneStartCommand = new AsyncRelayCommand(SaveDvdrDlMiddleZoneStartAsync);
SaveDvdrDlJumpIntervalSizeCommand = new AsyncRelayCommand(SaveDvdrDlJumpIntervalSizeAsync);
2022-03-06 13:29:38 +00:00
2025-08-20 21:19:43 +01:00
SaveDvdrDlManualLayerJumpStartLbaCommand = new AsyncRelayCommand(SaveDvdrDlManualLayerJumpStartLbaAsync);
2022-03-06 13:29:38 +00:00
2025-08-20 21:19:43 +01:00
SaveDvdrDlRemapAnchorPointCommand = new AsyncRelayCommand(SaveDvdrDlRemapAnchorPointAsync);
SaveDvdPlusAdipCommand = new AsyncRelayCommand(SaveDvdPlusAdipAsync);
SaveDvdPlusDcbCommand = new AsyncRelayCommand(SaveDvdPlusDcbAsync);
2022-03-06 13:29:38 +00:00
_dvdRamDds = dds;
_dvdRamCartridgeStatus = cartridgeStatus;
_dvdRamSpareArea = spareArea;
_dvdLastBorderOutRmd = lastBorderOutRmd;
_dvdPreRecordedInfo = preRecordedInfo;
_dvdrMediaIdentifier = mediaIdentifier;
_dvdrPhysicalInformation = physicalInformation;
_hddvdrMediumStatus = mediumStatus;
_hddvdrLastRmd = hdLastRmd;
_dvdrLayerCapacity = layerCapacity;
_dvdrDlMiddleZoneStart = middleZoneStart;
_dvdrDlJumpIntervalSize = jumpIntervalSize;
_dvdrDlManualLayerJumpStartLba = manualLayerJumpStartLba;
_dvdrDlRemapAnchorPoint = remapAnchorPoint;
_dvdPlusAdip = adip;
_dvdPlusDcb = dcb;
/* TODO: Pass back
switch(mediaType)
{
2022-03-06 13:29:38 +00:00
case MediaType.DVDR:
Text = "DVD-R";
break;
case MediaType.DVDRW:
Text = "DVD-RW";
break;
case MediaType.DVDPR:
Text = "DVD+R";
break;
case MediaType.DVDPRW:
Text = "DVD+RW";
break;
case MediaType.DVDPRWDL:
Text = "DVD+RW DL";
break;
case MediaType.DVDRDL:
Text = "DVD-R DL";
break;
case MediaType.DVDPRDL:
Text = "DVD+R DL";
break;
case MediaType.DVDRAM:
Text = "DVD-RAM";
break;
case MediaType.DVDRWDL:
Text = "DVD-RW DL";
break;
case MediaType.HDDVDRAM:
Text = "HD DVD-RAM";
break;
case MediaType.HDDVDR:
Text = "HD DVD-R";
break;
case MediaType.HDDVDRW:
Text = "HD DVD-RW";
break;
case MediaType.HDDVDRDL:
Text = "HD DVD-R DL";
break;
case MediaType.HDDVDRWDL:
Text = "HD DVD-RW DL";
break;
}
2022-03-06 13:29:38 +00:00
*/
2024-05-01 04:05:22 +01:00
if(dds != null) DvdRamDdsText = DDS.Prettify(dds);
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(cartridgeStatus != null) DvdRamCartridgeStatusText = Cartridge.Prettify(cartridgeStatus);
2022-03-06 13:29:38 +00:00
if(spareArea != null)
{
if(spareArea.Length == 12)
{
var tmp = new byte[16];
Array.Copy(spareArea, 0, tmp, 4, 12);
spareArea = tmp;
}
DvdRamSpareAreaInformationText = Spare.Prettify(spareArea);
}
2022-03-06 13:29:38 +00:00
SaveDvdRamDdsVisible = dds != null;
SaveDvdRamCartridgeStatusVisible = cartridgeStatus != null;
SaveDvdRamSpareAreaInformationVisible = spareArea != null;
SaveLastBorderOutRmdVisible = lastBorderOutRmd != null;
SaveDvdPreRecordedInfoVisible = preRecordedInfo != null;
SaveDvdrMediaIdentifierVisible = mediaIdentifier != null;
SaveDvdrPhysicalInformationVisible = physicalInformation != null;
SaveHddvdrMediumStatusVisible = mediumStatus != null;
SaveHddvdrLastRmdVisible = hdLastRmd != null;
SaveDvdrLayerCapacityVisible = layerCapacity != null;
SaveDvdrDlMiddleZoneStartVisible = middleZoneStart != null;
SaveDvdrDlJumpIntervalSizeVisible = jumpIntervalSize != null;
SaveDvdrDlManualLayerJumpStartLbaVisible = manualLayerJumpStartLba != null;
SaveDvdrDlRemapAnchorPointVisible = remapAnchorPoint != null;
SaveDvdPlusAdipVisible = adip != null;
SaveDvdPlusDcbVisible = dcb != null;
}
2025-08-20 21:19:43 +01:00
public string DvdRamDdsText { get; }
public string DvdRamCartridgeStatusText { get; }
public string DvdRamSpareAreaInformationText { get; }
public bool SaveDvdRamDdsVisible { get; }
public bool SaveDvdRamCartridgeStatusVisible { get; }
public bool SaveDvdRamSpareAreaInformationVisible { get; }
public bool SaveLastBorderOutRmdVisible { get; }
public bool SaveDvdPreRecordedInfoVisible { get; }
public bool SaveDvdrMediaIdentifierVisible { get; }
public bool SaveDvdrPhysicalInformationVisible { get; }
public bool SaveHddvdrMediumStatusVisible { get; }
public bool SaveHddvdrLastRmdVisible { get; }
public bool SaveDvdrLayerCapacityVisible { get; }
public bool SaveDvdrDlMiddleZoneStartVisible { get; }
public bool SaveDvdrDlJumpIntervalSizeVisible { get; }
public bool SaveDvdrDlManualLayerJumpStartLbaVisible { get; }
public bool SaveDvdrDlRemapAnchorPointVisible { get; }
public bool SaveDvdPlusAdipVisible { get; }
public bool SaveDvdPlusDcbVisible { get; }
public ICommand SaveDvdRamDdsCommand { get; }
public ICommand SaveDvdRamCartridgeStatusCommand { get; }
public ICommand SaveDvdRamSpareAreaInformationCommand { get; }
public ICommand SaveLastBorderOutRmdCommand { get; }
public ICommand SaveDvdPreRecordedInfoCommand { get; }
public ICommand SaveDvdrMediaIdentifierCommand { get; }
public ICommand SaveDvdrPhysicalInformationCommand { get; }
public ICommand SaveHddvdrMediumStatusCommand { get; }
public ICommand SaveHddvdrLastRmdCommand { get; }
public ICommand SaveDvdrLayerCapacityCommand { get; }
public ICommand SaveDvdrDlMiddleZoneStartCommand { get; }
public ICommand SaveDvdrDlJumpIntervalSizeCommand { get; }
public ICommand SaveDvdrDlManualLayerJumpStartLbaCommand { get; }
public ICommand SaveDvdrDlRemapAnchorPointCommand { get; }
public ICommand SaveDvdPlusAdipCommand { get; }
public ICommand SaveDvdPlusDcbCommand { get; }
2025-08-20 21:19:43 +01:00
async Task SaveElementAsync(byte[] data)
2022-03-06 13:29:38 +00:00
{
IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
2022-03-06 13:29:38 +00:00
{
FileTypeChoices = new List<FilePickerFileType>
{
FilePickerFileTypes.Binary
}
2022-03-06 13:29:38 +00:00
});
2024-05-01 04:05:22 +01:00
if(result is null) return;
var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create);
2022-03-06 13:29:38 +00:00
saveFs.Write(data, 0, data.Length);
2022-03-06 13:29:38 +00:00
saveFs.Close();
}
2025-08-20 21:19:43 +01:00
Task SaveDvdRamDdsAsync() => SaveElementAsync(_dvdRamDds);
2025-08-20 21:19:43 +01:00
Task SaveDvdRamCartridgeStatusAsync() => SaveElementAsync(_dvdRamCartridgeStatus);
2025-08-20 21:19:43 +01:00
Task SaveDvdRamSpareAreaInformationAsync() => SaveElementAsync(_dvdRamSpareArea);
2025-08-20 21:19:43 +01:00
Task SaveLastBorderOutRmdAsync() => SaveElementAsync(_dvdLastBorderOutRmd);
2025-08-20 21:19:43 +01:00
Task SaveDvdPreRecordedInfoAsync() => SaveElementAsync(_dvdPreRecordedInfo);
2025-08-20 21:19:43 +01:00
Task SaveDvdrMediaIdentifierAsync() => SaveElementAsync(_dvdrMediaIdentifier);
2025-08-20 21:19:43 +01:00
Task SaveDvdrPhysicalInformationAsync() => SaveElementAsync(_dvdrPhysicalInformation);
2025-08-20 21:19:43 +01:00
Task SaveHddvdrMediumStatusAsync() => SaveElementAsync(_hddvdrMediumStatus);
2025-08-20 21:19:43 +01:00
Task SaveHddvdrLastRmdAsync() => SaveElementAsync(_hddvdrLastRmd);
2025-08-20 21:19:43 +01:00
Task SaveDvdrLayerCapacityAsync() => SaveElementAsync(_dvdrLayerCapacity);
2025-08-20 21:19:43 +01:00
Task SaveDvdrDlMiddleZoneStartAsync() => SaveElementAsync(_dvdrDlMiddleZoneStart);
2025-08-20 21:19:43 +01:00
Task SaveDvdrDlJumpIntervalSizeAsync() => SaveElementAsync(_dvdrDlJumpIntervalSize);
2025-08-20 21:19:43 +01:00
Task SaveDvdrDlManualLayerJumpStartLbaAsync() => SaveElementAsync(_dvdrDlManualLayerJumpStartLba);
2025-08-20 21:19:43 +01:00
Task SaveDvdrDlRemapAnchorPointAsync() => SaveElementAsync(_dvdrDlRemapAnchorPoint);
2025-08-20 21:19:43 +01:00
Task SaveDvdPlusAdipAsync() => SaveElementAsync(_dvdPlusAdip);
2025-08-20 21:19:43 +01:00
Task SaveDvdPlusDcbAsync() => SaveElementAsync(_dvdPlusDcb);
}