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

189 lines
7.0 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : PcmciaInfoViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the PCMCIA 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;
2025-08-20 21:19:43 +01:00
using System.Windows.Input;
2020-02-27 00:33:26 +00:00
using Aaru.Decoders.PCMCIA;
using Aaru.Gui.Models;
using Aaru.Localization;
using Aaru.Logging;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
2025-08-20 21:19:43 +01:00
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
2020-07-22 13:20:25 +01:00
using JetBrains.Annotations;
2025-08-14 15:51:32 +01:00
using Tuple = Aaru.Decoders.PCMCIA.Tuple;
namespace Aaru.Gui.ViewModels.Tabs;
2025-08-20 21:19:43 +01:00
public sealed partial class PcmciaInfoViewModel : ViewModelBase
{
2023-10-03 23:27:57 +01:00
const string MODULE_NAME = "PCMCIA Information ViewModel";
readonly byte[] _cis;
readonly Window _view;
2025-08-20 21:19:43 +01:00
[ObservableProperty]
string _pcmciaCisText;
PcmciaCisModel _selectedCis;
2022-03-06 13:29:38 +00:00
internal PcmciaInfoViewModel([CanBeNull] byte[] pcmciaCis, Window view)
{
2024-05-01 04:05:22 +01:00
if(pcmciaCis == null) return;
2022-03-06 13:29:38 +00:00
_cis = pcmciaCis;
2024-05-01 04:39:38 +01:00
CisList = [];
2025-08-20 21:19:43 +01:00
SavePcmciaCisCommand = new AsyncRelayCommand(SavePcmciaCisAsync);
2022-03-06 13:29:38 +00:00
_view = view;
2022-03-06 13:29:38 +00:00
Tuple[] tuples = CIS.GetTuples(_cis);
2022-03-06 13:29:38 +00:00
if(tuples != null)
2023-10-03 23:27:57 +01:00
{
2022-03-06 13:29:38 +00:00
foreach(Tuple tuple in tuples)
{
string tupleCode;
string tupleDescription;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
switch(tuple.Code)
{
2022-03-06 13:29:38 +00:00
case TupleCodes.CISTPL_NULL:
2023-10-03 23:27:57 +01:00
case TupleCodes.CISTPL_END:
continue;
2022-03-06 13:29:38 +00:00
case TupleCodes.CISTPL_DEVICEGEO:
case TupleCodes.CISTPL_DEVICEGEO_A:
tupleCode = UI.Device_Geometry_Tuples;
2022-03-06 13:29:38 +00:00
tupleDescription = CIS.PrettifyDeviceGeometryTuple(tuple);
break;
case TupleCodes.CISTPL_MANFID:
tupleCode = UI.Manufacturer_Identification_Tuple;
2022-03-06 13:29:38 +00:00
tupleDescription = CIS.PrettifyManufacturerIdentificationTuple(tuple);
break;
case TupleCodes.CISTPL_VERS_1:
tupleCode = UI.Level_1_Version_Product_Information_Tuple;
2022-03-06 13:29:38 +00:00
tupleDescription = CIS.PrettifyLevel1VersionTuple(tuple);
break;
case TupleCodes.CISTPL_ALTSTR:
case TupleCodes.CISTPL_BAR:
case TupleCodes.CISTPL_BATTERY:
case TupleCodes.CISTPL_BYTEORDER:
case TupleCodes.CISTPL_CFTABLE_ENTRY:
case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
case TupleCodes.CISTPL_CHECKSUM:
case TupleCodes.CISTPL_CONFIG:
case TupleCodes.CISTPL_CONFIG_CB:
case TupleCodes.CISTPL_DATE:
case TupleCodes.CISTPL_DEVICE:
case TupleCodes.CISTPL_DEVICE_A:
case TupleCodes.CISTPL_DEVICE_OA:
case TupleCodes.CISTPL_DEVICE_OC:
case TupleCodes.CISTPL_EXTDEVIC:
case TupleCodes.CISTPL_FORMAT:
case TupleCodes.CISTPL_FORMAT_A:
case TupleCodes.CISTPL_FUNCE:
case TupleCodes.CISTPL_FUNCID:
case TupleCodes.CISTPL_GEOMETRY:
case TupleCodes.CISTPL_INDIRECT:
case TupleCodes.CISTPL_JEDEC_A:
case TupleCodes.CISTPL_JEDEC_C:
case TupleCodes.CISTPL_LINKTARGET:
case TupleCodes.CISTPL_LONGLINK_A:
case TupleCodes.CISTPL_LONGLINK_C:
case TupleCodes.CISTPL_LONGLINK_CB:
case TupleCodes.CISTPL_LONGLINK_MFC:
case TupleCodes.CISTPL_NO_LINK:
case TupleCodes.CISTPL_ORG:
case TupleCodes.CISTPL_PWR_MGMNT:
case TupleCodes.CISTPL_SPCL:
case TupleCodes.CISTPL_SWIL:
case TupleCodes.CISTPL_VERS_2:
tupleCode = string.Format(UI.Undecoded_tuple_ID_0, tuple.Code);
tupleDescription = string.Format(UI.Undecoded_tuple_ID_0, tuple.Code);
2022-03-06 13:29:38 +00:00
break;
default:
tupleCode = $"0x{(byte)tuple.Code:X2}";
tupleDescription = string.Format(Localization.Core.Found_unknown_tuple_ID_0, (byte)tuple.Code);
2022-03-06 13:29:38 +00:00
break;
}
2022-03-06 13:29:38 +00:00
CisList.Add(new PcmciaCisModel
{
Code = tupleCode,
Description = tupleDescription
});
}
2023-10-03 23:27:57 +01:00
}
2022-03-06 13:29:38 +00:00
else
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(MODULE_NAME, UI.PCMCIA_CIS_returned_no_tuples);
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
public ObservableCollection<PcmciaCisModel> CisList { get; }
2022-03-06 13:29:38 +00:00
public PcmciaCisModel SelectedCis
{
get => _selectedCis;
set
{
2024-05-01 04:05:22 +01:00
if(_selectedCis == value) return;
2022-03-06 13:29:38 +00:00
PcmciaCisText = value?.Description;
2025-08-20 21:19:43 +01:00
SetProperty(ref _selectedCis, value);
}
2022-03-06 13:29:38 +00:00
}
2025-08-20 21:19:43 +01:00
public ICommand SavePcmciaCisCommand { get; }
2025-08-20 21:19:43 +01:00
async Task SavePcmciaCisAsync()
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
});
2020-02-29 18:03:35 +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(_cis, 0, _cis.Length);
2022-03-06 13:29:38 +00:00
saveFs.Close();
}
}