2020-04-17 21:45:50 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : XboxInfoViewModel.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : GUI view models.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// View model and code for the Xbox Game 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-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 18:59:16 +01:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Reactive;
|
2022-03-26 16:52:00 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-04-12 18:59:16 +01:00
|
|
|
using Aaru.Core.Media.Info;
|
|
|
|
|
using Aaru.Decoders.Xbox;
|
2022-11-19 21:10:41 +00:00
|
|
|
using Aaru.Localization;
|
2020-04-12 18:59:16 +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 18:59:16 +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 XboxInfoViewModel
|
2020-04-12 18:59:16 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
readonly Window _view;
|
|
|
|
|
readonly byte[] _xboxSecuritySector;
|
|
|
|
|
|
|
|
|
|
public XboxInfoViewModel([CanBeNull] XgdInfo xgdInfo, [CanBeNull] byte[] dmi, [CanBeNull] byte[] securitySector,
|
2023-10-03 23:27:57 +01:00
|
|
|
SS.SecuritySector? decodedSecuritySector, Window view)
|
2020-04-12 18:59:16 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
_xboxSecuritySector = securitySector;
|
|
|
|
|
_view = view;
|
|
|
|
|
SaveXboxSsCommand = ReactiveCommand.Create(ExecuteSaveXboxSsCommand);
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(xgdInfo != null)
|
2020-04-12 18:59:16 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
XboxInformationVisible = true;
|
2022-11-19 21:10:41 +00:00
|
|
|
XboxL0VideoText = string.Format(Localization.Core._0_sectors, xgdInfo.L0Video);
|
|
|
|
|
XboxL1VideoText = string.Format(Localization.Core._0_sectors, xgdInfo.L1Video);
|
|
|
|
|
XboxMiddleZoneText = string.Format(Localization.Core._0_sectors, xgdInfo.MiddleZone);
|
|
|
|
|
XboxGameSizeText = string.Format(Localization.Core._0_sectors, xgdInfo.GameSize);
|
|
|
|
|
XboxTotalSizeText = string.Format(Localization.Core._0_sectors, xgdInfo.TotalSize);
|
2022-03-06 13:29:38 +00:00
|
|
|
XboxRealBreakText = xgdInfo.LayerBreak.ToString();
|
|
|
|
|
}
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(dmi != null)
|
|
|
|
|
{
|
|
|
|
|
if(DMI.IsXbox(dmi))
|
2024-05-01 04:05:22 +01:00
|
|
|
XboxDmiText = DMI.PrettifyXbox(dmi);
|
|
|
|
|
else if(DMI.IsXbox360(dmi)) XboxDmiText = DMI.PrettifyXbox360(dmi);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(decodedSecuritySector.HasValue) XboxSsText = SS.Prettify(decodedSecuritySector);
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
SaveXboxSsVisible = securitySector != null;
|
|
|
|
|
}
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
public ReactiveCommand<Unit, Task> SaveXboxSsCommand { get; }
|
2022-03-06 13:29:38 +00:00
|
|
|
public bool XboxInformationVisible { get; }
|
|
|
|
|
public bool SaveXboxSsVisible { get; }
|
|
|
|
|
public string XboxL0VideoText { get; }
|
|
|
|
|
public string XboxL1VideoText { get; }
|
|
|
|
|
public string XboxMiddleZoneText { get; }
|
|
|
|
|
public string XboxGameSizeText { get; }
|
|
|
|
|
public string XboxTotalSizeText { get; }
|
|
|
|
|
public string XboxRealBreakText { get; }
|
|
|
|
|
public string XboxDmiText { get; }
|
|
|
|
|
public string XboxSsText { get; }
|
2020-04-12 18:59:16 +01:00
|
|
|
|
2022-11-19 21:10:41 +00:00
|
|
|
public string XboxL0VideoLabel => Localization.Core.Video_layer_zero_size;
|
|
|
|
|
public string XboxL1VideoLabel => Localization.Core.Video_layer_one_size;
|
|
|
|
|
public string XboxMiddleZoneLabel => Localization.Core.Middle_zone_size;
|
|
|
|
|
public string XboxGameSizeLabel => Localization.Core.Game_data_size;
|
|
|
|
|
public string XboxTotalSizeLabel => Localization.Core.Total_size;
|
|
|
|
|
public string XboxRealBreakLabel => Localization.Core.Real_layer_break;
|
|
|
|
|
public string XboxDmiLabel => UI.Title_Disc_Manufacturing_Information;
|
|
|
|
|
public string XboxSsLabel => UI.Title_Security_Sector;
|
|
|
|
|
public string SaveXboxSsLabel => UI.ButtonLabel_Save_Xbox_Security_Sector;
|
2022-11-16 21:40:54 +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 18:59:16 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(result is null) return;
|
2020-04-12 18:59:16 +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 18:59:16 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
saveFs.Close();
|
2020-04-12 18:59:16 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-03-26 16:52:00 +00:00
|
|
|
public async Task ExecuteSaveXboxSsCommand() => await SaveElement(_xboxSecuritySector);
|
2020-04-12 18:59:16 +01:00
|
|
|
}
|