1.1.4 -> 1.1.5 第27次更新

This commit is contained in:
Space Time 2025-06-06 10:35:25 +08:00
parent 938ca77fc1
commit 479c16c2a1
2 changed files with 17 additions and 30 deletions

View File

@ -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();
}
}

View File

@ -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();