From 5fe7f574d6dfed88d9766b0b0f0b206c4196a60a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 24 Nov 2025 01:40:50 +0000 Subject: [PATCH] [Refactor] Replace backing fields with auto-properties in view models --- Aaru.Checksums/Native.cs | 5 ++- .../Localization/LocalizedDescription.cs | 6 ++-- Aaru.Compression/Native.cs | 5 ++- Aaru.Gui/ConsoleHandler.cs | 22 ++++++------- .../ViewModels/Dialogs/ConsoleViewModel.cs | 5 ++- .../ViewModels/Tabs/PcmciaInfoViewModel.cs | 7 ++-- Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs | 21 ++++++------ .../Windows/DecodeMediaTagsViewModel.cs | 5 ++- .../ViewModels/Windows/MainWindowViewModel.cs | 7 ++-- .../ViewModels/Windows/ViewSectorViewModel.cs | 10 +++--- .../ViewModels/Windows/FileViewViewModel.cs | 5 ++- .../Windows/ImageWindowViewModel.cs | 32 +++++++++---------- 12 files changed, 57 insertions(+), 73 deletions(-) diff --git a/Aaru.Checksums/Native.cs b/Aaru.Checksums/Native.cs index c3c2ec5a5..2be8b8d4c 100644 --- a/Aaru.Checksums/Native.cs +++ b/Aaru.Checksums/Native.cs @@ -39,7 +39,6 @@ namespace Aaru.Checksums; /// Handles native implementations of compression algorithms public static partial class Native { - static bool _checked; static bool _supported; /// Set to return native as never supported @@ -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 { diff --git a/Aaru.CommonTypes/Localization/LocalizedDescription.cs b/Aaru.CommonTypes/Localization/LocalizedDescription.cs index b34d77d36..5e3b30d06 100644 --- a/Aaru.CommonTypes/Localization/LocalizedDescription.cs +++ b/Aaru.CommonTypes/Localization/LocalizedDescription.cs @@ -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; } \ No newline at end of file diff --git a/Aaru.Compression/Native.cs b/Aaru.Compression/Native.cs index 73bf509b6..ffbff2275 100644 --- a/Aaru.Compression/Native.cs +++ b/Aaru.Compression/Native.cs @@ -39,7 +39,6 @@ namespace Aaru.Compression; /// Handles native implementations of compression algorithms public static partial class Native { - static bool _checked; static bool _supported; /// Set to return native as never supported @@ -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 { diff --git a/Aaru.Gui/ConsoleHandler.cs b/Aaru.Gui/ConsoleHandler.cs index bea1493e4..a869ac11a 100644 --- a/Aaru.Gui/ConsoleHandler.cs +++ b/Aaru.Gui/ConsoleHandler.cs @@ -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 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() { diff --git a/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs b/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs index 555bded96..af9c82b95 100644 --- a/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs +++ b/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs @@ -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); } } diff --git a/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs index d086fc520..b1c5588dd 100644 --- a/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs @@ -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); } } diff --git a/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs index e2bce3397..46e246345 100644 --- a/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs @@ -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 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); } } diff --git a/Aaru.Gui/ViewModels/Windows/DecodeMediaTagsViewModel.cs b/Aaru.Gui/ViewModels/Windows/DecodeMediaTagsViewModel.cs index 69189b340..3678586ab 100644 --- a/Aaru.Gui/ViewModels/Windows/DecodeMediaTagsViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/DecodeMediaTagsViewModel.cs @@ -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; diff --git a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs index cea6b3a7b..da5e84000 100644 --- a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs @@ -96,7 +96,6 @@ public partial class MainWindowViewModel : ViewModelBase string _title; [ObservableProperty] ObservableCollection _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; diff --git a/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs b/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs index a6ddea098..8d9d95c89 100644 --- a/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs @@ -45,14 +45,12 @@ public sealed partial class ViewSectorViewModel : ViewModelBase readonly IMediaImage _inputFormat; [ObservableProperty] List _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 _) diff --git a/Aaru.Tui/ViewModels/Windows/FileViewViewModel.cs b/Aaru.Tui/ViewModels/Windows/FileViewViewModel.cs index 38793ebb2..b95a76bfd 100644 --- a/Aaru.Tui/ViewModels/Windows/FileViewViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/FileViewViewModel.cs @@ -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)); diff --git a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs index dae3bd333..671d0a5f8 100644 --- a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs @@ -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)); }