diff --git a/src/MaaWpfGui/App.xaml.cs b/src/MaaWpfGui/App.xaml.cs index 5bb5c3a998..bb0fe11b9f 100644 --- a/src/MaaWpfGui/App.xaml.cs +++ b/src/MaaWpfGui/App.xaml.cs @@ -30,7 +30,7 @@ namespace MaaWpfGui public void Hyperlink_Click(object sender, RoutedEventArgs e) { Hyperlink link = sender as Hyperlink; - if (!string.IsNullOrEmpty(link.NavigateUri.AbsoluteUri)) + if (!string.IsNullOrEmpty(link?.NavigateUri?.AbsoluteUri)) { Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri)); } diff --git a/src/MaaWpfGui/Constants/MaaUrls.cs b/src/MaaWpfGui/Constants/MaaUrls.cs index c1add4ea80..29eb0ce1fb 100644 --- a/src/MaaWpfGui/Constants/MaaUrls.cs +++ b/src/MaaWpfGui/Constants/MaaUrls.cs @@ -38,23 +38,18 @@ namespace MaaWpfGui.Constants public const string QQchannel = "https://pd.qq.com/s/4j1ju9z47"; - public static string HelpUri - { - get - { - var language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage); - return $"https://maa.plus/docs/{_helpUrl[language]}"; - } - } - public static string OverseasAdaptation + private static string language => ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage); + + public static string HelpUri => $"https://maa.plus/docs/{_helpUrl[language]}"; + + public static string OverseasAdaptation => $"https://maa.plus/docs/{_overseasAdaptation[language]}"; + + public static string NewIssueUri => language switch { - get - { - var language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage); - return $"https://maa.plus/docs/{_overseasAdaptation[language]}"; - } - } + "zh-cn" => "https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/new?assignees=&labels=bug&template=cn-bug-report.yaml", + _ => "https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/new?assignees=&labels=bug&template=en-bug-report.yaml", + }; private static readonly Dictionary _overseasAdaptation = new Dictionary { diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs index 21a2b86d78..a6c690245b 100644 --- a/src/MaaWpfGui/Main/Bootstrapper.cs +++ b/src/MaaWpfGui/Main/Bootstrapper.cs @@ -178,7 +178,7 @@ namespace MaaWpfGui.Main _logger.Fatal(e.Exception, "Unhandled exception"); } - var errorView = new ErrorView(e.Exception.Message, e.Exception.StackTrace, true); + var errorView = new ErrorView(e.Exception, true); errorView.ShowDialog(); } } diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index c801a43d06..22cb43745e 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -440,19 +440,23 @@ The video resolution is required to be 16:9, and there are no interference facto - - The resource is damaged, please download the full package again + Error + MAA has encountered an error Details Solution Please refer to the documentation: FAQ - Crashes to solve. Please use administrator to open MAA + Create a GitHub issue + Join QQ Group + Copy error message + + + The resource is damaged, please download the full package again ADB File NOT exists ADB Download Failed Please do it manually (rename adb.exe and replace the adb file in the emulator) Successfully Replaced ADB File - Create a GitHub issue - Join QQ Group Initialization error! Emulator resolution not supported, please set at least 720P with 16:9 ratio fails to be obtain emulator resolution . Please restart computer or consider try other emulator diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 4a78021d87..980dd8a7b2 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -442,19 +442,23 @@ - - 资源损坏,请重新下载完整安装包 + 错误 + MAA 遇到了问题 详细信息 解决方案 请参考文档:常见问题 - 闪退 进行操作 请使用管理员权限打开 MAA 进行操作 + 创建 GitHub issue + 加入QQ群反馈问题 + 复制错误信息 + + + 资源损坏,请重新下载完整安装包 ADB 路径不存在 ADB 下载失败 请手动进行操作(将 adb.exe 重命名后替换上方模拟器自带 adb 即可) 成功替换 ADB 文件 - 创建 GitHub issue - 加入QQ群反馈问题 初始化错误! 模拟器分辨率不支持,请设置为 720p 或更高,且为 16:9 比例 模拟器分辨率获取失败,建议重启电脑,或更换模拟器后再次尝试 diff --git a/src/MaaWpfGui/Views/UI/ErrorView.xaml b/src/MaaWpfGui/Views/UI/ErrorView.xaml index 96d9fac932..ef289d25ef 100644 --- a/src/MaaWpfGui/Views/UI/ErrorView.xaml +++ b/src/MaaWpfGui/Views/UI/ErrorView.xaml @@ -1,5 +1,6 @@ - - - - + + + + - - + + + + + + +
+ + + + + + +
+
+ + + + + + +
+
+ + + + + + +
- - +
+
- - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - - - - - + + + + + + + +
diff --git a/src/MaaWpfGui/Views/UI/ErrorView.xaml.cs b/src/MaaWpfGui/Views/UI/ErrorView.xaml.cs index ec3a7ec228..a19eff2892 100644 --- a/src/MaaWpfGui/Views/UI/ErrorView.xaml.cs +++ b/src/MaaWpfGui/Views/UI/ErrorView.xaml.cs @@ -12,9 +12,14 @@ // using System; +using System.ComponentModel; using System.Diagnostics; +using System.IO; +using System.Text; +using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; +using System.Windows.Media; using MaaWpfGui.Constants; using MaaWpfGui.Helper; @@ -23,29 +28,56 @@ namespace MaaWpfGui.Views.UI /// /// ErrorView.xaml 的交互逻辑 /// - public partial class ErrorView + public partial class ErrorView : INotifyPropertyChanged { protected bool ShouldExit { get; set; } + public string ExceptionMessage { get; set; } + + public string PossibleSolution { get; set; } + + public string ExceptionDetails { get; set; } + public ErrorView() { InitializeComponent(); } - public ErrorView(string error, string details, bool shouldExit) + public ErrorView(Exception exc, bool shouldExit) { InitializeComponent(); - Title = error; - Error.Text = error; - ErrorDetails.Text = details; - ErrorSolution.Text = GetSolution(error, details); + var exc0 = exc; + var errorb = new StringBuilder(); + while (true) + { + errorb.Append(exc.Message); + exc = exc.InnerException; + if (exc != null) + { + errorb.AppendLine(); + } + else + { + break; + } + } + var error = errorb.ToString(); + var details = exc0.ToString(); + ExceptionMessage = error; + ExceptionDetails = details; + PossibleSolution = GetSolution(error, details); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ExceptionMessage))); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PossibleSolution))); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ExceptionDetails))); ShouldExit = shouldExit; var isZhCn = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage) == "zh-cn"; - ErrorQqGroupLink.Visibility = isZhCn ? Visibility.Visible : Visibility.Hidden; + ErrorQqGroupLink.Visibility = isZhCn ? Visibility.Visible : Visibility.Collapsed; } + public event PropertyChangedEventHandler PropertyChanged; + private string GetSolution(string error, string details) { if (details.Contains("AsstGetVersion()") || details.Contains("DllNotFoundException") || details.Contains("lambda_method")) @@ -75,5 +107,31 @@ namespace MaaWpfGui.Views.UI { Process.Start(((Hyperlink)sender).NavigateUri.AbsoluteUri); } + + private void CopyToClipboard() + { + var range = new TextRange(RichTextBox.Document.ContentStart, RichTextBox.Document.ContentEnd); + var data = new DataObject(); + data.SetText(range.Text); + if (range.CanSave(DataFormats.Rtf)) + { + var ms = new MemoryStream(); + range.Save(ms, DataFormats.Rtf); + var arr = ms.ToArray(); + + // Save to RTF doesn't write non-ascii characters (implementation-defined behavior?) + data.SetData(DataFormats.Rtf, Encoding.UTF8.GetString(arr)); + } + + Clipboard.SetDataObject(data, true); + } + + private async void CopyErrorMessage_Click(object sender, RoutedEventArgs e) + { + CopyToClipboard(); + CopiedTip.IsOpen = true; + await Task.Delay(3000); + CopiedTip.IsOpen = false; + } } }