diff --git a/src/Models/Issue.cs b/src/Models/Issue.cs index 36a069ed..52e531d6 100644 --- a/src/Models/Issue.cs +++ b/src/Models/Issue.cs @@ -1,70 +1,31 @@ using System; using System.Reflection; +using System.IO; using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; - -#if NET6_0_OR_GREATER -using System.Net.Http; -#else -using System.Net; -#endif +using System.Diagnostics; namespace SourceGit.Models { /// - /// 崩溃日志上报 + /// 崩溃日志生成 /// public class Issue { - [JsonPropertyName("access_token")] - public string AccessToken { get; set; } - [JsonPropertyName("repo")] - public string Repo { get; set; } - [JsonPropertyName("title")] - public string Title { get; set; } - [JsonPropertyName("body")] - public string Body { get; set; } - - /// - /// 创建Gitee平台ISSUE - /// - /// public static void Create(System.Exception e) { - if (!Preference.Instance.General.EnableCrashReport) return; + var builder = new StringBuilder(); + builder.Append("Crash: "); + builder.Append(e.Message); + builder.Append("\n\n"); + builder.Append("----------------------------\n"); + builder.Append($"Windows OS: {Environment.OSVersion}\n"); + builder.Append($"Version: {Assembly.GetExecutingAssembly().GetName().Version}"); + builder.Append($"Platform: {AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}"); + builder.Append($"Source: {e.Source}"); + builder.Append($"---------------------------\n\n"); + builder.Append(e.StackTrace); - try { - var issue = new Issue(); - issue.AccessToken = "d0d56410f13a3826b87fb0868d5a26ce"; // 这是我个人的Token,仅启用ISSUE创建功能,请不要使用 - issue.Repo = "sourcegit"; - issue.Title = "CrashReport: " + e.Message; - issue.Body = string.Format( - "{0}\n\n**Base Information:**\n\n| Windows OS | {1} |\n|---|---|\n| Version | {2} |\n| Platform | {3} |\n\n**Source:** {4}\n\n**StackTrace:**\n\n ```\n{5}\n```\n", - e.Message, - Environment.OSVersion.ToString(), - Assembly.GetExecutingAssembly().GetName().Version.ToString(), - AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName, - e.Source, - e.StackTrace); - -#if NET6_0_OR_GREATER - var content = new StringContent(JsonSerializer.Serialize(issue), Encoding.UTF8, "application/json"); - var req = new HttpClient() { Timeout = TimeSpan.FromSeconds(1) }; - req.PostAsync("https://gitee.com/api/v5/repos/sourcegit/issues", content).Wait(); -#else - var req = WebRequest.CreateHttp("https://gitee.com/api/v5/repos/sourcegit/issues"); - req.Method = "POST"; - req.ContentType = "application/json"; - req.Headers.Add("charset", "UTF-8"); - req.Timeout = 1000; - - using (var writer = req.GetRequestStream()) { - var data = JsonSerializer.Serialize(issue); - var raw = Encoding.UTF8.GetBytes(data); - writer.Write(raw, 0, raw.Length); - } - - req.GetResponse(); -#endif - } catch { } + var time = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + var file = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + file = Path.Combine(file, $"sourcegit_crash_{time}.log"); + File.WriteAllText(file, builder.ToString()); } } } diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index 4ba96233..077733ab 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -68,11 +68,6 @@ namespace SourceGit.Models { /// public int LastCheckDay { get; set; } = 0; - /// - /// 是否启用崩溃上报 - /// - public bool EnableCrashReport { get; set; } = false; - /// /// 是否尝试使用 Windows Terminal 打开终端 /// diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml index 78a75ab3..95a48339 100644 --- a/src/Views/Preference.xaml +++ b/src/Views/Preference.xaml @@ -12,7 +12,7 @@ WindowStartupLocation="CenterOwner" ResizeMode="NoResize" Title="{DynamicResource Text.Preference}" - Width="500" Height="340"> + Width="500" Height="312"> @@ -68,7 +68,6 @@ - @@ -168,15 +167,9 @@ Content="{DynamicResource Text.Preference.RestoreTabs}" IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Restore.IsEnabled, Mode=TwoWay}"/> - - -