UserErrorDialog.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.ApplicationNotFound:
  49. return "Application not found";
  50. case UserError.Unknown:
  51. return "Unknown error";
  52. default:
  53. return "Undefined error";
  54. }
  55. }
  56. private static string GetErrorDescription(UserError error)
  57. {
  58. switch (error)
  59. {
  60. case UserError.NoKeys:
  61. return "Ryujinx was unable to find your 'prod.keys' file";
  62. case UserError.NoFirmware:
  63. return "Ryujinx was unable to find any firmwares installed";
  64. case UserError.FirmwareParsingFailed:
  65. return "Ryujinx was unable to parse the provided firmware. This is usually caused by outdated keys.";
  66. case UserError.ApplicationNotFound:
  67. return "Ryujinx couldn't find a valid application at the given path.";
  68. case UserError.Unknown:
  69. return "An unknown error occured!";
  70. default:
  71. return "An undefined error occured! This shouldn't happen, please contact a dev!";
  72. }
  73. }
  74. private static bool IsCoveredBySetupGuide(UserError error)
  75. {
  76. switch (error)
  77. {
  78. case UserError.NoKeys:
  79. case UserError.NoFirmware:
  80. case UserError.FirmwareParsingFailed:
  81. return true;
  82. default:
  83. return false;
  84. }
  85. }
  86. private static string GetSetupGuideUrl(UserError error)
  87. {
  88. if (!IsCoveredBySetupGuide(error))
  89. {
  90. return null;
  91. }
  92. switch (error)
  93. {
  94. case UserError.NoKeys:
  95. return SetupGuideUrl + "#initial-setup---placement-of-prodkeys";
  96. case UserError.NoFirmware:
  97. return SetupGuideUrl + "#initial-setup-continued---installation-of-firmware";
  98. }
  99. return SetupGuideUrl;
  100. }
  101. private void UserErrorDialog_Response(object sender, ResponseArgs args)
  102. {
  103. int responseId = (int)args.ResponseId;
  104. if (responseId == SetupGuideResponseId)
  105. {
  106. UrlHelper.OpenUrl(GetSetupGuideUrl(_userError));
  107. }
  108. Dispose();
  109. }
  110. public static void CreateUserErrorDialog(UserError error)
  111. {
  112. new UserErrorDialog(error).Run();
  113. }
  114. }
  115. }