2020-04-17 21:45:50 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : CompactDiscInfoViewModel.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : GUI view models.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// View model and code for the Compact Disc 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
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2020-04-12 14:19:12 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reactive;
|
2022-03-26 16:52:00 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-04-12 14:19:12 +01:00
|
|
|
using Aaru.Decoders.CD;
|
|
|
|
|
using Aaru.Decoders.SCSI.MMC;
|
|
|
|
|
using Aaru.Gui.Models;
|
2022-11-19 21:10:41 +00:00
|
|
|
using Aaru.Localization;
|
2020-04-12 14:19:12 +01:00
|
|
|
using Avalonia.Controls;
|
|
|
|
|
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 CompactDiscInfoViewModel : ViewModelBase
|
2020-04-12 14:19:12 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
readonly byte[] _atipData;
|
|
|
|
|
readonly byte[] _cdTextLeadInData;
|
|
|
|
|
readonly byte[] _compactDiscInformationData;
|
|
|
|
|
readonly byte[] _pmaData;
|
|
|
|
|
readonly byte[] _rawTocData;
|
|
|
|
|
readonly byte[] _sessionData;
|
|
|
|
|
readonly byte[] _tocData;
|
|
|
|
|
readonly Window _view;
|
|
|
|
|
|
|
|
|
|
public CompactDiscInfoViewModel(byte[] toc, byte[] atip, byte[] compactDiscInformation, byte[] session,
|
|
|
|
|
byte[] rawToc, byte[] pma, byte[] cdTextLeadIn, TOC.CDTOC? decodedToc,
|
|
|
|
|
ATIP.CDATIP decodedAtip, Session.CDSessionInfo? decodedSession,
|
|
|
|
|
FullTOC.CDFullTOC? fullToc, CDTextOnLeadIn.CDText? decodedCdTextLeadIn,
|
2022-03-07 07:36:44 +00:00
|
|
|
DiscInformation.StandardDiscInformation? decodedCompactDiscInformation, string mcn,
|
|
|
|
|
Dictionary<byte, string> isrcs, Window view)
|
2020-04-12 14:19:12 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
_tocData = toc;
|
|
|
|
|
_atipData = atip;
|
|
|
|
|
_compactDiscInformationData = compactDiscInformation;
|
|
|
|
|
_sessionData = session;
|
|
|
|
|
_rawTocData = rawToc;
|
|
|
|
|
_pmaData = pma;
|
|
|
|
|
_cdTextLeadInData = cdTextLeadIn;
|
|
|
|
|
_view = view;
|
2024-05-01 04:39:38 +01:00
|
|
|
IsrcList = [];
|
2022-03-06 13:29:38 +00:00
|
|
|
SaveCdInformationCommand = ReactiveCommand.Create(ExecuteSaveCdInformationCommand);
|
|
|
|
|
SaveCdTocCommand = ReactiveCommand.Create(ExecuteSaveCdTocCommand);
|
|
|
|
|
SaveCdFullTocCommand = ReactiveCommand.Create(ExecuteSaveCdFullTocCommand);
|
|
|
|
|
SaveCdSessionCommand = ReactiveCommand.Create(ExecuteSaveCdSessionCommand);
|
|
|
|
|
SaveCdTextCommand = ReactiveCommand.Create(ExecuteSaveCdTextCommand);
|
|
|
|
|
SaveCdAtipCommand = ReactiveCommand.Create(ExecuteSaveCdAtipCommand);
|
|
|
|
|
SaveCdPmaCommand = ReactiveCommand.Create(ExecuteSaveCdPmaCommand);
|
|
|
|
|
|
|
|
|
|
if(decodedCompactDiscInformation.HasValue)
|
|
|
|
|
CdInformationText = DiscInformation.Prettify000b(decodedCompactDiscInformation);
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedToc.HasValue) CdTocText = TOC.Prettify(decodedToc);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(fullToc.HasValue) CdFullTocText = FullTOC.Prettify(fullToc);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedSession.HasValue) CdSessionText = Session.Prettify(decodedSession);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedCdTextLeadIn.HasValue) CdTextText = CDTextOnLeadIn.Prettify(decodedCdTextLeadIn);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedAtip != null) CdAtipText = ATIP.Prettify(atip);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!string.IsNullOrEmpty(mcn)) McnText = mcn;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-11-13 20:46:24 +00:00
|
|
|
if(isrcs is { Count: > 0 })
|
2023-10-03 23:27:57 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(KeyValuePair<byte, string> isrc in isrcs)
|
2023-10-03 23:27:57 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
IsrcList.Add(new IsrcModel
|
|
|
|
|
{
|
|
|
|
|
Track = isrc.Key.ToString(),
|
|
|
|
|
Isrc = isrc.Value
|
|
|
|
|
});
|
2023-10-03 23:27:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
MiscellaneousVisible = McnText != null || isrcs?.Count > 0 || pma != null;
|
|
|
|
|
CdPmaVisible = pma != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CdInformationText { get; }
|
|
|
|
|
public string CdTocText { get; }
|
|
|
|
|
public string CdFullTocText { get; }
|
|
|
|
|
public string CdSessionText { get; }
|
|
|
|
|
public string CdTextText { get; }
|
|
|
|
|
public string CdAtipText { get; }
|
|
|
|
|
public bool MiscellaneousVisible { get; }
|
|
|
|
|
public string McnText { get; }
|
|
|
|
|
public bool CdPmaVisible { get; }
|
2022-03-26 16:52:00 +00:00
|
|
|
public ReactiveCommand<Unit, Task> SaveCdInformationCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdTocCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdFullTocCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdSessionCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdTextCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdAtipCommand { get; }
|
|
|
|
|
public ReactiveCommand<Unit, Task> SaveCdPmaCommand { get; }
|
2022-03-06 13:29:38 +00:00
|
|
|
public ObservableCollection<IsrcModel> IsrcList { get; }
|
|
|
|
|
|
2022-11-19 21:10:41 +00:00
|
|
|
public string CdInformationLabel => UI.Title_Information;
|
|
|
|
|
public string SaveCdInformationLabel => UI.ButtonLabel_Save_READ_DISC_INFORMATION_response;
|
|
|
|
|
public string CdTocLabel => UI.Title_TOC;
|
|
|
|
|
public string SaveCdTocLabel => UI.ButtonLabel_Save_READ_TOC_response;
|
|
|
|
|
public string CdFullTocLabel => UI.Title_TOC_full;
|
|
|
|
|
public string SaveCdFullTocLabel => UI.ButtonLabel_Save_READ_RAW_TOC_response;
|
|
|
|
|
public string CdSessionLabel => Localization.Core.Title_Session;
|
|
|
|
|
public string SaveCdSessionLabel => UI.ButtonLabel_Save_READ_SESSION_response;
|
|
|
|
|
public string CdTextLabel => UI.Title_CD_TEXT;
|
|
|
|
|
public string SaveCdTextLabel => UI.ButtonLabel_Save_Lead_In_CD_TEXT;
|
|
|
|
|
public string CdAtipLabel => UI.Title_ATIP;
|
|
|
|
|
public string SaveCdAtipLabel => UI.ButtonLabel_Save_READ_ATIP_response;
|
|
|
|
|
public string MiscellaneousLabel => UI.Title_Miscellaneous;
|
|
|
|
|
public string McnLabel => UI.Title_Media_catalog_number;
|
2023-10-05 01:52:48 +01:00
|
|
|
public string IsrCsLabel => UI.Title_ISRCs;
|
2022-11-19 21:10:41 +00:00
|
|
|
public string TrackLabel => Localization.Core.Title_Track;
|
|
|
|
|
public string ISRCLabel => UI.Title_ISRC;
|
|
|
|
|
public string SaveCdPmaLabel => UI.ButtonLabel_Save_READ_PMA_response;
|
2022-11-16 21:40:54 +00:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdInformationCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_compactDiscInformationData, 0, _compactDiscInformationData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdTocCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_tocData, 0, _tocData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdFullTocCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_rawTocData, 0, _rawTocData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdSessionCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_sessionData, 0, _sessionData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdTextCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_cdTextLeadInData, 0, _cdTextLeadInData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdAtipCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_atipData, 0, _atipData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
|
|
|
|
}
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
async Task ExecuteSaveCdPmaCommand()
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var dlgSaveBinary = new SaveFileDialog();
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-11-15 01:35:06 +00:00
|
|
|
dlgSaveBinary.Filters?.Add(new FileDialogFilter
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
Extensions =
|
|
|
|
|
[
|
|
|
|
|
..new[]
|
|
|
|
|
{
|
|
|
|
|
"*.bin"
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-10-04 17:34:40 +01:00
|
|
|
Name = UI.Dialog_Binary_files
|
2022-03-06 13:29:38 +00:00
|
|
|
});
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string result = await dlgSaveBinary.ShowAsync(_view);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var saveFs = new FileStream(result, FileMode.Create);
|
|
|
|
|
saveFs.Write(_pmaData, 0, _pmaData.Length);
|
2020-04-12 14:19:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
2020-04-12 14:19:12 +01:00
|
|
|
}
|
|
|
|
|
}
|