From 2a6c3304bf19e9e49d32f238f13fda727890dfc6 Mon Sep 17 00:00:00 2001 From: Forgot-Dream <56014859+Forgot-Dream@users.noreply.github.com> Date: Sun, 3 Dec 2023 21:15:29 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat(CommonWebsiteTest):=E5=A2=9E=E5=8A=A0B?= =?UTF-8?q?=E7=AB=99=E3=80=81=E7=9F=A5=E4=B9=8E=E3=80=81=E7=9F=A5=E7=BD=91?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=B5=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SduNetCheckTool.Core.csproj | 1 + .../Tests/CommonWebsiteTest.cs | 37 +++++++++++++++++++ SduNetCheckTool.Core/Tests/SduWebsiteTest.cs | 4 +- .../ViewModels/TestViewModel.cs | 3 +- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs diff --git a/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj b/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj index 3bb643f..57fee7a 100644 --- a/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj +++ b/SduNetCheckTool.Core/SduNetCheckTool.Core.csproj @@ -50,6 +50,7 @@ + diff --git a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs new file mode 100644 index 0000000..195eb33 --- /dev/null +++ b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs @@ -0,0 +1,37 @@ +using SduNetCheckTool.Core.Repairs; +using SduNetCheckTool.Core.Utils; +using System; +using System.Collections.Generic; + +namespace SduNetCheckTool.Core.Tests +{ + public class CommonWebsiteTest : ITest + { + public Tuple Test() + { + var sduWebsites = new Dictionary + { + { "哔哩哔哩" , "https://www.bilibili.com" }, + { "知乎" , "https://www.zhihu.com" }, + { "知网" , "https://www.cnki.net" } + }; + + var retList = new List(); + var result = TestResult.Success; + + foreach (var sduWebsite in sduWebsites) + { + var response = HttpUtil.GetHttpResponse(sduWebsite.Value); + if (response != null) + { + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode}"); + continue; + } + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); + result = TestResult.Failed; + } + + return Tuple.Create(result, string.Join("\n", retList), null); + } + } +} diff --git a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs index fe9d4ab..6ffe74c 100644 --- a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs @@ -23,10 +23,10 @@ public Tuple Test() var response = HttpUtil.GetHttpResponse(sduWebsite.Value); if (response != null) { - retList.Add($"{sduWebsite.Key}({sduWebsite.Value}) - {response.StatusCode}"); + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode}"); continue; } - retList.Add($"{sduWebsite.Key}({sduWebsite.Value}) - 无法访问"); + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); result = TestResult.Failed; } diff --git a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs index fdcd81c..b7f4253 100644 --- a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs +++ b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs @@ -30,7 +30,8 @@ private void Init() new DetectionTask(new SduNetTest(),"校园网状态检测"), new DetectionTask(new SystemProxyTest(),"系统代理检测"), new DetectionTask(new SystemGatewayTest(),"系统网关检测"), - new DetectionTask(new SduWebsiteTest(),"山大网站连通性检测") + new DetectionTask(new SduWebsiteTest(),"山大网站连通性检测"), + new DetectionTask(new CommonWebsiteTest(),"常用网站检测") }; _repairs = new Collection(); } From e30138b5620f865390f3eefc5f0ca4cc85acdb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ForDream=E4=B8=B6=E6=A2=A6=E7=A9=BA?= <56014859+Forgot-Dream@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:43:46 +0800 Subject: [PATCH 2/5] [skip ci] Update README.md --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 406d2aa..f2c4cdd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ - [x] 网关检测 - [x] 校内网站检测 - [x] 指定IP检测 && 路由跟踪 -- [ ] 一键修复 +- [x] 一键修复 +- [x] 常用网站检测 ## 引用的库 @@ -18,4 +19,14 @@ |:---:|:---:| |CommunityToolkit.Mvvm|MIT| |Microsoft.Extensions.DependencyInjection|MIT| -|ModernWpfUI|MIT| \ No newline at end of file +|ModernWpfUI|MIT| + +## CI/CD + +您可以在[Github Action](https://github.com/SDUQD-SNA/SduNetCheckTool/actions)获取最新构建的**测试**版本。 + +## 开源协议 + +本软件以[GPLv3](https://github.com/SDUQD-SNA/SduNetCheckTool/blob/master/LICENSE.txt)协议开源。 + +Copyright © 2023 SDUQD-SNA From 3fe1339052ce03de9aba0c8c90778ad0198872f8 Mon Sep 17 00:00:00 2001 From: Application Date: Sun, 3 Dec 2023 23:27:29 +0800 Subject: [PATCH 3/5] Added PAC proxy detection and operation (#3) * Added PAC proxy detection and operation Now sduchecktool supports detecting if a system PAC proxy is set and turn off PAC setting! --- SduNetCheckTool.Core/Repairs/ProxyRepair.cs | 5 ++-- SduNetCheckTool.Core/Tests/SystemProxyTest.cs | 5 +++- SduNetCheckTool.Core/Utils/RegUtil.cs | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/SduNetCheckTool.Core/Repairs/ProxyRepair.cs b/SduNetCheckTool.Core/Repairs/ProxyRepair.cs index 908e62b..267a8a1 100644 --- a/SduNetCheckTool.Core/Repairs/ProxyRepair.cs +++ b/SduNetCheckTool.Core/Repairs/ProxyRepair.cs @@ -10,16 +10,17 @@ public class ProxyRepair : IRepair { public Tuple Repair() { - RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "0"); try { + RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "0"); + RegUtil.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL", ""); ResetIEProxy(); } catch (Exception ex) { return new Tuple(RepairResult.Failed, ex.Message); } - return new Tuple(RepairResult.Success, "已经尝试关闭系统代理,此操作并不会关闭你的代理软件!"); + return new Tuple(RepairResult.Success, "已经尝试关闭系统全局代理和PAC代理,此操作并不会关闭你的代理软件!"); } private enum RET_ERRORS : int diff --git a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs index 1530233..e9b7fa8 100644 --- a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs @@ -32,7 +32,10 @@ public Tuple Test() break; } - data.Add($"代理状态:{proxyEnabledString}"); + data.Add($"系统全局代理状态:{proxyEnabledString}"); + + var PACproxyEnabledString = (RegUtil.IsExisted(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL") ? "开启" : "关闭"); + data.Add($"PAC代理状态:{PACproxyEnabledString}"); } catch (Exception) { diff --git a/SduNetCheckTool.Core/Utils/RegUtil.cs b/SduNetCheckTool.Core/Utils/RegUtil.cs index 85299e4..075fdf9 100644 --- a/SduNetCheckTool.Core/Utils/RegUtil.cs +++ b/SduNetCheckTool.Core/Utils/RegUtil.cs @@ -66,5 +66,32 @@ public static bool IsNullOrEmpty(string text) } return text == "null"; } + + public static bool IsExisted(string path, string name) + { + RegistryKey? regKey = null; + var isExisted = false; + try + { + regKey = Registry.CurrentUser.OpenSubKey(path); + string[] subkeyNames = regKey.GetValueNames(); + foreach (string keyname in subkeyNames) + { + if (keyname == name) + { + isExisted = true; + } + } + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + } + finally + { + regKey?.Close(); + } + return isExisted; + } } } From a763b63a0ed3f54e253f1e27faeac30b5f73d34b Mon Sep 17 00:00:00 2001 From: Application Date: Mon, 4 Dec 2023 23:05:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0PAC=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=A3=80=E6=B5=8B=20=E5=A2=9E=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E7=AB=99ping=E5=BB=B6=E8=BF=9F=E6=A3=80=E6=B5=8B=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added PAC proxy detection and operation Now sduchecktool supports detecting if a system PAC proxy is set and turn off PAC setting! * update ping delay detection for websites update ping delay detection for websites. Most of my time was given to fundamental knowledge!!! --- SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs | 10 ++++++++-- SduNetCheckTool.Core/Tests/SduWebsiteTest.cs | 10 ++++++++-- SduNetCheckTool.Core/Tests/SystemGatewayTest.cs | 14 +++++++------- SduNetCheckTool.Core/Tests/SystemProxyTest.cs | 14 +++++++++----- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs index 195eb33..72ee77a 100644 --- a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs @@ -2,6 +2,7 @@ using SduNetCheckTool.Core.Utils; using System; using System.Collections.Generic; +using System.Net.NetworkInformation; namespace SduNetCheckTool.Core.Tests { @@ -21,10 +22,15 @@ public Tuple Test() foreach (var sduWebsite in sduWebsites) { + var domain = new Uri(sduWebsite.Value).Host; + var ping = new Ping(); + var reply = ping.Send(domain, 2000); + var response = HttpUtil.GetHttpResponse(sduWebsite.Value); - if (response != null) + + if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode}"); + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs index 6ffe74c..ae6c88c 100644 --- a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs @@ -2,6 +2,7 @@ using SduNetCheckTool.Core.Utils; using System; using System.Collections.Generic; +using System.Net.NetworkInformation; namespace SduNetCheckTool.Core.Tests { @@ -20,10 +21,15 @@ public Tuple Test() foreach (var sduWebsite in sduWebsites) { + var domain = new Uri(sduWebsite.Value).Host; + var ping = new Ping(); + var reply = ping.Send(domain, 2000); + var response = HttpUtil.GetHttpResponse(sduWebsite.Value); - if (response != null) + + if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode}"); + retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs index 5e8c309..51af0ef 100644 --- a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Net; using System.Net.NetworkInformation; +using System.Threading; namespace SduNetCheckTool.Core.Tests { @@ -24,19 +25,18 @@ public Tuple Test() IPAddressCollection addresses = iPInterfaceProperties.DhcpServerAddresses; foreach (var item in gatewayIPAddressInformation) { - data.Add($"网卡信息:......{networkInterface.Description}"); - data.Add($"网关地址:......{item.Address}"); - PingReply reply = ping.Send(item.Address); - data.Add($"是否封禁:......{(reply.Status == IPStatus.Success ? "未封禁" : "封禁")}"); + data.Add($"网卡信息: {networkInterface.Description}"); + data.Add($"网关地址: {item.Address}"); + PingReply reply = ping.Send(item.Address, 200); if (reply.Status == IPStatus.Success) { - data.Add($"网关延迟:......{reply.RoundtripTime} ms"); + data.Add($"网关延迟: {reply.RoundtripTime} ms"); } if (addresses.Count > 0) { foreach (IPAddress address in addresses) { - data.Add($"Dhcp地址:.....{address}\n"); + data.Add($"DHCP服务器: {address}\n"); } } } @@ -47,7 +47,7 @@ public Tuple Test() { //ignored } - return new Tuple(result,string.Join("\n",data), null); + return new Tuple(result, string.Join("\n", data), null); } } } diff --git a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs index e9b7fa8..593cd2b 100644 --- a/SduNetCheckTool.Core/Tests/SystemProxyTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemProxyTest.cs @@ -10,7 +10,9 @@ public class SystemProxyTest : ITest public Tuple Test() { var data = new List(); - var result = TestResult.Failed; + var commonProxyEnabledResult = TestResult.Failed; + var pacProxyEnabledResult = TestResult.Failed; + try { var proxyEnabled = RegUtil.RegReadValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "-1"); @@ -22,7 +24,7 @@ public Tuple Test() break; case "0": proxyEnabledString = "关闭"; - result = TestResult.Success; + commonProxyEnabledResult = TestResult.Success; break; case "-1": proxyEnabledString = "获取失败"; @@ -32,16 +34,18 @@ public Tuple Test() break; } - data.Add($"系统全局代理状态:{proxyEnabledString}"); + data.Add($"系统全局代理状态: {proxyEnabledString}"); var PACproxyEnabledString = (RegUtil.IsExisted(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL") ? "开启" : "关闭"); - data.Add($"PAC代理状态:{PACproxyEnabledString}"); + if (PACproxyEnabledString == "关闭") pacProxyEnabledResult = TestResult.Success; + + data.Add($"PAC代理状态: {PACproxyEnabledString}"); } catch (Exception) { //ignored } - return new Tuple(result,string.Join("\n",data), new ProxyRepair()); + return new Tuple((commonProxyEnabledResult == TestResult.Success) && (pacProxyEnabledResult == TestResult.Success) ? TestResult.Success : TestResult.Failed, string.Join("\n", data), new ProxyRepair()); } } } From edc9433a0cf49f370acd577e72e75a2c841bbbb1 Mon Sep 17 00:00:00 2001 From: Application Date: Thu, 7 Dec 2023 20:31:04 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E6=A3=80=E6=B5=8B=E7=BD=91=E7=AB=99=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E9=94=AE=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加检测网站 - 增加导出文件自动打开以及一键复制 --- .../Tests/CommonWebsiteTest.cs | 23 +++++++++++--- SduNetCheckTool.Core/Tests/SduWebsiteTest.cs | 2 +- .../Tests/SystemGatewayTest.cs | 4 ++- .../SduNetCheckTool.GUI.csproj | 5 +++- SduNetCheckTool.GUI/Utils/FileUtil.cs | 28 +++++++++++++++-- .../ViewModels/TestViewModel.cs | 30 +++++++++++++++++-- 6 files changed, 81 insertions(+), 11 deletions(-) diff --git a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs index 72ee77a..bffa47e 100644 --- a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs @@ -12,9 +12,24 @@ public Tuple Test() { var sduWebsites = new Dictionary { - { "哔哩哔哩" , "https://www.bilibili.com" }, - { "知乎" , "https://www.zhihu.com" }, - { "知网" , "https://www.cnki.net" } + { + "必应", "https://cn.bing.com" + }, + { + "知网", "https://www.cnki.net" + }, + { + "知乎", "https://www.zhihu.com" + }, + { + "百度", "https://www.baidu.com" + }, + { + "哔哩哔哩", "https://www.bilibili.com" + }, + { + "中国大学MOOC", "https://www.icourse163.org" + }, }; var retList = new List(); @@ -30,7 +45,7 @@ public Tuple Test() if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs index ae6c88c..be3befc 100644 --- a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs @@ -29,7 +29,7 @@ public Tuple Test() if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs index 51af0ef..a5944f2 100644 --- a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs @@ -1,6 +1,7 @@ using SduNetCheckTool.Core.Repairs; using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Threading; @@ -36,9 +37,10 @@ public Tuple Test() { foreach (IPAddress address in addresses) { - data.Add($"DHCP服务器: {address}\n"); + data.Add($"DHCP服务器: {address}"); } } + data[data.Count - 1] = data.Last() + "\n"; } } result = TestResult.Success; diff --git a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj index 8219bce..5ad2866 100644 --- a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj +++ b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj @@ -168,6 +168,9 @@ 7.0.0 + + 7.1.3 + 0.9.6 @@ -196,4 +199,4 @@ - + \ No newline at end of file diff --git a/SduNetCheckTool.GUI/Utils/FileUtil.cs b/SduNetCheckTool.GUI/Utils/FileUtil.cs index cdd3097..7c01b8e 100644 --- a/SduNetCheckTool.GUI/Utils/FileUtil.cs +++ b/SduNetCheckTool.GUI/Utils/FileUtil.cs @@ -1,4 +1,5 @@ using SduNetCheckTool.GUI.Common; +using System; using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -14,17 +15,40 @@ public static string ExportReport(ObservableCollection tasks) var exportFilePath = ExportPath + "\\" + System.DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; if (tasks.Any(i => i.TaskStatusEnum == TaskStatusEnum.Waiting)) - return "请先运行测试"; + return "NoRecords"; if (!Directory.Exists(ExportPath)) Directory.CreateDirectory(ExportPath); foreach (var detectionTask in tasks) { - File.AppendAllText(exportFilePath, detectionTask.Tips + '\n', Encoding.UTF8); + File.AppendAllText(exportFilePath, detectionTask.Tips + '\n' + '\n', Encoding.UTF8); } return exportFilePath; } + + public static string ReadFile(string filePath) + { + if (!File.Exists(filePath)) return "FileNotExists"; + + try + { + StreamReader sr = new StreamReader(filePath); + string data = "", line = ""; + + while ((line = sr.ReadLine()) != null) + { + data += line + "\n"; + } + + return data; + } + catch (Exception e) + { + // + } + return "-1"; + } } } diff --git a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs index b7f4253..9fd3e5a 100644 --- a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs +++ b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Windows.Input; using SduNetCheckTool.GUI.Utils; +using Microsoft.Toolkit.Uwp.Notifications; namespace SduNetCheckTool.GUI.ViewModels { @@ -52,7 +53,7 @@ public ObservableCollection Tasks public ICommand StartCommand { get; } public ICommand RepairCommand { get; } - + public ICommand ExportReportCommand { get; } private async void Repair() @@ -92,7 +93,32 @@ await Task.Run(() => private void ExportReport() { - MessageBox.Show("日志文件导出:" + FileUtil.ExportReport(Tasks)); + var output = FileUtil.ExportReport(Tasks); + if (output == "NoRecords") + { + MessageBox.Show("请先点击'开始检测'运行测试! >_<", "提示"); + } + else + { + MessageBoxResult result = MessageBox.Show("日志文件已生成! (⑅•ᴗ•⑅) \n路径: " + output + "\n点击'确定'打开日志并自动复制到剪贴板!", "提示"); + if (result == MessageBoxResult.OK) + { + System.Diagnostics.Process.Start(output); + string data = FileUtil.ReadFile(output); + if (data == "FileNotExists" || data == "-1") + { + MessageBox.Show("出现了一点小错误..."); + return; + } + Clipboard.SetText(data); + new ToastContentBuilder() + .AddArgument("action", "viewConversation") + .AddArgument("conversationId", 9813) + .AddText("已经成功复制内容到剪贴板啦! ๐•ᴗ•๐") + .AddText("可以直接分享给同学哦~") + .Show(); + } + } } } }