content & viewmodel object creation helper with out param, touch up firmware install step

This commit is contained in:
GreemDev 2025-11-22 18:35:37 -06:00
parent fa3a0c11ce
commit beb697b7f7
3 changed files with 40 additions and 12 deletions

View file

@ -2,6 +2,8 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Controls;
using Ryujinx.Ava.UI.ViewModels;
using System.Threading.Tasks;
namespace Ryujinx.Ava.Systems.SetupWizard
@ -52,6 +54,15 @@ namespace Ryujinx.Ava.Systems.SetupWizard
return this;
}
public SetupWizardPageBuilder WithContent<TControl, TViewModel>(out TViewModel boundViewModel)
where TControl : RyujinxControl<TViewModel>, new()
where TViewModel : BaseModel, new()
{
boundViewModel = new();
return WithContent<TControl>(boundViewModel);
}
public SetupWizardPageBuilder WithActionContent(LocaleKeys content) =>
WithActionContent(LocaleManager.Instance[content]);

View file

@ -49,10 +49,9 @@ namespace Ryujinx.Ava.UI.SetupWizard
if (!mwvm.VirtualFileSystem.HasKeySet)
{
Retry:
SetupKeysPageViewModel kpvm = new();
bool result = await NextPage()
.WithTitle(LocaleKeys.SetupWizardKeysPageTitle)
.WithContent<SetupKeysPage>(kpvm)
.WithContent<SetupKeysPage, SetupKeysPageViewModel>(out SetupKeysPageViewModel kpvm)
.Show();
if (!result)
@ -77,15 +76,14 @@ namespace Ryujinx.Ava.UI.SetupWizard
{
if (!mwvm.VirtualFileSystem.HasKeySet)
{
NotificationHelper.ShowError("Keys still seem to not be installed. Are you sure they're in that folder?");
NotificationHelper.ShowError("Keys still seem to not be installed. Please try again.");
return false;
}
Retry:
SetupFirmwarePageViewModel fwvm = new();
bool result = await NextPage()
.WithTitle(LocaleKeys.SetupWizardFirmwarePageTitle)
.WithContent<SetupFirmwarePage>(fwvm)
.WithContent<SetupFirmwarePage, SetupFirmwarePageViewModel>(out SetupFirmwarePageViewModel fwvm)
.Show();
if (!result)
@ -98,11 +96,22 @@ namespace Ryujinx.Ava.UI.SetupWizard
{
mwvm.ContentManager.InstallFirmware(fwvm.FirmwareSourcePath);
SystemVersion installedFwVer = mwvm.ContentManager.GetCurrentFirmwareVersion();
NotificationHelper.ShowInformation(
"Firmware installed",
$"Installed firmware version {installedFwVer.VersionString}."
);
mwvm.RefreshFirmwareStatus(installedFwVer);
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."
);
}
mwvm.RefreshFirmwareStatus(installedFwVer, allowNullVersion: true);
// Purge Applet Cache.

View file

@ -1758,11 +1758,19 @@ namespace Ryujinx.Ava.UI.ViewModels
public static void UpdateGameMetadata(string titleId, TimeSpan playTime)
=> ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata => appMetadata.UpdatePostGame(playTime));
public void RefreshFirmwareStatus(SystemVersion version = null)
/// <remarks>
/// By default, this method will try to retrieve the installed FW version if the version parameter is null.
/// <paramref name="allowNullVersion"/> forces this method to accept null and not re-lookup
/// in the case you want to deliberately cause an update with a missing firmware version;
///
/// i.e., in the setup wizard.
/// </remarks>
public void RefreshFirmwareStatus(SystemVersion version = null, bool allowNullVersion = false)
{
try
{
version ??= ContentManager.GetCurrentFirmwareVersion();
if (!allowNullVersion)
version ??= ContentManager.GetCurrentFirmwareVersion();
}
catch (Exception)
{