From 00a30e718b5a7e1035d0da82a4cb3b8294418cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=88=E6=A3=AE=E5=90=B4?= <8402134@qq.com> Date: Mon, 14 Nov 2022 14:02:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=BE=AE=E4=BF=A1=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCRobot/PCRobot.csproj | 3 +- PCRobot/PCRobotForm.cs | 10 ++++ PCRobot/Utils/WeChatActivateHelper.cs | 41 +++++++++++++++ PCRobot/app.manifest | 75 +++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 PCRobot/app.manifest diff --git a/PCRobot/PCRobot.csproj b/PCRobot/PCRobot.csproj index 9eaee61..48b42fe 100644 --- a/PCRobot/PCRobot.csproj +++ b/PCRobot/PCRobot.csproj @@ -42,7 +42,7 @@ tencent_qqpim_72px_1127550_easyicon.net.ico - Properties\app.manifest + app.manifest @@ -316,6 +316,7 @@ WechatUpdate.cs + diff --git a/PCRobot/PCRobotForm.cs b/PCRobot/PCRobotForm.cs index cdf0b3d..1eb4f33 100644 --- a/PCRobot/PCRobotForm.cs +++ b/PCRobot/PCRobotForm.cs @@ -39,6 +39,16 @@ namespace PCRobot private void PCRobotForm_Load(object sender, EventArgs e) { + try + { + WeChatActivateHelper.Set_Hosts("dldir1v6.qq.com", "127.0.0.1"); + WeChatActivateHelper.Set_Hosts("dldir1.qq.com", "127.0.0.1"); + LogHelper.GetSingleObj().Info("屏蔽", "屏蔽微信自动更新成功"); + } + catch (Exception exception) + { + LogHelper.GetSingleObj().Info("屏蔽", "屏蔽微信自动更新异常"); + } try { diff --git a/PCRobot/Utils/WeChatActivateHelper.cs b/PCRobot/Utils/WeChatActivateHelper.cs index 0ca5d81..cdb28e2 100644 --- a/PCRobot/Utils/WeChatActivateHelper.cs +++ b/PCRobot/Utils/WeChatActivateHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -171,6 +172,8 @@ namespace WechatHelper } } + + /// /// 关闭窗口 /// @@ -298,6 +301,44 @@ namespace WechatHelper { _mouseHeartbeatTime = DateTime.Now; } + + public static void Set_Hosts(string domain, string ip) + { + string path = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\drivers\\etc\\hosts"; + if (File.GetAttributes(path) == (FileAttributes.ReadOnly | FileAttributes.Archive)) + { + File.SetAttributes(path, FileAttributes.Archive); + } + + + string[] hosts = File.ReadAllLines(path); + List list = hosts.ToList(); + string temp = hosts.ToList().FirstOrDefault(x => x.Contains(domain)); + if (string.IsNullOrEmpty(temp)) + { + list.Add($"{ip} {domain}"); + } + File.WriteAllLines(path, list.ToArray()); + } + + public static void Remove_Hosts(string hosts_str) + { + string path = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\drivers\\etc\\hosts"; + string[] hosts = File.ReadAllLines(path); + List list = hosts.ToList(); + //int index = list.FindIndex(x => x.Contains(hosts_str)); + //list.RemoveAt(index); + list.RemoveAll(x => x.Contains(hosts_str)); + //foreach (string item in list.ToArray()) + //{ + // if (item.Contains(hosts_str)) + // { + // list.Remove(item); + // } + //} + File.WriteAllLines(path, list.ToArray()); + } + } internal class MouseHook diff --git a/PCRobot/app.manifest b/PCRobot/app.manifest new file mode 100644 index 0000000..60a45a2 --- /dev/null +++ b/PCRobot/app.manifest @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +