mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-12 20:32:09 +08:00
1.1.4 -> 1.1.5 第27次更新
This commit is contained in:
parent
938ca77fc1
commit
479c16c2a1
@ -2,44 +2,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sheas_Cealer.Utils;
|
||||
|
||||
internal static class NginxCleaner
|
||||
{
|
||||
internal static readonly SemaphoreSlim IsNginxCleaningSemaphore = new(1);
|
||||
|
||||
internal static async Task Clean()
|
||||
{
|
||||
if (!await IsNginxCleaningSemaphore.WaitAsync(0))
|
||||
return;
|
||||
string hostsContent = await File.ReadAllTextAsync(MainConst.HostsConfPath);
|
||||
int hostsConfStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker, StringComparison.Ordinal);
|
||||
int hostsConfEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker, StringComparison.Ordinal);
|
||||
|
||||
try
|
||||
{
|
||||
string hostsContent = await File.ReadAllTextAsync(MainConst.HostsConfPath);
|
||||
int hostsConfStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker, StringComparison.Ordinal);
|
||||
int hostsConfEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker, StringComparison.Ordinal);
|
||||
if (hostsConfStartIndex != -1 && hostsConfEndIndex != -1)
|
||||
await File.WriteAllTextAsync(MainConst.HostsConfPath, hostsContent.Remove(hostsConfStartIndex, hostsConfEndIndex - hostsConfStartIndex + MainConst.HostsConfEndMarker.Length));
|
||||
|
||||
if (hostsConfStartIndex != -1 && hostsConfEndIndex != -1)
|
||||
await File.WriteAllTextAsync(MainConst.HostsConfPath, hostsContent.Remove(hostsConfStartIndex, hostsConfEndIndex - hostsConfStartIndex + MainConst.HostsConfEndMarker.Length));
|
||||
using X509Store certStore = new(StoreName.Root, StoreLocation.LocalMachine, OpenFlags.ReadWrite);
|
||||
|
||||
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);
|
||||
|
||||
foreach (X509Certificate2 storedCert in certStore.Certificates)
|
||||
if (storedCert.Subject == MainConst.NginxRootCertSubjectName)
|
||||
while (true)
|
||||
try
|
||||
{
|
||||
certStore.Remove(storedCert);
|
||||
break;
|
||||
}
|
||||
catch { }
|
||||
|
||||
break;
|
||||
}
|
||||
catch { }
|
||||
|
||||
certStore.Close();
|
||||
}
|
||||
finally { IsNginxCleaningSemaphore.Release(); }
|
||||
certStore.Close();
|
||||
}
|
||||
}
|
@ -206,9 +206,6 @@ public partial class MainWin : Window
|
||||
|
||||
if (!MainPres.IsConginxRunning && !MainPres.IsNginxRunning)
|
||||
{
|
||||
if (NginxCleaner.IsNginxCleaningSemaphore.CurrentCount == 0 || !await IsNginxLaunchingSemaphore.WaitAsync(0))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if ((!MainPres.IsConginxExist && !MainPres.IsNginxExist) ||
|
||||
@ -238,7 +235,7 @@ public partial class MainWin : Window
|
||||
rootCertRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
||||
|
||||
using X509Certificate2 rootCert = rootCertRequest.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(100));
|
||||
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
||||
using X509Store certStore = new(StoreName.Root, StoreLocation.LocalMachine, OpenFlags.ReadWrite);
|
||||
|
||||
certStore.Add(rootCert);
|
||||
certStore.Close();
|
||||
|
Loading…
Reference in New Issue
Block a user