UserErrorDialog.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Gtk;
  2. using Ryujinx.Ui.Helper;
  3. namespace Ryujinx.Ui.Widgets
  4. {
  5. internal class UserErrorDialog : MessageDialog
  6. {
  7. private const string SetupGuideUrl = "https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide";
  8. private const int OkResponseId = 0;
  9. private const int SetupGuideResponseId = 1;
  10. private readonly UserError _userError;
  11. private UserErrorDialog(UserError error) : base(null, DialogFlags.Modal, MessageType.Error, ButtonsType.None, null)
  12. {
  13. _userError = error;
  14. WindowPosition = WindowPosition.Center;
  15. SecondaryUseMarkup = true;
  16. Response += UserErrorDialog_Response;
  17. SetSizeRequest(120, 50);
  18. AddButton("OK", OkResponseId);
  19. bool isInSetupGuide = IsCoveredBySetupGuide(error);
  20. if (isInSetupGuide)
  21. {
  22. AddButton("Open the Setup Guide", SetupGuideResponseId);
  23. }
  24. string errorCode = GetErrorCode(error);
  25. SecondaryUseMarkup = true;
  26. Title = $"Ryujinx error ({errorCode})";
  27. Text = $"{errorCode}: {GetErrorTitle(error)}";
  28. SecondaryText = GetErrorDescription(error);
  29. if (isInSetupGuide)
  30. {
  31. SecondaryText += "\n<b>For more information on how to fix this error, follow our Setup Guide.</b>";
  32. }
  33. }
  34. private string GetErrorCode(UserError error)
  35. {
  36. return $"RYU-{(uint)error:X4}";
  37. }
  38. private string GetErrorTitle(UserError error)
  39. {
  40. return error switch
  41. {
  42. UserError.NoKeys => "Keys not found",
  43. UserError.NoFirmware => "Firmware not found",
  44. UserError.FirmwareParsingFailed => "Firmware parsing error",
  45. UserError.ApplicationNotFound => "Application not found",
  46. UserError.Unknown => "Unknown error",
  47. _ => "Undefined error",
  48. };
  49. }
  50. private string GetErrorDescription(UserError error)
  51. {
  52. return error switch
  53. {
  54. UserError.NoKeys => "Ryujinx was unable to find your 'prod.keys' file",
  55. UserError.NoFirmware => "Ryujinx was unable to find any firmwares installed",
  56. UserError.FirmwareParsingFailed => "Ryujinx was unable to parse the provided firmware. This is usually caused by outdated keys.",
  57. UserError.ApplicationNotFound => "Ryujinx couldn't find a valid application at the given path.",
  58. UserError.Unknown => "An unknown error occured!",
  59. _ => "An undefined error occured! This shouldn't happen, please contact a dev!",
  60. };
  61. }
  62. private static bool IsCoveredBySetupGuide(UserError error)
  63. {
  64. return error switch
  65. {
  66. UserError.NoKeys or
  67. UserError.NoFirmware or
  68. UserError.FirmwareParsingFailed => true,
  69. _ => false,
  70. };
  71. }
  72. private static string GetSetupGuideUrl(UserError error)
  73. {
  74. if (!IsCoveredBySetupGuide(error))
  75. {
  76. return null;
  77. }
  78. return error switch
  79. {
  80. UserError.NoKeys => SetupGuideUrl + "#initial-setup---placement-of-prodkeys",
  81. UserError.NoFirmware => SetupGuideUrl + "#initial-setup-continued---installation-of-firmware",
  82. _ => SetupGuideUrl,
  83. };
  84. }
  85. private void UserErrorDialog_Response(object sender, ResponseArgs args)
  86. {
  87. int responseId = (int)args.ResponseId;
  88. if (responseId == SetupGuideResponseId)
  89. {
  90. OpenHelper.OpenUrl(GetSetupGuideUrl(_userError));
  91. }
  92. Dispose();
  93. }
  94. public static void CreateUserErrorDialog(UserError error)
  95. {
  96. new UserErrorDialog(error).Run();
  97. }
  98. }
  99. }