diff --git a/Consts/MainMultilangConst.Designer.cs b/Consts/MainMultilangConst.Designer.cs
index e45ea05..21b3415 100644
--- a/Consts/MainMultilangConst.Designer.cs
+++ b/Consts/MainMultilangConst.Designer.cs
@@ -70,7 +70,7 @@ namespace Sheas_Cealer.Consts {
}
///
- /// 查找类似 The config cannot be recognized. Check if the config contain syntax errors 的本地化字符串。
+ /// 查找类似 The config contains syntax errors and cannot be recognized 的本地化字符串。
///
public static string _ConfErrorMsg {
get {
@@ -79,7 +79,7 @@ namespace Sheas_Cealer.Consts {
}
///
- /// 查找类似 I know you would do it, but nothing will actually happen. Whee. 的本地化字符串。
+ /// 查找类似 I know you would do it, but nothing will actually happen. Whee 的本地化字符串。
///
public static string _GameClickOnceMsg {
get {
@@ -88,7 +88,7 @@ namespace Sheas_Cealer.Consts {
}
///
- /// 查找类似 Ugh, what are you doing. Please stop, I don't want to hurt anyone. Stop please, this is your last chance. Ugh, I can't control it anymore. 的本地化字符串。
+ /// 查找类似 Ugh, what are you doing. Please stop, I don't want to hurt anyone. Stop please, this is your last chance. Ugh, I can't control it anymore 的本地化字符串。
///
public static string _GameClickThreeMsg {
get {
@@ -142,11 +142,11 @@ namespace Sheas_Cealer.Consts {
}
///
- /// 查找类似 The args cannot be recognized. Check if the hosts contain syntax errors 的本地化字符串。
+ /// 查找类似 Some hosts contain syntax errors and cannot be recognized. Do you want to continue anyway? 的本地化字符串。
///
- public static string _HostErrorMsg {
+ public static string _HostErrorPrompt {
get {
- return ResourceManager.GetString("_HostErrorMsg", resourceCulture);
+ return ResourceManager.GetString("_HostErrorPrompt", resourceCulture);
}
}
@@ -177,6 +177,24 @@ namespace Sheas_Cealer.Consts {
}
}
+ ///
+ /// 查找类似 The local port 80 is occupied, which may cause the http connection to fail to automatically jump to https. Do you want to continue? 的本地化字符串。
+ ///
+ public static string _NginxHttpPortOccupiedPrompt {
+ get {
+ return ResourceManager.GetString("_NginxHttpPortOccupiedPrompt", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 The local port 443 is occupied, which may cause the global forgery to fail to take effect. Do you want to continue? 的本地化字符串。
+ ///
+ public static string _NginxHttpsPortOccupiedPrompt {
+ get {
+ return ResourceManager.GetString("_NginxHttpsPortOccupiedPrompt", resourceCulture);
+ }
+ }
+
///
/// 查找类似 There is an update available. Do you want to update upstream host? If No it will only open the upstream host page for you 的本地化字符串。
///
diff --git a/Consts/MainMultilangConst.resx b/Consts/MainMultilangConst.resx
index 7b8a72a..3350d0d 100644
--- a/Consts/MainMultilangConst.resx
+++ b/Consts/MainMultilangConst.resx
@@ -256,13 +256,13 @@
Browser
- The config cannot be recognized. Check if the config contain syntax errors
+ The config contains syntax errors and cannot be recognized
- I know you would do it, but nothing will actually happen. Whee.
+ I know you would do it, but nothing will actually happen. Whee
- Ugh, what are you doing. Please stop, I don't want to hurt anyone. Stop please, this is your last chance. Ugh, I can't control it anymore.
+ Ugh, what are you doing. Please stop, I don't want to hurt anyone. Stop please, this is your last chance. Ugh, I can't control it anymore
No no no, don't click me. Sorry, I shouldn't have lied to you, I am a cursed button, and continuing to click me will bring disaster to the entire Sheas Cealer. Please believe me, this is not a game, and there are no new features here. Listen to me and use the normal functions, okay?
@@ -279,8 +279,8 @@
No, please kill me, I...can't control myself...
-
- The args cannot be recognized. Check if the hosts contain syntax errors
+
+ Some hosts contain syntax errors and cannot be recognized. Do you want to continue anyway?
All processes of the selected browser will be closed before launching. Do you want to continue?
@@ -291,6 +291,12 @@
Please remember to come back and stop the proxy manually after use. Do you want to continue?
+
+ The local port 80 is occupied, which may cause the http connection to fail to automatically jump to https. Do you want to continue?
+
+
+ The local port 443 is occupied, which may cause the global forgery to fail to take effect. Do you want to continue?
+
There is an update available. Do you want to update upstream host? If No it will only open the upstream host page for you
diff --git a/Consts/MainMultilangConst.zh.resx b/Consts/MainMultilangConst.zh.resx
index 4db1ca9..3e86524 100644
--- a/Consts/MainMultilangConst.zh.resx
+++ b/Consts/MainMultilangConst.zh.resx
@@ -256,7 +256,7 @@
浏览器
- 配置无法识别,请检查配置文件中是否含有语法错误
+ 配置文件中含有语法错误,配置无法识别
就知道你会点,但其实什么事情都不会发生的。嘻嘻
@@ -279,8 +279,8 @@
不,求你杀了我,我...控制不住了...
-
- 规则无法识别,请检查伪造规则中是否含有语法错误
+
+ 伪造规则中含有语法错误,部分规则无法识别,是否仍然继续?
启动前将关闭所选浏览器的所有进程,是否继续?
@@ -291,6 +291,12 @@
使用完请务必记得回来手动关闭代理,是否继续?
+
+ 本地 80 端口被占用,这可能导致 http 连接无法自动跳转到 https,是否继续?
+
+
+ 本地 443 端口被占用,这可能导致全局伪造无法正常生效,是否继续?
+
上游规则有更新可用,需要更新吗?否则只为你打开上游规则网页
diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs
index 55acf16..d986d46 100644
--- a/Wins/MainWin.xaml.cs
+++ b/Wins/MainWin.xaml.cs
@@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
+using System.Net;
using System.Net.Http;
+using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
@@ -45,6 +47,12 @@ public partial class MainWin : Window
private static string? MihomoConfs;
private static string? ExtraMihomoConfs;
+ private static bool IsCealHostError = false;
+
+ private static int NginxHttpPort = 80;
+ private static int NginxHttpsPort = 443;
+ private static int MihomoMixedPort = 7880;
+
private static int GameClickTime = 0;
private static int GameFlashInterval = 1000;
@@ -150,9 +158,8 @@ public partial class MainWin : Window
{
HoldButtonTimer?.Stop();
- if (string.IsNullOrWhiteSpace(CealArgs))
- throw new Exception(MainConst._HostErrorMsg);
- if (MessageBox.Show(MainConst._KillBrowserProcessPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
+ if ((IsCealHostError && MessageBox.Show(MainConst._HostErrorPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
+ (MessageBox.Show(MainConst._KillBrowserProcessPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes))
return;
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres!.BrowserPath)))
@@ -183,11 +190,11 @@ public partial class MainWin : Window
if (!MainPres!.IsNginxRunning)
{
- if (string.IsNullOrWhiteSpace(CealArgs))
- throw new Exception(MainConst._HostErrorMsg);
- if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
- return;
- if (MainPres.IsFlashing && MessageBox.Show(MainConst._LaunchNginxFlashingPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
+ if ((IsCealHostError && MessageBox.Show(MainConst._HostErrorPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
+ (NginxHttpPort != 80 && MessageBox.Show(MainConst._NginxHttpPortOccupiedPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
+ (NginxHttpsPort != 443 && MessageBox.Show(MainConst._NginxHttpsPortOccupiedPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
+ (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
+ (MainPres.IsFlashing && MessageBox.Show(MainConst._LaunchNginxFlashingPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes))
return;
if (!File.Exists(MainConst.NginxConfPath))
@@ -256,7 +263,7 @@ public partial class MainWin : Window
{
try
{
- await Http.GetAsync("https://localhost", MainClient);
+ await Http.GetAsync($"https://localhost:{NginxHttpPort}", MainClient);
break;
}
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
@@ -318,7 +325,7 @@ public partial class MainWin : Window
{
try
{
- await Http.GetAsync("http://localhost:7880", MainClient);
+ await Http.GetAsync($"http://localhost:{MihomoMixedPort}", MainClient);
break;
}
catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx)
@@ -509,8 +516,15 @@ public partial class MainWin : Window
if (cealHostDomainPairs.Count != 0)
CealHostRulesDict[cealHostName].Add((cealHostDomainPairs, cealHostSni, cealHostIp));
}
+
+ IsCealHostError = false;
+ }
+ catch
+ {
+ CealHostRulesDict.Remove(cealHostName);
+
+ IsCealHostError = true;
}
- catch { CealHostRulesDict.Remove(cealHostName); }
finally
{
string hostRules = string.Empty;
@@ -552,6 +566,14 @@ public partial class MainWin : Window
if (!Directory.Exists(MainConst.NginxTempPath))
Directory.CreateDirectory(MainConst.NginxTempPath);
+ foreach (IPEndPoint activeTcpListener in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
+ if (activeTcpListener.Port == NginxHttpPort)
+ NginxHttpPort++;
+ else if (activeTcpListener.Port == NginxHttpsPort)
+ NginxHttpsPort++;
+ else if (activeTcpListener.Port > NginxHttpsPort)
+ break;
+
using FileStream nginxConfStream = new(MainConst.NginxConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
ExtraNginxConfs = new StreamReader(nginxConfStream).ReadToEnd();
@@ -573,7 +595,7 @@ public partial class MainWin : Window
.AddOrUpdate("events:worker_connections", "65536")
.AddOrUpdate("http:proxy_set_header", "Host $http_host")
.AddOrUpdate("http:proxy_ssl_server_name", !MainPres.IsFlashing ? "on" : "off")
- .AddOrUpdate($"http:server[{serverIndex}]:listen", "80 default_server")
+ .AddOrUpdate($"http:server[{serverIndex}]:listen", $"{NginxHttpPort} default_server")
.AddOrUpdate($"http:server[{serverIndex}]:return", "https://$host$request_uri");
foreach (List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string? cealHostSni, string cealHostIp)> cealHostRules in CealHostRulesDict.Values)
@@ -597,7 +619,7 @@ public partial class MainWin : Window
NginxConfs = NginxConfs
.AddOrUpdate($"http:server[{serverIndex}]:server_name", serverName.TrimEnd('|'))
- .AddOrUpdate($"http:server[{serverIndex}]:listen", "443 ssl")
+ .AddOrUpdate($"http:server[{serverIndex}]:listen", $"{NginxHttpsPort} ssl")
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate", Path.GetFileName(MainConst.NginxCertPath))
.AddOrUpdate($"http:server[{serverIndex}]:ssl_certificate_key", Path.GetFileName(MainConst.NginxKeyPath))
.AddOrUpdate($"http:server[{serverIndex}]:location", "/", true)
@@ -618,6 +640,12 @@ public partial class MainWin : Window
if (!File.Exists(MainConst.MihomoConfPath))
File.Create(MainConst.MihomoConfPath).Dispose();
+ foreach (IPEndPoint activeTcpListener in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
+ if (activeTcpListener.Port == MihomoMixedPort)
+ MihomoMixedPort++;
+ else if (activeTcpListener.Port > MihomoMixedPort)
+ break;
+
using FileStream mihomoConfStream = new(MainConst.MihomoConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
ExtraMihomoConfs = new StreamReader(mihomoConfStream).ReadToEnd();
@@ -627,7 +655,7 @@ public partial class MainWin : Window
.Build()
.Deserialize>(ExtraMihomoConfs) ?? [];
- mihomoConfDict["mixed-port"] = 7880;
+ mihomoConfDict["mixed-port"] = MihomoMixedPort;
mihomoConfDict["dns"] = new
{
enable = true,