1.1.3 -> 1.1.4 第85次更新

This commit is contained in:
Space Time 2024-12-20 13:15:28 +08:00
parent af28d96bf9
commit 13d8663a6e
7 changed files with 37 additions and 37 deletions

View File

@ -9,7 +9,7 @@ namespace Sheas_Cealer.Consts;
internal abstract partial class MainConst : MainMultilangConst internal abstract partial class MainConst : MainMultilangConst
{ {
internal enum SettingsMode internal enum SettingsMode
{ BrowserPathMode, UpstreamUrlMode, ExtraArgsMode }; { BrowserPathMode, UpstreamUrlMode, ExtraArgsMode }
public static bool IsAdmin => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); public static bool IsAdmin => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);

View File

@ -1,13 +1,14 @@
using Sheas_Cealer.Consts; using Sheas_Cealer.Consts;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
namespace Sheas_Cealer.Convs; namespace Sheas_Cealer.Convs;
internal class MainSettingsBoxTextConv : IMultiValueConverter internal class MainSettingsBoxTextConv : IMultiValueConverter
{ {
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{ {
MainConst.SettingsMode settingsMode = (MainConst.SettingsMode)values[0]; MainConst.SettingsMode settingsMode = (MainConst.SettingsMode)values[0];
string browserPath = (string)values[1]; string browserPath = (string)values[1];
@ -19,9 +20,9 @@ internal class MainSettingsBoxTextConv : IMultiValueConverter
MainConst.SettingsMode.BrowserPathMode => browserPath, MainConst.SettingsMode.BrowserPathMode => browserPath,
MainConst.SettingsMode.UpstreamUrlMode => upstreamUrl, MainConst.SettingsMode.UpstreamUrlMode => upstreamUrl,
MainConst.SettingsMode.ExtraArgsMode => extraArgs, MainConst.SettingsMode.ExtraArgsMode => extraArgs,
_ => throw new UnreachableException(), _ => throw new UnreachableException()
}; };
} }
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) => throw new NotImplementedException(); public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
} }

View File

@ -32,7 +32,7 @@ internal static partial class IconRemover
SetWindowPos(hwnd, nint.Zero, 0, 0, 0, 0, SwpNoMove | SwpNoSize | SwpNoZOrder | SwpFrameChanged); SetWindowPos(hwnd, nint.Zero, 0, 0, 0, 0, SwpNoMove | SwpNoSize | SwpNoZOrder | SwpFrameChanged);
SendMessage(hwnd, WmSetIcon, new nint(1), nint.Zero); SendMessage(hwnd, WmSetIcon, new(1), nint.Zero);
SendMessage(hwnd, WmSetIcon, nint.Zero, nint.Zero); SendMessage(hwnd, WmSetIcon, nint.Zero, nint.Zero);
} }
} }

View File

@ -5,42 +5,41 @@ using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Sheas_Cealer.Utils namespace Sheas_Cealer.Utils;
internal static class NginxCleaner
{ {
internal static class NginxCleaner private static readonly SemaphoreSlim IsCleaningSemaphore = new(1);
internal static async Task Clean()
{ {
private static readonly SemaphoreSlim IsCleaningSemaphore = new(1); if (!await IsCleaningSemaphore.WaitAsync(0))
return;
internal static async Task Clean() try
{ {
if (!await IsCleaningSemaphore.WaitAsync(0)) string hostsContent = await File.ReadAllTextAsync(MainConst.HostsConfPath);
return; int hostsConfStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker, StringComparison.Ordinal);
int hostsConfEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker, StringComparison.Ordinal);
try if (hostsConfStartIndex != -1 && hostsConfEndIndex != -1)
{ await File.WriteAllTextAsync(MainConst.HostsConfPath, hostsContent.Remove(hostsConfStartIndex, hostsConfEndIndex - hostsConfStartIndex + MainConst.HostsConfEndMarker.Length));
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) using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
await File.WriteAllTextAsync(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);
foreach (X509Certificate2 storedCert in certStore.Certificates) break;
if (storedCert.Subject == MainConst.NginxRootCertSubjectName) }
while (true) catch { }
try
{
certStore.Remove(storedCert);
break; certStore.Close();
}
catch { }
certStore.Close();
}
finally { IsCleaningSemaphore.Release(); }
} }
finally { IsCleaningSemaphore.Release(); }
} }
} }

View File

@ -16,7 +16,7 @@ namespace Sheas_Cealer.Wins;
public partial class AboutWin : Window public partial class AboutWin : Window
{ {
private readonly AboutPres AboutPres; private readonly AboutPres AboutPres;
private readonly HttpClient AboutClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); private readonly HttpClient AboutClient = new(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
internal AboutWin() internal AboutWin()
{ {

View File

@ -34,7 +34,7 @@ namespace Sheas_Cealer.Wins;
public partial class MainWin : Window public partial class MainWin : Window
{ {
private readonly MainPres MainPres; private readonly MainPres MainPres;
private readonly HttpClient MainClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); private readonly HttpClient MainClient = new(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
private DispatcherTimer? HoldButtonTimer; private DispatcherTimer? HoldButtonTimer;
private readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) }; private readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) };
private readonly FileSystemWatcher CealHostWatcher = new(Path.GetDirectoryName(MainConst.CealHostPath)!, Path.GetFileName(MainConst.CealHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private readonly FileSystemWatcher CealHostWatcher = new(Path.GetDirectoryName(MainConst.CealHostPath)!, Path.GetFileName(MainConst.CealHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
@ -346,7 +346,7 @@ public partial class MainWin : Window
if (!MainPres.IsMihomoRunning) if (!MainPres.IsMihomoRunning)
{ {
if (string.IsNullOrWhiteSpace(MihomoConfs)) if (string.IsNullOrWhiteSpace(MihomoConfs))
throw new Exception(MainConst._MihomoConfErrorMsg); throw new(MainConst._MihomoConfErrorMsg);
if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
return; return;
@ -532,7 +532,7 @@ public partial class MainWin : Window
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
(Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B); (Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); newButtonStyle.Setters.Add(new Setter(ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
Application.Current.Resources[typeof(Button)] = newButtonStyle; Application.Current.Resources[typeof(Button)] = newButtonStyle;
MainPres.AccentForegroundColor = newAccentForegroundColor; MainPres.AccentForegroundColor = newAccentForegroundColor;

View File

@ -47,7 +47,7 @@ public partial class SettingsWin : Window
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
(Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B); (Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); newButtonStyle.Setters.Add(new Setter(ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
Application.Current.Resources[typeof(Button)] = newButtonStyle; Application.Current.Resources[typeof(Button)] = newButtonStyle;
SettingsPres.AccentForegroundColor = newAccentForegroundColor; SettingsPres.AccentForegroundColor = newAccentForegroundColor;