1
1
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2025-09-23 06:32:01 -05:00

ui: Initial better user error reporting (#1503)

This update the "No keys" dialog and block starting NSP/XCI/NCA without firmware.

Also propose to the user if they want to install firmware if they start an untrimmed XCI and remove KEYS.md as it was completely outdated.

PS: Also fix a bug with "&" in URL with OpenUrl on Windows.
This commit is contained in:
Mary
2020-09-01 11:09:42 +02:00
committed by GitHub
parent bdfbcf4017
commit 3ec911a630
9 changed files with 429 additions and 65 deletions

View File

@@ -0,0 +1,36 @@
using Gtk;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Ryujinx.Ui.Diagnostic
{
internal class GuideDialog : MessageDialog
{
internal static bool _isExitDialogOpen = false;
public GuideDialog(string title, string mainText, string secondaryText) : base(null, DialogFlags.Modal, MessageType.Other, ButtonsType.None, null)
{
Title = title;
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
Text = mainText;
SecondaryText = secondaryText;
WindowPosition = WindowPosition.Center;
Response += GtkDialog_Response;
Button guideButton = new Button();
guideButton.Label = "Open the Setup Guide";
ContentArea.Add(guideButton);
SetSizeRequest(100, 10);
ShowAll();
}
private void GtkDialog_Response(object sender, ResponseArgs args)
{
Dispose();
}
}
}

View File

@@ -0,0 +1,118 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem.Content;
using System;
using System.IO;
namespace Ryujinx.Ui.Diagnostic
{
/// <summary>
/// Ensure installation validity
/// </summary>
static class SetupValidator
{
public static bool IsFirmwareValid(ContentManager contentManager, out UserError error)
{
bool hasFirmware = contentManager.GetCurrentFirmwareVersion() != null;
if (hasFirmware)
{
error = UserError.Success;
return true;
}
else
{
error = UserError.NoFirmware;
return false;
}
}
public static bool CanFixStartApplication(ContentManager contentManager, string baseApplicationPath, UserError error, out SystemVersion firmwareVersion)
{
try
{
firmwareVersion = contentManager.VerifyFirmwarePackage(baseApplicationPath);
}
catch (Exception)
{
firmwareVersion = null;
}
return error == UserError.NoFirmware && Path.GetExtension(baseApplicationPath).ToLowerInvariant() == ".xci" && firmwareVersion != null;
}
public static bool TryFixStartApplication(ContentManager contentManager, string baseApplicationPath, UserError error, out UserError outError)
{
if (error == UserError.NoFirmware)
{
string baseApplicationExtension = Path.GetExtension(baseApplicationPath).ToLowerInvariant();
// If the target app to start is a XCI, try to install firmware from it
if (baseApplicationExtension == ".xci")
{
SystemVersion firmwareVersion;
try
{
firmwareVersion = contentManager.VerifyFirmwarePackage(baseApplicationPath);
}
catch (Exception)
{
firmwareVersion = null;
}
// The XCI is a valid firmware package, try to install the firmware from it!
if (firmwareVersion != null)
{
try
{
Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
contentManager.InstallFirmware(baseApplicationPath);
Logger.Info?.Print(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed.");
outError = UserError.Success;
return true;
}
catch (Exception) { }
}
outError = error;
return false;
}
}
outError = error;
return false;
}
public static bool CanStartApplication(ContentManager contentManager, string baseApplicationPath, out UserError error)
{
if (Directory.Exists(baseApplicationPath) || File.Exists(baseApplicationPath))
{
string baseApplicationExtension = Path.GetExtension(baseApplicationPath).ToLowerInvariant();
// NOTE: We don't force homebrew developers to install a system firmware.
if (baseApplicationExtension == ".nro" || baseApplicationExtension == ".nso")
{
error = UserError.Success;
return true;
}
return IsFirmwareValid(contentManager, out error);
}
else
{
error = UserError.ApplicationNotFound;
return false;
}
}
}
}

View File

@@ -0,0 +1,39 @@
namespace Ryujinx.Ui.Diagnostic
{
/// <summary>
/// Represent a common error that could be reported to the user by the emulator.
/// </summary>
public enum UserError
{
/// <summary>
/// No error to report.
/// </summary>
Success = 0x0,
/// <summary>
/// No keys are present.
/// </summary>
NoKeys = 0x1,
/// <summary>
/// No firmware is installed.
/// </summary>
NoFirmware = 0x2,
/// <summary>
/// Firmware parsing failed.
/// </summary>
/// <remarks>Most likely related to keys.</remarks>
FirmwareParsingFailed = 0x3,
/// <summary>
/// No application was found at the given path.
/// </summary>
ApplicationNotFound = 0x4,
/// <summary>
/// An unknown error.
/// </summary>
Unknown = 0xDEAD
}
}

View File

@@ -0,0 +1,133 @@
using Gtk;
using System.Reflection;
namespace Ryujinx.Ui.Diagnostic
{
internal class UserErrorDialog : MessageDialog
{
private static string SetupGuideUrl = "https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide";
private const int OkResponseId = 0;
private const int SetupGuideResponseId = 1;
private UserError _userError;
private UserErrorDialog(UserError error) : base(null, DialogFlags.Modal, MessageType.Error, ButtonsType.None, null)
{
_userError = error;
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
WindowPosition = WindowPosition.Center;
Response += UserErrorDialog_Response;
SetSizeRequest(120, 50);
AddButton("OK", OkResponseId);
bool isInSetupGuide = IsCoveredBySetupGuide(error);
if (isInSetupGuide)
{
AddButton("Open the Setup Guide", SetupGuideResponseId);
}
string errorCode = GetErrorCode(error);
SecondaryUseMarkup = true;
Title = $"Ryujinx error ({errorCode})";
Text = $"{errorCode}: {GetErrorTitle(error)}";
SecondaryText = GetErrorDescription(error);
if (isInSetupGuide)
{
SecondaryText += "\n<b>For more information on how to fix this error, follow our Setup Guide.</b>";
}
}
private static string GetErrorCode(UserError error)
{
return $"RYU-{(uint)error:X4}";
}
private static string GetErrorTitle(UserError error)
{
switch (error)
{
case UserError.NoKeys:
return "Keys not found";
case UserError.NoFirmware:
return "Firmware not found";
case UserError.FirmwareParsingFailed:
return "Firmware parsing error";
case UserError.Unknown:
return "Unknown error";
default:
return "Undefined error";
}
}
private static string GetErrorDescription(UserError error)
{
switch (error)
{
case UserError.NoKeys:
return "Ryujinx was unable to find your 'prod.keys' file";
case UserError.NoFirmware:
return "Ryujinx was unable to find any firmwares installed";
case UserError.FirmwareParsingFailed:
return "Ryujinx was unable to parse the provided firmware. This is usually caused by outdated keys.";
case UserError.Unknown:
return "An unknown error occured!";
default:
return "An undefined error occured! This shouldn't happen, please contact a dev!";
}
}
private static bool IsCoveredBySetupGuide(UserError error)
{
switch (error)
{
case UserError.NoKeys:
case UserError.NoFirmware:
case UserError.FirmwareParsingFailed:
return true;
default:
return false;
}
}
private static string GetSetupGuideUrl(UserError error)
{
if (!IsCoveredBySetupGuide(error))
{
return null;
}
switch (error)
{
case UserError.NoKeys:
return SetupGuideUrl + "#initial-setup---placement-of-prodkeys";
case UserError.NoFirmware:
return SetupGuideUrl + "#initial-setup-continued---installation-of-firmware";
}
return SetupGuideUrl;
}
private void UserErrorDialog_Response(object sender, ResponseArgs args)
{
int responseId = (int)args.ResponseId;
if (responseId == SetupGuideResponseId)
{
UrlHelper.OpenUrl(GetSetupGuideUrl(_userError));
}
Dispose();
}
public static void CreateUserErrorDialog(UserError error)
{
new UserErrorDialog(error).Run();
}
}
}