forked from cmliu/SubsCheck-Win-GUI
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMainGui.cs
More file actions
4680 lines (4071 loc) · 211 KB
/
MainGui.cs
File metadata and controls
4680 lines (4071 loc) · 211 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoUpdaterDotNET;
using Newtonsoft.Json.Linq;
using static subs_check.win.gui.Proxy;
namespace subs_check.win.gui
{
public partial class MainGui : Form
{
//string 版本号;
string 标题;
private Process subsCheckProcess = null;
string nodeInfo;//进度
private Icon originalNotifyIcon; // 保存原始图标
private ToolStripMenuItem startMenuItem;
private ToolStripMenuItem stopMenuItem;
string githubProxyURL = "";
string sysProxyURL = "";
int run = 0;
string currentKernel = "原版内核";
string currentArch = "i386";
string 当前GUI版本号 = "未知版本";
string 最新GUI版本号 = "未知版本";
string 当前subsCheck版本号 = "未知版本";
string 最新内核版本号 = "未知版本";
private string nextCheckTime = null;// 用于存储下次检查时间
string WebUIapiKey = "CMLiussss";
int downloading = 0;
private SysProxyResult SysProxySetting = null;
private DateTime _lastCheckTime = DateTime.MinValue;
private static DateTime _lastGetGithubProxyRunTime = DateTime.MinValue;
private static string _lastGithubProxyUrl = null;
// ——用于避免无意义的重复 UI 重绘——
private string _lastLogLabelNodeInfoText = string.Empty;
private string _lastNotifyText = string.Empty;
// 存储groupBox原始位置
private Point _pipeOriginalLocation;
private Point _enhanceOriginalLocation;
private bool _originalLocationSaved = false;
// 存储媒体解锁平台数组
private List<string> selectedPlatforms = new List<string>();
// 是否需要选择媒体解锁平台
private bool NeedSelectPlatforms = true;
public MainGui()
{
InitializeComponent();
this.Shown += MainGui_Shown;
originalNotifyIcon = notifyIcon1.Icon;
// 设置提示信息
toolTip1.SetToolTip(numericUpDownConcurrent, "并发线程数:推荐 宽带峰值/50M。\n\n如启用高性能模式而未单独设置分段并发数,将使用该值计算自适应并发数.\n启用高性能模式后,此值可安全设置,下载速度会被限制在一个较小的值,同时加快检测速度");
toolTip1.SetToolTip(numericUpDownInterval, "检查间隔时间(分钟):放置后台的时候,下次自动测速的间隔时间。\n\n 双击切换 使用「cron表达式」");
toolTip1.SetToolTip(labelInterval, "检查间隔时间(分钟):放置后台的时候,下次自动测速的间隔时间。\n\n 双击切换 使用「cron表达式」");
toolTip1.SetToolTip(labelCron, "双击切换 使用「分钟倒计时」");
toolTip1.SetToolTip(textBoxCron, "支持标准cron表达式,如:\n 0 */2 * * * 表示每2小时的整点执行\n 0 0 */2 * * 表示每2天的0点执行\n 0 0 1 * * 表示每月1日0点执行\n */30 * * * * 表示每30分钟执行一次\n\n 双击切换 使用「分钟倒计时」");
toolTip1.SetToolTip(numericUpDownTimeout, "超时时间(毫秒):节点的最大延迟。");
toolTip1.SetToolTip(numericUpDownMinSpeed, "最低测速结果舍弃(KB/s)。");
toolTip1.SetToolTip(checkBoxHighConcurrent, "启用高性能内核。\n将同时开启以下功能:\n1. 测活、测速、媒体检测独立并发设置;\n2. 持久化保存并加载历次成功节点;\n3. 统计订阅信息,包括可用节点数量,成功率;\n4. 增强位置标签;\n5. 全新设计的WebUI,一键进入sub-store");
toolTip1.SetToolTip(checkBoxSwitchArch64, "启用64位版本内核。");
toolTip1.SetToolTip(buttonTriggerCheck, "⏯️开始检测:发送开始检测信号,开始检测;\n⏸️结束检测:发送停止信号,内核保持后台运行。");
toolTip1.SetToolTip(buttonStartCheck, "启动内核检测进程。");
toolTip1.SetToolTip(checkBoxPipeAuto, "auto: 切换自适应流水线分段并发模式。");
toolTip1.SetToolTip(numericUpDownPipeAlive, "测活任务并发数:\n取决于CPU和路由器芯片性能,建议设置 100-1000。\n\n量力而行!");
toolTip1.SetToolTip(numericUpDownPipeSpeed, "测速任务并发数。\n建议设置 10-32。");
toolTip1.SetToolTip(numericUpDownPipeMedia, "流媒体检测任务并发数。\n建议设置100-200。");
toolTip1.SetToolTip(checkBoxEhanceTag, "开启增强位置标签:\n- 无法访问 CF 的 CF 节点: HK⁻¹\r\n- 正常访问 CF: a.出口位置与cdn位置一致: HK¹⁺; b.位置不一致: HK¹-US⁰\r\n- 非 CF 节点,直接显示: HK²\r\n- 未获取到位置: HKˣ (使用原方案)\r\n- 前两位字母是实际浏览网站识别的位置,-US⁰为使用CF CDN服务的网站识别的位置,比如GPT, X等。");
toolTip1.SetToolTip(checkBoxDropBadCFNodes, "丢弃无法访问CF CDN网站的节点。\r\n- 这类节点可以正常访问YouTube、Google等网站。\r\n- 无法访问cloudflare及使用了CDN服务的网站,比如Twitter、claude等。\r\n- 开启会导致节点数量大幅减少。");
toolTip1.SetToolTip(comboBoxSubscriptionType, "通用订阅:内置了Sub-Store程序,自适应订阅格式。\nClash订阅:带规则的 Mihomo、Clash 订阅格式。\nSingbox:带规则的singbox订阅,需匹配版本");
toolTip1.SetToolTip(comboBoxOverwriteUrls, "生成带规则的 Clash 订阅所需的覆写规则文件");
toolTip1.SetToolTip(checkBoxStartup, "开机启动:勾选后,程序将在Windows启动时自动运行");
toolTip1.SetToolTip(buttonAdvanceSettings, "高级设置:展开更多设置参数项");
toolTip1.SetToolTip(buttonMoreSettings, "更多参数: 添加GUI未涵盖的参数项");
toolTip1.SetToolTip(buttonCheckUpdate, "检查GUI和内核版本更新");
toolTip1.SetToolTip(numericUpDownDLTimehot, "下载测试时间(s):与下载链接大小相关,默认最大测试10s。");
toolTip1.SetToolTip(numericUpDownWebUIPort, "本地监听端口:用于WebUi,返回软件运行信息等。");
toolTip1.SetToolTip(numericUpDownSubStorePort, "Sub-Store监听端口:用于订阅转换。\n注意:\n请设置sub-store-path以防止被扫描主机");
toolTip1.SetToolTip(textBoxSubStorePath, "Sub-Store自定义路径\n设置path之后,可以安全暴露到公网,开启订阅分享功能。\r\n# 订阅示例:http://127.0.0.1:8299/{sub-store-path}/api/file/mihomo\r\n# WebUI 支持分享订阅,直接复制订阅链接");
toolTip1.SetToolTip(numericUpDownDownloadMb, "下载测试限制(MB):当达到下载数据大小时,停止下载,可节省测速流量,减少测速测死的概率");
toolTip1.SetToolTip(textBoxSubsUrls, "节点池订阅地址:支持 Link、Base64、Clash 格式的订阅链接。");
toolTip1.SetToolTip(checkBoxEnableRenameNode, "以节点IP查询位置重命名节点。\n质量差的节点可能造成IP查询失败,造成整体检查速度稍微变慢。");
toolTip1.SetToolTip(checkBoxEnableMediaCheck, "是否开启流媒体检测,其中IP欺诈依赖'节点地址查询',内核版本需要 v2.0.8 以上\n\n示例:美国1 | ⬇️ 5.6MB/s |0%|Netflix|Disney|Openai\n风控值:0% (使用ping0.cc标准)\n流媒体解锁:Netflix、Disney、Openai");
toolTip1.SetToolTip(comboBoxSysProxy, "系统代理设置: 适用于拉取代理、消息推送、文件上传等等。");
toolTip1.SetToolTip(comboBoxGithubProxyUrl, "GitHub 代理:代理订阅 GitHub raw 节点池。");
toolTip1.SetToolTip(comboBoxSpeedtestUrl, "测速地址:注意 并发数*节点速度<最大网速 否则测速结果不准确\n尽量不要使用Speedtest,Cloudflare提供的下载链接,因为很多节点屏蔽测速网站。\n可选择 random 使用随机测速地址\n大部分机场屏蔽测速,建议不测速或设置较低的速度上限,实际使用可能更好");
toolTip1.SetToolTip(textBox7, "将测速结果推送到Worker的地址。");
toolTip1.SetToolTip(textBox6, "Worker令牌。");
toolTip1.SetToolTip(comboBoxSaveMethod, "测速结果的保存方法。");
toolTip1.SetToolTip(textBox2, "Gist ID:注意!非Github用户名!");
toolTip1.SetToolTip(textBox3, "Github TOKEN");
toolTip1.SetToolTip(checkBoxEnableSuccessLimit, "保存几个成功的节点,不选代表不限制,内核版本需要 v2.1.0 以上\n如果你的并发数量超过这个参数,那么成功的结果可能会大于这个数值");
toolTip1.SetToolTip(checkBoxTotalBandwidthLimit, "总的下载速度限制,不选代表不限制");
toolTip1.SetToolTip(numericUpDownSuccessLimit, "保存几个成功的节点,不选代表不限制,内核版本需要 v2.1.0 以上\n如果你的并发数量超过这个参数,那么成功的结果可能会大于这个数值");
toolTip1.SetToolTip(numericUpDownTotalBandwidthLimit, "总的下载速度限制,不选代表不限制");
toolTip1.SetToolTip(labelCron, "双击切换 使用「分钟倒计时」");
toolTip1.SetToolTip(textBoxCron, "支持标准cron表达式,如:\n 0 */2 * * * 表示每2小时的整点执行\n 0 0 */2 * * 表示每2天的0点执行\n 0 0 1 * * 表示每月1日0点执行\n */30 * * * * 表示每30分钟执行一次\n\n 双击切换 使用「分钟倒计时」");
toolTip1.SetToolTip(checkBoxKeepSucced, "勾选会保留成功节点以便下次使用(持久化存储)\n1. 将加载上次成功节点;\n2. 将加载历次检测成功节点。");
toolTip1.SetToolTip(checkBoxSubsStats, "仅在 “高性能模式“可用”。\n勾选会在 /output/stats 文件夹生成每个订阅链接内的节点数量,可用节点数量以及成功率。");
toolTip1.SetToolTip(checkBoxIspCheck, "是否执行 isp 类型检测\n检测是否 原生/广播IP,以及住宅、机房等类型\n将为节点添加类似 [原生|机房]的标签");
toolTip1.SetToolTip(checkBoxEnableWebUI, "勾选后启用WebUI管理界面\n建议启用\n开启后可一键管理sub-store\n建议使用 Cloudflare Tunel隧道 映射主机端口\r\n可使用域名编辑、管理配置,开始、结束检测任务\n本地管理地址: http://127.0.0.1:8199/admin\n");
toolTip1.SetToolTip(buttonWebUi, "更方便的subs-check管理面板\n可一键分享订阅\n支持一键进入sub-store\n支持远程管理");
toolTip1.SetToolTip(textBoxWebUiAPIKey, "Web控制面板的api-key");
// 设置通知图标的上下文菜单
SetupNotifyIconContextMenu();
}
private async void MainGui_Shown(object sender, EventArgs e)
{
// 先检查系统代理
await AutoCheckSysProxy();
// 再初始化 AutoUpdater
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;
AutoUpdater.Icon = Properties.Resources.download;
AutoUpdater.ShowRemindLaterButton = false;
AutoUpdater.ReportErrors = true;
AutoUpdater.HttpUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
AutoUpdater.Start("https://gh.39.al/raw.githubusercontent.com/sinspired/subsCheck-Win-GUI/master/update.xml");
}
// 更新程序退出事件处理器
private async void AutoUpdater_ApplicationExitEvent()
{
StopSubsCheckProcess();
await KillNodeProcessAsync();
Application.Exit();
}
//自定义检查更新事件
private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args.Error == null)
{
if (args.IsUpdateAvailable)
{
// 如果你想显示标准更新窗口,请取消下面这行的注释
AutoUpdater.ShowUpdateForm(args);
}
}
else
{
if (args.Error is WebException)
{
MessageBox.Show(
@"无法连接到更新服务器。请检查您的网络连接并稍后重试。",
@"更新检查失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show(args.Error.Message,
args.Error.GetType().ToString(), MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
public async Task AutoCheckSysProxy(bool noRepeat = true)
{
// 如果10秒内已经执行过,直接返回
if ((DateTime.Now - _lastCheckTime).TotalSeconds < 10 && noRepeat)
{
//Log("10秒内已检测过系统代理,跳过执行", GetRichTextBoxAllLog());
return;
}
_lastCheckTime = DateTime.Now; // 更新执行时间
// 自动检测系统代理
string configProxy = comboBoxSysProxy.Text;
if (configProxy == "自动检测" || string.IsNullOrEmpty(configProxy) || configProxy == "http://" || configProxy == "https://")
{
configProxy = "";
}
if ((!configProxy.StartsWith("http://") || !configProxy.StartsWith("https://")) && configProxy != "")
{
configProxy = "http://" + configProxy;
}
SysProxySetting = await Proxy.GetSysProxyAsync(configProxy);
if (SysProxySetting != null && SysProxySetting.IsAvailable)
{
if (comboBoxSysProxy.Text == SysProxySetting.Address)
{
Log("设置系统代理: " + SysProxySetting.Address, GetRichTextBoxAllLog());
}
else
{
string input = SysProxySetting.Address?.Trim() ?? string.Empty;
// 检查是否存在 "://" 协议部分
int protocolIndex = input.IndexOf("://");
if (protocolIndex >= 0)
{
input = input.Substring(protocolIndex + 3);
}
// 检查是否存在 "/" 路径部分
int pathIndex = input.IndexOf('/');
if (pathIndex >= 0)
{
input = input.Substring(0, pathIndex);
}
comboBoxSysProxy.Text = input;
Log("检测到可用系统代理并设置: " + SysProxySetting.Address, GetRichTextBoxAllLog());
//await SaveConfig(false);
}
}
else
{
Log("未发现系统代理或系统代理不可用", GetRichTextBoxAllLog());
}
}
//临时禁用/恢复控件重绘
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0x000B;
private void SuspendRedraw(Control c)
{
if (c != null && c.IsHandleCreated)
SendMessage(c.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
}
private void ResumeRedraw(Control c)
{
if (c != null && c.IsHandleCreated)
{
SendMessage(c.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
c.Invalidate();
}
}
private void SetupNotifyIconContextMenu()
{
// 创建上下文菜单
ContextMenuStrip contextMenu = new ContextMenuStrip();
// 创建"▶️ 启动"菜单项
startMenuItem = new ToolStripMenuItem("启动");
startMenuItem.Click += (sender, e) =>
{
if (buttonStartCheck.Text == "▶️ 启动")
{
buttonStartCheck.ForeColor = Color.Black;
buttonStartCheck_Click(sender, e);
}
};
// 创建"⏹️ 停止"菜单项
stopMenuItem = new ToolStripMenuItem("停止");
stopMenuItem.Click += (sender, e) =>
{
if (buttonStartCheck.Text == "⏹️ 停止")
{
buttonStartCheck.ForeColor = Color.Red;
buttonStartCheck_Click(sender, e);
}
};
stopMenuItem.Enabled = false; // 初始状态下禁用
// 创建"退出"菜单项
ToolStripMenuItem exitMenuItem = new ToolStripMenuItem("退出");
exitMenuItem.Click += async (sender, e) =>
{
try
{
// 如果程序正在运行,先停止它
if (subsCheckProcess != null && !subsCheckProcess.HasExited)
{
await KillNodeProcessAsync();
StopSubsCheckProcess();
}
// 确保通知图标被移除
notifyIcon1.Visible = false;
// 使用更直接的退出方式
Environment.Exit(0);
}
catch (Exception ex)
{
MessageBox.Show($"退出程序时发生错误: {ex.Message}", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
// 如果仍然失败,尝试强制退出
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
};
// 将菜单项添加到上下文菜单
contextMenu.Items.Add(startMenuItem);
contextMenu.Items.Add(stopMenuItem);
contextMenu.Items.Add(new ToolStripSeparator()); // 分隔线
contextMenu.Items.Add(exitMenuItem);
// 将上下文菜单分配给通知图标
notifyIcon1.ContextMenuStrip = contextMenu;
// 确保通知图标可见
notifyIcon1.Visible = true;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
// 取消关闭操作
e.Cancel = true;
// 调用隐藏窗口方法
隐藏窗口();
}
}
private async void timerinitial_Tick(object sender, EventArgs e)//初始化
{
timerinitial.Enabled = false;
if (buttonAdvanceSettings.Text == "高级设置∧") buttonAdvanceSettings_Click(sender, e);
// 检查并创建config文件夹
string executablePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
string configFolderPath = System.IO.Path.Combine(executablePath, "config");
if (!System.IO.Directory.Exists(configFolderPath))
{
// 文件不存在,可以给用户反馈
string 免责声明 = "SubsCheck-Win-GUI 项目仅供教育、研究和安全测试目的而设计和开发。本项目旨在为安全研究人员、学术界人士及技术爱好者提供一个探索和实践网络通信技术的工具。\r\n在下载和使用本项目代码时,使用者必须严格遵守其所适用的法律和规定。使用者有责任确保其行为符合所在地区的法律框架、规章制度及其他相关规定。\r\n\r\n使用条款\r\n\r\n教育与研究用途:本软件仅可用于网络技术和编程领域的学习、研究和安全测试。\r\n禁止非法使用:严禁将 SubsCheck-Win-GUI 用于任何非法活动或违反使用者所在地区法律法规的行为。\r\n使用时限:基于学习和研究目的,建议用户在完成研究或学习后,或在安装后的24小时内,删除本软件及所有相关文件。\r\n免责声明:SubsCheck-Win-GUI 的创建者和贡献者不对因使用或滥用本软件而导致的任何损害或法律问题负责。\r\n用户责任:用户对使用本软件的方式以及由此产生的任何后果完全负责。\r\n无技术支持:本软件的创建者不提供任何技术支持或使用协助。\r\n知情同意:使用 SubsCheck-Win-GUI 即表示您已阅读并理解本免责声明,并同意受其条款的约束。\r\n\r\n请记住:本软件的主要目的是促进学习、研究和安全测试。创作者不支持或认可任何其他用途。使用者应当在合法和负责任的前提下使用本工具。\r\n\r\n同意以上条款请点击\"是 / Yes\",否则程序将退出。";
// 显示带有 "同意" 和 "拒绝" 选项的对话框
DialogResult result = MessageBox.Show(免责声明, "SubsCheck-Win-GUI 免责声明", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// 如果用户点击 "拒绝" (对应于 No 按钮)
if (result == DialogResult.No)
{
// 退出程序
Environment.Exit(0); // 立即退出程序
}
System.IO.Directory.CreateDirectory(configFolderPath);
}
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
当前GUI版本号 = "v" + myFileVersionInfo.FileVersion;
最新GUI版本号 = 当前GUI版本号;
标题 = "SubsCheck Win GUI " + 当前GUI版本号;
this.Text = 标题;// + " TG:CMLiussss BY:CM喂饭 干货满满";
comboBoxSaveMethod.Text = "本地";
comboBoxSubscriptionType.Text = "通用订阅";
ReadConfig();
if (checkBoxHighConcurrent.Checked)
{
groupBoxGist.Location = new Point(groupBoxGist.Location.X, groupBoxGist.Location.Y + groupBoxPipeConcurrent.Height);
groupBoxR2.Location = groupBoxGist.Location;
groupBoxWebdav.Location = groupBoxGist.Location;
}
if (CheckCommandLineParameter("-auto"))
{
Log("检测到开机启动,准备执行任务...", GetRichTextBoxAllLog());
buttonStartCheck_Click(this, EventArgs.Empty);
this.Hide();
notifyIcon1.Visible = true;
}
else await CheckGitHubVersionAsync();
}
private async Task CheckGitHubVersionAsync()
{
try
{
// 首先检查网络(你已有 IsNetworkAvailable() 方法)
if (!IsNetworkAvailable())
return;
// 并行获取 GUI 和 Kernel 的最新版本(更快)
var taskGui = 获取版本号("https://api.github.com/repos/sinspired/SubsCheck-Win-GUI/releases/latest");
// 动态决定使用哪个仓库(checkBoxHighConcurrent 为 true 时使用 sinspired,否则使用 beck-8)
string repoOwner = checkBoxHighConcurrent.Checked ? "sinspired" : "beck-8";
string apiUrl = $"https://api.github.com/repos/{repoOwner}/subs-check/releases/latest";
var taskKernel = 获取版本号(apiUrl);
await Task.WhenAll(taskGui, taskKernel);
string latestGui = taskGui.Result.Item1;
string latestKernel = taskKernel.Result.Item1;
bool hasNewGui = false;
bool hasNewKernel = false;
string newTitle = $"SubsCheck Win GUI {当前GUI版本号}";
// ========= 检查 GUI 更新 =========
if (latestGui != "未知版本" && !string.Equals(latestGui, 当前GUI版本号, StringComparison.OrdinalIgnoreCase))
{
// 尝试用 Version 类精确比较
if (TryParseVersion(latestGui, out Version vLatest) &&
TryParseVersion(当前GUI版本号, out Version vCurrent) &&
vLatest > vCurrent)
{
hasNewGui = true;
最新GUI版本号 = latestGui;
}
else if (string.Compare(latestGui.TrimStart('v'), 当前GUI版本号.TrimStart('v'), StringComparison.OrdinalIgnoreCase) > 0)
{
// 回退到字符串比较(带 v 或不带 v 都支持)
hasNewGui = true;
最新GUI版本号 = latestGui;
}
}
// ========= 检查 Kernel 更新 =========
if (latestKernel != "未知版本" && !string.Equals(latestKernel, 当前subsCheck版本号, StringComparison.OrdinalIgnoreCase))
{
if (TryParseVersion(latestKernel, out Version vLatestK) &&
TryParseVersion(当前subsCheck版本号, out Version vCurrentK) &&
vLatestK > vCurrentK)
{
hasNewKernel = true;
最新内核版本号 = latestKernel; // 假设你有这个字段,没有就新建一个 string 最新内核版本号;
}
else if (string.Compare(latestKernel.TrimStart('v'), 当前subsCheck版本号.TrimStart('v'), StringComparison.OrdinalIgnoreCase) > 0)
{
hasNewKernel = true;
最新内核版本号 = latestKernel;
}
}
// ========= 生成标题提示 =========
if (hasNewGui && hasNewKernel)
{
newTitle += $" 有新版本!GUI → {最新GUI版本号} 内核 → {最新内核版本号}";
}
else if (hasNewGui)
{
newTitle += $" 发现新GUI版本: {最新GUI版本号} 请及时更新!";
}
else if (hasNewKernel)
{
newTitle += $" 发现新内核版本: {最新内核版本号} 请更新内核!";
}
if (hasNewGui || hasNewKernel)
{
// 检查更新按钮颜色
buttonCheckUpdate.ForeColor = Color.LimeGreen;
buttonCheckUpdate.Text = "有新版本";
标题 = newTitle;
this.Text = 标题; // 更新窗口标题
// 可选:这里再弹个小气泡提示更友好
notifyIcon1.ShowBalloonTip(8000, "SubsCheck 更新提醒",
hasNewGui && hasNewKernel ? $"GUI 和内核均有新版本!\nGUI: {最新GUI版本号}\n内核: {最新内核版本号}"
: hasNewGui ? $"GUI 有新版本:{最新GUI版本号}"
: $"内核有新版本:{最新内核版本号}", ToolTipIcon.Info);
}
}
catch
{
// 所有异常静默处理,不打扰用户
}
}
// 辅助方法:安全解析版本号(自动去掉 v 前缀)
private bool TryParseVersion(string input, out Version version)
{
version = null;
if (string.IsNullOrWhiteSpace(input)) return false;
string clean = input.TrimStart('v', 'V');
return Version.TryParse(clean, out version);
}
// 添加检查网络连接的辅助方法
private bool IsNetworkAvailable()
{
try
{
return NetworkInterface.GetIsNetworkAvailable();
}
catch
{
return false; // 如果无法检查网络状态,假设网络不可用
}
}
private async void ReadConfig()//读取配置文件
{
checkBoxStartup.CheckedChanged -= checkBoxStartup_CheckedChanged;// 临时移除事件处理器,防止触发事件
try
{
string executablePath = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
string configFilePath = Path.Combine(executablePath, "config", "config.yaml");
if (File.Exists(configFilePath))
{
// 读取YAML文件内容
string yamlContent = File.ReadAllText(configFilePath);
// 使用YamlDotNet解析YAML
var deserializer = new YamlDotNet.Serialization.Deserializer();
var config = deserializer.Deserialize<Dictionary<string, object>>(yamlContent);
// 变量放在前面,以防后续读取时未定义
string subscheckArch = 读取config字符串(config, "subscheck-arch");
if (!string.IsNullOrWhiteSpace(subscheckArch)) currentArch = subscheckArch;
string subscheckKernel = 读取config字符串(config, "subscheck-kernel");
if (!string.IsNullOrWhiteSpace(subscheckKernel)) currentKernel = subscheckKernel;
string githubproxy = 读取config字符串(config, "githubproxy");
if (githubproxy != null) comboBoxGithubProxyUrl.Text = githubproxy;
const string githubRawPrefix = "https://raw.githubusercontent.com/";
// 使用新函数获取整数值并设置UI控件
int? concurrentValue = 读取config整数(config, "concurrent");
if (concurrentValue.HasValue) numericUpDownConcurrent.Value = concurrentValue.Value;
// 临时禁用事件
numericUpDownPipeAlive.ValueChanged -= numericUpDownPipeAlive_ValueChanged;
numericUpDownPipeSpeed.ValueChanged -= numericUpDownPipeSpeed_ValueChanged;
numericUpDownPipeMedia.ValueChanged -= numericUpDownPipeMedia_ValueChanged;
// 测活/测速/流媒体阶段并发数(先赋值到控件,再从控件读取最终值,保证非 null)
int? aliveConcurrentValue = 读取config整数(config, "alive-concurrent");
if (aliveConcurrentValue.HasValue) numericUpDownPipeAlive.Value = aliveConcurrentValue.Value;
int? speedConcurrentValue = 读取config整数(config, "speed-concurrent");
if (speedConcurrentValue.HasValue) numericUpDownPipeSpeed.Value = speedConcurrentValue.Value;
int? mediaConcurrentValue = 读取config整数(config, "media-concurrent");
if (mediaConcurrentValue.HasValue) numericUpDownPipeMedia.Value = mediaConcurrentValue.Value;
// 根据各阶段并发数切换设置项, 如果任一为0, 则启用自适应高性能
switchPipeAutoConcurrent(); // 现在控件已被赋值,函数可以安全读取 numericUpDown 的值
// 重新启用事件
numericUpDownPipeAlive.ValueChanged += numericUpDownPipeAlive_ValueChanged;
numericUpDownPipeSpeed.ValueChanged += numericUpDownPipeSpeed_ValueChanged;
numericUpDownPipeMedia.ValueChanged += numericUpDownPipeMedia_ValueChanged;
// Enhance-tag 相关设置(稳健解析 "true"/"false")
string enhanceTagRaw = 读取config字符串(config, "enhanced-tag");
bool enhanceTagFlag = false;
if (!string.IsNullOrWhiteSpace(enhanceTagRaw))
{
bool.TryParse(enhanceTagRaw.Trim(), out enhanceTagFlag);
}
checkBoxEhanceTag.Checked = enhanceTagFlag;
// 丢弃低质量的 cf 节点
string dropBadCFRaw = 读取config字符串(config, "drop-bad-cf-nodes");
bool dropBadCFFlag = false;
if (!string.IsNullOrWhiteSpace(dropBadCFRaw))
{
bool.TryParse(dropBadCFRaw.Trim(), out dropBadCFFlag);
}
checkBoxDropBadCFNodes.Checked = dropBadCFFlag;
// 读取 enable-high-concurrent,并解析为 bool
string enableHighConcurrentRaw = 读取config字符串(config, "enable-high-concurrent");
bool enableHighConcurrentFlag = false;
if (!string.IsNullOrWhiteSpace(enableHighConcurrentRaw))
{
bool.TryParse(enableHighConcurrentRaw.Trim(), out enableHighConcurrentFlag);
}
// 决定是否启用高性能:只要显式开启 或 drop/enhance 为 true 或 三阶段并发均 > 0
bool needHighConcurrent = enableHighConcurrentFlag
|| dropBadCFFlag
|| enhanceTagFlag
|| (aliveConcurrentValue > 0 && speedConcurrentValue > 0 && mediaConcurrentValue > 0);
checkBoxHighConcurrent.Checked = needHighConcurrent;
if (checkBoxHighConcurrent.Checked)
{
if (!comboBoxSubscriptionType.Items.Contains("Singbox1.11"))
{
comboBoxSubscriptionType.Items.AddRange(new object[] { "Singbox1.11" });
}
if (!comboBoxSubscriptionType.Items.Contains("Singbox1.12"))
{
comboBoxSubscriptionType.Items.AddRange(new object[] { "Singbox1.12" });
}
}
// 根据是否启用高性能,调整界面布局
string sysproxy;
if (!checkBoxHighConcurrent.Checked)
{
sysproxy = 读取config字符串(config, "proxy");
if (sysproxy == null || sysproxy == "")
{
sysproxy = 读取config字符串(config, "system-proxy");
}
}
else
{
sysproxy = 读取config字符串(config, "system-proxy");
if (sysproxy == null || sysproxy == "")
{
sysproxy = 读取config字符串(config, "proxy");
}
}
if (sysproxy != null)
{
string input = sysproxy.Trim();
// 检查是否存在 "://" 协议部分
int protocolIndex = input.IndexOf("://");
if (protocolIndex >= 0)
{
// 保留 "://" 之后的内容
input = input.Substring(protocolIndex + 3);
}
// 检查是否存在 "/" 路径部分
int pathIndex = input.IndexOf('/');
if (pathIndex >= 0)
{
// 只保留 "/" 之前的域名部分
input = input.Substring(0, pathIndex);
}
// 更新 comboBox3 的文本
sysproxy = input;
comboBoxSysProxy.Text = sysproxy;
}
else
{
comboBoxSysProxy.Text = "自动检测";
}
string switchX64 = 读取config字符串(config, "switch-x64");
if (switchX64 != null && switchX64 == "true") checkBoxSwitchArch64.Checked = true;
else checkBoxSwitchArch64.Checked = false;
int? checkIntervalValue = 读取config整数(config, "check-interval");
if (checkIntervalValue.HasValue) numericUpDownInterval.Value = checkIntervalValue.Value;
int? timeoutValue = 读取config整数(config, "timeout");
if (timeoutValue.HasValue) numericUpDownTimeout.Value = timeoutValue.Value;
int? minspeedValue = 读取config整数(config, "min-speed");
if (minspeedValue.HasValue) numericUpDownMinSpeed.Value = minspeedValue.Value;
int? downloadtimeoutValue = 读取config整数(config, "download-timeout");
if (downloadtimeoutValue.HasValue) numericUpDownDLTimehot.Value = downloadtimeoutValue.Value;
int? downloadLimitSizeValue = 读取config整数(config, "download-mb");
if (downloadLimitSizeValue.HasValue) numericUpDownDownloadMb.Value = downloadLimitSizeValue.Value;
int? downloadLimitSpeedValue = 读取config整数(config, "total-speed-limit");
if (downloadLimitSpeedValue.HasValue) numericUpDownTotalBandwidthLimit.Value = downloadLimitSpeedValue.Value;
string speedTestUrl = 读取config字符串(config, "speed-test-url");
if (checkBoxHighConcurrent.Checked && !comboBoxSpeedtestUrl.Items.Contains("random"))
{
// 只有当列表里至少有1个元素时,才能插在第2个位置(索引1)
// 否则只能插在第1个位置(索引0)
int insertIndex = comboBoxSpeedtestUrl.Items.Count > 0 ? 1 : 0;
comboBoxSpeedtestUrl.Items.Insert(insertIndex, "random");
}
else
{
comboBoxSpeedtestUrl.Items.Remove("random");
if (comboBoxSpeedtestUrl.Text == "random") comboBoxSpeedtestUrl.Text = "不测速";
}
if (speedTestUrl != null)
{
if (speedTestUrl == "")
{
comboBoxSpeedtestUrl.Text = "不测速";
}
else
{
comboBoxSpeedtestUrl.Items.Add(speedTestUrl);
comboBoxSpeedtestUrl.Text = speedTestUrl;
}
}
else
{
comboBoxSpeedtestUrl.Text = "不测速";
}
string listenport = 读取config字符串(config, "listen-port");
if (listenport != null)
{
// 查找最后一个冒号的位置
int colonIndex = listenport.LastIndexOf(':');
if (colonIndex >= 0 && colonIndex < listenport.Length - 1)
{
// 提取冒号后面的部分作为端口号
string portStr = listenport.Substring(colonIndex + 1);
if (decimal.TryParse(portStr, out decimal port))
{
numericUpDownWebUIPort.Value = port;
}
}
}
/*
int? substoreport = 读取config整数(config, "sub-store-port");
if (substoreport.HasValue) numericUpDown7.Value = substoreport.Value;
*/
string substoreport = 读取config字符串(config, "sub-store-port");
if (substoreport != null)
{
// 查找最后一个冒号的位置
int colonIndex = substoreport.LastIndexOf(':');
if (colonIndex >= 0 && colonIndex < substoreport.Length - 1)
{
// 提取冒号后面的部分作为端口号
string portStr = substoreport.Substring(colonIndex + 1);
if (decimal.TryParse(portStr, out decimal port))
{
numericUpDownSubStorePort.Value = port;
}
}
}
string mihomoOverwriteUrl = 读取config字符串(config, "mihomo-overwrite-url");
int mihomoOverwriteUrlIndex = mihomoOverwriteUrl.IndexOf(githubRawPrefix);
if (mihomoOverwriteUrl != null)
{
if (mihomoOverwriteUrl.Contains("http://127.0.0"))
{
if (mihomoOverwriteUrl.EndsWith("bdg.yaml", StringComparison.OrdinalIgnoreCase))
{
comboBoxOverwriteUrls.Text = "[内置]布丁狗的订阅转换";
await comboBoxOverwriteUrlsSelection();
}
else if (mihomoOverwriteUrl.EndsWith("ACL4SSR_Online_Full.yaml", StringComparison.OrdinalIgnoreCase))
{
comboBoxOverwriteUrls.Text = "[内置]ACL4SSR_Online_Full";
await comboBoxOverwriteUrlsSelection();
}
}
else if (mihomoOverwriteUrlIndex > 0) comboBoxOverwriteUrls.Text = mihomoOverwriteUrl.Substring(mihomoOverwriteUrlIndex);
else comboBoxOverwriteUrls.Text = mihomoOverwriteUrl;
}
// 处理URLs,检查是否包含GitHub raw链接
List<string> subUrls = 读取config列表(config, "sub-urls");
if (subUrls != null && subUrls.Count > 0)
{
// 创建一个新的过滤后的列表
var filteredUrls = new List<string>();
for (int i = 0; i < subUrls.Count; i++)
{
// 排除本地URL
string localUrlPattern = $"http://127.0.0.1:{numericUpDownWebUIPort.Value}/all.yaml";
if (!subUrls[i].Equals(localUrlPattern, StringComparison.OrdinalIgnoreCase))
{
// 处理GitHub raw链接
int index = subUrls[i].IndexOf(githubRawPrefix);
if (index > 0) // 如果找到且不在字符串开头
{
// 只保留从githubRawPrefix开始的部分
filteredUrls.Add(subUrls[i].Substring(index));
}
else
{
// 如果不是GitHub链接,直接添加
filteredUrls.Add(subUrls[i]);
}
}
}
string extraURL01 = "https://raw.githubusercontent.com/officialputuid/KangProxy/KangProxy/xResults/old-data/RAW.txt";
string extraURL02 = "https://raw.githubusercontent.com/officialputuid/KangProxy/KangProxy/xResults/Proxies.txt";
if (checkBoxHighConcurrent.Checked)
{
if (filteredUrls.Contains(extraURL01) == false) filteredUrls.Add(extraURL01);
if (filteredUrls.Contains(extraURL02) == false) filteredUrls.Add(extraURL02);
}
else
{
if (filteredUrls.Contains(extraURL01) == true) filteredUrls.Remove(extraURL01);
if (filteredUrls.Contains(extraURL02) == true) filteredUrls.Remove(extraURL02);
}
// 将过滤后的列表中的每个URL放在单独的行上
textBoxSubsUrls.Text = string.Join(Environment.NewLine, filteredUrls);
}
string renamenode = 读取config字符串(config, "rename-node");
if (renamenode != null && renamenode == "true") checkBoxEnableRenameNode.Checked = true;
else checkBoxEnableRenameNode.Checked = false;
List<string> platforms = 读取config列表(config, "platforms");
if (platforms != null && platforms.Count > 0)
{
selectedPlatforms = platforms;
NeedSelectPlatforms = false;
}
else
{
selectedPlatforms = new List<string>();
}
string mediacheck = 读取config字符串(config, "media-check");
if (mediacheck != null && mediacheck == "true") checkBoxEnableMediaCheck.Checked = true;
else checkBoxEnableMediaCheck.Checked = false;
string githubapimirror = 读取config字符串(config, "github-api-mirror");
if (githubapimirror != null) textBox4.Text = githubapimirror;
string savemethod = 读取config字符串(config, "save-method");
if (savemethod != null)
{
if (savemethod == "local") comboBoxSaveMethod.Text = "本地";
else comboBoxSaveMethod.Text = savemethod;
}
string githubgistid = 读取config字符串(config, "github-gist-id");
if (githubgistid != null) textBox2.Text = githubgistid;
string githubtoken = 读取config字符串(config, "github-token");
if (githubtoken != null) textBox3.Text = githubtoken;
string workerurl = 读取config字符串(config, "worker-url");
if (workerurl != null) textBox7.Text = workerurl;
string workertoken = 读取config字符串(config, "worker-token");
if (workertoken != null) textBox6.Text = workertoken;
string webdavusername = 读取config字符串(config, "webdav-username");
if (webdavusername != null) textBox9.Text = webdavusername;
string webdavpassword = 读取config字符串(config, "webdav-password");
if (webdavpassword != null) textBox8.Text = webdavpassword;
string webdavurl = 读取config字符串(config, "webdav-url");
if (webdavurl != null) textBox5.Text = webdavurl;
string subscheckversion = 读取config字符串(config, "subscheck-version");
if (subscheckversion != null) 当前subsCheck版本号 = subscheckversion;
string keepSucced = 读取config字符串(config, "keep-success-proxies");
if (keepSucced != null && keepSucced == "true") checkBoxKeepSucced.Checked = true;
else checkBoxKeepSucced.Checked = false;
string SubsStats = 读取config字符串(config, "sub-urls-stats");
if (SubsStats != null && SubsStats == "true") checkBoxSubsStats.Checked = true;
else checkBoxSubsStats.Checked = false;
string ispCheck = 读取config字符串(config, "isp-check");
if (ispCheck != null && ispCheck == "true") checkBoxIspCheck.Checked = true;
else checkBoxIspCheck.Checked = false;
int? successlimit = 读取config整数(config, "success-limit");
if (successlimit.HasValue)
{
if (successlimit.Value == 0)
{
checkBoxEnableSuccessLimit.Checked = false;
numericUpDownSuccessLimit.Enabled = false;
}
else
{
checkBoxEnableSuccessLimit.Checked = true;
numericUpDownSuccessLimit.Enabled = true;
numericUpDownSuccessLimit.Value = successlimit.Value;
}
}
int? totalspeedlimit = 读取config整数(config, "total-speed-limit");
if (totalspeedlimit.HasValue)
{
if (totalspeedlimit.Value == 0)
{
checkBoxTotalBandwidthLimit.Checked = false;
numericUpDownTotalBandwidthLimit.Enabled = false;
}
else
{
checkBoxTotalBandwidthLimit.Checked = true;
numericUpDownTotalBandwidthLimit.Enabled = true;
numericUpDownTotalBandwidthLimit.Value = totalspeedlimit.Value;
}
}
string enablewebui = 读取config字符串(config, "enable-web-ui");
if (enablewebui != null && enablewebui == "true") checkBoxEnableWebUI.Checked = true;
else checkBoxEnableWebUI.Checked = false;
string apikey = 读取config字符串(config, "api-key");
if (apikey != null)
{
if (apikey == GetComputerNameMD5())
{
checkBoxEnableWebUI.Checked = false;
string oldapikey = 读取config字符串(config, "old-api-key");
if (oldapikey != null)
{
textBoxWebUiAPIKey.Text = oldapikey;
}
else
{
textBoxWebUiAPIKey.PasswordChar = '\0';
textBoxWebUiAPIKey.Text = "请输入密钥";
textBoxWebUiAPIKey.ForeColor = Color.Gray;
}
}
else
{
textBoxWebUiAPIKey.Text = apikey;
}
}
string substorePath = 读取config字符串(config, "sub-store-path");
if (!string.IsNullOrEmpty(substorePath))
{
if (substorePath.StartsWith("/")) substorePath = substorePath.Substring(1);
textBoxSubStorePath.Text = substorePath;
}
else
{
textBoxSubStorePath.Text = GetComputerNameMD5();
}
string cronexpression = 读取config字符串(config, "cron-expression");
if (cronexpression != null)
{
textBoxCron.Text = cronexpression;
string cronDescription = GetCronExpressionDescription(textBoxCron.Text);
labelCron.Location = new Point(labelCron.Location.X, labelInterval.Location.Y);
textBoxCron.Location = new Point(textBoxCron.Location.X, numericUpDownInterval.Location.Y);
labelCron.Visible = true;
textBoxCron.Visible = true;
labelInterval.Visible = false;
numericUpDownInterval.Visible = false;
}
string guiauto = 读取config字符串(config, "gui-auto");
if (guiauto != null && guiauto == "true") checkBoxStartup.Checked = true;
else checkBoxStartup.Checked = false;
}
else
{
comboBoxGithubProxyUrl.Text = "自动选择";
comboBoxSysProxy.Text = "自动检测";
comboBoxOverwriteUrls.Text = "[内置]布丁狗的订阅转换";