mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-13 21:02:08 +08:00
1.1.1 -> 1.1.2 第42次更新
This commit is contained in:
parent
f72d9bbd79
commit
788b639c1f
18
Consts/MainMultilangConst.Designer.cs
generated
18
Consts/MainMultilangConst.Designer.cs
generated
@ -321,6 +321,15 @@ namespace Sheas_Cealer.Consts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Global Purging is Initing 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string MihomoButtonIsInitingContent {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("MihomoButtonIsInitingContent", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Stop Global Purging 的本地化字符串。
|
/// 查找类似 Stop Global Purging 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -357,6 +366,15 @@ namespace Sheas_Cealer.Consts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Global Cealing is Initing 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string NginxButtonIsInitingContent {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("NginxButtonIsInitingContent", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Stop Global Cealing 的本地化字符串。
|
/// 查找类似 Stop Global Cealing 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -159,6 +159,9 @@
|
|||||||
<data name="ExtraArgsSettingsModeName" xml:space="preserve">
|
<data name="ExtraArgsSettingsModeName" xml:space="preserve">
|
||||||
<value>Extra Args</value>
|
<value>Extra Args</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="MihomoButtonIsInitingContent" xml:space="preserve">
|
||||||
|
<value>Global Purging is Initing</value>
|
||||||
|
</data>
|
||||||
<data name="MihomoButtonIsRunningContent" xml:space="preserve">
|
<data name="MihomoButtonIsRunningContent" xml:space="preserve">
|
||||||
<value>Stop Global Purging</value>
|
<value>Stop Global Purging</value>
|
||||||
</data>
|
</data>
|
||||||
@ -171,6 +174,9 @@
|
|||||||
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
|
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
|
||||||
<value>Click to launch a local Mihomo</value>
|
<value>Click to launch a local Mihomo</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NginxButtonIsInitingContent" xml:space="preserve">
|
||||||
|
<value>Global Cealing is Initing</value>
|
||||||
|
</data>
|
||||||
<data name="NginxButtonIsRunningContent" xml:space="preserve">
|
<data name="NginxButtonIsRunningContent" xml:space="preserve">
|
||||||
<value>Stop Global Cealing</value>
|
<value>Stop Global Cealing</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -159,6 +159,9 @@
|
|||||||
<data name="ExtraArgsSettingsModeName" xml:space="preserve">
|
<data name="ExtraArgsSettingsModeName" xml:space="preserve">
|
||||||
<value>额外参数</value>
|
<value>额外参数</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="MihomoButtonIsInitingContent" xml:space="preserve">
|
||||||
|
<value>全局净化启动中</value>
|
||||||
|
</data>
|
||||||
<data name="MihomoButtonIsRunningContent" xml:space="preserve">
|
<data name="MihomoButtonIsRunningContent" xml:space="preserve">
|
||||||
<value>停止全局净化</value>
|
<value>停止全局净化</value>
|
||||||
</data>
|
</data>
|
||||||
@ -171,6 +174,9 @@
|
|||||||
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
|
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
|
||||||
<value>点击启动本地 Mihomo</value>
|
<value>点击启动本地 Mihomo</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NginxButtonIsInitingContent" xml:space="preserve">
|
||||||
|
<value>全局伪造启动中</value>
|
||||||
|
</data>
|
||||||
<data name="NginxButtonIsRunningContent" xml:space="preserve">
|
<data name="NginxButtonIsRunningContent" xml:space="preserve">
|
||||||
<value>停止全局伪造</value>
|
<value>停止全局伪造</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -5,14 +5,16 @@ using Sheas_Cealer.Consts;
|
|||||||
|
|
||||||
namespace Sheas_Cealer.Convs;
|
namespace Sheas_Cealer.Convs;
|
||||||
|
|
||||||
internal class MainMihomoButtonContentConv : IValueConverter
|
internal class MainMihomoButtonContentConv : IMultiValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
bool isMihomoRunning = (bool)value;
|
bool isMihomoRunning = (bool)values[0];
|
||||||
|
bool isMihomoIniting = (bool)values[1];
|
||||||
|
|
||||||
return isMihomoRunning ? MainConst.MihomoButtonIsRunningContent : MainConst.MihomoButtonIsStoppedContent;
|
return isMihomoIniting ? MainConst.MihomoButtonIsInitingContent :
|
||||||
|
isMihomoRunning ? MainConst.MihomoButtonIsRunningContent : MainConst.MihomoButtonIsStoppedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||||
}
|
}
|
@ -5,14 +5,16 @@ using Sheas_Cealer.Consts;
|
|||||||
|
|
||||||
namespace Sheas_Cealer.Convs;
|
namespace Sheas_Cealer.Convs;
|
||||||
|
|
||||||
internal class MainNginxButtonContentConv : IValueConverter
|
internal class MainNginxButtonContentConv : IMultiValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
bool isNginxRunning = (bool)value;
|
bool isNginxRunning = (bool)values[0];
|
||||||
|
bool isNginxIniting = (bool)values[1];
|
||||||
|
|
||||||
return isNginxRunning ? MainConst.NginxButtonIsRunningContent : MainConst.NginxButtonIsStoppedContent;
|
return isNginxIniting ? MainConst.NginxButtonIsInitingContent :
|
||||||
|
isNginxRunning ? MainConst.NginxButtonIsRunningContent : MainConst.NginxButtonIsStoppedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||||
}
|
}
|
18
Convs/MainProxyButtonIsEnabledConv.cs
Normal file
18
Convs/MainProxyButtonIsEnabledConv.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace Sheas_Cealer.Convs;
|
||||||
|
|
||||||
|
internal class MainProxyButtonIsEnabledConv : IMultiValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
bool isProxyExist = (bool)values[0];
|
||||||
|
bool isProxyIniting = (bool)values[1];
|
||||||
|
|
||||||
|
return !isProxyIniting && isProxyExist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||||
|
}
|
@ -84,12 +84,18 @@ internal partial class MainPres : ObservableObject
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe"));
|
private bool isNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe"));
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isNginxIniting = false;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isNginxRunning = Process.GetProcessesByName("Cealing-Nginx").Length != 0;
|
private bool isNginxRunning = Process.GetProcessesByName("Cealing-Nginx").Length != 0;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe"));
|
private bool isMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe"));
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isMihomoIniting = false;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isMihomoRunning = Process.GetProcessesByName("Cealing-Mihomo").Length != 0;
|
private bool isMihomoRunning = Process.GetProcessesByName("Cealing-Mihomo").Length != 0;
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
using System;
|
using SheasCore;
|
||||||
using Microsoft.Win32;
|
|
||||||
using SheasCore;
|
|
||||||
|
|
||||||
namespace Sheas_Cealer.Utils;
|
namespace Sheas_Cealer.Utils;
|
||||||
|
|
||||||
internal class MihomoProc : Proc
|
internal class MihomoProc : Proc
|
||||||
{
|
{
|
||||||
internal MihomoProc() : base("Cealing-Mihomo.exe") { }
|
internal MihomoProc() : base("Cealing-Mihomo.exe") { }
|
||||||
|
|
||||||
public override void Process_Exited(object sender, EventArgs e) => Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true)!.SetValue("ProxyEnable", 0);
|
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using Sheas_Cealer.Consts;
|
using Sheas_Cealer.Consts;
|
||||||
using SheasCore;
|
using SheasCore;
|
||||||
|
|
||||||
@ -17,5 +18,11 @@ internal class NginxProc : Proc
|
|||||||
|
|
||||||
if (cealingNginxStartIndex != -1 && cealingNginxEndIndex != -1)
|
if (cealingNginxStartIndex != -1 && cealingNginxEndIndex != -1)
|
||||||
File.WriteAllText(MainConst.HostsConfPath, hostsContent.Remove(cealingNginxStartIndex, cealingNginxEndIndex - cealingNginxStartIndex + "# Cealing Nginx End".Length));
|
File.WriteAllText(MainConst.HostsConfPath, hostsContent.Remove(cealingNginxStartIndex, cealingNginxEndIndex - cealingNginxStartIndex + "# Cealing Nginx End".Length));
|
||||||
|
|
||||||
|
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
||||||
|
|
||||||
|
foreach (X509Certificate2 cert in certStore.Certificates)
|
||||||
|
if (cert.Subject == "CN=Cealing Cert Root")
|
||||||
|
certStore.Remove(cert);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@
|
|||||||
</Binding.Converter>
|
</Binding.Converter>
|
||||||
</Binding>
|
</Binding>
|
||||||
</Window.Width>
|
</Window.Width>
|
||||||
|
|
||||||
<Grid Margin="5">
|
<Grid Margin="5">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@ -123,8 +123,7 @@
|
|||||||
</MultiBinding>
|
</MultiBinding>
|
||||||
</Button.IsEnabled>
|
</Button.IsEnabled>
|
||||||
</Button>
|
</Button>
|
||||||
<Button IsEnabled="{Binding IsNginxExist}"
|
<Button Grid.Column="1" Margin="5" d:Content="# # # #"
|
||||||
Grid.Column="1" Margin="5" d:Content="# # # #"
|
|
||||||
Click="NginxButton_Click" PreviewMouseDown="NginxButton_PreviewMouseDown">
|
Click="NginxButton_Click" PreviewMouseDown="NginxButton_PreviewMouseDown">
|
||||||
<Button.Visibility>
|
<Button.Visibility>
|
||||||
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
|
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
|
||||||
@ -133,12 +132,25 @@
|
|||||||
</Binding.Converter>
|
</Binding.Converter>
|
||||||
</Binding>
|
</Binding>
|
||||||
</Button.Visibility>
|
</Button.Visibility>
|
||||||
|
<Button.IsEnabled>
|
||||||
|
<MultiBinding>
|
||||||
|
<MultiBinding.Converter>
|
||||||
|
<convs:MainProxyButtonIsEnabledConv />
|
||||||
|
</MultiBinding.Converter>
|
||||||
|
|
||||||
|
<Binding Path="IsNginxExist" />
|
||||||
|
<Binding Path="IsNginxIniting" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Button.IsEnabled>
|
||||||
<Button.Content>
|
<Button.Content>
|
||||||
<Binding Path="IsNginxRunning">
|
<MultiBinding>
|
||||||
<Binding.Converter>
|
<MultiBinding.Converter>
|
||||||
<convs:MainNginxButtonContentConv />
|
<convs:MainNginxButtonContentConv />
|
||||||
</Binding.Converter>
|
</MultiBinding.Converter>
|
||||||
</Binding>
|
|
||||||
|
<Binding Path="IsNginxRunning" />
|
||||||
|
<Binding Path="IsNginxIniting" />
|
||||||
|
</MultiBinding>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
<Button.ToolTip>
|
<Button.ToolTip>
|
||||||
<Binding Path="IsNginxRunning">
|
<Binding Path="IsNginxRunning">
|
||||||
@ -148,8 +160,7 @@
|
|||||||
</Binding>
|
</Binding>
|
||||||
</Button.ToolTip>
|
</Button.ToolTip>
|
||||||
</Button>
|
</Button>
|
||||||
<Button IsEnabled="{Binding IsMihomoExist}"
|
<Button Grid.Column="2" Margin="5" d:Content="# # # #"
|
||||||
Grid.Column="2" Margin="5" d:Content="# # # #"
|
|
||||||
Click="MihomoButton_Click" PreviewMouseDown="MihomoButton_PreviewMouseDown">
|
Click="MihomoButton_Click" PreviewMouseDown="MihomoButton_PreviewMouseDown">
|
||||||
<Button.Visibility>
|
<Button.Visibility>
|
||||||
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
|
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
|
||||||
@ -158,12 +169,25 @@
|
|||||||
</Binding.Converter>
|
</Binding.Converter>
|
||||||
</Binding>
|
</Binding>
|
||||||
</Button.Visibility>
|
</Button.Visibility>
|
||||||
|
<Button.IsEnabled>
|
||||||
|
<MultiBinding>
|
||||||
|
<MultiBinding.Converter>
|
||||||
|
<convs:MainProxyButtonIsEnabledConv />
|
||||||
|
</MultiBinding.Converter>
|
||||||
|
|
||||||
|
<Binding Path="IsMihomoExist" />
|
||||||
|
<Binding Path="IsMihomoIniting" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Button.IsEnabled>
|
||||||
<Button.Content>
|
<Button.Content>
|
||||||
<Binding Path="IsMihomoRunning">
|
<MultiBinding>
|
||||||
<Binding.Converter>
|
<MultiBinding.Converter>
|
||||||
<convs:MainMihomoButtonContentConv />
|
<convs:MainMihomoButtonContentConv />
|
||||||
</Binding.Converter>
|
</MultiBinding.Converter>
|
||||||
</Binding>
|
|
||||||
|
<Binding Path="IsMihomoRunning" />
|
||||||
|
<Binding Path="IsMihomoIniting" />
|
||||||
|
</MultiBinding>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
<Button.ToolTip>
|
<Button.ToolTip>
|
||||||
<Binding Path="IsMihomoRunning">
|
<Binding Path="IsMihomoRunning">
|
||||||
|
@ -169,7 +169,6 @@ public partial class MainWin : Window
|
|||||||
{
|
{
|
||||||
if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!File.Exists(MainConst.NginxConfPath))
|
if (!File.Exists(MainConst.NginxConfPath))
|
||||||
File.Create(MainConst.NginxConfPath).Dispose();
|
File.Create(MainConst.NginxConfPath).Dispose();
|
||||||
if (!Directory.Exists(MainConst.NginxLogsPath))
|
if (!Directory.Exists(MainConst.NginxLogsPath))
|
||||||
@ -180,13 +179,18 @@ public partial class MainWin : Window
|
|||||||
RSA certKey = RSA.Create(2048);
|
RSA certKey = RSA.Create(2048);
|
||||||
|
|
||||||
CertificateRequest rootCertRequest = new("CN=Cealing Cert Root", certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
CertificateRequest rootCertRequest = new("CN=Cealing Cert Root", certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||||
|
|
||||||
rootCertRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
rootCertRequest.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
||||||
|
|
||||||
X509Certificate2 rootCert = rootCertRequest.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(100));
|
X509Certificate2 rootCert = rootCertRequest.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(100));
|
||||||
|
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
||||||
|
|
||||||
|
certStore.Add(rootCert);
|
||||||
|
certStore.Close();
|
||||||
|
|
||||||
CertificateRequest childCertRequest = new("CN=Cealing Cert Child", certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
CertificateRequest childCertRequest = new("CN=Cealing Cert Child", certKey, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||||
|
|
||||||
SubjectAlternativeNameBuilder childCertSanBuilder = new();
|
SubjectAlternativeNameBuilder childCertSanBuilder = new();
|
||||||
|
|
||||||
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
||||||
foreach ((List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, _, _) in hostRules)
|
foreach ((List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, _, _) in hostRules)
|
||||||
foreach ((string hostIncludeDomain, _) in hostDomainPairs)
|
foreach ((string hostIncludeDomain, _) in hostDomainPairs)
|
||||||
@ -209,15 +213,6 @@ public partial class MainWin : Window
|
|||||||
File.WriteAllText(MainConst.NginxCertPath, childCert.ExportCertificatePem());
|
File.WriteAllText(MainConst.NginxCertPath, childCert.ExportCertificatePem());
|
||||||
File.WriteAllText(MainConst.NginxKeyPath, certKey.ExportPkcs8PrivateKeyPem());
|
File.WriteAllText(MainConst.NginxKeyPath, certKey.ExportPkcs8PrivateKeyPem());
|
||||||
|
|
||||||
using X509Store certStore = new(StoreName.Root, StoreLocation.CurrentUser, OpenFlags.ReadWrite);
|
|
||||||
|
|
||||||
foreach (X509Certificate2 cert in certStore.Certificates)
|
|
||||||
if (cert.Subject == "CN=Cealing Cert Root")
|
|
||||||
certStore.Remove(cert);
|
|
||||||
|
|
||||||
certStore.Add(rootCert);
|
|
||||||
certStore.Close();
|
|
||||||
|
|
||||||
string hostsAppendContent = MainConst.HostsConfStartMarker;
|
string hostsAppendContent = MainConst.HostsConfStartMarker;
|
||||||
|
|
||||||
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
foreach (List<(List<(string hostIncludeDomain, string hostExcludeDomain)> hostDomainPairs, string hostSni, string hostIp)> hostRules in HostRulesDict.Values)
|
||||||
@ -240,12 +235,14 @@ public partial class MainWin : Window
|
|||||||
|
|
||||||
File.AppendAllText(MainConst.HostsConfPath, hostsAppendContent);
|
File.AppendAllText(MainConst.HostsConfPath, hostsAppendContent);
|
||||||
|
|
||||||
|
MainPres.IsNginxIniting = true;
|
||||||
ConfWatcher.EnableRaisingEvents = false;
|
ConfWatcher.EnableRaisingEvents = false;
|
||||||
NginxConfs!.Save(MainConst.NginxConfPath);
|
NginxConfs!.Save(MainConst.NginxConfPath);
|
||||||
|
|
||||||
new NginxProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @$"-c ""{MainConst.NginxConfPath}""");
|
new NginxProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @$"-c ""{MainConst.NginxConfPath}""");
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Http.GetAsync<HttpResponseMessage>("https://localhost", MainClient);
|
await Http.GetAsync<HttpResponseMessage>("https://localhost", MainClient);
|
||||||
@ -257,27 +254,23 @@ public partial class MainWin : Window
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!MainPres.IsNginxRunning)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
File.WriteAllText(MainConst.NginxConfPath, ExtraConfs);
|
File.WriteAllText(MainConst.NginxConfPath, ExtraConfs);
|
||||||
ConfWatcher.EnableRaisingEvents = true;
|
ConfWatcher.EnableRaisingEvents = true;
|
||||||
|
MainPres.IsNginxIniting = false;
|
||||||
|
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
Application.Current.Dispatcher.InvokeShutdown();
|
Application.Current.Dispatcher.InvokeShutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
string hostsContent = File.ReadAllText(MainConst.HostsConfPath);
|
|
||||||
int cealingNginxStartIndex = hostsContent.IndexOf(MainConst.HostsConfStartMarker);
|
|
||||||
int cealingNginxEndIndex = hostsContent.LastIndexOf(MainConst.HostsConfEndMarker);
|
|
||||||
|
|
||||||
if (cealingNginxStartIndex != -1 && cealingNginxEndIndex != -1)
|
|
||||||
File.WriteAllText(MainConst.HostsConfPath, hostsContent.Remove(cealingNginxStartIndex, cealingNginxEndIndex - cealingNginxStartIndex + "# Cealing Nginx End".Length));
|
|
||||||
|
|
||||||
foreach (Process nginxProcess in Process.GetProcessesByName("Cealing-Nginx"))
|
foreach (Process nginxProcess in Process.GetProcessesByName("Cealing-Nginx"))
|
||||||
{
|
{
|
||||||
nginxProcess.Kill();
|
nginxProcess.Kill();
|
||||||
nginxProcess.WaitForExit();
|
nginxProcess.WaitForExit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private void MihomoButton_Click(object sender, RoutedEventArgs e)
|
private void MihomoButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
@ -294,25 +287,17 @@ public partial class MainWin : Window
|
|||||||
{
|
{
|
||||||
HoldButtonTimer?.Stop();
|
HoldButtonTimer?.Stop();
|
||||||
|
|
||||||
RegistryKey proxyKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true)!;
|
|
||||||
|
|
||||||
if (!MainPres!.IsMihomoRunning)
|
if (!MainPres!.IsMihomoRunning)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!File.Exists(MainConst.MihomoConfPath))
|
if (!File.Exists(MainConst.MihomoConfPath))
|
||||||
File.Create(MainConst.MihomoConfPath).Dispose();
|
File.Create(MainConst.MihomoConfPath).Dispose();
|
||||||
|
|
||||||
string extraConfs = File.ReadAllText(MainConst.MihomoConfPath);
|
string extraConfs = File.ReadAllText(MainConst.MihomoConfPath);
|
||||||
|
Dictionary<string, object> mihomoConfs = new DeserializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build().Deserialize<Dictionary<string, object>>(extraConfs) ?? [];
|
||||||
Dictionary<string, object> mihomoConfs = new DeserializerBuilder()
|
|
||||||
.WithNamingConvention(HyphenatedNamingConvention.Instance)
|
|
||||||
.Build().Deserialize<Dictionary<string, object>>(extraConfs) ?? []; ;
|
|
||||||
|
|
||||||
mihomoConfs["mixed-port"] = 7880;
|
mihomoConfs["mixed-port"] = 7880;
|
||||||
mihomoConfs["ipv6"] = true;
|
|
||||||
mihomoConfs["log-level"] = "silent";
|
|
||||||
mihomoConfs["dns"] = new
|
mihomoConfs["dns"] = new
|
||||||
{
|
{
|
||||||
enable = true,
|
enable = true,
|
||||||
@ -328,16 +313,14 @@ public partial class MainWin : Window
|
|||||||
autoDetectInterface = true,
|
autoDetectInterface = true,
|
||||||
dnsHijack = new[] { "any:53", "tcp://any:53" }
|
dnsHijack = new[] { "any:53", "tcp://any:53" }
|
||||||
};
|
};
|
||||||
mihomoConfs["rules"] = new[] { "MATCH,DIRECT" };
|
|
||||||
|
|
||||||
|
MainPres.IsMihomoIniting = true;
|
||||||
File.WriteAllText(MainConst.MihomoConfPath, new SerializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build().Serialize(mihomoConfs));
|
File.WriteAllText(MainConst.MihomoConfPath, new SerializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build().Serialize(mihomoConfs));
|
||||||
|
|
||||||
proxyKey.SetValue("ProxyEnable", 1);
|
|
||||||
proxyKey.SetValue("ProxyServer", "127.0.0.1:7880");
|
|
||||||
|
|
||||||
new MihomoProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @$"-d ""{Path.GetDirectoryName(MainConst.MihomoConfPath)}""");
|
new MihomoProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @$"-d ""{Path.GetDirectoryName(MainConst.MihomoConfPath)}""");
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Http.GetAsync<HttpResponseMessage>("http://localhost:7880", MainClient);
|
await Http.GetAsync<HttpResponseMessage>("http://localhost:7880", MainClient);
|
||||||
@ -349,21 +332,22 @@ public partial class MainWin : Window
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!MainPres.IsMihomoRunning)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
File.WriteAllText(MainConst.MihomoConfPath, extraConfs);
|
File.WriteAllText(MainConst.MihomoConfPath, extraConfs);
|
||||||
|
MainPres.IsMihomoIniting = false;
|
||||||
|
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
Application.Current.Dispatcher.InvokeShutdown();
|
Application.Current.Dispatcher.InvokeShutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
proxyKey.SetValue("ProxyEnable", 0);
|
|
||||||
|
|
||||||
foreach (Process mihomoProcess in Process.GetProcessesByName("Cealing-Mihomo"))
|
foreach (Process mihomoProcess in Process.GetProcessesByName("Cealing-Mihomo"))
|
||||||
{
|
{
|
||||||
mihomoProcess.Kill();
|
mihomoProcess.Kill();
|
||||||
mihomoProcess.WaitForExit();
|
mihomoProcess.WaitForExit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user