1.1.1 -> 1.1.2 第15次更新

This commit is contained in:
Space Time 2024-10-02 21:36:28 +08:00
parent a3b1dc6525
commit 859e25f05e
17 changed files with 469 additions and 45 deletions

View File

@ -69,6 +69,15 @@ namespace Sheas_Cealer.Consts {
} }
} }
/// <summary>
/// 查找类似 The config cannot be recognized, check if the config contain syntax errors 的本地化字符串。
/// </summary>
public static string _ConfigErrorHint {
get {
return ResourceManager.GetString("_ConfigErrorHint", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 The args cannot be recognized, check if the hosts contain syntax errors 的本地化字符串。 /// 查找类似 The args cannot be recognized, check if the hosts contain syntax errors 的本地化字符串。
/// </summary> /// </summary>
@ -187,20 +196,74 @@ namespace Sheas_Cealer.Consts {
} }
/// <summary> /// <summary>
/// 查找类似 Start Proxy 的本地化字符串。 /// 查找类似 Stop Mihomo 的本地化字符串。
/// </summary> /// </summary>
public static string ProxyButtonContent { public static string MihomoButtonIsRunningContent {
get { get {
return ResourceManager.GetString("ProxyButtonContent", resourceCulture); return ResourceManager.GetString("MihomoButtonIsRunningContent", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// 查找类似 Click to launch a local proxy 的本地化字符串。 /// 查找类似 Click to stop the local Mihomo 的本地化字符串。
/// </summary> /// </summary>
public static string ProxyButtonToolTip { public static string MihomoButtonIsRunningToolTip {
get { get {
return ResourceManager.GetString("ProxyButtonToolTip", resourceCulture); return ResourceManager.GetString("MihomoButtonIsRunningToolTip", resourceCulture);
}
}
/// <summary>
/// 查找类似 Start Mihomo 的本地化字符串。
/// </summary>
public static string MihomoButtonIsStoppedContent {
get {
return ResourceManager.GetString("MihomoButtonIsStoppedContent", resourceCulture);
}
}
/// <summary>
/// 查找类似 Click to launch a local Mihomo 的本地化字符串。
/// </summary>
public static string MihomoButtonIsStoppedToolTip {
get {
return ResourceManager.GetString("MihomoButtonIsStoppedToolTip", resourceCulture);
}
}
/// <summary>
/// 查找类似 Stop Nginx 的本地化字符串。
/// </summary>
public static string NginxButtonIsRunningContent {
get {
return ResourceManager.GetString("NginxButtonIsRunningContent", resourceCulture);
}
}
/// <summary>
/// 查找类似 Click to stop the local Nginx 的本地化字符串。
/// </summary>
public static string NginxButtonIsRunningToolTip {
get {
return ResourceManager.GetString("NginxButtonIsRunningToolTip", resourceCulture);
}
}
/// <summary>
/// 查找类似 Start Nginx 的本地化字符串。
/// </summary>
public static string NginxButtonIsStoppedContent {
get {
return ResourceManager.GetString("NginxButtonIsStoppedContent", resourceCulture);
}
}
/// <summary>
/// 查找类似 Click to launch a local Nginx 的本地化字符串。
/// </summary>
public static string NginxButtonIsStoppedToolTip {
get {
return ResourceManager.GetString("NginxButtonIsStoppedToolTip", resourceCulture);
} }
} }

View File

@ -141,11 +141,29 @@
<data name="ExtraArgsSettingsModeName" xml:space="preserve"> <data name="ExtraArgsSettingsModeName" xml:space="preserve">
<value>Extra Args</value> <value>Extra Args</value>
</data> </data>
<data name="ProxyButtonContent" xml:space="preserve"> <data name="MihomoButtonIsRunningContent" xml:space="preserve">
<value>Start Proxy</value> <value>Stop Mihomo</value>
</data> </data>
<data name="ProxyButtonToolTip" xml:space="preserve"> <data name="MihomoButtonIsRunningToolTip" xml:space="preserve">
<value>Click to launch a local proxy</value> <value>Click to stop the local Mihomo</value>
</data>
<data name="MihomoButtonIsStoppedContent" xml:space="preserve">
<value>Start Mihomo</value>
</data>
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
<value>Click to launch a local Mihomo</value>
</data>
<data name="NginxButtonIsRunningContent" xml:space="preserve">
<value>Stop Nginx</value>
</data>
<data name="NginxButtonIsRunningToolTip" xml:space="preserve">
<value>Click to stop the local Nginx</value>
</data>
<data name="NginxButtonIsStoppedContent" xml:space="preserve">
<value>Start Nginx</value>
</data>
<data name="NginxButtonIsStoppedToolTip" xml:space="preserve">
<value>Click to launch a local Nginx</value>
</data> </data>
<data name="SettingsBoxBrowserPathToolTip" xml:space="preserve"> <data name="SettingsBoxBrowserPathToolTip" xml:space="preserve">
<value>Fill in a Chromium-based browser path</value> <value>Fill in a Chromium-based browser path</value>
@ -201,6 +219,9 @@
<data name="_BrowserPathDialogFilterFileType" xml:space="preserve"> <data name="_BrowserPathDialogFilterFileType" xml:space="preserve">
<value>Browser</value> <value>Browser</value>
</data> </data>
<data name="_ConfigErrorHint" xml:space="preserve">
<value>The config cannot be recognized, check if the config contain syntax errors</value>
</data>
<data name="_HostErrorHint" xml:space="preserve"> <data name="_HostErrorHint" xml:space="preserve">
<value>The args cannot be recognized, check if the hosts contain syntax errors</value> <value>The args cannot be recognized, check if the hosts contain syntax errors</value>
</data> </data>

View File

@ -141,11 +141,29 @@
<data name="ExtraArgsSettingsModeName" xml:space="preserve"> <data name="ExtraArgsSettingsModeName" xml:space="preserve">
<value>额外参数</value> <value>额外参数</value>
</data> </data>
<data name="ProxyButtonContent" xml:space="preserve"> <data name="MihomoButtonIsRunningContent" xml:space="preserve">
<value>启动代理</value> <value>停止 Mihomo</value>
</data> </data>
<data name="ProxyButtonToolTip" xml:space="preserve"> <data name="MihomoButtonIsRunningToolTip" xml:space="preserve">
<value>点击启动本地代理</value> <value>点击停止本地 Mihomo</value>
</data>
<data name="MihomoButtonIsStoppedContent" xml:space="preserve">
<value>启动 Mihomo</value>
</data>
<data name="MihomoButtonIsStoppedToolTip" xml:space="preserve">
<value>点击启动本地 Mihomo</value>
</data>
<data name="NginxButtonIsRunningContent" xml:space="preserve">
<value>停止 Nginx</value>
</data>
<data name="NginxButtonIsRunningToolTip" xml:space="preserve">
<value>点击停止 Nginx</value>
</data>
<data name="NginxButtonIsStoppedContent" xml:space="preserve">
<value>启动 Nginx</value>
</data>
<data name="NginxButtonIsStoppedToolTip" xml:space="preserve">
<value>点击启动本地 Nginx</value>
</data> </data>
<data name="SettingsBoxBrowserPathToolTip" xml:space="preserve"> <data name="SettingsBoxBrowserPathToolTip" xml:space="preserve">
<value>填入任意以 Chromium 为内核的浏览器路径</value> <value>填入任意以 Chromium 为内核的浏览器路径</value>
@ -201,6 +219,9 @@
<data name="_BrowserPathDialogFilterFileType" xml:space="preserve"> <data name="_BrowserPathDialogFilterFileType" xml:space="preserve">
<value>浏览器</value> <value>浏览器</value>
</data> </data>
<data name="_ConfigErrorHint" xml:space="preserve">
<value>配置无法识别,请检查配置文件中是否含有语法错误</value>
</data>
<data name="_HostErrorHint" xml:space="preserve"> <data name="_HostErrorHint" xml:space="preserve">
<value>规则无法识别,请检查伪造规则中是否含有语法错误</value> <value>规则无法识别,请检查伪造规则中是否含有语法错误</value>
</data> </data>

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs;
internal class MainMihomoButtonContentConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isMihomoRunning = (bool)value;
return isMihomoRunning ? MainConst.MihomoButtonIsRunningContent : MainConst.MihomoButtonIsStoppedContent;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,17 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Sheas_Cealer.Convs;
internal class MainMihomoButtonIsEnabledConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isMihomoExist = (bool)value;
return isMihomoExist;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs;
internal class MainMihomoButtonToolTipConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isMihomoRunning = (bool)value;
return isMihomoRunning ? MainConst.MihomoButtonIsRunningToolTip : MainConst.MihomoButtonIsStoppedToolTip;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs;
internal class MainNginxButtonContentConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isNginxRunning = (bool)value;
return isNginxRunning ? MainConst.NginxButtonIsRunningContent : MainConst.NginxButtonIsStoppedContent;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,17 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Sheas_Cealer.Convs;
internal class MainNginxButtonIsEnabledConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isNginxExist = (bool)value;
return isNginxExist;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs;
internal class MainNginxButtonToolTipConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isNginxRunning = (bool)value;
return isNginxRunning ? MainConst.NginxButtonIsRunningToolTip : MainConst.NginxButtonIsStoppedToolTip;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Sheas_Cealer.Convs;
internal class MainProxyButtonVisibilityConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isAdmin = (bool)value;
return isAdmin ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Sheas_Cealer.Convs;
internal class MainProxyColumnWidthConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isAdmin = (bool)value;
return new GridLength(1, isAdmin ? GridUnitType.Star : GridUnitType.Auto);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
@ -19,9 +20,9 @@ internal partial class MainPres : ObservableObject
BrowserPath = browserPathIndex != 0 && browserPathIndex != args.Length ? args[browserPathIndex] : BrowserPath = browserPathIndex != 0 && browserPathIndex != args.Length ? args[browserPathIndex] :
!string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : !string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath :
(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe", string.Empty, null) ?? (Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe")?.GetValue(string.Empty, null) ??
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", string.Empty, null) ?? Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe")?.GetValue(string.Empty, null) ??
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe", string.Empty, null) ?? Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe")?.GetValue(string.Empty, null) ??
string.Empty).ToString()!; string.Empty).ToString()!;
UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ? UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ?
@ -36,17 +37,6 @@ internal partial class MainPres : ObservableObject
[ObservableProperty] [ObservableProperty]
private MainConst.SettingsMode settingsMode; private MainConst.SettingsMode settingsMode;
[ObservableProperty]
private bool? isLightTheme = null;
partial void OnIsLightThemeChanged(bool? value)
{
PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme();
newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit);
paletteHelper.SetTheme(newTheme);
}
[ObservableProperty] [ObservableProperty]
private string browserPath; private string browserPath;
partial void OnBrowserPathChanged(string value) partial void OnBrowserPathChanged(string value)
@ -79,4 +69,27 @@ internal partial class MainPres : ObservableObject
Settings.Default.Save(); Settings.Default.Save();
} }
} }
[ObservableProperty]
private bool? isLightTheme = null;
partial void OnIsLightThemeChanged(bool? value)
{
PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme();
newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit);
paletteHelper.SetTheme(newTheme);
}
[ObservableProperty]
private bool isNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe"));
[ObservableProperty]
private bool isNginxRunning = Process.GetProcessesByName("Cealing-Nginx").Length != 0;
[ObservableProperty]
private bool isMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe"));
[ObservableProperty]
private bool isMihomoRunning = Process.GetProcessesByName("Cealing-Mihomo").Length != 0;
} }

View File

@ -76,6 +76,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="MaterialDesignThemes" Version="5.0.0" /> <PackageReference Include="MaterialDesignThemes" Version="5.0.0" />
<PackageReference Include="YamlDotNet" Version="16.1.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

8
Utils/MihomoProc.cs Normal file
View File

@ -0,0 +1,8 @@
using SheasCore;
namespace Sheas_Cealer.Utils;
internal class MihomoProc : Proc
{
internal MihomoProc() : base("Cealing-Mihomo.exe") { }
}

8
Utils/NginxProc.cs Normal file
View File

@ -0,0 +1,8 @@
using SheasCore;
namespace Sheas_Cealer.Utils;
internal class NginxProc : Proc
{
internal NginxProc() : base("Cealing-Nginx.exe") { }
}

View File

@ -79,7 +79,24 @@
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="*" /> <ColumnDefinition>
<ColumnDefinition.Width>
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
<Binding.Converter>
<convs:MainProxyColumnWidthConv />
</Binding.Converter>
</Binding>
</ColumnDefinition.Width>
</ColumnDefinition>
<ColumnDefinition>
<ColumnDefinition.Width>
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
<Binding.Converter>
<convs:MainProxyColumnWidthConv />
</Binding.Converter>
</Binding>
</ColumnDefinition.Width>
</ColumnDefinition>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button IsDefault="True" <Button IsDefault="True"
@ -96,9 +113,68 @@
</MultiBinding> </MultiBinding>
</Button.IsEnabled> </Button.IsEnabled>
</Button> </Button>
<Button IsEnabled="{Binding Source={x:Static consts:MainConst.IsAdmin}, Mode=OneTime}" <Button Grid.Column="1" Margin="5"
Grid.Column="1" Margin="5" Content="{Binding Source={x:Static consts:MainConst.ProxyButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.ProxyButtonToolTip}}" Click="NginxButton_Click">
Click="ProxyButton_Click" /> <Button.IsEnabled>
<Binding Path="IsNginxExist">
<Binding.Converter>
<convs:MainNginxButtonIsEnabledConv />
</Binding.Converter>
</Binding>
</Button.IsEnabled>
<Button.Visibility>
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
<Binding.Converter>
<convs:MainProxyButtonVisibilityConv />
</Binding.Converter>
</Binding>
</Button.Visibility>
<Button.Content>
<Binding Path="IsNginxRunning">
<Binding.Converter>
<convs:MainNginxButtonContentConv />
</Binding.Converter>
</Binding>
</Button.Content>
<Button.ToolTip>
<Binding Path="IsNginxRunning">
<Binding.Converter>
<convs:MainNginxButtonToolTipConv />
</Binding.Converter>
</Binding>
</Button.ToolTip>
</Button>
<Button Grid.Column="2" Margin="5"
Click="MihomoButton_Click">
<Button.IsEnabled>
<Binding Path="IsMihomoExist">
<Binding.Converter>
<convs:MainMihomoButtonIsEnabledConv />
</Binding.Converter>
</Binding>
</Button.IsEnabled>
<Button.Visibility>
<Binding Source="{x:Static consts:MainConst.IsAdmin}" Mode="OneTime">
<Binding.Converter>
<convs:MainProxyButtonVisibilityConv />
</Binding.Converter>
</Binding>
</Button.Visibility>
<Button.Content>
<Binding Path="IsMihomoRunning">
<Binding.Converter>
<convs:MainMihomoButtonContentConv />
</Binding.Converter>
</Binding>
</Button.Content>
<Button.ToolTip>
<Binding Path="IsMihomoRunning">
<Binding.Converter>
<convs:MainMihomoButtonToolTipConv />
</Binding.Converter>
</Binding>
</Button.ToolTip>
</Button>
</Grid> </Grid>
<Grid Grid.Row="2"> <Grid Grid.Row="2">

View File

@ -15,6 +15,7 @@ using OnaCore;
using Sheas_Cealer.Consts; using Sheas_Cealer.Consts;
using Sheas_Cealer.Preses; using Sheas_Cealer.Preses;
using Sheas_Cealer.Utils; using Sheas_Cealer.Utils;
using YamlDotNet.RepresentationModel;
using File = System.IO.File; using File = System.IO.File;
namespace Sheas_Cealer.Wins; namespace Sheas_Cealer.Wins;
@ -24,6 +25,7 @@ public partial class MainWin : Window
private static MainPres? MainPres; private static MainPres? MainPres;
private static readonly HttpClient MainClient = new(); private static readonly HttpClient MainClient = new();
private static DispatcherTimer? HoldButtonTimer; private static DispatcherTimer? HoldButtonTimer;
private static readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) };
private static readonly FileSystemWatcher HostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-*.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private static readonly FileSystemWatcher HostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-*.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static readonly Dictionary<string, (string hostRulesFragments, string hostResolverRulesFragments)> CealArgsFragments = []; private static readonly Dictionary<string, (string hostRulesFragments, string hostResolverRulesFragments)> CealArgsFragments = [];
private static string CealArgs = string.Empty; private static string CealArgs = string.Empty;
@ -34,8 +36,10 @@ public partial class MainWin : Window
DataContext = MainPres = new(args); DataContext = MainPres = new(args);
HostWatcher.Changed += HostWatcher_Changed; ProxyTimer.Tick += ProxyTimer_Tick;
ProxyTimer.Start();
HostWatcher.Changed += HostWatcher_Changed;
foreach (string hostPath in Directory.GetFiles(HostWatcher.Path, HostWatcher.Filter)) foreach (string hostPath in Directory.GetFiles(HostWatcher.Path, HostWatcher.Filter))
HostWatcher_Changed(null!, new(new(), Path.GetDirectoryName(hostPath)!, Path.GetFileName(hostPath))); HostWatcher_Changed(null!, new(new(), Path.GetDirectoryName(hostPath)!, Path.GetFileName(hostPath)));
} }
@ -132,8 +136,69 @@ public partial class MainWin : Window
new CommandProc(sender == null).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, ($"{CealArgs} {MainPres!.ExtraArgs}").Trim()); new CommandProc(sender == null).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, ($"{CealArgs} {MainPres!.ExtraArgs}").Trim());
} }
private void ProxyButton_Click(object sender, RoutedEventArgs e) private void NginxButton_Click(object sender, RoutedEventArgs e)
{ {
string configPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "nginx.conf");
string logsPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "logs");
string tempPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "temp");
if (!MainPres!.IsNginxRunning)
{
if (!File.Exists(configPath))
File.Create(configPath).Dispose();
if (!Directory.Exists(logsPath))
Directory.CreateDirectory(logsPath);
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
new NginxProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"-c nginx.conf");
}
else
{
foreach (Process mihomoProcess in Process.GetProcessesByName("Cealing-Nginx"))
{
mihomoProcess.Kill();
mihomoProcess.WaitForExit();
}
}
}
private void MihomoButton_Click(object sender, RoutedEventArgs e)
{
RegistryKey proxyKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true)!;
string configPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "config.yaml");
if (!MainPres!.IsMihomoRunning)
{
YamlStream configStream = [];
YamlMappingNode configMapNode;
YamlNode mihomoPortNode;
if (!File.Exists(configPath))
File.Create(configPath).Dispose();
configStream.Load(File.OpenText(configPath));
try { configMapNode = (YamlMappingNode)configStream.Documents[0].RootNode; }
catch { throw new Exception(MainConst._ConfigErrorHint); }
if (!configMapNode.Children.TryGetValue("mixed-port", out mihomoPortNode!) && !configMapNode.Children.TryGetValue("port", out mihomoPortNode!))
mihomoPortNode = "7890";
proxyKey.SetValue("ProxyEnable", 1);
proxyKey.SetValue("ProxyServer", "127.0.0.1:" + mihomoPortNode);
new MihomoProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "-d .");
}
else
{
proxyKey.SetValue("ProxyEnable", 0);
foreach (Process mihomoProcess in Process.GetProcessesByName("Cealing-Mihomo"))
{
mihomoProcess.Kill();
mihomoProcess.WaitForExit();
}
}
} }
private void EditHostButton_Click(object sender, RoutedEventArgs e) private void EditHostButton_Click(object sender, RoutedEventArgs e)
@ -150,34 +215,40 @@ public partial class MainWin : Window
} }
private async void UpdateUpstreamHostButton_Click(object sender, RoutedEventArgs e) private async void UpdateUpstreamHostButton_Click(object sender, RoutedEventArgs e)
{ {
string upstreamHostUrl = (MainPres!.UpstreamUrl.StartsWith("http://") || MainPres!.UpstreamUrl.StartsWith("https://") ? string.Empty : "https://") + MainPres!.UpstreamUrl; string newUpstreamHostUrl = (MainPres!.UpstreamUrl.StartsWith("http://") || MainPres!.UpstreamUrl.StartsWith("https://") ? string.Empty : "https://") + MainPres!.UpstreamUrl;
string upstreamHostString = await Http.GetAsync<string>(upstreamHostUrl, MainClient); string newUpstreamHostString = await Http.GetAsync<string>(newUpstreamHostUrl, MainClient);
string localHostPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json"); string oldUpstreamHostPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json");
string localHostString; string oldUpstreamHostString;
if (!File.Exists(localHostPath)) if (!File.Exists(oldUpstreamHostPath))
File.Create(localHostPath).Dispose(); File.Create(oldUpstreamHostPath).Dispose();
using (StreamReader localHostStreamReader = new(localHostPath)) oldUpstreamHostString = File.ReadAllText(oldUpstreamHostPath);
localHostString = localHostStreamReader.ReadToEnd();
if (localHostString.Replace("\r", string.Empty) == upstreamHostString) if (oldUpstreamHostString.Replace("\r", string.Empty) == newUpstreamHostString)
MessageBox.Show(MainConst._UpstreamHostUtdHint); MessageBox.Show(MainConst._UpstreamHostUtdHint);
else else
{ {
MessageBoxResult overrideOptionResult = MessageBox.Show(MainConst._OverrideUpstreamHostPrompt, string.Empty, MessageBoxButton.YesNoCancel); MessageBoxResult overrideOptionResult = MessageBox.Show(MainConst._OverrideUpstreamHostPrompt, string.Empty, MessageBoxButton.YesNoCancel);
if (overrideOptionResult == MessageBoxResult.Yes) if (overrideOptionResult == MessageBoxResult.Yes)
{ {
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json"), upstreamHostString); File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host-Upstream.json"), newUpstreamHostString);
MessageBox.Show(MainConst._UpdateUpstreamHostSuccessHint); MessageBox.Show(MainConst._UpdateUpstreamHostSuccessHint);
} }
else if (overrideOptionResult == MessageBoxResult.No) else if (overrideOptionResult == MessageBoxResult.No)
Process.Start(new ProcessStartInfo(upstreamHostUrl) { UseShellExecute = true }); Process.Start(new ProcessStartInfo(newUpstreamHostUrl) { UseShellExecute = true });
} }
} }
private void ThemesButton_Click(object sender, RoutedEventArgs e) => MainPres!.IsLightTheme = MainPres.IsLightTheme.HasValue ? MainPres.IsLightTheme.Value ? null : true : false; private void ThemesButton_Click(object sender, RoutedEventArgs e) => MainPres!.IsLightTheme = MainPres.IsLightTheme.HasValue ? MainPres.IsLightTheme.Value ? null : true : false;
private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog(); private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog();
private void ProxyTimer_Tick(object? sender, EventArgs e)
{
MainPres!.IsNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Nginx.exe"));
MainPres.IsNginxRunning = Process.GetProcessesByName("Cealing-Nginx").Length != 0;
MainPres.IsMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Mihomo.exe"));
MainPres.IsMihomoRunning = Process.GetProcessesByName("Cealing-Mihomo").Length != 0;
}
private void HostWatcher_Changed(object sender, FileSystemEventArgs e) private void HostWatcher_Changed(object sender, FileSystemEventArgs e)
{ {
string hostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray()); string hostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray());