1.1.3 -> 1.1.4 第32次更新

This commit is contained in:
Space Time 2024-12-07 13:06:49 +08:00
parent abd180c0e7
commit 8c44b0b82a
3 changed files with 47 additions and 25 deletions

View File

@ -0,0 +1,42 @@
using System.IO;
using System.Security.Cryptography.X509Certificates;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Utils
{
internal static class GlobalCealCleaner
{
private static bool IsCleaning = false;
internal static void Clean()
{
if (IsCleaning)
return;
IsCleaning = true;
string hostsContent = File.ReadAllText(MainConst.HostsConfPath);
int hostsConfStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker);
int hostsConfEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker);
if (hostsConfStartIndex != -1 && hostsConfEndIndex != -1)
File.WriteAllText(MainConst.HostsConfPath, hostsContent.Remove(hostsConfStartIndex, hostsConfEndIndex - hostsConfStartIndex + MainConst.HostsConfEndMarker.Length));
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
foreach (X509Certificate2 storedCert in certStore.Certificates)
if (storedCert.Subject == MainConst.NginxRootCertSubjectName)
while (true)
try
{
certStore.Remove(storedCert);
break;
}
catch { }
certStore.Close();
IsCleaning = false;
}
}
}

View File

@ -1,6 +1,4 @@
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using Sheas_Cealer.Consts;
using SheasCore;
@ -10,27 +8,5 @@ internal class NginxProc : Proc
{
internal NginxProc() : base(MainConst.NginxPath) { }
public override void Process_Exited(object sender, EventArgs e)
{
string hostsContent = File.ReadAllText(MainConst.HostsConfPath);
int hostsConfStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker);
int hostsConfEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker);
if (hostsConfStartIndex != -1 && hostsConfEndIndex != -1)
File.WriteAllText(MainConst.HostsConfPath, hostsContent.Remove(hostsConfStartIndex, hostsConfEndIndex - hostsConfStartIndex + MainConst.HostsConfEndMarker.Length));
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
foreach (X509Certificate2 storedCert in certStore.Certificates)
if (storedCert.Subject == MainConst.NginxRootCertSubjectName)
while (true)
try
{
certStore.Remove(storedCert);
break;
}
catch { }
certStore.Close();
}
public override void Process_Exited(object sender, EventArgs e) => GlobalCealCleaner.Clean();
}

View File

@ -285,11 +285,15 @@ public partial class MainWin : Window
MainPres.IsNginxIniting = false;
}
else
{
foreach (Process nginxProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.NginxPath)))
{
nginxProcess.Kill();
await nginxProcess.WaitForExitAsync();
}
GlobalCealCleaner.Clean();
}
}
private void MihomoButton_Click(object sender, RoutedEventArgs e)
{