mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 11:14:25 +00:00
[Refactor] Replace backing fields with auto-properties in view models
This commit is contained in:
@@ -39,7 +39,6 @@ namespace Aaru.Checksums;
|
||||
/// <summary>Handles native implementations of compression algorithms</summary>
|
||||
public static partial class Native
|
||||
{
|
||||
static bool _checked;
|
||||
static bool _supported;
|
||||
|
||||
/// <summary>Set to return native as never supported</summary>
|
||||
@@ -55,10 +54,10 @@ public static partial class Native
|
||||
{
|
||||
if(ForceManaged) return false;
|
||||
|
||||
if(_checked) return _supported;
|
||||
if(field) return _supported;
|
||||
|
||||
ulong version;
|
||||
_checked = true;
|
||||
field = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -5,9 +5,7 @@ namespace Aaru.CommonTypes;
|
||||
|
||||
public class LocalizedDescriptionAttribute : DescriptionAttribute
|
||||
{
|
||||
private readonly string _resourceKey;
|
||||
public LocalizedDescriptionAttribute(string resourceKey) => Description = resourceKey;
|
||||
|
||||
public LocalizedDescriptionAttribute(string resourceKey) => _resourceKey = resourceKey;
|
||||
|
||||
public override string Description => UI.ResourceManager.GetString(_resourceKey) ?? _resourceKey;
|
||||
public override string Description => UI.ResourceManager.GetString(field) ?? field;
|
||||
}
|
||||
@@ -39,7 +39,6 @@ namespace Aaru.Compression;
|
||||
/// <summary>Handles native implementations of compression algorithms</summary>
|
||||
public static partial class Native
|
||||
{
|
||||
static bool _checked;
|
||||
static bool _supported;
|
||||
|
||||
/// <summary>Set to return native as never supported</summary>
|
||||
@@ -55,10 +54,10 @@ public static partial class Native
|
||||
{
|
||||
if(ForceManaged) return false;
|
||||
|
||||
if(_checked) return _supported;
|
||||
if(field) return _supported;
|
||||
|
||||
ulong version;
|
||||
_checked = true;
|
||||
field = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -41,18 +41,17 @@ namespace Aaru.Gui;
|
||||
|
||||
static class ConsoleHandler
|
||||
{
|
||||
static bool _debug;
|
||||
static bool _verbose;
|
||||
|
||||
public static bool Debug
|
||||
{
|
||||
set
|
||||
{
|
||||
if(_debug == value) return;
|
||||
if(field == value) return;
|
||||
|
||||
_debug = value;
|
||||
field = value;
|
||||
|
||||
if(_debug)
|
||||
if(field)
|
||||
{
|
||||
AaruLogging.DebugEvent += OnDebugWriteHandler;
|
||||
AaruLogging.WriteExceptionEvent += OnWriteExceptionEvent;
|
||||
@@ -67,13 +66,14 @@ static class ConsoleHandler
|
||||
|
||||
public static ObservableCollection<LogEntry> Entries { get; } = [];
|
||||
|
||||
static void OnWriteExceptionEvent([NotNull] Exception ex, string message, params object[] objects) => Entries.Add(new LogEntry
|
||||
{
|
||||
Message = string.Format(message, objects),
|
||||
Module = null,
|
||||
Timestamp = DateTime.Now,
|
||||
Type = UI.LogEntry_Type_Exception
|
||||
});
|
||||
static void OnWriteExceptionEvent([NotNull] Exception ex, string message, params object[] objects) =>
|
||||
Entries.Add(new LogEntry
|
||||
{
|
||||
Message = string.Format(message, objects),
|
||||
Module = null,
|
||||
Timestamp = DateTime.Now,
|
||||
Type = UI.LogEntry_Type_Exception
|
||||
});
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace Aaru.Gui.ViewModels.Dialogs;
|
||||
public sealed class ConsoleViewModel : ViewModelBase
|
||||
{
|
||||
readonly Console _view;
|
||||
bool _debugChecked;
|
||||
|
||||
public ConsoleViewModel(Console view)
|
||||
{
|
||||
@@ -67,11 +66,11 @@ public sealed class ConsoleViewModel : ViewModelBase
|
||||
|
||||
public bool DebugChecked
|
||||
{
|
||||
get => _debugChecked;
|
||||
get;
|
||||
set
|
||||
{
|
||||
ConsoleHandler.Debug = value;
|
||||
SetProperty(ref _debugChecked, value);
|
||||
SetProperty(ref field, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@ public sealed partial class PcmciaInfoViewModel : ViewModelBase
|
||||
readonly Window _view;
|
||||
[ObservableProperty]
|
||||
string _pcmciaCisText;
|
||||
PcmciaCisModel _selectedCis;
|
||||
|
||||
internal PcmciaInfoViewModel([CanBeNull] byte[] pcmciaCis, Window view)
|
||||
{
|
||||
@@ -157,13 +156,13 @@ public sealed partial class PcmciaInfoViewModel : ViewModelBase
|
||||
|
||||
public PcmciaCisModel SelectedCis
|
||||
{
|
||||
get => _selectedCis;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if(_selectedCis == value) return;
|
||||
if(field == value) return;
|
||||
|
||||
PcmciaCisText = value?.Description;
|
||||
SetProperty(ref _selectedCis, value);
|
||||
SetProperty(ref field, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,9 +64,6 @@ public sealed partial class ScsiInfoViewModel : ViewModelBase
|
||||
string _mmcFeatureText;
|
||||
[ObservableProperty]
|
||||
string _modeSensePageText;
|
||||
object _selectedEvpdPage;
|
||||
object _selectedMmcFeature;
|
||||
object _selectedModeSensePage;
|
||||
|
||||
public ScsiInfoViewModel(byte[] scsiInquiryData, Inquiry? scsiInquiry, Dictionary<byte, byte[]> scsiEvpdPages,
|
||||
Modes.DecodedMode? scsiMode, PeripheralDeviceTypes scsiType, byte[] scsiModeSense6,
|
||||
@@ -728,40 +725,40 @@ public sealed partial class ScsiInfoViewModel : ViewModelBase
|
||||
|
||||
public object SelectedModeSensePage
|
||||
{
|
||||
get => _selectedModeSensePage;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if(value == _selectedModeSensePage) return;
|
||||
if(value == field) return;
|
||||
|
||||
if(value is ScsiPageModel pageModel) ModeSensePageText = pageModel.Description;
|
||||
|
||||
SetProperty(ref _selectedModeSensePage, value);
|
||||
SetProperty(ref field, value);
|
||||
}
|
||||
}
|
||||
|
||||
public object SelectedEvpdPage
|
||||
{
|
||||
get => _selectedEvpdPage;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if(value == _selectedEvpdPage) return;
|
||||
if(value == field) return;
|
||||
|
||||
if(value is ScsiPageModel pageModel) EvpdPageText = pageModel.Description;
|
||||
|
||||
SetProperty(ref _selectedEvpdPage, value);
|
||||
SetProperty(ref field, value);
|
||||
}
|
||||
}
|
||||
|
||||
public object SelectedMmcFeature
|
||||
{
|
||||
get => _selectedMmcFeature;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if(value == _selectedMmcFeature) return;
|
||||
if(value == field) return;
|
||||
|
||||
if(value is ScsiPageModel pageModel) MmcFeatureText = pageModel.Description;
|
||||
|
||||
SetProperty(ref _selectedMmcFeature, value);
|
||||
SetProperty(ref field, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@ public sealed partial class DecodeMediaTagsViewModel : ViewModelBase
|
||||
bool _decodedVisible;
|
||||
[ObservableProperty]
|
||||
byte[] _hexData;
|
||||
MediaTagModel _selectedTag;
|
||||
|
||||
public DecodeMediaTagsViewModel([NotNull] IMediaImage inputFormat)
|
||||
{
|
||||
@@ -93,10 +92,10 @@ public sealed partial class DecodeMediaTagsViewModel : ViewModelBase
|
||||
|
||||
public MediaTagModel SelectedTag
|
||||
{
|
||||
get => _selectedTag;
|
||||
get;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedTag, value);
|
||||
SetProperty(ref field, value);
|
||||
|
||||
if(value is null) return;
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
string _title;
|
||||
[ObservableProperty]
|
||||
ObservableCollection<RootModel> _treeRoot;
|
||||
object _treeViewSelectedItem;
|
||||
|
||||
public MainWindowViewModel(Window view)
|
||||
{
|
||||
@@ -187,12 +186,12 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
public object TreeViewSelectedItem
|
||||
{
|
||||
get => _treeViewSelectedItem;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if(value == _treeViewSelectedItem) return;
|
||||
if(value == field) return;
|
||||
|
||||
SetProperty(ref _treeViewSelectedItem, value);
|
||||
SetProperty(ref field, value);
|
||||
|
||||
ContentPanel = null;
|
||||
|
||||
|
||||
@@ -45,14 +45,12 @@ public sealed partial class ViewSectorViewModel : ViewModelBase
|
||||
readonly IMediaImage _inputFormat;
|
||||
[ObservableProperty]
|
||||
List<ColorRange> _highlightRanges;
|
||||
bool _longSectorChecked;
|
||||
[ObservableProperty]
|
||||
bool _longSectorVisible;
|
||||
[ObservableProperty]
|
||||
string _printHexText;
|
||||
[ObservableProperty]
|
||||
byte[] _sectorData;
|
||||
double _sectorNumber;
|
||||
[ObservableProperty]
|
||||
string _totalSectorsText;
|
||||
|
||||
@@ -70,10 +68,10 @@ public sealed partial class ViewSectorViewModel : ViewModelBase
|
||||
|
||||
public bool LongSectorChecked
|
||||
{
|
||||
get => _longSectorChecked;
|
||||
get;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _longSectorChecked, value);
|
||||
SetProperty(ref field, value);
|
||||
|
||||
ErrorNumber errno = LongSectorChecked
|
||||
? _inputFormat.ReadSectorLong((ulong)SectorNumber, false, out byte[] sector, out _)
|
||||
@@ -88,10 +86,10 @@ public sealed partial class ViewSectorViewModel : ViewModelBase
|
||||
|
||||
public double SectorNumber
|
||||
{
|
||||
get => _sectorNumber;
|
||||
get;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _sectorNumber, value);
|
||||
SetProperty(ref field, value);
|
||||
|
||||
ErrorNumber errno = LongSectorChecked
|
||||
? _inputFormat.ReadSectorLong((ulong)SectorNumber, false, out byte[] sector, out _)
|
||||
|
||||
@@ -37,7 +37,6 @@ public sealed partial class FileViewViewModel : ViewModelBase
|
||||
string _informationalVersion;
|
||||
[ObservableProperty]
|
||||
bool _isStatusVisible;
|
||||
FileModel? _selectedFile;
|
||||
[ObservableProperty]
|
||||
string _status;
|
||||
|
||||
@@ -62,10 +61,10 @@ public sealed partial class FileViewViewModel : ViewModelBase
|
||||
|
||||
public FileModel? SelectedFile
|
||||
{
|
||||
get => _selectedFile;
|
||||
get;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedFile, value);
|
||||
SetProperty(ref field, value);
|
||||
OnPropertyChanged(nameof(IsFileInfoAvailable));
|
||||
OnPropertyChanged(nameof(SelectedFileIsNotDirectory));
|
||||
OnPropertyChanged(nameof(SelectedFileLength));
|
||||
|
||||
@@ -79,7 +79,6 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
||||
string _partitionStart;
|
||||
[ObservableProperty]
|
||||
string _partitionType;
|
||||
FileSystemModelNode? _selectedNode;
|
||||
[ObservableProperty]
|
||||
string? _status;
|
||||
|
||||
@@ -93,29 +92,28 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
||||
|
||||
public FileSystemModelNode? SelectedNode
|
||||
{
|
||||
get => _selectedNode;
|
||||
get;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedNode, value);
|
||||
SetProperty(ref field, value);
|
||||
|
||||
if(_selectedNode is null) return;
|
||||
if(field is null) return;
|
||||
|
||||
if(_selectedNode.Partition is not null && _selectedNode.Filesystem is null)
|
||||
if(field.Partition is not null && field.Filesystem is null)
|
||||
{
|
||||
IsPartitionInformationVisible = true;
|
||||
|
||||
PartitionSequence = _selectedNode.Partition.Value.Sequence.ToString();
|
||||
PartitionName = _selectedNode.Partition.Value.Name;
|
||||
PartitionType = _selectedNode.Partition.Value.Type;
|
||||
PartitionStart = _selectedNode.Partition.Value.Start.ToString();
|
||||
PartitionOffset = ByteSize.FromBytes(_selectedNode.Partition.Value.Offset).Humanize();
|
||||
PartitionSequence = field.Partition.Value.Sequence.ToString();
|
||||
PartitionName = field.Partition.Value.Name;
|
||||
PartitionType = field.Partition.Value.Type;
|
||||
PartitionStart = field.Partition.Value.Start.ToString();
|
||||
PartitionOffset = ByteSize.FromBytes(field.Partition.Value.Offset).Humanize();
|
||||
|
||||
PartitionLength =
|
||||
string.Format(Localization.Resources._0_sectors, _selectedNode.Partition.Value.Length);
|
||||
PartitionLength = string.Format(Localization.Resources._0_sectors, field.Partition.Value.Length);
|
||||
|
||||
PartitionSize = ByteSize.FromBytes(_selectedNode.Partition.Value.Size).Humanize();
|
||||
PartitionScheme = _selectedNode.Partition.Value.Scheme;
|
||||
PartitionDescription = _selectedNode.Partition.Value.Description;
|
||||
PartitionSize = ByteSize.FromBytes(field.Partition.Value.Size).Humanize();
|
||||
PartitionScheme = field.Partition.Value.Scheme;
|
||||
PartitionDescription = field.Partition.Value.Description;
|
||||
|
||||
OnPropertyChanged(nameof(PartitionSequence));
|
||||
OnPropertyChanged(nameof(PartitionName));
|
||||
@@ -130,10 +128,10 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
||||
else
|
||||
IsPartitionInformationVisible = false;
|
||||
|
||||
if(_selectedNode.Filesystem is not null)
|
||||
if(field.Filesystem is not null)
|
||||
{
|
||||
IsFilesystemInformationVisible = true;
|
||||
FilesystemInformation = _selectedNode.FilesystemInformation ?? "";
|
||||
FilesystemInformation = field.FilesystemInformation ?? "";
|
||||
|
||||
OnPropertyChanged(nameof(FilesystemInformation));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user