mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-12-12 07:36:59 +00:00
Bake setup step logic into the view models themselves instead of being in the setup wizard implementation
renamed view models to contexts (like TKMM), however the contexts here are actually of a unique base type; containing aforementioned setup step logic. if the return value is of an error state result, it will prompt a retry of the page.
This commit is contained in:
parent
df675813a4
commit
3202ec72b2
13 changed files with 123 additions and 104 deletions
|
|
@ -44,7 +44,7 @@
|
|||
<PackageVersion Include="Ryujinx.LibHac" Version="0.21.0-alpha.126" />
|
||||
<PackageVersion Include="Ryujinx.UpdateClient" Version="1.0.44" />
|
||||
<PackageVersion Include="Ryujinx.Systems.Update.Common" Version="1.0.44" />
|
||||
<PackageVersion Include="Gommon" Version="2.8.0.1" />
|
||||
<PackageVersion Include="Gommon" Version="2.8.0.2" />
|
||||
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
|
||||
<PackageVersion Include="Sep" Version="0.11.1" />
|
||||
<PackageVersion Include="shaderc.net" Version="0.1.0" />
|
||||
|
|
@ -59,4 +59,4 @@
|
|||
<PackageVersion Include="System.Management" Version="9.0.2" />
|
||||
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using Avalonia;
|
|||
using Avalonia.Controls;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.SetupWizard;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.SetupWizard
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ using Avalonia.Controls.Presenters;
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.SetupWizard;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
|||
10
src/Ryujinx/Systems/SetupWizard/SetupWizardPageContext.cs
Normal file
10
src/Ryujinx/Systems/SetupWizard/SetupWizardPageContext.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Gommon;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.SetupWizard
|
||||
{
|
||||
public abstract class SetupWizardPageContext: BaseModel
|
||||
{
|
||||
public abstract Result CompleteStep();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:markup="clr-namespace:Ryujinx.Ava.Common.Markup"
|
||||
xmlns:pages="clr-namespace:Ryujinx.Ava.UI.SetupWizard.Pages"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:DataType="pages:SetupFirmwarePageViewModel"
|
||||
x:DataType="pages:SetupFirmwarePageContext"
|
||||
x:Class="Ryujinx.Ava.UI.SetupWizard.Pages.SetupFirmwarePage">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{markup:Locale SetupWizardFirmwarePageDescription}"/>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using Ryujinx.Ava.UI.Controls;
|
|||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
||||
{
|
||||
public partial class SetupFirmwarePage : RyujinxControl<SetupFirmwarePageViewModel>
|
||||
public partial class SetupFirmwarePage : RyujinxControl<SetupFirmwarePageContext>
|
||||
{
|
||||
public SetupFirmwarePage()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,16 +3,20 @@ using Avalonia.Platform.Storage;
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Ava.Systems.SetupWizard;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.Utilities;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
||||
{
|
||||
public partial class SetupFirmwarePageViewModel : BaseModel
|
||||
public partial class SetupFirmwarePageContext : SetupWizardPageContext
|
||||
{
|
||||
[ObservableProperty]
|
||||
public partial string FirmwareSourcePath { get; set; }
|
||||
|
|
@ -65,5 +69,54 @@ namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
|||
tb.Text = firmwareFolder.TryGetLocalPath();
|
||||
}
|
||||
}
|
||||
|
||||
public override Result CompleteStep()
|
||||
{
|
||||
if (!Directory.Exists(FirmwareSourcePath))
|
||||
return Result.Fail;
|
||||
|
||||
try
|
||||
{
|
||||
RyujinxApp.MainWindow.ContentManager.InstallFirmware(FirmwareSourcePath);
|
||||
SystemVersion installedFwVer = RyujinxApp.MainWindow.ContentManager.GetCurrentFirmwareVersion();
|
||||
if (installedFwVer != null)
|
||||
{
|
||||
NotificationHelper.ShowInformation(
|
||||
"Firmware installed",
|
||||
$"Installed firmware version {installedFwVer.VersionString}."
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationHelper.ShowError(
|
||||
"Firmware not installed",
|
||||
$"It seems some error occurred when trying to install the firmware at path '{FirmwareSourcePath}'." +
|
||||
"\nDid that folder contain a firmware dump?"
|
||||
);
|
||||
}
|
||||
RyujinxApp.MainWindow.ViewModel.RefreshFirmwareStatus(installedFwVer, allowNullVersion: true);
|
||||
|
||||
if (installedFwVer is null)
|
||||
return Result.Fail;
|
||||
|
||||
// Purge Applet Cache.
|
||||
|
||||
DirectoryInfo miiEditorCacheFolder = new(
|
||||
Path.Combine(AppDataManager.GamesDirPath, "0100000000001009", "cache")
|
||||
);
|
||||
|
||||
if (miiEditorCacheFolder.Exists)
|
||||
{
|
||||
miiEditorCacheFolder.Delete(true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NotificationHelper.ShowError(e.Message, waitingExit: true);
|
||||
return Result.Fail;
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
xmlns:markup="clr-namespace:Ryujinx.Ava.Common.Markup"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Ryujinx.Ava.UI.SetupWizard.Pages.SetupKeysPage"
|
||||
x:DataType="pages:SetupKeysPageViewModel">
|
||||
x:DataType="pages:SetupKeysPageContext">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{markup:Locale SetupWizardKeysPageDescription}" Margin="0,0,0,10"/>
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using Ryujinx.Ava.UI.Controls;
|
|||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
||||
{
|
||||
public partial class SetupKeysPage : RyujinxControl<SetupKeysPageViewModel>
|
||||
public partial class SetupKeysPage : RyujinxControl<SetupKeysPageContext>
|
||||
{
|
||||
public SetupKeysPage()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,19 +1,48 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DynamicData;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.Systems.SetupWizard;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.Utilities;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard
|
||||
namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
||||
{
|
||||
public partial class RyujinxSetupWizard
|
||||
public partial class SetupKeysPageContext : SetupWizardPageContext
|
||||
{
|
||||
private Result InstallKeys(string directory)
|
||||
public override Result CompleteStep() =>
|
||||
!Directory.Exists(KeysFolderPath)
|
||||
? Result.Fail
|
||||
: InstallKeys(KeysFolderPath);
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string KeysFolderPath { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
private static async Task Browse(TextBox tb)
|
||||
{
|
||||
Optional<IStorageFolder> result = await RyujinxApp.MainWindow.ViewModel.StorageProvider.OpenSingleFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = LocaleManager.Instance[LocaleKeys.SetupWizardKeysPageFolderPopupTitle]
|
||||
});
|
||||
|
||||
if (result.TryGet(out IStorageFolder keyFolder))
|
||||
{
|
||||
tb.Text = keyFolder.TryGetLocalPath();
|
||||
}
|
||||
}
|
||||
|
||||
private static Result InstallKeys(string directory)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -53,11 +82,11 @@ namespace Ryujinx.Ava.UI.SetupWizard
|
|||
|
||||
NotificationHelper.ShowError(message, waitingExit: true);
|
||||
|
||||
return Result.Failure(new MessageError(ex.Message));
|
||||
return Result.Failure(new MessageError(message));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mainWindow.VirtualFileSystem.ReloadKeySet();
|
||||
RyujinxApp.MainWindow.VirtualFileSystem.ReloadKeySet();
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Ava.Utilities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard.Pages
|
||||
{
|
||||
public partial class SetupKeysPageViewModel : BaseModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
public partial string KeysFolderPath { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
private static async Task Browse(TextBox tb)
|
||||
{
|
||||
Optional<IStorageFolder> result = await RyujinxApp.MainWindow.ViewModel.StorageProvider.OpenSingleFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = LocaleManager.Instance[LocaleKeys.SetupWizardKeysPageFolderPopupTitle]
|
||||
});
|
||||
|
||||
if (result.TryGet(out IStorageFolder keyFolder))
|
||||
{
|
||||
tb.Text = keyFolder.TryGetLocalPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +1,19 @@
|
|||
using Avalonia.Controls.Presenters;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.Systems.Configuration;
|
||||
using Ryujinx.Ava.Systems.SetupWizard;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.SetupWizard.Pages;
|
||||
using Ryujinx.Ava.UI.Windows;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.Ava.UI.SetupWizard
|
||||
{
|
||||
public partial class RyujinxSetupWizard(RyujinxSetupWizardWindow wizardWindow)
|
||||
public class RyujinxSetupWizard(RyujinxSetupWizardWindow wizardWindow)
|
||||
: BaseSetupWizard(wizardWindow.WizardPresenter)
|
||||
{
|
||||
private readonly MainWindow _mainWindow = RyujinxApp.MainWindow;
|
||||
|
||||
private bool _configWasModified = false;
|
||||
private bool _configWasModified;
|
||||
|
||||
public bool HasFirmware => _mainWindow.ContentManager.GetCurrentFirmwareVersion() != null;
|
||||
|
||||
|
|
@ -60,20 +54,14 @@ namespace Ryujinx.Ava.UI.SetupWizard
|
|||
Retry:
|
||||
bool result = await NextPage()
|
||||
.WithTitle(LocaleKeys.SetupWizardKeysPageTitle)
|
||||
.WithContent<SetupKeysPage, SetupKeysPageViewModel>(out SetupKeysPageViewModel kpvm)
|
||||
.WithContent<SetupKeysPage, SetupKeysPageContext>(out SetupKeysPageContext keyContext)
|
||||
.Show();
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if (!Directory.Exists(kpvm.KeysFolderPath))
|
||||
if (!keyContext.CompleteStep())
|
||||
goto Retry;
|
||||
|
||||
Result installResult = InstallKeys(kpvm.KeysFolderPath);
|
||||
if (!installResult.IsSuccess)
|
||||
{
|
||||
goto Retry;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -92,55 +80,22 @@ namespace Ryujinx.Ava.UI.SetupWizard
|
|||
Retry:
|
||||
bool result = await NextPage()
|
||||
.WithTitle(LocaleKeys.SetupWizardFirmwarePageTitle)
|
||||
.WithContent<SetupFirmwarePage, SetupFirmwarePageViewModel>(out SetupFirmwarePageViewModel fwvm)
|
||||
.WithContent<SetupFirmwarePage, SetupFirmwarePageContext>(out SetupFirmwarePageContext fwContext)
|
||||
.Show();
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if (!Directory.Exists(fwvm.FirmwareSourcePath))
|
||||
if (!fwContext.CompleteStep())
|
||||
goto Retry;
|
||||
|
||||
try
|
||||
{
|
||||
_mainWindow.ContentManager.InstallFirmware(fwvm.FirmwareSourcePath);
|
||||
SystemVersion installedFwVer = _mainWindow.ContentManager.GetCurrentFirmwareVersion();
|
||||
if (installedFwVer != null)
|
||||
{
|
||||
NotificationHelper.ShowInformation(
|
||||
"Firmware installed",
|
||||
$"Installed firmware version {installedFwVer.VersionString}."
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationHelper.ShowError(
|
||||
"Firmware not installed",
|
||||
$"It seems some error occurred when trying to install the firmware at path '{fwvm.FirmwareSourcePath}'. " +
|
||||
"\nPlease check the log or try again."
|
||||
);
|
||||
}
|
||||
_mainWindow.ViewModel.RefreshFirmwareStatus(installedFwVer, allowNullVersion: true);
|
||||
|
||||
// Purge Applet Cache.
|
||||
|
||||
DirectoryInfo miiEditorCacheFolder = new(
|
||||
Path.Combine(AppDataManager.GamesDirPath, "0100000000001009", "cache")
|
||||
);
|
||||
|
||||
if (miiEditorCacheFolder.Exists)
|
||||
{
|
||||
miiEditorCacheFolder.Delete(true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NotificationHelper.ShowError(e.Message, waitingExit: true);
|
||||
goto Retry;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SignalConfigModified()
|
||||
{
|
||||
_configWasModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Avalonia.Controls;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Systems.Configuration;
|
||||
using Ryujinx.Ava.Systems.SetupWizard;
|
||||
using Ryujinx.Ava.UI.Windows;
|
||||
|
|
@ -28,10 +29,10 @@ namespace Ryujinx.Ava.UI.SetupWizard
|
|||
{
|
||||
if (!CanShowSetupWizard)
|
||||
return Task.CompletedTask;
|
||||
|
||||
|
||||
Task windowTask = ShowAsync(
|
||||
CreateWindow(out BaseSetupWizard wiz),
|
||||
owner ?? RyujinxApp.MainWindow
|
||||
owner
|
||||
);
|
||||
_ = wiz.Start();
|
||||
return windowTask;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue