mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-13 12:52:08 +08:00
1.1.3 -> 1.1.4 第32次更新
This commit is contained in:
parent
abd180c0e7
commit
8c44b0b82a
42
Utils/GlobalCealCleaner.cs
Normal file
42
Utils/GlobalCealCleaner.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user