UserErrorDialog.cs 4.2 KB

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