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:
GreemDev
2025-11-23 19:56:52 -06:00
parent fd2ecee479
commit 133ac41425
13 changed files with 123 additions and 104 deletions

View File

@@ -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;
}
}
}