Files
Aaru/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs

87 lines
3.0 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : ViewSectorViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the sector viewing window.
//
// --[ 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 Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
2025-08-20 21:19:43 +01:00
using CommunityToolkit.Mvvm.ComponentModel;
2020-07-22 13:20:25 +01:00
using JetBrains.Annotations;
namespace Aaru.Gui.ViewModels.Windows;
2025-08-20 21:19:43 +01:00
public sealed partial class ViewSectorViewModel : ViewModelBase
{
2022-03-06 13:29:38 +00:00
const int HEX_COLUMNS = 32;
readonly IMediaImage _inputFormat;
2025-08-20 21:19:43 +01:00
[ObservableProperty]
bool _longSectorChecked;
[ObservableProperty]
bool _longSectorVisible;
[ObservableProperty]
string _printHexText;
double _sectorNumber;
[ObservableProperty]
string _title;
[ObservableProperty]
string _totalSectorsText;
2022-03-06 13:29:38 +00:00
// TODO: Show message when sector was not dumped
2022-03-06 13:29:38 +00:00
public ViewSectorViewModel([NotNull] IMediaImage inputFormat)
{
2022-03-06 13:29:38 +00:00
_inputFormat = inputFormat;
ErrorNumber errno = inputFormat.ReadSectorLong(0, false, out _, out _);
2022-03-06 13:29:38 +00:00
if(errno == ErrorNumber.NoError)
LongSectorChecked = true;
else
LongSectorVisible = false;
2022-03-06 13:29:38 +00:00
TotalSectorsText = $"of {inputFormat.Info.Sectors}";
SectorNumber = 0;
}
2022-03-06 13:29:38 +00:00
public double SectorNumber
{
get => _sectorNumber;
set
{
2025-08-20 21:19:43 +01:00
SetProperty(ref _sectorNumber, value);
2023-10-03 23:27:57 +01:00
ErrorNumber errno = LongSectorChecked
? _inputFormat.ReadSectorLong((ulong)SectorNumber, false, out byte[] sector, out _)
: _inputFormat.ReadSector((ulong)SectorNumber, false, out sector, out _);
2024-05-01 04:05:22 +01:00
if(errno == ErrorNumber.NoError) PrintHexText = PrintHex.ByteArrayToHexArrayString(sector, HEX_COLUMNS);
}
2022-03-06 13:29:38 +00:00
}
}