UserErrorDialog.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Gtk;
  2. using System.Reflection;
  3. namespace Ryujinx.Ui.Diagnostic
  4. {
  5. internal class UserErrorDialog : MessageDialog
  6. {
  7. private static 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 UserError _userError;
  11. private UserErrorDialog(UserError error) : base(null, DialogFlags.Modal, MessageType.Error, ButtonsType.None, null)
  12. {
  13. _userError = error;
  14. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
  15. WindowPosition = WindowPosition.Center;
  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 static string GetErrorCode(UserError error)
  35. {
  36. return $"RYU-{(uint)error:X4}";
  37. }
  38. private static string GetErrorTitle(UserError error)
  39. {
  40. switch (error)
  41. {
  42. case UserError.NoKeys:
  43. return "Keys not found";
  44. case UserError.NoFirmware:
  45. return "Firmware not found";
  46. case UserError.FirmwareParsingFailed:
  47. return "Firmware parsing error";
  48. case UserError.Unknown:
  49. return "Unknown error";
  50. default:
  51. return "Undefined error";
  52. }
  53. }
  54. private static string GetErrorDescription(UserError error)
  55. {
  56. switch (error)
  57. {
  58. case UserError.NoKeys:
  59. return "Ryujinx was unable to find your 'prod.keys' file";
  60. case UserError.NoFirmware:
  61. return "Ryujinx was unable to find any firmwares installed";
  62. case UserError.FirmwareParsingFailed:
  63. return "Ryujinx was unable to parse the provided firmware. This is usually caused by outdated keys.";
  64. case UserError.Unknown:
  65. return "An unknown error occured!";
  66. default:
  67. return "An undefined error occured! This shouldn't happen, please contact a dev!";
  68. }
  69. }
  70. private static bool IsCoveredBySetupGuide(UserError error)
  71. {
  72. switch (error)
  73. {
  74. case UserError.NoKeys:
  75. case UserError.NoFirmware:
  76. case UserError.FirmwareParsingFailed:
  77. return true;
  78. default:
  79. return false;
  80. }
  81. }
  82. private static string GetSetupGuideUrl(UserError error)
  83. {
  84. if (!IsCoveredBySetupGuide(error))
  85. {
  86. return null;
  87. }
  88. switch (error)
  89. {
  90. case UserError.NoKeys:
  91. return SetupGuideUrl + "#initial-setup---placement-of-prodkeys";
  92. case UserError.NoFirmware:
  93. return SetupGuideUrl + "#initial-setup-continued---installation-of-firmware";
  94. }
  95. return SetupGuideUrl;
  96. }
  97. private void UserErrorDialog_Response(object sender, ResponseArgs args)
  98. {
  99. int responseId = (int)args.ResponseId;
  100. if (responseId == SetupGuideResponseId)
  101. {
  102. UrlHelper.OpenUrl(GetSetupGuideUrl(_userError));
  103. }
  104. Dispose();
  105. }
  106. public static void CreateUserErrorDialog(UserError error)
  107. {
  108. new UserErrorDialog(error).Run();
  109. }
  110. }
  111. }