UserErrorDialog.cs 4.3 KB

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