diff --git a/src/nxDumpFuse/App.axaml.cs b/src/nxDumpFuse/App.axaml.cs index 5e6ce1d..13b4f35 100644 --- a/src/nxDumpFuse/App.axaml.cs +++ b/src/nxDumpFuse/App.axaml.cs @@ -2,8 +2,8 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using nxDumpFuse.Extensions; -using nxDumpFuse.Interfaces; using nxDumpFuse.ViewModels; +using nxDumpFuse.ViewModels.Interfaces; using nxDumpFuse.Views; using Splat; diff --git a/src/nxDumpFuse/DependencyInjection/Bootstrapper.cs b/src/nxDumpFuse/DependencyInjection/Bootstrapper.cs index 7b030fb..f383dcc 100644 --- a/src/nxDumpFuse/DependencyInjection/Bootstrapper.cs +++ b/src/nxDumpFuse/DependencyInjection/Bootstrapper.cs @@ -6,6 +6,7 @@ namespace nxDumpFuse.DependencyInjection { public static void Register(IMutableDependencyResolver services, IReadonlyDependencyResolver resolver) { + FuseServiceBootstrapper.RegisterFuseService(services, resolver); DialogServiceBootstrapper.RegisterDialogService(services, resolver); ViewModelBootstrapper.RegisterViewModels(services, resolver); } diff --git a/src/nxDumpFuse/DependencyInjection/DialogServiceBootstrapper.cs b/src/nxDumpFuse/DependencyInjection/DialogServiceBootstrapper.cs index 71f7e2c..d32bd7c 100644 --- a/src/nxDumpFuse/DependencyInjection/DialogServiceBootstrapper.cs +++ b/src/nxDumpFuse/DependencyInjection/DialogServiceBootstrapper.cs @@ -1,6 +1,6 @@ using nxDumpFuse.Extensions; -using nxDumpFuse.Interfaces; using nxDumpFuse.Services; +using nxDumpFuse.ViewModels.Interfaces; using Splat; namespace nxDumpFuse.DependencyInjection @@ -9,7 +9,7 @@ namespace nxDumpFuse.DependencyInjection { public static void RegisterDialogService(IMutableDependencyResolver services, IReadonlyDependencyResolver resolver) { - services.RegisterLazySingleton((() => new MainWindowProvider())); + services.RegisterLazySingleton(() => new MainWindowProvider()); services.RegisterLazySingleton(() => new DialogService( resolver.GetRequiredService())); } diff --git a/src/nxDumpFuse/DependencyInjection/FuseServiceBootstrapper.cs b/src/nxDumpFuse/DependencyInjection/FuseServiceBootstrapper.cs new file mode 100644 index 0000000..ca15ff3 --- /dev/null +++ b/src/nxDumpFuse/DependencyInjection/FuseServiceBootstrapper.cs @@ -0,0 +1,14 @@ +using nxDumpFuse.Services; +using Splat; + +namespace nxDumpFuse.DependencyInjection +{ + public static class FuseServiceBootstrapper + { + public static void RegisterFuseService(IMutableDependencyResolver services, + IReadonlyDependencyResolver resolver) + { + services.RegisterLazySingleton(() => new FuseService()); + } + } +} diff --git a/src/nxDumpFuse/DependencyInjection/ViewModelBootstrapper.cs b/src/nxDumpFuse/DependencyInjection/ViewModelBootstrapper.cs index 3745fac..e9041a6 100644 --- a/src/nxDumpFuse/DependencyInjection/ViewModelBootstrapper.cs +++ b/src/nxDumpFuse/DependencyInjection/ViewModelBootstrapper.cs @@ -1,6 +1,7 @@ using nxDumpFuse.Extensions; -using nxDumpFuse.Interfaces; +using nxDumpFuse.Services; using nxDumpFuse.ViewModels; +using nxDumpFuse.ViewModels.Interfaces; using Splat; namespace nxDumpFuse.DependencyInjection @@ -15,7 +16,8 @@ namespace nxDumpFuse.DependencyInjection )); services.RegisterLazySingleton(() => new FuseViewModel( - resolver.GetRequiredService())); + resolver.GetRequiredService(), + resolver.GetRequiredService())); services.RegisterLazySingleton(() => new AboutViewModel()); } } diff --git a/src/nxDumpFuse/MainWindowProvider.cs b/src/nxDumpFuse/MainWindowProvider.cs index 2e5f6ed..116d1c7 100644 --- a/src/nxDumpFuse/MainWindowProvider.cs +++ b/src/nxDumpFuse/MainWindowProvider.cs @@ -1,7 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; -using nxDumpFuse.Interfaces; +using nxDumpFuse.ViewModels.Interfaces; namespace nxDumpFuse { diff --git a/src/nxDumpFuse/Services/DialogService.cs b/src/nxDumpFuse/Services/DialogService.cs index 7cfc904..fba9235 100644 --- a/src/nxDumpFuse/Services/DialogService.cs +++ b/src/nxDumpFuse/Services/DialogService.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; using Avalonia.Controls; -using nxDumpFuse.Interfaces; +using nxDumpFuse.ViewModels.Interfaces; namespace nxDumpFuse.Services { diff --git a/src/nxDumpFuse/Model/Fuse.cs b/src/nxDumpFuse/Services/FuseService.cs similarity index 93% rename from src/nxDumpFuse/Model/Fuse.cs rename to src/nxDumpFuse/Services/FuseService.cs index c2bebbe..9254f26 100644 --- a/src/nxDumpFuse/Model/Fuse.cs +++ b/src/nxDumpFuse/Services/FuseService.cs @@ -6,27 +6,21 @@ using System.Threading; using System.Threading.Tasks; using nxDumpFuse.Events; using nxDumpFuse.Extensions; +using nxDumpFuse.Model; using nxDumpFuse.Model.Enums; -namespace nxDumpFuse.Model +namespace nxDumpFuse.Services { - public class Fuse + public class FuseService : IFuseService { - private readonly CancellationTokenSource _cts; - private readonly string _inputFilePath; - private readonly string _outputDir; - private string _outputFilePath = string.Empty; + private CancellationTokenSource? _cts; + private string? _inputFilePath; + private string? _outputDir; + private string? _outputFilePath; private FileCase _fileCase; private readonly Stopwatch _sw = new(); - public Fuse(string inputFilePath, string outputDir) - { - _inputFilePath = inputFilePath; - _outputDir = outputDir; - _cts = new CancellationTokenSource(); - } - public event EventHandlers.FuseUpdateEventHandler? FuseUpdateEvent; public event EventHandlers.FuseSimpleLogEventHandler? FuseSimpleLogEvent; @@ -58,8 +52,12 @@ namespace nxDumpFuse.Model OnFuseSimpleLogEvent(new FuseSimpleLog(type, DateTime.Now, message)); } - public void Start() + public void Start(string inputFilePath, string outputDir) { + _inputFilePath = inputFilePath; + _outputDir = outputDir; + _cts = new CancellationTokenSource(); + if (string.IsNullOrEmpty(_inputFilePath)) { Log(FuseSimpleLogType.Error, "Input File cannot be empty"); @@ -118,7 +116,7 @@ namespace nxDumpFuse.Model } } - private async void FuseFiles(List inputFiles) + public async void FuseFiles(List inputFiles) { var buffer = new byte[1024 * 1024]; var count = 0; diff --git a/src/nxDumpFuse/Interfaces/IDialogService.cs b/src/nxDumpFuse/Services/IDialogService.cs similarity index 89% rename from src/nxDumpFuse/Interfaces/IDialogService.cs rename to src/nxDumpFuse/Services/IDialogService.cs index 44c6834..0b1a304 100644 --- a/src/nxDumpFuse/Interfaces/IDialogService.cs +++ b/src/nxDumpFuse/Services/IDialogService.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Avalonia.Controls; -namespace nxDumpFuse.Interfaces +namespace nxDumpFuse.Services { public interface IDialogService { diff --git a/src/nxDumpFuse/Services/IFuseService.cs b/src/nxDumpFuse/Services/IFuseService.cs new file mode 100644 index 0000000..a4354f4 --- /dev/null +++ b/src/nxDumpFuse/Services/IFuseService.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using nxDumpFuse.Events; + +namespace nxDumpFuse.Services +{ + public interface IFuseService + { + public event EventHandlers.FuseUpdateEventHandler? FuseUpdateEvent; + public event EventHandlers.FuseSimpleLogEventHandler? FuseSimpleLogEvent; + + void Start(string inputFilePath, string outputDir); + + void Stop(); + + void FuseFiles(List inputFiles); + } +} diff --git a/src/nxDumpFuse/ViewModels/AboutViewModel.cs b/src/nxDumpFuse/ViewModels/AboutViewModel.cs index a970c62..22700e1 100644 --- a/src/nxDumpFuse/ViewModels/AboutViewModel.cs +++ b/src/nxDumpFuse/ViewModels/AboutViewModel.cs @@ -2,7 +2,7 @@ using System.Reactive; using System.Runtime.InteropServices; using System.Text; -using nxDumpFuse.Interfaces; +using nxDumpFuse.ViewModels.Interfaces; using ReactiveUI; namespace nxDumpFuse.ViewModels diff --git a/src/nxDumpFuse/ViewModels/FuseViewModel.cs b/src/nxDumpFuse/ViewModels/FuseViewModel.cs index 4e0c530..4349976 100644 --- a/src/nxDumpFuse/ViewModels/FuseViewModel.cs +++ b/src/nxDumpFuse/ViewModels/FuseViewModel.cs @@ -4,9 +4,10 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Reactive; using Avalonia.Controls; -using nxDumpFuse.Interfaces; using nxDumpFuse.Model; using nxDumpFuse.Model.Enums; +using nxDumpFuse.Services; +using nxDumpFuse.ViewModels.Interfaces; using ReactiveUI; namespace nxDumpFuse.ViewModels @@ -14,13 +15,15 @@ namespace nxDumpFuse.ViewModels public class FuseViewModel : ViewModelBase, IFuseViewModel { private readonly IDialogService _dialogService; - private Fuse? _fuse; + private readonly IFuseService _fuseService; private readonly Stopwatch _sw = new(); private TimeSpan _elapsed; - public FuseViewModel(IDialogService dialogService) + public FuseViewModel(IDialogService dialogService, IFuseService fuseServiceService) { _dialogService = dialogService; + _fuseService = fuseServiceService; + SelectInputFileCommand = ReactiveCommand.Create(SelectInputFile); SelectOutputFolderCommand = ReactiveCommand.Create(SelectOutputFolder); FuseCommand = ReactiveCommand.Create(FuseNxDump); @@ -100,24 +103,23 @@ namespace nxDumpFuse.ViewModels private void FuseNxDump() { - _fuse = new Fuse(InputFilePath, OutputDir); - _fuse.FuseUpdateEvent += OnFuseUpdate; - _fuse.FuseSimpleLogEvent += OnFuseSimpleLogEvent; + _fuseService.FuseUpdateEvent += OnFuseServiceUpdate; + _fuseService.FuseSimpleLogEvent += OnFuseServiceSimpleLogEvent; _sw.Start(); try { - _fuse.Start(); + _fuseService.Start(InputFilePath, OutputDir); } catch (Exception e) { _sw.Stop(); - OnFuseSimpleLogEvent(new FuseSimpleLog(FuseSimpleLogType.Error, DateTime.Now, e.Message)); + OnFuseServiceSimpleLogEvent(new FuseSimpleLog(FuseSimpleLogType.Error, DateTime.Now, e.Message)); } } private void StopDump() { _sw.Stop(); - _fuse?.Stop(); + _fuseService?.Stop(); ProgressText = string.Empty; } @@ -126,7 +128,7 @@ namespace nxDumpFuse.ViewModels LogItems.Clear(); } - private void OnFuseUpdate(FuseUpdateInfo fuseUpdateInfo) + private void OnFuseServiceUpdate(FuseUpdateInfo fuseUpdateInfo) { if (fuseUpdateInfo.Complete) { @@ -144,7 +146,7 @@ namespace nxDumpFuse.ViewModels ProgressText = $"({fuseUpdateInfo.Speed:0}MB/s) {Progress:0}% "; } - private void OnFuseSimpleLogEvent(FuseSimpleLog log) + private void OnFuseServiceSimpleLogEvent(FuseSimpleLog log) { LogItems.Add(log); } diff --git a/src/nxDumpFuse/Interfaces/IAboutViewModel.cs b/src/nxDumpFuse/ViewModels/Interfaces/IAboutViewModel.cs similarity index 53% rename from src/nxDumpFuse/Interfaces/IAboutViewModel.cs rename to src/nxDumpFuse/ViewModels/Interfaces/IAboutViewModel.cs index 0685b87..387b652 100644 --- a/src/nxDumpFuse/Interfaces/IAboutViewModel.cs +++ b/src/nxDumpFuse/ViewModels/Interfaces/IAboutViewModel.cs @@ -1,4 +1,4 @@ -namespace nxDumpFuse.Interfaces +namespace nxDumpFuse.ViewModels.Interfaces { public interface IAboutViewModel { diff --git a/src/nxDumpFuse/Interfaces/IFuseViewModel.cs b/src/nxDumpFuse/ViewModels/Interfaces/IFuseViewModel.cs similarity index 53% rename from src/nxDumpFuse/Interfaces/IFuseViewModel.cs rename to src/nxDumpFuse/ViewModels/Interfaces/IFuseViewModel.cs index addcd84..fcbdb0f 100644 --- a/src/nxDumpFuse/Interfaces/IFuseViewModel.cs +++ b/src/nxDumpFuse/ViewModels/Interfaces/IFuseViewModel.cs @@ -1,4 +1,4 @@ -namespace nxDumpFuse.Interfaces +namespace nxDumpFuse.ViewModels.Interfaces { public interface IFuseViewModel { diff --git a/src/nxDumpFuse/Interfaces/IMainWindowProvider.cs b/src/nxDumpFuse/ViewModels/Interfaces/IMainWindowProvider.cs similarity index 73% rename from src/nxDumpFuse/Interfaces/IMainWindowProvider.cs rename to src/nxDumpFuse/ViewModels/Interfaces/IMainWindowProvider.cs index 98a1de5..b20e3fd 100644 --- a/src/nxDumpFuse/Interfaces/IMainWindowProvider.cs +++ b/src/nxDumpFuse/ViewModels/Interfaces/IMainWindowProvider.cs @@ -1,6 +1,6 @@ using Avalonia.Controls; -namespace nxDumpFuse.Interfaces +namespace nxDumpFuse.ViewModels.Interfaces { public interface IMainWindowProvider { diff --git a/src/nxDumpFuse/Interfaces/IMainWindowViewModel.cs b/src/nxDumpFuse/ViewModels/Interfaces/IMainWindowViewModel.cs similarity index 55% rename from src/nxDumpFuse/Interfaces/IMainWindowViewModel.cs rename to src/nxDumpFuse/ViewModels/Interfaces/IMainWindowViewModel.cs index b10a1a0..c576519 100644 --- a/src/nxDumpFuse/Interfaces/IMainWindowViewModel.cs +++ b/src/nxDumpFuse/ViewModels/Interfaces/IMainWindowViewModel.cs @@ -1,4 +1,4 @@ -namespace nxDumpFuse.Interfaces +namespace nxDumpFuse.ViewModels.Interfaces { public interface IMainWindowViewModel { diff --git a/src/nxDumpFuse/ViewModels/MainWindowViewModel.cs b/src/nxDumpFuse/ViewModels/MainWindowViewModel.cs index 94fce6c..dbf968f 100644 --- a/src/nxDumpFuse/ViewModels/MainWindowViewModel.cs +++ b/src/nxDumpFuse/ViewModels/MainWindowViewModel.cs @@ -1,5 +1,4 @@ - -using nxDumpFuse.Interfaces; +using nxDumpFuse.ViewModels.Interfaces; namespace nxDumpFuse.ViewModels {