From 9da97bc911e83550cee3e7c152ee67957c635f4b Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sun, 8 Dec 2024 13:05:09 -0600 Subject: [PATCH] misc: chore: Collapse XCIFileTrimmerLog implementations into a single class. --- .../Common/XCIFileTrimmerMainWindowLog.cs | 24 ---------- src/Ryujinx/Common/XCIFileTrimmerWindowLog.cs | 23 ---------- src/Ryujinx/Common/XCITrimmerLog.cs | 45 +++++++++++++++++++ .../UI/ViewModels/MainWindowViewModel.cs | 4 +- .../UI/ViewModels/XCITrimmerViewModel.cs | 11 +++-- 5 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 src/Ryujinx/Common/XCIFileTrimmerMainWindowLog.cs delete mode 100644 src/Ryujinx/Common/XCIFileTrimmerWindowLog.cs create mode 100644 src/Ryujinx/Common/XCITrimmerLog.cs diff --git a/src/Ryujinx/Common/XCIFileTrimmerMainWindowLog.cs b/src/Ryujinx/Common/XCIFileTrimmerMainWindowLog.cs deleted file mode 100644 index 98347968e..000000000 --- a/src/Ryujinx/Common/XCIFileTrimmerMainWindowLog.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Avalonia.Threading; -using Ryujinx.Ava.UI.ViewModels; - -namespace Ryujinx.Ava.Common -{ - internal class XCIFileTrimmerMainWindowLog : Ryujinx.Common.Logging.XCIFileTrimmerLog - { - private readonly MainWindowViewModel _viewModel; - - public XCIFileTrimmerMainWindowLog(MainWindowViewModel viewModel) - { - _viewModel = viewModel; - } - - public override void Progress(long current, long total, string text, bool complete) - { - Dispatcher.UIThread.Post(() => - { - _viewModel.StatusBarProgressMaximum = (int)(total); - _viewModel.StatusBarProgressValue = (int)(current); - }); - } - } -} diff --git a/src/Ryujinx/Common/XCIFileTrimmerWindowLog.cs b/src/Ryujinx/Common/XCIFileTrimmerWindowLog.cs deleted file mode 100644 index 2481d9107..000000000 --- a/src/Ryujinx/Common/XCIFileTrimmerWindowLog.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Avalonia.Threading; -using Ryujinx.Ava.UI.ViewModels; - -namespace Ryujinx.Ava.Common -{ - internal class XCIFileTrimmerWindowLog : Ryujinx.Common.Logging.XCIFileTrimmerLog - { - private readonly XCITrimmerViewModel _viewModel; - - public XCIFileTrimmerWindowLog(XCITrimmerViewModel viewModel) - { - _viewModel = viewModel; - } - - public override void Progress(long current, long total, string text, bool complete) - { - Dispatcher.UIThread.Post(() => - { - _viewModel.SetProgress((int)(current), (int)(total)); - }); - } - } -} diff --git a/src/Ryujinx/Common/XCITrimmerLog.cs b/src/Ryujinx/Common/XCITrimmerLog.cs new file mode 100644 index 000000000..b661d918d --- /dev/null +++ b/src/Ryujinx/Common/XCITrimmerLog.cs @@ -0,0 +1,45 @@ +using Avalonia.Threading; +using Ryujinx.Ava.UI.ViewModels; + +namespace Ryujinx.Ava.Common +{ + public static class XCITrimmerLog + { + internal class MainWindow : Ryujinx.Common.Logging.XCIFileTrimmerLog + { + private readonly MainWindowViewModel _viewModel; + + public MainWindow(MainWindowViewModel viewModel) + { + _viewModel = viewModel; + } + + public override void Progress(long current, long total, string text, bool complete) + { + Dispatcher.UIThread.Post(() => + { + _viewModel.StatusBarProgressMaximum = (int)(total); + _viewModel.StatusBarProgressValue = (int)(current); + }); + } + } + + internal class TrimmerWindow : Ryujinx.Common.Logging.XCIFileTrimmerLog + { + private readonly XCITrimmerViewModel _viewModel; + + public TrimmerWindow(XCITrimmerViewModel viewModel) + { + _viewModel = viewModel; + } + + public override void Progress(long current, long total, string text, bool complete) + { + Dispatcher.UIThread.Post(() => + { + _viewModel.SetProgress((int)(current), (int)(total)); + }); + } + } + } +} diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index 04db947b9..b8c4a851f 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -402,7 +402,7 @@ namespace Ryujinx.Ava.UI.ViewModels public bool OpenDeviceSaveDirectoryEnabled => !SelectedApplication.ControlHolder.ByteSpan.IsZeros() && SelectedApplication.ControlHolder.Value.DeviceSaveDataSize > 0; - public bool TrimXCIEnabled => Ryujinx.Common.Utilities.XCIFileTrimmer.CanTrim(SelectedApplication.Path, new Common.XCIFileTrimmerMainWindowLog(this)); + public bool TrimXCIEnabled => XCIFileTrimmer.CanTrim(SelectedApplication.Path, new XCITrimmerLog.MainWindow(this)); public bool OpenBcatSaveDirectoryEnabled => !SelectedApplication.ControlHolder.ByteSpan.IsZeros() && SelectedApplication.ControlHolder.Value.BcatDeliveryCacheStorageSize > 0; @@ -2165,7 +2165,7 @@ namespace Ryujinx.Ava.UI.ViewModels return; } - var trimmer = new XCIFileTrimmer(filename, new Common.XCIFileTrimmerMainWindowLog(this)); + var trimmer = new XCIFileTrimmer(filename, new XCITrimmerLog.MainWindow(this)); if (trimmer.CanBeTrimmed) { diff --git a/src/Ryujinx/UI/ViewModels/XCITrimmerViewModel.cs b/src/Ryujinx/UI/ViewModels/XCITrimmerViewModel.cs index b582360f1..e1f9eead5 100644 --- a/src/Ryujinx/UI/ViewModels/XCITrimmerViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/XCITrimmerViewModel.cs @@ -33,7 +33,7 @@ namespace Ryujinx.Ava.UI.ViewModels private const string _FileExtXCI = "XCI"; private readonly Ryujinx.Common.Logging.XCIFileTrimmerLog _logger; - private readonly ApplicationLibrary _applicationLibrary; + private ApplicationLibrary ApplicationLibrary => _mainWindowViewModel.ApplicationLibrary; private Optional _processingApplication = null; private AvaloniaList _allXCIFiles = new(); private AvaloniaList _selectedXCIFiles = new(); @@ -47,15 +47,14 @@ namespace Ryujinx.Ava.UI.ViewModels public XCITrimmerViewModel(MainWindowViewModel mainWindowViewModel) { - _logger = new XCIFileTrimmerWindowLog(this); + _logger = new XCITrimmerLog.TrimmerWindow(this); _mainWindowViewModel = mainWindowViewModel; - _applicationLibrary = _mainWindowViewModel.ApplicationLibrary; LoadXCIApplications(); } private void LoadXCIApplications() { - var apps = _applicationLibrary.Applications.Items + var apps = ApplicationLibrary.Applications.Items .Where(app => app.FileExtension == _FileExtXCI); foreach (var xciApp in apps) @@ -68,7 +67,7 @@ namespace Ryujinx.Ava.UI.ViewModels string path, OperationOutcome operationOutcome = OperationOutcome.Undetermined) { - var xciApp = _applicationLibrary.Applications.Items.First(app => app.FileExtension == _FileExtXCI && app.Path == path); + var xciApp = ApplicationLibrary.Applications.Items.First(app => app.FileExtension == _FileExtXCI && app.Path == path); return XCITrimmerFileModel.FromApplicationData(xciApp, _logger) with { ProcessingOutcome = operationOutcome }; } @@ -538,4 +537,4 @@ namespace Ryujinx.Ava.UI.ViewModels } } } -} \ No newline at end of file +}