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