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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2020-04-17 21:45:50 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-04-13 23:54:35 +01:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
using Aaru.Helpers;
|
2020-07-22 13:20:25 +01:00
|
|
|
using JetBrains.Annotations;
|
2020-04-13 23:54:35 +01:00
|
|
|
using ReactiveUI;
|
|
|
|
|
|
2020-04-16 20:40:25 +01:00
|
|
|
namespace Aaru.Gui.ViewModels.Windows
|
2020-04-13 23:54:35 +01:00
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed class ViewSectorViewModel : ViewModelBase
|
2020-04-13 23:54:35 +01:00
|
|
|
{
|
|
|
|
|
const int HEX_COLUMNS = 32;
|
2020-07-22 13:20:25 +01:00
|
|
|
readonly IMediaImage _inputFormat;
|
2020-04-13 23:54:35 +01:00
|
|
|
bool _longSectorChecked;
|
|
|
|
|
bool _longSectorVisible;
|
|
|
|
|
string _printHexText;
|
|
|
|
|
double _sectorNumber;
|
|
|
|
|
string _title;
|
|
|
|
|
string _totalSectorsText;
|
|
|
|
|
|
2020-07-22 13:20:25 +01:00
|
|
|
public ViewSectorViewModel([NotNull] IMediaImage inputFormat)
|
2020-04-13 23:54:35 +01:00
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
_inputFormat = inputFormat;
|
2020-04-13 23:54:35 +01:00
|
|
|
|
2021-09-20 14:22:22 +01:00
|
|
|
ErrorNumber errno = inputFormat.ReadSectorLong(0, out _);
|
|
|
|
|
|
|
|
|
|
if(errno == ErrorNumber.NoError)
|
2020-04-13 23:54:35 +01:00
|
|
|
LongSectorChecked = true;
|
2021-09-20 14:22:22 +01:00
|
|
|
else
|
2020-04-13 23:54:35 +01:00
|
|
|
LongSectorVisible = false;
|
|
|
|
|
|
|
|
|
|
TotalSectorsText = $"of {inputFormat.Info.Sectors}";
|
|
|
|
|
SectorNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get => _title;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _title, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double SectorNumber
|
|
|
|
|
{
|
|
|
|
|
get => _sectorNumber;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.RaiseAndSetIfChanged(ref _sectorNumber, value);
|
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
byte[] sector;
|
2021-09-20 14:22:22 +01:00
|
|
|
ErrorNumber errno;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2021-09-20 14:22:22 +01:00
|
|
|
errno = LongSectorChecked ? _inputFormat.ReadSectorLong((ulong)SectorNumber, out sector)
|
|
|
|
|
: _inputFormat.ReadSector((ulong)SectorNumber, out sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
|
|
|
if(errno == ErrorNumber.NoError)
|
|
|
|
|
PrintHexText = PrintHex.ByteArrayToHexArrayString(sector, HEX_COLUMNS);
|
2020-04-13 23:54:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TotalSectorsText { get; }
|
|
|
|
|
|
|
|
|
|
public bool LongSectorChecked
|
|
|
|
|
{
|
|
|
|
|
get => _longSectorChecked;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _longSectorChecked, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool LongSectorVisible { get; }
|
|
|
|
|
|
|
|
|
|
public string PrintHexText
|
|
|
|
|
{
|
|
|
|
|
get => _printHexText;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _printHexText, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|