System firmware installer (#791)

* firmware installer

* Add directory installation option and fix 9.x support for directory

* Fix missing system font error while installing for the first time

* Address code style comments

* Create and use InvalidFirmwarePackageException

* Fix LDj3SNuD's comments

* addressed alex's comments

* add label to status bar to show current firmware version

Co-authored-by: Thog <thog@protonmail.com>
This commit is contained in:
emmauss 2020-01-12 02:10:55 +00:00 committed by Ac_K
parent 1661ce99ca
commit e485ee049d
8 changed files with 936 additions and 27 deletions

View file

@ -44,6 +44,8 @@ namespace Ryujinx.Ui
[GUI] CheckMenuItem _fullScreen;
[GUI] MenuItem _stopEmulation;
[GUI] CheckMenuItem _favToggle;
[GUI] MenuItem _firmwareInstallFile;
[GUI] MenuItem _firmwareInstallDirectory;
[GUI] CheckMenuItem _iconToggle;
[GUI] CheckMenuItem _appToggle;
[GUI] CheckMenuItem _developerToggle;
@ -56,6 +58,7 @@ namespace Ryujinx.Ui
[GUI] TreeView _gameTable;
[GUI] TreeSelection _gameTableSelection;
[GUI] Label _progressLabel;
[GUI] Label _firmwareVersionLabel;
[GUI] LevelBar _progressBar;
#pragma warning restore CS0649
#pragma warning restore IDE0044
@ -134,6 +137,8 @@ namespace Ryujinx.Ui
#pragma warning disable CS4014
UpdateGameTable();
#pragma warning restore CS4014
Task.Run(RefreshFirmwareLabel);
}
internal static void ApplyTheme()
@ -297,6 +302,9 @@ namespace Ryujinx.Ui
_gameLoaded = true;
_stopEmulation.Sensitive = true;
_firmwareInstallFile.Sensitive = false;
_firmwareInstallDirectory.Sensitive = false;
DiscordIntegrationModule.SwitchToPlayingState(_device.System.TitleId, _device.System.TitleName);
string metadataFolder = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", _device.System.TitleId, "gui");
@ -556,7 +564,199 @@ namespace Ryujinx.Ui
_gameLoaded = false;
}
private void FullScreen_Toggled(object sender, EventArgs args)
private void Installer_File_Pressed(object o, EventArgs args)
{
FileChooserDialog fileChooser = new FileChooserDialog("Choose the firmware file to open",
this,
FileChooserAction.Open,
"Cancel",
ResponseType.Cancel,
"Open",
ResponseType.Accept);
fileChooser.Filter = new FileFilter();
fileChooser.Filter.AddPattern("*.zip");
fileChooser.Filter.AddPattern("*.xci");
HandleInstallerDialog(fileChooser);
}
private void Installer_Directory_Pressed(object o, EventArgs args)
{
FileChooserDialog directoryChooser = new FileChooserDialog("Choose the firmware directory to open",
this,
FileChooserAction.SelectFolder,
"Cancel",
ResponseType.Cancel,
"Open",
ResponseType.Accept);
HandleInstallerDialog(directoryChooser);
}
private void RefreshFirmwareLabel()
{
var currentFirmware = _device.System.GetCurrentFirmwareVersion();
GLib.Idle.Add(new GLib.IdleHandler(() =>
{
_firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
return false;
}));
}
private void HandleInstallerDialog(FileChooserDialog fileChooser)
{
if (fileChooser.Run() == (int)ResponseType.Accept)
{
MessageDialog dialog = null;
try
{
string filename = fileChooser.Filename;
fileChooser.Dispose();
var firmwareVersion = _device.System.VerifyFirmwarePackage(filename);
if (firmwareVersion == null)
{
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
dialog.Text = "Firmware not found.";
dialog.SecondaryText = $"A valid system firmware was not found in {filename}.";
Logger.PrintError(LogClass.Application, $"A valid system firmware was not found in {filename}.");
dialog.Run();
dialog.Hide();
dialog.Dispose();
return;
}
var currentVersion = _device.System.GetCurrentFirmwareVersion();
string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
if (currentVersion != null)
{
dialogMessage += $"This will replace the current system version {currentVersion.VersionString}. ";
}
dialogMessage += "Do you want to continue?";
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, false, "");
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
dialog.SecondaryText = dialogMessage;
int response = dialog.Run();
dialog.Dispose();
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.None, false, "");
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
dialog.SecondaryText = "Installing firmware...";
if (response == (int)ResponseType.Yes)
{
Logger.PrintInfo(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
Thread thread = new Thread(() =>
{
GLib.Idle.Add(new GLib.IdleHandler(() =>
{
dialog.Run();
return false;
}));
try
{
_device.System.InstallFirmware(filename);
GLib.Idle.Add(new GLib.IdleHandler(() =>
{
dialog.Dispose();
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
dialog.SecondaryText = $"System version {firmwareVersion.VersionString} successfully installed.";
Logger.PrintInfo(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed.");
dialog.Run();
dialog.Dispose();
return false;
}));
}
catch (Exception ex)
{
GLib.Idle.Add(new GLib.IdleHandler(() =>
{
dialog.Dispose();
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
dialog.Text = $"Install Firmware {firmwareVersion.VersionString} Failed.";
dialog.SecondaryText = $"An error occured while installing system version {firmwareVersion.VersionString}." +
" Please check logs for more info.";
Logger.PrintError(LogClass.Application, ex.Message);
dialog.Run();
dialog.Dispose();
return false;
}));
}
finally
{
RefreshFirmwareLabel();
}
});
thread.Start();
}
else
{
dialog.Dispose();
}
}
catch (Exception ex)
{
if (dialog != null)
{
dialog.Dispose();
}
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
dialog.Text = "Parsing Firmware Failed.";
dialog.SecondaryText = "An error occured while parsing firmware. Please check the logs for more info.";
Logger.PrintError(LogClass.Application, ex.Message);
dialog.Run();
dialog.Dispose();
}
}
else
{
fileChooser.Dispose();
}
}
private void FullScreen_Toggled(object o, EventArgs args)
{
if (_fullScreen.Active)
{

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.21.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="_mainWin">
@ -8,9 +8,6 @@
<property name="window_position">center</property>
<property name="default_width">1280</property>
<property name="default_height">750</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="_box">
<property name="visible">True</property>
@ -263,6 +260,44 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tools</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="FirmwareSubMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Install Firmware</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="_firmwareInstallFile">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Install a firmware from XCI or ZIP</property>
<property name="use_underline">True</property>
<signal name="activate" handler="Installer_File_Pressed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="_firmwareInstallDirectory">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Install a firmware from a directory</property>
<property name="use_underline">True</property>
<signal name="activate" handler="Installer_Directory_Pressed" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
@ -370,7 +405,7 @@
<object class="GtkLabel" id="_progressLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_left">10</property>
<property name="margin_right">5</property>
<property name="margin_top">2</property>
<property name="margin_bottom">2</property>
@ -388,7 +423,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_left">10</property>
<property name="margin_right">5</property>
</object>
<packing>
@ -397,6 +432,57 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">System Version</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="_firmwareVersionLabel">
<property name="width_request">50</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -413,5 +499,8 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>