Migrate to CommunityToolkit.Mvvm

This commit is contained in:
2025-07-24 11:11:27 +01:00
parent c5da48fa47
commit b0e0ba4502
18 changed files with 364 additions and 920 deletions

View File

@@ -4,10 +4,10 @@
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.3.2"/> <PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.3.2"/>
<PackageVersion Include="Avalonia.Desktop" Version="11.3.2"/> <PackageVersion Include="Avalonia.Desktop" Version="11.3.2"/>
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.2"/> <PackageVersion Include="Avalonia.Diagnostics" Version="11.3.2"/>
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.3.2"/>
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.3.0"/> <PackageVersion Include="Avalonia.Svg.Skia" Version="11.3.0"/>
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.2"/> <PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.2"/>
<PackageVersion Include="Avalonia" Version="11.3.2"/> <PackageVersion Include="Avalonia" Version="11.3.2"/>
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0"/>
<PackageVersion Include="DotNetZip" Version="1.16.0"/> <PackageVersion Include="DotNetZip" Version="1.16.0"/>
<PackageVersion Include="EFCore.BulkExtensions" Version="9.0.1"/> <PackageVersion Include="EFCore.BulkExtensions" Version="9.0.1"/>
<PackageVersion Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2"/> <PackageVersion Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2"/>
@@ -33,17 +33,14 @@
<PackageVersion Include="System.Security.Principal.Windows" Version="5.0.0"/> <PackageVersion Include="System.Security.Principal.Windows" Version="5.0.0"/>
<PackageVersion Include="Text.Analyzers" Version="4.14.0"/> <PackageVersion Include="Text.Analyzers" Version="4.14.0"/>
<PackageVersion Include="winfsp.net" Version="2.1.25156"/> <PackageVersion Include="winfsp.net" Version="2.1.25156"/>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3"/> <PackageVersion Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageVersion Include="SabreTools.Hashing" Version="1.2.3"/> <PackageVersion Include="SabreTools.Hashing" Version="1.2.3"/>
<PackageVersion Include="SabreTools.IO" Version="1.4.13"/> <PackageVersion Include="SabreTools.IO" Version="1.4.13"/>
<PackageVersion Include="SabreTools.Matching" Version="1.3.4"/> <PackageVersion Include="SabreTools.Matching" Version="1.3.4"/>
<PackageVersion Include="SabreTools.Skippers" Version="1.1.3"/> <PackageVersion Include="SabreTools.Skippers" Version="1.1.3"/>
<PackageVersion Include="System.IO.Compression" Version="4.3.0"/> <PackageVersion Include="System.IO.Compression" Version="4.3.0"/>
<PackageVersion Include="SharpCompress" Version="0.38.0"/> <PackageVersion Include="SharpCompress" Version="0.38.0"/>
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0"/> <PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0"/>
<PackageVersion Include="ZstdSharp.Port" Version="0.8.1"/> <PackageVersion Include="ZstdSharp.Port" Version="0.8.1"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,59 +1,29 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Media; using Avalonia.Media;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
namespace RomRepoMgr.Models; namespace RomRepoMgr.Models;
public class DatImporter : ReactiveObject public partial class DatImporter : ObservableObject
{ {
bool _indeterminate; [ObservableProperty]
double _maximum; bool _indeterminate;
double _minimum; [ObservableProperty]
double _progress; double _maximum;
Color _statusColor; [ObservableProperty]
string _statusMessage; double _minimum;
[ObservableProperty]
double _progress;
[ObservableProperty]
Color _statusColor;
[ObservableProperty]
string _statusMessage;
public string Filename { get; internal init; } public string Filename { get; internal init; }
public Task Task { get; set; } public Task Task { get; set; }
public bool Running { get; private set; } = true; public bool Running { get; private set; } = true;
public bool Indeterminate
{
get => _indeterminate;
set => this.RaiseAndSetIfChanged(ref _indeterminate, value);
}
public double Progress
{
get => _progress;
set => this.RaiseAndSetIfChanged(ref _progress, value);
}
public double Maximum
{
get => _maximum;
set => this.RaiseAndSetIfChanged(ref _maximum, value);
}
public double Minimum
{
get => _minimum;
set => this.RaiseAndSetIfChanged(ref _minimum, value);
}
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public Color StatusColor
{
get => _statusColor;
set => this.RaiseAndSetIfChanged(ref _statusColor, value);
}
internal void OnErrorOccurred(object sender, ErrorEventArgs e) internal void OnErrorOccurred(object sender, ErrorEventArgs e)
{ {
StatusMessage = e.Message; StatusMessage = e.Message;

View File

@@ -1,75 +1,29 @@
using System; using System;
using Avalonia.Media; using Avalonia.Media;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
namespace RomRepoMgr.Models; namespace RomRepoMgr.Models;
public class RomImporter : ReactiveObject public partial class RomImporter : ObservableObject
{ {
bool _indeterminate; [ObservableProperty]
double _maximum; bool _indeterminate;
double _minimum; [ObservableProperty]
double _progress; double _maximum;
bool _progressVisible = true; [ObservableProperty]
Color _statusColor; double _minimum;
string _statusMessage; [ObservableProperty]
double _progress;
[ObservableProperty]
bool _progressVisible = true;
[ObservableProperty]
Color _statusColor;
[ObservableProperty]
string _statusMessage;
public string Filename { get; internal init; } public string Filename { get; internal init; }
public bool Running { get; private set; } = true; public bool Running { get; private set; } = true;
public bool Indeterminate
{
get => _indeterminate;
set => this.RaiseAndSetIfChanged(ref _indeterminate, value);
}
public double Progress
{
get => _progress;
set => this.RaiseAndSetIfChanged(ref _progress, value);
}
public double Maximum
{
get => _maximum;
set => this.RaiseAndSetIfChanged(ref _maximum, value);
}
public double Minimum
{
get => _minimum;
set => this.RaiseAndSetIfChanged(ref _minimum, value);
}
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public Color StatusColor
{
get => _statusColor;
set => this.RaiseAndSetIfChanged(ref _statusColor, value);
}
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
internal void OnErrorOccurred(object sender, ErrorEventArgs e)
{
StatusMessage = e.Message;
StatusColor = Colors.Red;
if(!Indeterminate) return;
Indeterminate = false;
Progress = 0;
}
internal void OnSetIndeterminateProgress(object sender, EventArgs e) internal void OnSetIndeterminateProgress(object sender, EventArgs e)
{ {
Indeterminate = true; Indeterminate = true;

View File

@@ -25,7 +25,6 @@
using Avalonia; using Avalonia;
using Avalonia.Logging; using Avalonia.Logging;
using Avalonia.ReactiveUI;
namespace RomRepoMgr; namespace RomRepoMgr;
@@ -39,6 +38,5 @@ internal static class Program
// Avalonia configuration, don't remove; also used by visual designer. // Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>() public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>()
.UsePlatformDetect() .UsePlatformDetect()
.LogToTrace(LogEventLevel.Debug) .LogToTrace(LogEventLevel.Debug);
.UseReactiveUI();
} }

View File

@@ -19,9 +19,9 @@
<PackageReference Include="Avalonia.Controls.DataGrid"/> <PackageReference Include="Avalonia.Controls.DataGrid"/>
<PackageReference Include="Avalonia.Desktop"/> <PackageReference Include="Avalonia.Desktop"/>
<PackageReference Include="Avalonia.Diagnostics"/> <PackageReference Include="Avalonia.Diagnostics"/>
<PackageReference Include="Avalonia.ReactiveUI"/>
<PackageReference Include="Avalonia.Svg.Skia"/> <PackageReference Include="Avalonia.Svg.Skia"/>
<PackageReference Include="Avalonia.Themes.Fluent"/> <PackageReference Include="Avalonia.Themes.Fluent"/>
<PackageReference Include="CommunityToolkit.Mvvm"/>
<PackageReference Include="MessageBox.Avalonia"/> <PackageReference Include="MessageBox.Avalonia"/>
<PackageReference Include="AsyncFixer"/> <PackageReference Include="AsyncFixer"/>
<PackageReference Include="ErrorProne.NET.CoreAnalyzers"/> <PackageReference Include="ErrorProne.NET.CoreAnalyzers"/>

View File

@@ -26,20 +26,22 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reactive;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.Models; using RomRepoMgr.Core.Models;
using RomRepoMgr.Views; using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class AboutViewModel : ViewModelBase public sealed partial class AboutViewModel : ViewModelBase
{ {
readonly About _view; readonly About _view;
string _versionText; [ObservableProperty]
string _versionText;
public AboutViewModel() public AboutViewModel()
{ {
@@ -57,26 +59,20 @@ public sealed class AboutViewModel : ViewModelBase
public string SuiteName => "ROM Repository Manager"; public string SuiteName => "ROM Repository Manager";
public string Copyright => "© 2020-2024 Natalia Portillo"; public string Copyright => "© 2020-2024 Natalia Portillo";
public string Website => "https://www.claunia.com"; public string Website => "https://www.claunia.com";
public ReactiveCommand<Unit, Unit> WebsiteCommand { get; private set; } public ICommand WebsiteCommand { get; private set; }
public ReactiveCommand<Unit, Unit> LicenseCommand { get; private set; } public ICommand LicenseCommand { get; private set; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; private set; } public ICommand CloseCommand { get; private set; }
public ObservableCollection<AssemblyModel> Assemblies { get; private set; } public ObservableCollection<AssemblyModel> Assemblies { get; private set; }
public string VersionText
{
get => _versionText;
private set => this.RaiseAndSetIfChanged(ref _versionText, value);
}
void LoadData() void LoadData()
{ {
VersionText = VersionText =
(Attribute.GetCustomAttribute(typeof(App).Assembly, typeof(AssemblyInformationalVersionAttribute)) as (Attribute.GetCustomAttribute(typeof(App).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion; AssemblyInformationalVersionAttribute)?.InformationalVersion;
WebsiteCommand = ReactiveCommand.Create(ExecuteWebsiteCommand); WebsiteCommand = new RelayCommand(ExecuteWebsiteCommand);
LicenseCommand = ReactiveCommand.Create(ExecuteLicenseCommand); LicenseCommand = new RelayCommand(ExecuteLicenseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
Assemblies = []; Assemblies = [];

View File

@@ -24,9 +24,10 @@
*******************************************************************************/ *******************************************************************************/
using System; using System;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using ReactiveUI; using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Models; using RomRepoMgr.Core.Models;
using RomRepoMgr.Database; using RomRepoMgr.Database;
@@ -35,7 +36,7 @@ using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public class EditDatViewModel : ViewModelBase public partial class EditDatViewModel : ViewModelBase
{ {
readonly RomSetModel _romSet; readonly RomSetModel _romSet;
readonly EditDat _view; readonly EditDat _view;
@@ -45,9 +46,10 @@ public class EditDatViewModel : ViewModelBase
string _date; string _date;
string _description; string _description;
string _homepage; string _homepage;
bool _modified; [ObservableProperty]
string _name; bool _modified;
string _version; string _name;
string _version;
// Mock // Mock
public EditDatViewModel() public EditDatViewModel()
@@ -96,26 +98,20 @@ public class EditDatViewModel : ViewModelBase
_date = romSet.Date; _date = romSet.Date;
_description = romSet.Description; _description = romSet.Description;
_homepage = romSet.Homepage; _homepage = romSet.Homepage;
SaveCommand = ReactiveCommand.CreateFromTask(ExecuteSaveCommandAsync); SaveCommand = new AsyncRelayCommand(ExecuteSaveCommandAsync);
CancelCommand = ReactiveCommand.Create(ExecuteCloseCommand); CancelCommand = new RelayCommand(ExecuteCloseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
} }
public ReactiveCommand<Unit, Unit> SaveCommand { get; } public ICommand SaveCommand { get; }
public ReactiveCommand<Unit, Unit> CancelCommand { get; } public ICommand CancelCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; } public ICommand CloseCommand { get; }
public long TotalMachines => _romSet.TotalMachines; public long TotalMachines => _romSet.TotalMachines;
public long CompleteMachines => _romSet.CompleteMachines; public long CompleteMachines => _romSet.CompleteMachines;
public long IncompleteMachines => _romSet.IncompleteMachines; public long IncompleteMachines => _romSet.IncompleteMachines;
public long TotalRoms => _romSet.TotalRoms; public long TotalRoms => _romSet.TotalRoms;
public long HaveRoms => _romSet.HaveRoms; public long HaveRoms => _romSet.HaveRoms;
public long MissRoms => _romSet.MissRoms; public long MissRoms => _romSet.MissRoms;
public bool Modified
{
get => _modified;
set => this.RaiseAndSetIfChanged(ref _modified, value);
}
public string Name public string Name
{ {
@@ -124,7 +120,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _name) Modified = true; if(value != _name) Modified = true;
this.RaiseAndSetIfChanged(ref _name, value); SetProperty(ref _name, value);
} }
} }
@@ -135,7 +131,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _version) Modified = true; if(value != _version) Modified = true;
this.RaiseAndSetIfChanged(ref _version, value); SetProperty(ref _version, value);
} }
} }
@@ -146,7 +142,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _author) Modified = true; if(value != _author) Modified = true;
this.RaiseAndSetIfChanged(ref _author, value); SetProperty(ref _author, value);
} }
} }
@@ -157,7 +153,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _comment) Modified = true; if(value != _comment) Modified = true;
this.RaiseAndSetIfChanged(ref _comment, value); SetProperty(ref _comment, value);
} }
} }
@@ -168,7 +164,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _category) Modified = true; if(value != _category) Modified = true;
this.RaiseAndSetIfChanged(ref _category, value); SetProperty(ref _category, value);
} }
} }
@@ -179,7 +175,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _date) Modified = true; if(value != _date) Modified = true;
this.RaiseAndSetIfChanged(ref _date, value); SetProperty(ref _date, value);
} }
} }
@@ -190,7 +186,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _description) Modified = true; if(value != _description) Modified = true;
this.RaiseAndSetIfChanged(ref _description, value); SetProperty(ref _description, value);
} }
} }
@@ -201,7 +197,7 @@ public class EditDatViewModel : ViewModelBase
{ {
if(value != _homepage) Modified = true; if(value != _homepage) Modified = true;
this.RaiseAndSetIfChanged(ref _homepage, value); SetProperty(ref _homepage, value);
} }
} }

View File

@@ -24,10 +24,11 @@
*******************************************************************************/ *******************************************************************************/
using System.IO; using System.IO;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core; using RomRepoMgr.Core;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
@@ -37,17 +38,22 @@ using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class ExportDatViewModel : ViewModelBase public sealed partial class ExportDatViewModel : ViewModelBase
{ {
readonly string _datHash; readonly string _datHash;
readonly string _outPath; readonly string _outPath;
readonly ExportDat _view; readonly ExportDat _view;
readonly Compression _worker; readonly Compression _worker;
bool _canClose; [ObservableProperty]
string _errorMessage; bool _canClose;
bool _errorVisible; [ObservableProperty]
bool _progressVisible; string _errorMessage;
string _statusMessage; [ObservableProperty]
bool _errorVisible;
[ObservableProperty]
bool _progressVisible;
[ObservableProperty]
string _statusMessage;
// Mock // Mock
public ExportDatViewModel() {} public ExportDatViewModel() {}
@@ -57,7 +63,7 @@ public sealed class ExportDatViewModel : ViewModelBase
_view = view; _view = view;
_datHash = datHash; _datHash = datHash;
_outPath = outPath; _outPath = outPath;
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
ProgressVisible = false; ProgressVisible = false;
ErrorVisible = false; ErrorVisible = false;
_worker = new Compression(); _worker = new Compression();
@@ -65,37 +71,7 @@ public sealed class ExportDatViewModel : ViewModelBase
_worker.FailedWithText += OnWorkerOnFailedWithText; _worker.FailedWithText += OnWorkerOnFailedWithText;
} }
public string StatusMessage public ICommand CloseCommand { get; }
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public bool ErrorVisible
{
get => _errorVisible;
set => this.RaiseAndSetIfChanged(ref _errorVisible, value);
}
public string ErrorMessage
{
get => _errorMessage;
set => this.RaiseAndSetIfChanged(ref _errorMessage, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
void OnWorkerOnFinishedWithText(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() => void OnWorkerOnFinishedWithText(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() =>
{ {

View File

@@ -24,39 +24,59 @@
*******************************************************************************/ *******************************************************************************/
using System; using System;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
using RomRepoMgr.Views; using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class ExportRomsViewModel : ViewModelBase public sealed partial class ExportRomsViewModel : ViewModelBase
{ {
readonly long _romSetId; readonly long _romSetId;
readonly ExportRoms _view; readonly ExportRoms _view;
bool _canClose; [ObservableProperty]
bool _progress2IsIndeterminate; bool _canClose;
double _progress2Maximum; [ObservableProperty]
double _progress2Minimum; bool _progress2IsIndeterminate;
double _progress2Value; [ObservableProperty]
bool _progress2Visible; double _progress2Maximum;
bool _progress3IsIndeterminate; [ObservableProperty]
double _progress3Maximum; double _progress2Minimum;
double _progress3Minimum; [ObservableProperty]
double _progress3Value; double _progress2Value;
bool _progress3Visible; [ObservableProperty]
bool _progressIsIndeterminate; bool _progress2Visible;
double _progressMaximum; [ObservableProperty]
double _progressMinimum; bool _progress3IsIndeterminate;
double _progressValue; [ObservableProperty]
bool _progressVisible; double _progress3Maximum;
string _status2Message; [ObservableProperty]
string _status3Message; double _progress3Minimum;
string _statusMessage; [ObservableProperty]
double _progress3Value;
[ObservableProperty]
bool _progress3Visible;
[ObservableProperty]
bool _progressIsIndeterminate;
[ObservableProperty]
double _progressMaximum;
[ObservableProperty]
double _progressMinimum;
[ObservableProperty]
double _progressValue;
[ObservableProperty]
bool _progressVisible;
[ObservableProperty]
string _status2Message;
[ObservableProperty]
string _status3Message;
[ObservableProperty]
string _statusMessage;
// Mock // Mock
public ExportRomsViewModel() public ExportRomsViewModel()
@@ -71,127 +91,12 @@ public sealed class ExportRomsViewModel : ViewModelBase
_view = view; _view = view;
_romSetId = romSetId; _romSetId = romSetId;
FolderPath = folderPath; FolderPath = folderPath;
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
CanClose = false; CanClose = false;
} }
public string FolderPath { get; } public string FolderPath { get; }
public ICommand CloseCommand { get; }
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public double ProgressMinimum
{
get => _progressMinimum;
set => this.RaiseAndSetIfChanged(ref _progressMinimum, value);
}
public double ProgressMaximum
{
get => _progressMaximum;
set => this.RaiseAndSetIfChanged(ref _progressMaximum, value);
}
public double ProgressValue
{
get => _progressValue;
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
}
public bool ProgressIsIndeterminate
{
get => _progressIsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progressIsIndeterminate, value);
}
public bool Progress2Visible
{
get => _progress2Visible;
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
}
public string Status2Message
{
get => _status2Message;
set => this.RaiseAndSetIfChanged(ref _status2Message, value);
}
public double Progress2Minimum
{
get => _progress2Minimum;
set => this.RaiseAndSetIfChanged(ref _progress2Minimum, value);
}
public double Progress2Maximum
{
get => _progress2Maximum;
set => this.RaiseAndSetIfChanged(ref _progress2Maximum, value);
}
public double Progress2Value
{
get => _progress2Value;
set => this.RaiseAndSetIfChanged(ref _progress2Value, value);
}
public bool Progress2IsIndeterminate
{
get => _progress2IsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progress2IsIndeterminate, value);
}
public bool Progress3Visible
{
get => _progress3Visible;
set => this.RaiseAndSetIfChanged(ref _progress3Visible, value);
}
public string Status3Message
{
get => _status3Message;
set => this.RaiseAndSetIfChanged(ref _status3Message, value);
}
public double Progress3Minimum
{
get => _progress3Minimum;
set => this.RaiseAndSetIfChanged(ref _progress3Minimum, value);
}
public double Progress3Maximum
{
get => _progress3Maximum;
set => this.RaiseAndSetIfChanged(ref _progress3Maximum, value);
}
public double Progress3Value
{
get => _progress3Value;
set => this.RaiseAndSetIfChanged(ref _progress3Value, value);
}
public bool Progress3IsIndeterminate
{
get => _progress3IsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progress3IsIndeterminate, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
void ExecuteCloseCommand() => _view.Close(); void ExecuteCloseCommand() => _view.Close();

View File

@@ -4,75 +4,70 @@ using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Models; using RomRepoMgr.Models;
using RomRepoMgr.Resources; using RomRepoMgr.Resources;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public class ImportDatFolderViewModel : ViewModelBase public sealed partial class ImportDatFolderViewModel : ViewModelBase
{ {
readonly Stopwatch _stopwatch = new(); readonly Stopwatch _stopwatch = new();
bool _allFilesChecked; bool _allFilesChecked;
bool _canClose; [ObservableProperty]
bool _canStart; bool _canClose;
string _category; [ObservableProperty]
string[] _datFiles; bool _canStart;
string _folderPath; [ObservableProperty]
bool _isImporting; string _category;
bool _isReady; string[] _datFiles;
int _listPosition; [ObservableProperty]
bool _progressIsIndeterminate; string _folderPath;
double _progressMaximum; [ObservableProperty]
double _progressMinimum; bool _isImporting;
double _progressValue; [ObservableProperty]
bool _progressVisible; bool _isReady;
bool _recursiveChecked; int _listPosition;
string _statusMessage; [ObservableProperty]
int _workers; bool _progressIsIndeterminate;
[ObservableProperty]
double _progressMaximum;
[ObservableProperty]
double _progressMinimum;
[ObservableProperty]
double _progressValue;
[ObservableProperty]
bool _progressVisible;
bool _recursiveChecked;
[ObservableProperty]
string _statusMessage;
int _workers;
public ImportDatFolderViewModel() public ImportDatFolderViewModel()
{ {
CanClose = true; CanClose = true;
IsReady = true; IsReady = true;
SelectFolderCommand = ReactiveCommand.CreateFromTask(SelectFolderAsync); SelectFolderCommand = new AsyncRelayCommand(SelectFolderAsync);
CloseCommand = ReactiveCommand.Create(Close); CloseCommand = new RelayCommand(Close);
StartCommand = ReactiveCommand.Create(Start); StartCommand = new RelayCommand(Start);
} }
public ReactiveCommand<Unit, Unit> SelectFolderCommand { get; } public ICommand SelectFolderCommand { get; }
public Window View { get; init; } public Window View { get; init; }
public bool IsReady
{
get => _isReady;
set => this.RaiseAndSetIfChanged(ref _isReady, value);
}
public string FolderPath
{
get => _folderPath;
set => this.RaiseAndSetIfChanged(ref _folderPath, value);
}
public string Category
{
get => _category;
set => this.RaiseAndSetIfChanged(ref _category, value);
}
public bool AllFilesChecked public bool AllFilesChecked
{ {
get => _allFilesChecked; get => _allFilesChecked;
set set
{ {
this.RaiseAndSetIfChanged(ref _allFilesChecked, value); SetProperty(ref _allFilesChecked, value);
RefreshFiles(); RefreshFiles();
} }
} }
@@ -82,67 +77,13 @@ public class ImportDatFolderViewModel : ViewModelBase
get => _recursiveChecked; get => _recursiveChecked;
set set
{ {
this.RaiseAndSetIfChanged(ref _recursiveChecked, value); SetProperty(ref _recursiveChecked, value);
RefreshFiles(); RefreshFiles();
} }
} }
public bool ProgressVisible public ICommand CloseCommand { get; }
{ public ICommand StartCommand { get; }
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public bool ProgressIsIndeterminate
{
get => _progressIsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progressIsIndeterminate, value);
}
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public bool CanStart
{
get => _canStart;
set => this.RaiseAndSetIfChanged(ref _canStart, value);
}
public double ProgressMinimum
{
get => _progressMinimum;
set => this.RaiseAndSetIfChanged(ref _progressMinimum, value);
}
public double ProgressMaximum
{
get => _progressMaximum;
set => this.RaiseAndSetIfChanged(ref _progressMaximum, value);
}
public double ProgressValue
{
get => _progressValue;
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
}
public bool IsImporting
{
get => _isImporting;
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
}
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ReactiveCommand<Unit, Unit> StartCommand { get; }
public ObservableCollection<DatImporter> Importers { get; } = []; public ObservableCollection<DatImporter> Importers { get; } = [];
void Start() void Start()

View File

@@ -24,29 +24,39 @@
*******************************************************************************/ *******************************************************************************/
using System; using System;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
using RomRepoMgr.Views; using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class ImportDatViewModel : ViewModelBase public sealed partial class ImportDatViewModel : ViewModelBase
{ {
readonly ImportDat _view; readonly ImportDat _view;
readonly DatImporter _worker; readonly DatImporter _worker;
bool _canClose; [ObservableProperty]
double _currentValue; bool _canClose;
string _errorMessage; [ObservableProperty]
bool _errorVisible; double _currentValue;
bool _indeterminateProgress; [ObservableProperty]
double _maximumValue; string _errorMessage;
double _minimumValue; [ObservableProperty]
bool _progressVisible; bool _errorVisible;
string _statusMessage; [ObservableProperty]
bool _indeterminateProgress;
[ObservableProperty]
double _maximumValue;
[ObservableProperty]
double _minimumValue;
[ObservableProperty]
bool _progressVisible;
[ObservableProperty]
string _statusMessage;
// Mock // Mock
public ImportDatViewModel() {} public ImportDatViewModel() {}
@@ -54,7 +64,7 @@ public sealed class ImportDatViewModel : ViewModelBase
public ImportDatViewModel(ImportDat view, string datPath) public ImportDatViewModel(ImportDat view, string datPath)
{ {
_view = view; _view = view;
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
IndeterminateProgress = true; IndeterminateProgress = true;
ProgressVisible = false; ProgressVisible = false;
ErrorVisible = false; ErrorVisible = false;
@@ -67,61 +77,7 @@ public sealed class ImportDatViewModel : ViewModelBase
_worker.WorkFinished += OnWorkerOnWorkFinished; _worker.WorkFinished += OnWorkerOnWorkFinished;
} }
public string StatusMessage public ICommand CloseCommand { get; }
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public bool IndeterminateProgress
{
get => _indeterminateProgress;
set => this.RaiseAndSetIfChanged(ref _indeterminateProgress, value);
}
public double MaximumValue
{
get => _maximumValue;
set => this.RaiseAndSetIfChanged(ref _maximumValue, value);
}
public double MinimumValue
{
get => _minimumValue;
set => this.RaiseAndSetIfChanged(ref _minimumValue, value);
}
public double CurrentValue
{
get => _currentValue;
set => this.RaiseAndSetIfChanged(ref _currentValue, value);
}
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public bool ErrorVisible
{
get => _errorVisible;
set => this.RaiseAndSetIfChanged(ref _errorVisible, value);
}
public string ErrorMessage
{
get => _errorMessage;
set => this.RaiseAndSetIfChanged(ref _errorMessage, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
void OnWorkerOnWorkFinished(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() => void OnWorkerOnWorkFinished(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() =>
{ {

View File

@@ -1,15 +1,17 @@
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reactive;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
using RomRepoMgr.Database; using RomRepoMgr.Database;
@@ -19,44 +21,65 @@ using RomRepoMgr.Resources;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public class ImportRomFolderViewModel : ViewModelBase public sealed partial class ImportRomFolderViewModel : ViewModelBase
{ {
readonly Context _ctx = Context.Create(Settings.Settings.Current.DatabasePath); readonly Context _ctx = Context.Create(Settings.Settings.Current.DatabasePath);
readonly ConcurrentBag<DbDisk> _newDisks = []; readonly ConcurrentBag<DbDisk> _newDisks = [];
readonly ConcurrentBag<DbFile> _newFiles = []; readonly ConcurrentBag<DbFile> _newFiles = [];
readonly ConcurrentBag<DbMedia> _newMedias = []; readonly ConcurrentBag<DbMedia> _newMedias = [];
readonly Stopwatch _stopwatch = new(); readonly Stopwatch _stopwatch = new();
bool _canClose; [ObservableProperty]
bool _canStart; bool _canClose;
string _folderPath; [ObservableProperty]
bool _isImporting; bool _canStart;
bool _isReady; [ObservableProperty]
bool _knownOnlyChecked; string _folderPath;
int _listPosition; [ObservableProperty]
bool _progress2IsIndeterminate; bool _isImporting;
double _progress2Maximum; [ObservableProperty]
double _progress2Minimum; bool _isReady;
double _progress2Value; [ObservableProperty]
bool _progress2Visible; bool _knownOnlyChecked;
bool _progressIsIndeterminate; int _listPosition;
double _progressMaximum; [ObservableProperty]
double _progressMinimum; bool _progress2IsIndeterminate;
double _progressValue; [ObservableProperty]
bool _progressVisible; double _progress2Maximum;
bool _recurseArchivesChecked; [ObservableProperty]
bool _removeFilesChecked; double _progress2Minimum;
bool _removeFilesEnabled; [ObservableProperty]
FileImporter _rootImporter; double _progress2Value;
string _statusMessage; [ObservableProperty]
string _statusMessage2; bool _progress2Visible;
bool _statusMessage2Visible; [ObservableProperty]
bool _progressIsIndeterminate;
[ObservableProperty]
double _progressMaximum;
[ObservableProperty]
double _progressMinimum;
[ObservableProperty]
double _progressValue;
[ObservableProperty]
bool _progressVisible;
bool _recurseArchivesChecked;
[ObservableProperty]
bool _removeFilesChecked;
[ObservableProperty]
bool _removeFilesEnabled;
FileImporter _rootImporter;
[ObservableProperty]
string _statusMessage;
[ObservableProperty]
string _statusMessage2;
[ObservableProperty]
bool _statusMessage2Visible;
public ImportRomFolderViewModel() public ImportRomFolderViewModel()
{ {
SelectFolderCommand = ReactiveCommand.CreateFromTask(SelectFolderAsync); SelectFolderCommand = new AsyncRelayCommand(SelectFolderAsync);
CloseCommand = ReactiveCommand.Create(Close); CloseCommand = new RelayCommand(Close);
StartCommand = ReactiveCommand.Create(Start); StartCommand = new RelayCommand(Start);
CanClose = true; CanClose = true;
RemoveFilesChecked = false; RemoveFilesChecked = false;
KnownOnlyChecked = true; KnownOnlyChecked = true;
@@ -64,31 +87,13 @@ public class ImportRomFolderViewModel : ViewModelBase
RemoveFilesEnabled = false; RemoveFilesEnabled = false;
} }
public ReactiveCommand<Unit, Unit> SelectFolderCommand { get; } public ICommand SelectFolderCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; } public ICommand CloseCommand { get; }
public ReactiveCommand<Unit, Unit> StartCommand { get; } public ICommand StartCommand { get; }
public Window View { get; init; } public Window View { get; init; }
public bool RecurseArchivesEnabled => Settings.Settings.UnArUsable; public bool RecurseArchivesEnabled => Settings.Settings.UnArUsable;
public bool RemoveFilesChecked
{
get => _removeFilesChecked;
set => this.RaiseAndSetIfChanged(ref _removeFilesChecked, value);
}
public bool KnownOnlyChecked
{
get => _knownOnlyChecked;
set => this.RaiseAndSetIfChanged(ref _knownOnlyChecked, value);
}
public bool RemoveFilesEnabled
{
get => _removeFilesEnabled;
set => this.RaiseAndSetIfChanged(ref _removeFilesEnabled, value);
}
public bool RecurseArchivesChecked public bool RecurseArchivesChecked
{ {
get => _recurseArchivesChecked; get => _recurseArchivesChecked;
@@ -97,119 +102,10 @@ public class ImportRomFolderViewModel : ViewModelBase
if(value) RemoveFilesChecked = false; if(value) RemoveFilesChecked = false;
RemoveFilesEnabled = !value; RemoveFilesEnabled = !value;
this.RaiseAndSetIfChanged(ref _recurseArchivesChecked, value); SetProperty(ref _recurseArchivesChecked, value);
} }
} }
public bool IsReady
{
get => _isReady;
set => this.RaiseAndSetIfChanged(ref _isReady, value);
}
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public double ProgressMinimum
{
get => _progressMinimum;
set => this.RaiseAndSetIfChanged(ref _progressMinimum, value);
}
public double ProgressMaximum
{
get => _progressMaximum;
set => this.RaiseAndSetIfChanged(ref _progressMaximum, value);
}
public double ProgressValue
{
get => _progressValue;
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
}
public bool ProgressIsIndeterminate
{
get => _progressIsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progressIsIndeterminate, value);
}
public bool Progress2Visible
{
get => _progress2Visible;
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
}
public bool StatusMessage2Visible
{
get => _statusMessage2Visible;
set => this.RaiseAndSetIfChanged(ref _statusMessage2Visible, value);
}
public string StatusMessage2
{
get => _statusMessage2;
set => this.RaiseAndSetIfChanged(ref _statusMessage2, value);
}
public double Progress2Minimum
{
get => _progress2Minimum;
set => this.RaiseAndSetIfChanged(ref _progress2Minimum, value);
}
public double Progress2Maximum
{
get => _progress2Maximum;
set => this.RaiseAndSetIfChanged(ref _progress2Maximum, value);
}
public double Progress2Value
{
get => _progress2Value;
set => this.RaiseAndSetIfChanged(ref _progress2Value, value);
}
public bool Progress2IsIndeterminate
{
get => _progress2IsIndeterminate;
set => this.RaiseAndSetIfChanged(ref _progress2IsIndeterminate, value);
}
public string FolderPath
{
get => _folderPath;
set => this.RaiseAndSetIfChanged(ref _folderPath, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public bool CanStart
{
get => _canStart;
set => this.RaiseAndSetIfChanged(ref _canStart, value);
}
public bool IsImporting
{
get => _isImporting;
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
}
public ObservableCollection<RomImporter> Importers { get; } = []; public ObservableCollection<RomImporter> Importers { get; } = [];
void Start() void Start()

View File

@@ -28,16 +28,17 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MsBox.Avalonia; using MsBox.Avalonia;
using MsBox.Avalonia.Enums; using MsBox.Avalonia.Enums;
using ReactiveUI;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Filesystem; using RomRepoMgr.Core.Filesystem;
using RomRepoMgr.Core.Models; using RomRepoMgr.Core.Models;
@@ -46,11 +47,13 @@ using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public class MainWindowViewModel : ViewModelBase public sealed partial class MainWindowViewModel : ViewModelBase
{ {
readonly MainWindow _view; readonly MainWindow _view;
RomSetModel _selectedRomSet; [ObservableProperty]
Vfs _vfs; RomSetModel _selectedRomSet;
[ObservableProperty]
Vfs _vfs;
// Mock // Mock
public MainWindowViewModel() {} public MainWindowViewModel() {}
@@ -58,19 +61,19 @@ public class MainWindowViewModel : ViewModelBase
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets) public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
{ {
_view = view; _view = view;
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand); ExitCommand = new RelayCommand(ExecuteExitCommand);
SettingsCommand = ReactiveCommand.CreateFromTask(ExecuteSettingsCommandAsync); SettingsCommand = new AsyncRelayCommand(ExecuteSettingsCommandAsync);
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand); AboutCommand = new RelayCommand(ExecuteAboutCommand);
ImportDatCommand = ReactiveCommand.CreateFromTask(ExecuteImportDatCommandAsync); ImportDatCommand = new AsyncRelayCommand(ExecuteImportDatCommandAsync);
ImportDatFolderCommand = ReactiveCommand.CreateFromTask(ExecuteImportDatFolderCommandAsync); ImportDatFolderCommand = new AsyncRelayCommand(ExecuteImportDatFolderCommandAsync);
ImportRomFolderCommand = ReactiveCommand.CreateFromTask(ExecuteImportRomFolderCommandAsync); ImportRomFolderCommand = new AsyncRelayCommand(ExecuteImportRomFolderCommandAsync);
DeleteRomSetCommand = ReactiveCommand.CreateFromTask(ExecuteDeleteRomSetCommandAsync); DeleteRomSetCommand = new AsyncRelayCommand(ExecuteDeleteRomSetCommandAsync);
EditRomSetCommand = ReactiveCommand.Create(ExecuteEditRomSetCommand); EditRomSetCommand = new RelayCommand(ExecuteEditRomSetCommand);
ExportDatCommand = ReactiveCommand.CreateFromTask(ExecuteExportDatCommandAsync); ExportDatCommand = new AsyncRelayCommand(ExecuteExportDatCommandAsync);
ExportRomsCommand = ReactiveCommand.CreateFromTask(ExecuteExportRomsCommandAsync); ExportRomsCommand = new AsyncRelayCommand(ExecuteExportRomsCommandAsync);
MountCommand = ReactiveCommand.CreateFromTask(ExecuteMountCommandAsync); MountCommand = new AsyncRelayCommand(ExecuteMountCommandAsync);
UmountCommand = ReactiveCommand.Create(ExecuteUmountCommand); UmountCommand = new RelayCommand(ExecuteUmountCommand);
UpdateStatsCommand = ReactiveCommand.CreateFromTask(ExecuteUpdateStatsCommandAsync); UpdateStatsCommand = new AsyncRelayCommand(ExecuteUpdateStatsCommandAsync);
RomSets = new ObservableCollection<RomSetModel>(romSets); RomSets = new ObservableCollection<RomSetModel>(romSets);
} }
@@ -81,31 +84,19 @@ public class MainWindowViewModel : ViewModelBase
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow); IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public ReactiveCommand<Unit, Unit> AboutCommand { get; } public ICommand AboutCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; } public ICommand ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; } public ICommand SettingsCommand { get; }
public ReactiveCommand<Unit, Unit> ImportDatCommand { get; } public ICommand ImportDatCommand { get; }
public ReactiveCommand<Unit, Unit> ImportDatFolderCommand { get; } public ICommand ImportDatFolderCommand { get; }
public ReactiveCommand<Unit, Unit> ImportRomFolderCommand { get; } public ICommand ImportRomFolderCommand { get; }
public ReactiveCommand<Unit, Unit> DeleteRomSetCommand { get; } public ICommand DeleteRomSetCommand { get; }
public ReactiveCommand<Unit, Unit> EditRomSetCommand { get; } public ICommand EditRomSetCommand { get; }
public ReactiveCommand<Unit, Unit> ExportDatCommand { get; } public ICommand ExportDatCommand { get; }
public ReactiveCommand<Unit, Unit> ExportRomsCommand { get; } public ICommand ExportRomsCommand { get; }
public ReactiveCommand<Unit, Unit> MountCommand { get; } public ICommand MountCommand { get; }
public ReactiveCommand<Unit, Unit> UmountCommand { get; } public ICommand UmountCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateStatsCommand { get; } public ICommand UpdateStatsCommand { get; }
public Vfs Vfs
{
get => _vfs;
set => this.RaiseAndSetIfChanged(ref _vfs, value);
}
public RomSetModel SelectedRomSet
{
get => _selectedRomSet;
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
}
internal Task ExecuteSettingsCommandAsync() internal Task ExecuteSettingsCommandAsync()
{ {

View File

@@ -26,7 +26,7 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
using RomRepoMgr.Core; using RomRepoMgr.Core;
using RomRepoMgr.Database; using RomRepoMgr.Database;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
@@ -35,11 +35,12 @@ using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class RemoveDatViewModel : ViewModelBase public sealed partial class RemoveDatViewModel : ViewModelBase
{ {
readonly long _romSetId; readonly long _romSetId;
readonly RemoveDat _view; readonly RemoveDat _view;
string _statusMessage; [ObservableProperty]
string _statusMessage;
// Mock // Mock
public RemoveDatViewModel() {} public RemoveDatViewModel() {}
@@ -50,12 +51,6 @@ public sealed class RemoveDatViewModel : ViewModelBase
_romSetId = romSetId; _romSetId = romSetId;
} }
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
internal void OnOpened() internal void OnOpened()
{ {
_ = Task.Run(() => _ = Task.Run(() =>

View File

@@ -26,14 +26,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using MsBox.Avalonia; using MsBox.Avalonia;
using MsBox.Avalonia.Enums; using MsBox.Avalonia.Enums;
using ReactiveUI;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
using RomRepoMgr.Database; using RomRepoMgr.Database;
@@ -43,7 +44,7 @@ using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class SettingsViewModel : ViewModelBase public sealed partial class SettingsViewModel : ViewModelBase
{ {
readonly SettingsDialog _view; readonly SettingsDialog _view;
bool _databaseChanged; bool _databaseChanged;
@@ -53,8 +54,10 @@ public sealed class SettingsViewModel : ViewModelBase
bool _temporaryChanged; bool _temporaryChanged;
string _temporaryPath; string _temporaryPath;
bool _unArChanged; bool _unArChanged;
string _unArPath; [ObservableProperty]
string _unArVersion; string _unArPath;
[ObservableProperty]
string _unArVersion;
// Mock // Mock
public SettingsViewModel() {} public SettingsViewModel() {}
@@ -67,12 +70,12 @@ public sealed class SettingsViewModel : ViewModelBase
_temporaryChanged = false; _temporaryChanged = false;
_unArChanged = false; _unArChanged = false;
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
UnArCommand = ReactiveCommand.CreateFromTask(ExecuteUnArCommandAsync); UnArCommand = new AsyncRelayCommand(ExecuteUnArCommandAsync);
TemporaryCommand = ReactiveCommand.CreateFromTask(ExecuteTemporaryCommandAsync); TemporaryCommand = new AsyncRelayCommand(ExecuteTemporaryCommandAsync);
RepositoryCommand = ReactiveCommand.CreateFromTask(ExecuteRepositoryCommandAsync); RepositoryCommand = new AsyncRelayCommand(ExecuteRepositoryCommandAsync);
DatabaseCommand = ReactiveCommand.CreateFromTask(ExecuteDatabaseCommandAsync); DatabaseCommand = new AsyncRelayCommand(ExecuteDatabaseCommandAsync);
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand); SaveCommand = new RelayCommand(ExecuteSaveCommand);
DatabasePath = Settings.Settings.Current.DatabasePath; DatabasePath = Settings.Settings.Current.DatabasePath;
RepositoryPath = Settings.Settings.Current.RepositoryPath; RepositoryPath = Settings.Settings.Current.RepositoryPath;
@@ -82,19 +85,19 @@ public sealed class SettingsViewModel : ViewModelBase
if(!string.IsNullOrWhiteSpace(UnArPath)) CheckUnAr(); if(!string.IsNullOrWhiteSpace(UnArPath)) CheckUnAr();
} }
public ReactiveCommand<Unit, Unit> UnArCommand { get; } public ICommand UnArCommand { get; }
public ReactiveCommand<Unit, Unit> TemporaryCommand { get; } public ICommand TemporaryCommand { get; }
public ReactiveCommand<Unit, Unit> RepositoryCommand { get; } public ICommand RepositoryCommand { get; }
public ReactiveCommand<Unit, Unit> DatabaseCommand { get; } public ICommand DatabaseCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; } public ICommand CloseCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; } public ICommand SaveCommand { get; }
public string DatabasePath public string DatabasePath
{ {
get => _databasePath; get => _databasePath;
set set
{ {
this.RaiseAndSetIfChanged(ref _databasePath, value); SetProperty(ref _databasePath, value);
_databaseChanged = true; _databaseChanged = true;
} }
} }
@@ -104,7 +107,7 @@ public sealed class SettingsViewModel : ViewModelBase
get => _repositoryPath; get => _repositoryPath;
set set
{ {
this.RaiseAndSetIfChanged(ref _repositoryPath, value); SetProperty(ref _repositoryPath, value);
// TODO: Refresh repository existing files // TODO: Refresh repository existing files
_repositoryChanged = true; _repositoryChanged = true;
@@ -116,23 +119,11 @@ public sealed class SettingsViewModel : ViewModelBase
get => _temporaryPath; get => _temporaryPath;
set set
{ {
this.RaiseAndSetIfChanged(ref _temporaryPath, value); SetProperty(ref _temporaryPath, value);
_temporaryChanged = true; _temporaryChanged = true;
} }
} }
public string UnArPath
{
get => _unArPath;
set => this.RaiseAndSetIfChanged(ref _unArPath, value);
}
public string UnArVersion
{
get => _unArVersion;
set => this.RaiseAndSetIfChanged(ref _unArVersion, value);
}
void CheckUnAr() void CheckUnAr()
{ {
var worker = new Compression(); var worker = new Compression();

View File

@@ -26,13 +26,14 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia; using Avalonia;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using ReactiveUI;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Models; using RomRepoMgr.Core.Models;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
@@ -40,28 +41,44 @@ using RomRepoMgr.Database;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class SplashWindowViewModel : ViewModelBase public sealed partial class SplashWindowViewModel : ViewModelBase
{ {
[ObservableProperty]
bool _checkingUnArError; bool _checkingUnArError;
[ObservableProperty]
bool _checkingUnArOk; bool _checkingUnArOk;
[ObservableProperty]
bool _checkingUnArUnknown; bool _checkingUnArUnknown;
[ObservableProperty]
bool _exitVisible; bool _exitVisible;
[ObservableProperty]
bool _loadingDatabaseError; bool _loadingDatabaseError;
[ObservableProperty]
bool _loadingDatabaseOk; bool _loadingDatabaseOk;
[ObservableProperty]
bool _loadingDatabaseUnknown; bool _loadingDatabaseUnknown;
[ObservableProperty]
bool _loadingRomSetsError; bool _loadingRomSetsError;
[ObservableProperty]
bool _loadingRomSetsOk; bool _loadingRomSetsOk;
[ObservableProperty]
bool _loadingRomSetsUnknown; bool _loadingRomSetsUnknown;
[ObservableProperty]
bool _loadingSettingsError; bool _loadingSettingsError;
[ObservableProperty]
bool _loadingSettingsOk; bool _loadingSettingsOk;
[ObservableProperty]
bool _loadingSettingsUnknown; bool _loadingSettingsUnknown;
[ObservableProperty]
bool _migratingDatabaseError; bool _migratingDatabaseError;
[ObservableProperty]
bool _migratingDatabaseOk; bool _migratingDatabaseOk;
[ObservableProperty]
bool _migratingDatabaseUnknown; bool _migratingDatabaseUnknown;
public SplashWindowViewModel() public SplashWindowViewModel()
{ {
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand); ExitCommand = new RelayCommand(ExecuteExitCommand);
LoadingSettingsOk = false; LoadingSettingsOk = false;
LoadingSettingsError = false; LoadingSettingsError = false;
@@ -81,103 +98,7 @@ public sealed class SplashWindowViewModel : ViewModelBase
ExitVisible = false; ExitVisible = false;
} }
public ReactiveCommand<Unit, Unit> ExitCommand { get; } public ICommand ExitCommand { get; }
public bool LoadingSettingsOk
{
get => _loadingSettingsOk;
set => this.RaiseAndSetIfChanged(ref _loadingSettingsOk, value);
}
public bool LoadingSettingsError
{
get => _loadingSettingsError;
set => this.RaiseAndSetIfChanged(ref _loadingSettingsError, value);
}
public bool LoadingSettingsUnknown
{
get => _loadingSettingsUnknown;
set => this.RaiseAndSetIfChanged(ref _loadingSettingsUnknown, value);
}
public bool CheckingUnArOk
{
get => _checkingUnArOk;
set => this.RaiseAndSetIfChanged(ref _checkingUnArOk, value);
}
public bool CheckingUnArError
{
get => _checkingUnArError;
set => this.RaiseAndSetIfChanged(ref _checkingUnArError, value);
}
public bool CheckingUnArUnknown
{
get => _checkingUnArUnknown;
set => this.RaiseAndSetIfChanged(ref _checkingUnArUnknown, value);
}
public bool LoadingDatabaseOk
{
get => _loadingDatabaseOk;
set => this.RaiseAndSetIfChanged(ref _loadingDatabaseOk, value);
}
public bool LoadingDatabaseError
{
get => _loadingDatabaseError;
set => this.RaiseAndSetIfChanged(ref _loadingDatabaseError, value);
}
public bool LoadingDatabaseUnknown
{
get => _loadingDatabaseUnknown;
set => this.RaiseAndSetIfChanged(ref _loadingDatabaseUnknown, value);
}
public bool MigratingDatabaseOk
{
get => _migratingDatabaseOk;
set => this.RaiseAndSetIfChanged(ref _migratingDatabaseOk, value);
}
public bool MigratingDatabaseError
{
get => _migratingDatabaseError;
set => this.RaiseAndSetIfChanged(ref _migratingDatabaseError, value);
}
public bool MigratingDatabaseUnknown
{
get => _migratingDatabaseUnknown;
set => this.RaiseAndSetIfChanged(ref _migratingDatabaseUnknown, value);
}
public bool ExitVisible
{
get => _exitVisible;
set => this.RaiseAndSetIfChanged(ref _exitVisible, value);
}
public bool LoadingRomSetsOk
{
get => _loadingRomSetsOk;
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsOk, value);
}
public bool LoadingRomSetsError
{
get => _loadingRomSetsError;
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsError, value);
}
public bool LoadingRomSetsUnknown
{
get => _loadingRomSetsUnknown;
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsUnknown, value);
}
public string LoadingText => "ROM Repository Manager"; public string LoadingText => "ROM Repository Manager";

View File

@@ -26,11 +26,12 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using ReactiveUI;
using RomRepoMgr.Core.Models; using RomRepoMgr.Core.Models;
using RomRepoMgr.Database; using RomRepoMgr.Database;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
@@ -39,17 +40,25 @@ using RomRepoMgr.Views;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public sealed class UpdateStatsViewModel : ViewModelBase public sealed partial class UpdateStatsViewModel : ViewModelBase
{ {
readonly UpdateStats _view; readonly UpdateStats _view;
bool _canClose; [ObservableProperty]
double _currentValue; bool _canClose;
bool _indeterminateProgress; [ObservableProperty]
double _maximumValue; double _currentValue;
double _minimumValue; [ObservableProperty]
bool _progressVisible; bool _indeterminateProgress;
RomSetModel _selectedRomSet; [ObservableProperty]
string _statusMessage; double _maximumValue;
[ObservableProperty]
double _minimumValue;
[ObservableProperty]
bool _progressVisible;
[ObservableProperty]
RomSetModel _selectedRomSet;
[ObservableProperty]
string _statusMessage;
// Mock // Mock
public UpdateStatsViewModel() {} public UpdateStatsViewModel() {}
@@ -57,63 +66,15 @@ public sealed class UpdateStatsViewModel : ViewModelBase
public UpdateStatsViewModel(UpdateStats view) public UpdateStatsViewModel(UpdateStats view)
{ {
_view = view; _view = view;
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); CloseCommand = new RelayCommand(ExecuteCloseCommand);
IndeterminateProgress = true; IndeterminateProgress = true;
ProgressVisible = false; ProgressVisible = false;
RomSets = []; RomSets = [];
} }
public string StatusMessage
{
get => _statusMessage;
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
}
public bool IndeterminateProgress
{
get => _indeterminateProgress;
set => this.RaiseAndSetIfChanged(ref _indeterminateProgress, value);
}
public double MaximumValue
{
get => _maximumValue;
set => this.RaiseAndSetIfChanged(ref _maximumValue, value);
}
public double MinimumValue
{
get => _minimumValue;
set => this.RaiseAndSetIfChanged(ref _minimumValue, value);
}
public double CurrentValue
{
get => _currentValue;
set => this.RaiseAndSetIfChanged(ref _currentValue, value);
}
public bool ProgressVisible
{
get => _progressVisible;
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
}
public RomSetModel SelectedRomSet
{
get => _selectedRomSet;
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
}
public bool CanClose
{
get => _canClose;
set => this.RaiseAndSetIfChanged(ref _canClose, value);
}
public ObservableCollection<RomSetModel> RomSets { get; } public ObservableCollection<RomSetModel> RomSets { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; } public ICommand CloseCommand { get; }
internal void OnOpened() internal void OnOpened()
{ {

View File

@@ -23,8 +23,8 @@
// Copyright © 2020-2024 Natalia Portillo // Copyright © 2020-2024 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel;
namespace RomRepoMgr.ViewModels; namespace RomRepoMgr.ViewModels;
public class ViewModelBase : ReactiveObject {} public class ViewModelBase : ObservableObject;