From 0f2f8f4647ca07b94a7778831fe48da32076b69b Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Thu, 7 Apr 2022 16:38:39 +0800
Subject: [PATCH] Enable subscription conversion
---
.../clashN/Forms/AddProfileForm.Designer.cs | 9 ++
clashN/clashN/Forms/AddProfileForm.cs | 13 +-
clashN/clashN/Forms/AddProfileForm.resx | 131 ++++++++++--------
.../clashN/Forms/AddProfileForm.zh-Hans.resx | 3 +
clashN/clashN/Global.cs | 3 +-
clashN/clashN/Handler/ConfigHandler.cs | 4 +
clashN/clashN/Handler/MainFormHandler.cs | 2 +-
clashN/clashN/Handler/SpeedtestHandler.cs | 2 +-
clashN/clashN/Handler/UpdateHandle.cs | 49 ++++---
clashN/clashN/Mode/Config.cs | 12 +-
clashN/clashN/Tool/Utils.cs | 10 +-
11 files changed, 135 insertions(+), 103 deletions(-)
diff --git a/clashN/clashN/Forms/AddProfileForm.Designer.cs b/clashN/clashN/Forms/AddProfileForm.Designer.cs
index 807c503..147805b 100644
--- a/clashN/clashN/Forms/AddProfileForm.Designer.cs
+++ b/clashN/clashN/Forms/AddProfileForm.Designer.cs
@@ -31,6 +31,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddProfileForm));
this.btnClose = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.chkEnableConvert = new System.Windows.Forms.CheckBox();
this.chkEnableTun = new System.Windows.Forms.CheckBox();
this.chkEnabled = new System.Windows.Forms.CheckBox();
this.txtUserAgent = new System.Windows.Forms.TextBox();
@@ -63,6 +64,7 @@
//
// groupBox1
//
+ this.groupBox1.Controls.Add(this.chkEnableConvert);
this.groupBox1.Controls.Add(this.chkEnableTun);
this.groupBox1.Controls.Add(this.chkEnabled);
this.groupBox1.Controls.Add(this.txtUserAgent);
@@ -82,6 +84,12 @@
this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false;
//
+ // chkEnableConvert
+ //
+ resources.ApplyResources(this.chkEnableConvert, "chkEnableConvert");
+ this.chkEnableConvert.Name = "chkEnableConvert";
+ this.chkEnableConvert.UseVisualStyleBackColor = true;
+ //
// chkEnableTun
//
resources.ApplyResources(this.chkEnableTun, "chkEnableTun");
@@ -226,5 +234,6 @@
private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox chkEnabled;
private System.Windows.Forms.CheckBox chkEnableTun;
+ private System.Windows.Forms.CheckBox chkEnableConvert;
}
}
\ No newline at end of file
diff --git a/clashN/clashN/Forms/AddProfileForm.cs b/clashN/clashN/Forms/AddProfileForm.cs
index 921f93c..3bdd906 100644
--- a/clashN/clashN/Forms/AddProfileForm.cs
+++ b/clashN/clashN/Forms/AddProfileForm.cs
@@ -34,7 +34,6 @@ namespace clashN.Forms
profileItem = new ProfileItem();
profileItem.groupId = groupId;
profileItem.enabled = true;
- ClearProfile();
}
}
@@ -49,6 +48,7 @@ namespace clashN.Forms
chkEnabled.Checked = profileItem.enabled;
txtUserAgent.Text = profileItem.userAgent;
chkEnableTun.Checked = profileItem.enableTun;
+ chkEnableConvert.Checked = profileItem.enableConvert;
if (profileItem.coreType == null)
{
@@ -60,16 +60,6 @@ namespace clashN.Forms
}
}
-
- ///
- /// 清除设置
- ///
- private void ClearProfile()
- {
- txtRemarks.Text = "";
- chkEnabled.Enabled = true;
- }
-
private void btnOK_Click(object sender, EventArgs e)
{
string remarks = txtRemarks.Text;
@@ -88,6 +78,7 @@ namespace clashN.Forms
profileItem.enabled = chkEnabled.Checked;
profileItem.userAgent = txtUserAgent.Text.TrimEx();
profileItem.enableTun = chkEnableTun.Checked;
+ profileItem.enableConvert = chkEnableConvert.Checked;
if (profileItem.enableTun)
{
diff --git a/clashN/clashN/Forms/AddProfileForm.resx b/clashN/clashN/Forms/AddProfileForm.resx
index 6a3f7b6..33d0588 100644
--- a/clashN/clashN/Forms/AddProfileForm.resx
+++ b/clashN/clashN/Forms/AddProfileForm.resx
@@ -83,17 +83,50 @@
0
-
+
True
+
+ NoControl
+
+
+ 143, 338
+
+
+
+ 4, 4, 4, 4
+
+
+ 208, 21
+
+
+ 50
+
+
+ Enable subscription conversion
+
+
+ chkEnableConvert
+
+
+ System.Windows.Forms.CheckBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ groupBox1
+
+
+ 0
+
+
+ True
+
NoControl
261, 266
-
4, 4, 4, 4
@@ -116,7 +149,7 @@
groupBox1
- 0
+ 1
True
@@ -149,7 +182,7 @@
groupBox1
- 1
+ 2
143, 222
@@ -173,7 +206,7 @@
groupBox1
- 2
+ 3
True
@@ -206,7 +239,7 @@
groupBox1
- 3
+ 4
143, 62
@@ -236,7 +269,7 @@
groupBox1
- 4
+ 5
True
@@ -269,7 +302,7 @@
groupBox1
- 5
+ 6
NoControl
@@ -296,7 +329,7 @@
groupBox1
- 6
+ 7
143, 264
@@ -317,7 +350,7 @@
groupBox1
- 7
+ 8
True
@@ -347,7 +380,7 @@
groupBox1
- 8
+ 9
NoControl
@@ -374,7 +407,7 @@
groupBox1
- 9
+ 10
143, 123
@@ -398,7 +431,7 @@
groupBox1
- 10
+ 11
True
@@ -425,7 +458,7 @@
groupBox1
- 11
+ 12
143, 23
@@ -446,7 +479,7 @@
groupBox1
- 12
+ 13
True
@@ -473,7 +506,7 @@
groupBox1
- 13
+ 14
True
@@ -500,7 +533,7 @@
groupBox1
- 14
+ 15
Fill
@@ -509,7 +542,7 @@
0, 10
- 642, 364
+ 642, 375
3
@@ -529,42 +562,6 @@
0
-
- btnOK
-
-
- System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- panel2
-
-
- 1
-
-
- Bottom
-
-
- 0, 374
-
-
- 642, 60
-
-
- 7
-
-
- panel2
-
-
- System.Windows.Forms.Panel, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- $this
-
-
- 1
-
357, 17
@@ -589,6 +586,30 @@
1
+
+ Bottom
+
+
+ 0, 385
+
+
+ 642, 60
+
+
+ 7
+
+
+ panel2
+
+
+ System.Windows.Forms.Panel, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ $this
+
+
+ 1
+
Top
@@ -620,7 +641,7 @@
7, 17
- 642, 434
+ 642, 445
6, 8, 6, 8
diff --git a/clashN/clashN/Forms/AddProfileForm.zh-Hans.resx b/clashN/clashN/Forms/AddProfileForm.zh-Hans.resx
index 6e0c780..a24843b 100644
--- a/clashN/clashN/Forms/AddProfileForm.zh-Hans.resx
+++ b/clashN/clashN/Forms/AddProfileForm.zh-Hans.resx
@@ -175,4 +175,7 @@
启用 tun 模式 (以管理员身份运行)
+
+ 启用订阅转换
+
\ No newline at end of file
diff --git a/clashN/clashN/Global.cs b/clashN/clashN/Global.cs
index 37fac4f..c8c0c87 100644
--- a/clashN/clashN/Global.cs
+++ b/clashN/clashN/Global.cs
@@ -18,7 +18,8 @@ namespace clashN
///
public const string SpeedTestUrl = @"http://cachefly.cachefly.net/10mb.test";
public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";
-
+ public const string SubConvertUrl = @"https://sub.xeton.dev/sub?target=clash&url={0}";
+
///
/// PromotionUrl
///
diff --git a/clashN/clashN/Handler/ConfigHandler.cs b/clashN/clashN/Handler/ConfigHandler.cs
index e3e5fec..d9678a3 100644
--- a/clashN/clashN/Handler/ConfigHandler.cs
+++ b/clashN/clashN/Handler/ConfigHandler.cs
@@ -90,6 +90,10 @@ namespace clashN.Handler
{
config.constItem = new ConstItem();
}
+ if (Utils.IsNullOrEmpty(config.constItem.subConvertUrl))
+ {
+ config.constItem.subConvertUrl = Global.SubConvertUrl;
+ }
if (Utils.IsNullOrEmpty(config.constItem.speedTestUrl))
{
config.constItem.speedTestUrl = Global.SpeedTestUrl;
diff --git a/clashN/clashN/Handler/MainFormHandler.cs b/clashN/clashN/Handler/MainFormHandler.cs
index a7e8605..f16f071 100644
--- a/clashN/clashN/Handler/MainFormHandler.cs
+++ b/clashN/clashN/Handler/MainFormHandler.cs
@@ -211,7 +211,7 @@ namespace clashN.Handler
return;
}
var urlBase = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.GetConfig().APIPort}/proxies";
- urlBase += @"/{0}/delay?timeout=10000&url=" + Global.SpeedPingTestUrl;
+ urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.GetConfig().constItem.speedPingTestUrl;
foreach (KeyValuePair kv in proxies)
{
diff --git a/clashN/clashN/Handler/SpeedtestHandler.cs b/clashN/clashN/Handler/SpeedtestHandler.cs
index 87ffe25..e59a9d8 100644
--- a/clashN/clashN/Handler/SpeedtestHandler.cs
+++ b/clashN/clashN/Handler/SpeedtestHandler.cs
@@ -107,7 +107,7 @@ namespace clashN.Handler
{
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
int responseTime = -1;
- string status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime);
+ string status = GetRealPingTime(LazyConfig.Instance.GetConfig().constItem.speedPingTestUrl, webProxy, out responseTime);
bool noError = Utils.IsNullOrEmpty(status);
return noError ? responseTime : -1;
}
diff --git a/clashN/clashN/Handler/UpdateHandle.cs b/clashN/clashN/Handler/UpdateHandle.cs
index e912d5f..cee58ac 100644
--- a/clashN/clashN/Handler/UpdateHandle.cs
+++ b/clashN/clashN/Handler/UpdateHandle.cs
@@ -38,8 +38,8 @@ namespace clashN.Handler
private const string clashCoreUrl32 = Global.clashCoreUrl + "/download/{0}/clash-windows-386-{0}.zip";
private const string clashCoreUrl64 = Global.clashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip";
private readonly string clashMetaCoreLatestUrl = Global.clashMetaCoreUrl + "/latest";
- private const string clashMetaCoreUrl32 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386.zip";
- private const string clashMetaCoreUrl64 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64V1.zip";
+ private const string clashMetaCoreUrl32 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386-{0}.zip";
+ private const string clashMetaCoreUrl64 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64V1-{0}.zip";
private const string geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
public void CheckUpdateGuiN(Config config, Action update)
@@ -180,26 +180,31 @@ namespace clashN.Handler
return;
}
- foreach (var item in config.profileItems)
+ Task.Run(async () =>
{
- if (item.enabled == false)
+ foreach (var item in config.profileItems)
{
- continue;
- }
- string indexId = item.indexId.TrimEx();
- string url = item.url.TrimEx();
- string userAgent = item.userAgent.TrimEx();
- string groupId = item.groupId.TrimEx();
- string hashCode = $"{item.remarks}->";
- if (Utils.IsNullOrEmpty(indexId) || Utils.IsNullOrEmpty(url))
- {
- //_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
- continue;
- }
+ if (item.enabled == false)
+ {
+ continue;
+ }
+ string indexId = item.indexId.TrimEx();
+ string url = item.url.TrimEx();
+ string userAgent = item.userAgent.TrimEx();
+ string groupId = item.groupId.TrimEx();
+ string hashCode = $"{item.remarks}->";
+ if (Utils.IsNullOrEmpty(indexId) || Utils.IsNullOrEmpty(url))
+ {
+ //_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
+ continue;
+ }
- Task.Run(async () =>
- {
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
+
+ if (item.enableConvert)
+ {
+ url = String.Format(config.constItem.subConvertUrl, Utils.UrlEncode(url));
+ }
var result = await (new DownloadHandle()).DownloadStringAsync(url, blProxy, userAgent);
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
@@ -213,14 +218,16 @@ namespace clashN.Handler
int ret = ConfigHandler.AddBatchProfiles(ref config, result, indexId, groupId);
if (ret == 0)
{
+ _updateFunc(false, $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}");
}
else
{
_updateFunc(false, $"{hashCode}{ResUI.MsgFailedImportSubscription}");
}
- _updateFunc(true, $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}");
- });
- }
+ _updateFunc(true, $"-------------------------------------------------------");
+ }
+ _updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}");
+ });
}
diff --git a/clashN/clashN/Mode/Config.cs b/clashN/clashN/Mode/Config.cs
index 14ec28f..4525959 100644
--- a/clashN/clashN/Mode/Config.cs
+++ b/clashN/clashN/Mode/Config.cs
@@ -176,6 +176,8 @@ namespace clashN.Mode
} = string.Empty;
public bool enableTun { get; set; }
+
+ public bool enableConvert { get; set; }
}
[Serializable]
@@ -197,16 +199,14 @@ namespace clashN.Mode
[Serializable]
public class ConstItem
{
- ///
- /// 自定义配置文件下载测速url
- ///
+ public string subConvertUrl
+ {
+ get; set;
+ }
public string speedTestUrl
{
get; set;
}
- ///
- /// 自定义“配置文件真连接延迟”测试url
- ///
public string speedPingTestUrl
{
get; set;
diff --git a/clashN/clashN/Tool/Utils.cs b/clashN/clashN/Tool/Utils.cs
index a50cf22..b0b630d 100644
--- a/clashN/clashN/Tool/Utils.cs
+++ b/clashN/clashN/Tool/Utils.cs
@@ -373,7 +373,7 @@ namespace clashN
public static string UrlEncode(string url)
{
- return HttpUtility.UrlEncode(url);
+ return Uri.EscapeDataString(url);
}
public static string UrlDecode(string url)
{
@@ -735,16 +735,12 @@ namespace clashN
{
if (enableSecurityProtocolTls13)
{
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
- | SecurityProtocolType.Tls11
- | SecurityProtocolType.Tls12
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
| SecurityProtocolType.Tls13;
}
else
{
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
- | SecurityProtocolType.Tls11
- | SecurityProtocolType.Tls12;
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}
ServicePointManager.DefaultConnectionLimit = 256;
}