mirror of
https://github.com/oMaN-Rod/nxDumpFuse.git
synced 2024-11-08 11:51:49 +00:00
Convert fuse to service and inject
This commit is contained in:
parent
78557108a1
commit
c34cf7670a
17 changed files with 74 additions and 41 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<IMainWindowProvider>((() => new MainWindowProvider()));
|
||||
services.RegisterLazySingleton<IMainWindowProvider>(() => new MainWindowProvider());
|
||||
services.RegisterLazySingleton<IDialogService>(() => new DialogService(
|
||||
resolver.GetRequiredService<IMainWindowProvider>()));
|
||||
}
|
||||
|
|
|
@ -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<IFuseService>(() => new FuseService());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IFuseViewModel>(() => new FuseViewModel(
|
||||
resolver.GetRequiredService<IDialogService>()));
|
||||
resolver.GetRequiredService<IDialogService>(),
|
||||
resolver.GetRequiredService<IFuseService>()));
|
||||
services.RegisterLazySingleton<IAboutViewModel>(() => new AboutViewModel());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using nxDumpFuse.Interfaces;
|
||||
using nxDumpFuse.ViewModels.Interfaces;
|
||||
|
||||
namespace nxDumpFuse
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using nxDumpFuse.Interfaces;
|
||||
using nxDumpFuse.ViewModels.Interfaces;
|
||||
|
||||
namespace nxDumpFuse.Services
|
||||
{
|
||||
|
|
|
@ -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<string> inputFiles)
|
||||
public async void FuseFiles(List<string> inputFiles)
|
||||
{
|
||||
var buffer = new byte[1024 * 1024];
|
||||
var count = 0;
|
|
@ -1,7 +1,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace nxDumpFuse.Interfaces
|
||||
namespace nxDumpFuse.Services
|
||||
{
|
||||
public interface IDialogService
|
||||
{
|
17
src/nxDumpFuse/Services/IFuseService.cs
Normal file
17
src/nxDumpFuse/Services/IFuseService.cs
Normal file
|
@ -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<string> inputFiles);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace nxDumpFuse.Interfaces
|
||||
namespace nxDumpFuse.ViewModels.Interfaces
|
||||
{
|
||||
public interface IAboutViewModel
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace nxDumpFuse.Interfaces
|
||||
namespace nxDumpFuse.ViewModels.Interfaces
|
||||
{
|
||||
public interface IFuseViewModel
|
||||
{
|
|
@ -1,6 +1,6 @@
|
|||
using Avalonia.Controls;
|
||||
|
||||
namespace nxDumpFuse.Interfaces
|
||||
namespace nxDumpFuse.ViewModels.Interfaces
|
||||
{
|
||||
public interface IMainWindowProvider
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace nxDumpFuse.Interfaces
|
||||
namespace nxDumpFuse.ViewModels.Interfaces
|
||||
{
|
||||
public interface IMainWindowViewModel
|
||||
{
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
using nxDumpFuse.Interfaces;
|
||||
using nxDumpFuse.ViewModels.Interfaces;
|
||||
|
||||
namespace nxDumpFuse.ViewModels
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue