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