diff --git a/res/App.Designer.cs b/res/App.Designer.cs index e83958f..5911284 100644 --- a/res/App.Designer.cs +++ b/res/App.Designer.cs @@ -113,6 +113,15 @@ namespace YaeAchievement.res { } } + /// + /// Looks up a localized string similar to Network error ({0}: {1}). + /// + internal static string ExceptionNetwork { + get { + return ResourceManager.GetString("ExceptionNetwork", resourceCulture); + } + } + /// /// Looks up a localized string similar to Export to: ///[0] Cocogoat (https://cocogoat.work/achievement, Default) diff --git a/res/App.resx b/res/App.resx index 7b06bc6..4d66260 100644 --- a/res/App.resx +++ b/res/App.resx @@ -134,4 +134,7 @@ Input a number (0-5): Installing Visual C++ Redistributable... + + Network error ({0}: {1}) + \ No newline at end of file diff --git a/res/App.zh.resx b/res/App.zh.resx index 98c53fc..145b729 100644 --- a/res/App.zh.resx +++ b/res/App.zh.resx @@ -128,4 +128,7 @@ 正在安装 Visual C++ Redistributable... + + 网络错误,请检查网络后重试 ({0}: {1}) + \ No newline at end of file diff --git a/src/Utils.cs b/src/Utils.cs index 6284873..f8f29e9 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO.Pipes; using System.Net; using System.Net.Http.Headers; +using System.Net.Sockets; using System.Runtime.InteropServices; using Microsoft.Win32; using YaeAchievement.AppCenterSDK; @@ -149,14 +150,23 @@ public static class Utils { public static void InstallExceptionHook() { AppDomain.CurrentDomain.UnhandledException += (_, e) => { var ex = e.ExceptionObject; - if (ex is ApplicationException exception) { - Console.WriteLine(exception.Message); - } else { - Console.WriteLine(ex.ToString()); - Console.WriteLine(App.UploadError); - AppCenter.TrackCrash((Exception) e.ExceptionObject); - AppCenter.Upload(); - Environment.Exit(-1); + switch (ex) { + case ApplicationException ex1: + Console.WriteLine(ex1.Message); + break; + case SocketException ex2: + Console.WriteLine(App.ExceptionNetwork, nameof(SocketException), ex2.Message); + break; + case HttpRequestException ex3: + Console.WriteLine(App.ExceptionNetwork, nameof(HttpRequestException), ex3.Message); + break; + default: + Console.WriteLine(ex.ToString()); + Console.WriteLine(App.UploadError); + AppCenter.TrackCrash((Exception) e.ExceptionObject); + AppCenter.Upload(); + Environment.Exit(-1); + break; } }; }