UserErrorDialog.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Ryujinx.Ava.Common.Locale;
  2. using Ryujinx.Ava.UI.Windows;
  3. using Ryujinx.Ui.Common;
  4. using Ryujinx.Ui.Common.Helper;
  5. using System.Threading.Tasks;
  6. namespace Ryujinx.Ava.UI.Helpers
  7. {
  8. internal class UserErrorDialog
  9. {
  10. private const string SetupGuideUrl = "https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide";
  11. private static string GetErrorCode(UserError error)
  12. {
  13. return $"RYU-{(uint)error:X4}";
  14. }
  15. private static string GetErrorTitle(UserError error)
  16. {
  17. return error switch
  18. {
  19. UserError.NoKeys => LocaleManager.Instance[LocaleKeys.UserErrorNoKeys],
  20. UserError.NoFirmware => LocaleManager.Instance[LocaleKeys.UserErrorNoFirmware],
  21. UserError.FirmwareParsingFailed => LocaleManager.Instance[LocaleKeys.UserErrorFirmwareParsingFailed],
  22. UserError.ApplicationNotFound => LocaleManager.Instance[LocaleKeys.UserErrorApplicationNotFound],
  23. UserError.Unknown => LocaleManager.Instance[LocaleKeys.UserErrorUnknown],
  24. _ => LocaleManager.Instance[LocaleKeys.UserErrorUndefined]
  25. };
  26. }
  27. private static string GetErrorDescription(UserError error)
  28. {
  29. return error switch
  30. {
  31. UserError.NoKeys => LocaleManager.Instance[LocaleKeys.UserErrorNoKeysDescription],
  32. UserError.NoFirmware => LocaleManager.Instance[LocaleKeys.UserErrorNoFirmwareDescription],
  33. UserError.FirmwareParsingFailed => LocaleManager.Instance[LocaleKeys.UserErrorFirmwareParsingFailedDescription],
  34. UserError.ApplicationNotFound => LocaleManager.Instance[LocaleKeys.UserErrorApplicationNotFoundDescription],
  35. UserError.Unknown => LocaleManager.Instance[LocaleKeys.UserErrorUnknownDescription],
  36. _ => LocaleManager.Instance[LocaleKeys.UserErrorUndefinedDescription]
  37. };
  38. }
  39. private static bool IsCoveredBySetupGuide(UserError error)
  40. {
  41. return error switch
  42. {
  43. UserError.NoKeys or
  44. UserError.NoFirmware or
  45. UserError.FirmwareParsingFailed => true,
  46. _ => false
  47. };
  48. }
  49. private static string GetSetupGuideUrl(UserError error)
  50. {
  51. if (!IsCoveredBySetupGuide(error))
  52. {
  53. return null;
  54. }
  55. return error switch
  56. {
  57. UserError.NoKeys => SetupGuideUrl + "#initial-setup---placement-of-prodkeys",
  58. UserError.NoFirmware => SetupGuideUrl + "#initial-setup-continued---installation-of-firmware",
  59. _ => SetupGuideUrl
  60. };
  61. }
  62. public static async Task ShowUserErrorDialog(UserError error, StyleableWindow owner)
  63. {
  64. string errorCode = GetErrorCode(error);
  65. bool isInSetupGuide = IsCoveredBySetupGuide(error);
  66. string setupButtonLabel = isInSetupGuide ? LocaleManager.Instance[LocaleKeys.OpenSetupGuideMessage] : "";
  67. var result = await ContentDialogHelper.CreateInfoDialog(
  68. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogUserErrorDialogMessage, errorCode, GetErrorTitle(error)),
  69. GetErrorDescription(error) + (isInSetupGuide
  70. ? LocaleManager.Instance[LocaleKeys.DialogUserErrorDialogInfoMessage]
  71. : ""), setupButtonLabel, LocaleManager.Instance[LocaleKeys.InputDialogOk],
  72. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogUserErrorDialogTitle, errorCode));
  73. if (result == UserResult.Ok)
  74. {
  75. OpenHelper.OpenUrl(GetSetupGuideUrl(error));
  76. }
  77. }
  78. }
  79. }