-
Notifications
You must be signed in to change notification settings - Fork 28
/
MainWindowWD.xaml.cs
1507 lines (1497 loc) · 66.9 KB
/
MainWindowWD.xaml.cs
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
// 用于处理后端逻辑。
/*
* You may think you know what the following code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many a sleepless
* night cursing the moment you thought youd be clever
* enough to "optimize" the code below.
* Now close this file and go play with something else.
* 你可能会认为你读得懂以下的代码。但是你不会懂的,相信我吧。
* 要是你尝试玩弄这段代码的话,你将会在无尽的通宵中不断地咒骂自己为什么会认为自己聪明到可以优化这段代码。
* 现在请关闭这个文件去玩点别的吧。
*/
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Security.Cryptography;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using Downloader;
using LLC_MOD_Toolbox.Models;
using log4net;
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using SevenZip;
namespace LLC_MOD_Toolbox
{
public partial class MainWindow : Window
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType ?? typeof(MainWindow));
private static string? useEndPoint;
private static string? useAPIEndPoint;
private static bool useGithub = false;
private static bool useMirrorGithub = false;
private static string limbusCompanyDir = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1973530", "InstallLocation", null) as string
?? string.Empty;
private static string limbusCompanyGameDir = Path.Combine(limbusCompanyDir, "LimbusCompany.exe");
private static readonly string currentDir = AppDomain.CurrentDomain.BaseDirectory;
private static List<Node> nodeList = [];
private static List<Node> apiList = [];
private static string defaultEndPoint = "https://node.zeroasso.top/d/od/";
private static string defaultAPIEndPoint = "https://api.kr.zeroasso.top/";
private static int installPhase = 0;
private readonly DispatcherTimer progressTimer;
private float progressPercentage = 0;
// GreyTest 灰度测试2.0
private static string greytestUrl = string.Empty;
private static bool greytestStatus = false;
private readonly string VERSION = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";
public MainWindow()
{
InitializeComponent();
progressTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(0.05)
};
progressTimer.Tick += ProgressTime_Tick;
}
private async void WindowLoaded(object sender, RoutedEventArgs e)
{
logger.Info("—————新日志分割线—————");
logger.Info("工具箱已进入加载流程。");
logger.Info("We have a lift off.");
logger.Info($"WPF架构工具箱 版本:{VERSION} 。");
InitNode();
await RefreshPage();
await ChangeEEPic("https://dl.kr.zeroasso.top/ee_pic/public/public.png");
CheckToolboxUpdate();
LoadConfig();
InitLink();
CheckLimbusCompanyPath();
SevenZipBase.SetLibraryPath(Path.Combine(currentDir, "7z.dll"));
logger.Info("加载流程完成。");
}
/// <summary>
/// 安装时输出统一格式日志。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="promptInfo"></param>
/// <param name="someObject"></param>
private static void PrintInstallInfo<T>(string promptInfo, T someObject)
{
if (someObject == null)
{
logger.Info($"{promptInfo}:空");
}
else
{
logger.Info($"{promptInfo}{someObject}");
}
}
#region 安装功能
/// <summary>
/// 处理自动安装页面的安装按钮。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void InstallButtonClick(object sender, RoutedEventArgs e)
{
isInstalling = true;
await RefreshPage();
logger.Info("开始安装。");
logger.Info("**********安装信息打印**********");
logger.Info("本次安装信息:");
PrintInstallInfo("是否使用Github:", useGithub);
PrintInstallInfo("是否使用Mirror Github:", useMirrorGithub);
PrintInstallInfo("Limbus公司目录:", limbusCompanyDir);
PrintInstallInfo("Limbus公司游戏目录:", limbusCompanyGameDir);
PrintInstallInfo("节点列表数量:", nodeList.Count);
PrintInstallInfo("使用节点", useEndPoint);
PrintInstallInfo("灰度测试状态:", greytestStatus);
logger.Info("**********安装信息打印**********");
if (useEndPoint == null)
{
logger.Warn("下载节点为空。");
}
installPhase = 0;
Process[] limbusProcess = Process.GetProcessesByName("LimbusCompany");
if (limbusProcess.Length > 0)
{
logger.Warn("LimbusCompany仍然开启。");
MessageBoxResult DialogResult = System.Windows.MessageBox.Show("检测到 Limbus Company 仍然处于开启状态!\n建议您关闭游戏后继续安装模组。\n若您已经关闭了 Limbus Company,请点击确定,否则请点击取消返回。", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
if (DialogResult == MessageBoxResult.Cancel)
{
return;
}
logger.Warn("用户选择无视警告。");
}
try
{
StartProgressTimer();
await InstallBepInEx();
if (!File.Exists(Path.Combine(limbusCompanyDir, "winhttp.dll")))
{
logger.Error("winhttp.dll不存在。");
System.Windows.MessageBox.Show("winhttp.dll不存在。\n请尝试关闭杀毒软件后再次安装。");
await StopInstall();
return;
}
await InstallTMP();
if (!greytestStatus)
{
await InstallMod();
}
else
{
await InstallGreytestMod();
}
}
catch (Exception ex)
{
ErrorReport(ex, true, "您可以尝试在设置中切换节点。\n");
}
installPhase = 0;
logger.Info("安装完成。");
MessageBoxResult RunResult = System.Windows.MessageBox.Show("安装已完成!\n点击“确定”立刻运行边狱公司。\n点击“取消”关闭弹窗。\n加载时请耐心等待。", "完成", MessageBoxButton.OKCancel);
if (RunResult == MessageBoxResult.OK)
{
try
{
OpenUrl("steam://rungameid/1973530");
}
catch (Exception ex)
{
logger.Error("出现了问题: ", ex);
System.Windows.MessageBox.Show("出现了问题。\n" + ex.ToString());
}
}
isInstalling = false;
progressPercentage = 0;
await ChangeProgressValue(0);
await RefreshPage();
}
private async Task StopInstall()
{
isInstalling = false;
installPhase = 0;
progressPercentage = 0;
await ChangeProgressValue(progressPercentage);
await RefreshPage();
}
private async Task InstallBepInEx()
{
await Task.Run(async () =>
{
logger.Info("已进入安装BepInEx流程。");
installPhase = 1;
string BepInExZipPath = Path.Combine(limbusCompanyDir, "BepInEx-IL2CPP-x64.7z");
logger.Info("BepInEx Zip目录: " + BepInExZipPath);
if (!File.Exists(limbusCompanyDir + "/BepInEx/core/BepInEx.Core.dll"))
{
System.Windows.MessageBox.Show("如果你安装了杀毒软件,接下来可能会提示工具箱正在修改关键dll。\n允许即可。如果不信任汉化补丁,可以退出本程序。", "警告");
if (useGithub)
{
await DownloadFileAsync("https://github.com/LocalizeLimbusCompany/BepInEx_For_LLC/releases/download/v6.0.1-LLC/BepInEx-IL2CPP-x64-6.0.1.7z", BepInExZipPath);
}
else if (!useMirrorGithub)
{
await DownloadFileAutoAsync("BepInEx-IL2CPP-x64.7z", BepInExZipPath);
}
else if (useMirrorGithub)
{
await DownloadFileAsync("https://mirror.ghproxy.com/https://github.com/LocalizeLimbusCompany/BepInEx_For_LLC/releases/download/v6.0.1-LLC/BepInEx-IL2CPP-x64-6.0.1.7z", BepInExZipPath);
}
logger.Info("开始解压 BepInEx zip。");
Unarchive(BepInExZipPath, limbusCompanyDir);
logger.Info("解压完成。删除 BepInEx zip。");
File.Delete(BepInExZipPath);
}
else
{
logger.Info("检测到正确BepInEx。");
}
});
}
private async Task InstallTMP()
{
await Task.Run(async () =>
{
logger.Info("已进入TMP流程。");
installPhase = 2;
string modsDir = limbusCompanyDir + "/BepInEx/plugins/LLC";
Directory.CreateDirectory(modsDir);
string tmpchineseZipPath = Path.Combine(limbusCompanyDir, "tmpchinese_BIE.7z");
string tmpchinese = modsDir + "/tmpchinesefont";
var LastWriteTime = File.Exists(tmpchinese) ? new FileInfo(tmpchinese).LastWriteTime.ToString("yyMMdd") : string.Empty;
FontUpdateResult result;
if (useGithub)
{
result = await CheckChineseFontAssetUpdate(LastWriteTime, true);
await DownloadFileAsync($"https://github.com/LocalizeLimbusCompany/LLC_ChineseFontAsset/releases/download/{result.Tag}/tmpchinesefont_BIE_{result.Tag}.7z", tmpchineseZipPath);
}
else
{
result = await CheckChineseFontAssetUpdate(LastWriteTime, false);
}
if (!result.IsNotLatestVersion)
{
return;
}
if (!useGithub && !useMirrorGithub && result.IsNotLatestVersion)
{
await DownloadFileAutoAsync("tmpchinesefont_BIE.7z", tmpchineseZipPath);
}
else if (result.IsNotLatestVersion)
{
await DownloadFileAsync($"https://mirror.ghproxy.com/https://github.com/LocalizeLimbusCompany/LLC_ChineseFontAsset/releases/download/{result.Tag}/tmpchinesefont_BIE_{result.Tag}.7z", tmpchineseZipPath);
}
logger.Info("解压 tmp zip 中。");
Unarchive(tmpchineseZipPath, limbusCompanyDir);
logger.Info("删除 tmp zip 。");
File.Delete(tmpchineseZipPath);
});
}
private async Task InstallMod()
{
await Task.Run(async () =>
{
logger.Info("开始安装模组。");
installPhase = 3;
string modsDir = limbusCompanyDir + "/BepInEx/plugins/LLC";
string limbusLocalizeDllPath = modsDir + "/LimbusLocalize_BIE.dll";
string limbusLocalizeZipPath = Path.Combine(limbusCompanyDir, "LimbusLocalize_BIE.7z");
string latestLLCVersion = string.Empty;
string currentVersion = string.Empty;
if (useGithub)
{
latestLLCVersion = await GetLatestLimbusLocalizeVersion(true);
logger.Info("最后模组版本: " + latestLLCVersion);
if (File.Exists(limbusLocalizeDllPath))
{
var versionInfo = FileVersionInfo.GetVersionInfo(limbusLocalizeDllPath);
currentVersion = versionInfo.ProductVersion;
if (string.IsNullOrEmpty(currentVersion))
{
logger.Info("模组版本获取失败");
System.Windows.MessageBox.Show("模组版本获取失败,请尝试卸载后重新安装。\n如果问题仍然出现,请进行反馈。", "获取失败");
await StopInstall();
}
else if (new Version(currentVersion) >= new Version(latestLLCVersion.Remove(0, 1)))
{
logger.Info("模组无需更新。");
return;
}
}
else
{
logger.Info("模组不存在。进行安装。");
}
await DownloadFileAsync($"https://github.com/LocalizeLimbusCompany/LocalizeLimbusCompany/releases/download/{latestLLCVersion}/LimbusLocalize_BIE_{latestLLCVersion}.7z", limbusLocalizeZipPath);
logger.Info("解压模组本体 zip 中。");
Unarchive(limbusLocalizeZipPath, limbusCompanyDir);
logger.Info("删除模组本体 zip 。");
File.Delete(limbusLocalizeZipPath);
return;
}
if (!useMirrorGithub)
{
latestLLCVersion = await GetLatestLimbusLocalizeVersion(false);
logger.Info("最后模组版本: " + latestLLCVersion);
if (File.Exists(limbusLocalizeDllPath))
{
var versionInfo = FileVersionInfo.GetVersionInfo(limbusLocalizeDllPath);
currentVersion = versionInfo.ProductVersion;
if (string.IsNullOrEmpty(currentVersion))
{
logger.Info("模组版本获取失败");
System.Windows.MessageBox.Show("模组版本获取失败,请尝试卸载后重新安装。\n如果问题仍然出现,请进行反馈。", "获取失败");
await StopInstall();
}
else if (new System.Version(currentVersion) >= new System.Version(latestLLCVersion.Remove(0, 1)))
{
logger.Info("模组无需更新。");
return;
}
}
else
{
logger.Info("模组不存在。进行安装。");
}
await DownloadFileAutoAsync($"LimbusLocalize_BIE_{latestLLCVersion}.7z", limbusLocalizeZipPath);
if (await GetLimbusLocalizeHash() != CalculateSHA256(limbusLocalizeZipPath))
{
logger.Error("校验Hash失败。");
System.Windows.MessageBox.Show("校验Hash失败。\n请等待数分钟或更换节点。\n如果问题仍然出现,请进行反馈。", "校验失败");
await StopInstall();
}
else
{
logger.Info("校验Hash成功。");
}
logger.Info("解压模组本体 zip 中。");
Unarchive(limbusLocalizeZipPath, limbusCompanyDir);
logger.Info("删除模组本体 zip 。");
File.Delete(limbusLocalizeZipPath);
}
else if (useMirrorGithub)
{
latestLLCVersion = await GetLatestLimbusLocalizeVersion(false);
logger.Info("最后模组版本: " + latestLLCVersion);
if (File.Exists(limbusLocalizeDllPath))
{
var versionInfo = FileVersionInfo.GetVersionInfo(limbusLocalizeDllPath);
currentVersion = versionInfo.ProductVersion;
if (string.IsNullOrEmpty(currentVersion))
{
logger.Info("模组版本获取失败");
System.Windows.MessageBox.Show("模组版本获取失败,请尝试卸载后重新安装。\n如果问题仍然出现,请进行反馈。", "获取失败");
await StopInstall();
}
else if (new System.Version(currentVersion) >= new System.Version(latestLLCVersion.Remove(0, 1)))
{
logger.Info("无需更新。");
return;
}
}
await DownloadFileAsync($"https://mirror.ghproxy.com/https://github.com/LocalizeLimbusCompany/LocalizeLimbusCompany/releases/download/{latestLLCVersion}/LimbusLocalize_BIE_{latestLLCVersion}.7z", limbusLocalizeZipPath);
logger.Info("解压模组本体 zip 中。");
Unarchive(limbusLocalizeZipPath, limbusCompanyDir);
logger.Info("删除模组本体 zip 。");
File.Delete(limbusLocalizeZipPath);
}
});
}
#endregion
#region 读取节点
private static bool APPChangeAPIUI = false;
public void InitNode()
{
var _jsonSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
}
};
var json = JsonConvert.DeserializeObject<RootModel>(File.ReadAllText($"NodeList.json"),_jsonSettings);
nodeList = json.DownloadNode;
apiList = json.ApiNode;
NodeCombobox.Items.Add("恢复默认");
foreach (var Node in nodeList)
{
if (Node.IsDefault == true)
{
defaultEndPoint = Node.Endpoint;
}
NodeCombobox.Items.Add(Node.Name);
}
NodeCombobox.Items.Add("Github直连");
NodeCombobox.Items.Add("Mirror Github");
// API
APICombobox.Items.Add("恢复默认");
foreach (var api in apiList)
{
if (api.IsDefault == true)
{
defaultAPIEndPoint = api.Endpoint;
useAPIEndPoint = defaultAPIEndPoint;
}
APICombobox.Items.Add(api.Name);
}
logger.Info("API数量:" + apiList.Count);
logger.Info("节点数量:" + nodeList.Count);
}
private static string FindNodeEndpoint(string Name)
{
foreach (var node in nodeList)
{
if (node.Name == Name)
{
return node.Endpoint;
}
}
return string.Empty;
}
private static string FindAPIEndpoint(string Name)
{
foreach (var api in apiList)
{
if (api.Name == Name)
{
return api.Endpoint;
}
}
return string.Empty;
}
public async Task<string> GetNodeComboboxText()
{
string combotext = string.Empty;
await this.Dispatcher.BeginInvoke(() =>
{
combotext = NodeCombobox.SelectedItem.ToString();
});
return combotext;
}
public async Task<string> GetAPIComboboxText()
{
string combotext = string.Empty;
await this.Dispatcher.BeginInvoke(() =>
{
combotext = APICombobox.SelectedItem.ToString();
});
return combotext;
}
public async Task<string> SetAPIComboboxText(string text)
{
APPChangeAPIUI = true;
string combotext = string.Empty;
await this.Dispatcher.BeginInvoke(() =>
{
APICombobox.SelectedItem = text;
});
return combotext;
}
private async void NodeComboboxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
string nodeComboboxText = await GetNodeComboboxText();
logger.Info("选择节点。");
if (nodeComboboxText != string.Empty)
{
if (nodeComboboxText == "恢复默认")
{
useEndPoint = string.Empty;
useMirrorGithub = false;
useGithub = false;
logger.Info("已恢复默认Endpoint。");
}
else if (nodeComboboxText == "Github直连")
{
logger.Info("选择Github节点。");
System.Windows.MessageBox.Show("如果您没有使用代理软件(包括Watt Toolkit)\n请不要使用此节点。\nGithub由于不可抗力因素,对国内网络十分不友好。\n如果您是国外用户,才应该使用此选项。", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
useEndPoint = string.Empty;
useGithub = true;
useMirrorGithub = false;
}
else if (nodeComboboxText == "Mirror Github")
{
logger.Info("选择镜像Github节点。");
System.Windows.MessageBox.Show("Mirror Github服务由【mirror.ghproxy.com】提供。\n零协会不对其可能造成的任何问题(包括不可使用,安全性相关)负责。", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
useMirrorGithub = true;
useGithub = false;
}
else
{
useEndPoint = FindNodeEndpoint(nodeComboboxText);
useMirrorGithub = false;
useGithub = false;
logger.Info("当前Endpoint:" + useEndPoint);
System.Windows.MessageBox.Show("切换成功。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
else
{
logger.Info("NodeComboboxText 为 null。");
}
}
private async void APIComboboxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (!useGithub)
{
string apiComboboxText = await GetAPIComboboxText();
logger.Info("选择API节点。");
if (apiComboboxText != string.Empty)
{
if (apiComboboxText == "恢复默认")
{
useAPIEndPoint = defaultAPIEndPoint;
logger.Info("已恢复默认API Endpoint。");
}
else
{
useAPIEndPoint = FindAPIEndpoint(apiComboboxText);
logger.Info("当前API Endpoint:" + useAPIEndPoint);
System.Windows.MessageBox.Show("切换成功。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
else
{
logger.Info("APIComboboxText 为 null。");
}
}
else if (APPChangeAPIUI == false)
{
await SetAPIComboboxText("恢复默认");
logger.Info("已开启Github。无法切换API。");
System.Windows.MessageBox.Show("切换失败。\n无法在节点为Github直连的情况下切换API。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
APPChangeAPIUI = false;
}
private void WhyShouldIUseThis(object sender, RoutedEventArgs e)
{
OpenUrl("https://www.zeroasso.top/docs/configuration/nodes");
}
#endregion
#region 常用方法
public static void Unarchive(string archivePath, string output)
{
using SevenZipExtractor extractor = new(archivePath);
extractor.ExtractArchive(output);
}
private static void CheckLimbusCompanyPath()
{
if (skipLCBPathCheck && !string.IsNullOrEmpty(LCBPath))
{
limbusCompanyDir = LCBPath;
logger.Info("跳过检查路径。");
}
else
{
MessageBoxResult CheckLCBPathResult = MessageBoxResult.OK;
if (!string.IsNullOrEmpty(limbusCompanyDir))
{
CheckLCBPathResult = System.Windows.MessageBox.Show($"这是您的边狱公司地址吗?\n{limbusCompanyDir}", "检查路径", MessageBoxButton.YesNo, MessageBoxImage.Question);
}
if (CheckLCBPathResult == MessageBoxResult.Yes)
{
logger.Info("用户确认路径。");
ChangeLCBPathConfig(limbusCompanyDir);
ChangeSkipPathCheckConfig(true);
}
if (string.IsNullOrEmpty(limbusCompanyDir) || CheckLCBPathResult == MessageBoxResult.No)
{
if (string.IsNullOrEmpty(limbusCompanyDir))
{
logger.Warn("未能找到 Limbus Company 目录,手动选择模式。");
System.Windows.MessageBox.Show("未能找到 Limbus Company 目录。请手动选择。", "提示");
}
else
{
logger.Warn("用户否认 Limbus Company 目录正确性。");
}
var fileDialog = new OpenFileDialog
{
Title = "请选择你的边狱公司游戏文件",
Multiselect = false,
InitialDirectory = limbusCompanyDir,
Filter = "LimbusCompany.exe|LimbusCompany.exe",
FileName = "LimbusCompany.exe"
};
if (fileDialog.ShowDialog() == true)
{
limbusCompanyDir = Path.GetDirectoryName(fileDialog.FileName) ?? limbusCompanyDir;
limbusCompanyGameDir = Path.GetFullPath(fileDialog.FileName);
}
if (!File.Exists(limbusCompanyGameDir))
{
logger.Error("选择了错误目录,关闭游戏。");
System.Windows.MessageBox.Show("选择目录有误,没有在当前目录找到游戏。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
System.Windows.Application.Current.Shutdown();
}
else
{
logger.Info("找到了正确目录。");
ChangeSkipPathCheckConfig(true);
ChangeLCBPathConfig(limbusCompanyDir);
}
}
}
limbusCompanyGameDir = Path.Combine(limbusCompanyDir, "LimbusCompany.exe");
logger.Info("边狱公司路径:" + limbusCompanyDir);
}
/// <summary>
/// 获取最新版汉化模组哈希
/// </summary>
/// <returns>返回Sha256</returns>
private static async Task<string> GetLimbusLocalizeHash()
{
string HashRaw = await GetURLText($"{useEndPoint ?? defaultEndPoint}LimbusLocalizeHash.json");
dynamic JsonObject = JsonConvert.DeserializeObject(HashRaw);
if (JsonObject == null)
{
logger.Error("获取模组Hash失败。");
throw new Exception("获取Hash失败。");
}
string Hash = JsonObject.hash;
logger.Info("获取到的最新Hash为:" + Hash);
return Hash;
}
/// <summary>
/// 计算文件Sha256
/// </summary>
/// <param name="filePath">文件地址</param>
/// <returns>返回Sha256</returns>
public static string CalculateSHA256(string filePath)
{
using var sha256 = SHA256.Create();
using var fileStream = File.OpenRead(filePath);
byte[] hashBytes = sha256.ComputeHash(fileStream);
logger.Info($"计算位置为 {filePath} 的文件的Hash结果为:{BitConverter.ToString(hashBytes).Replace("-", "").ToLower()}");
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}
/// <summary>
/// 处理使用Downloader下载文件的事件。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NewOnDownloadProgressChanged(object? sender, Downloader.DownloadProgressChangedEventArgs e)
{
logger.Debug("ProgressPercentage: " + e.ProgressPercentage + " ProgressPercentage(Int): " + (int)(e.ProgressPercentage));
if (installPhase != 0)
{
progressPercentage = (float)((installPhase - 1) * 33 + e.ProgressPercentage * 0.33);
}
}
private void NewOnDownloadProgressCompleted(object? sender, AsyncCompletedEventArgs e)
{
if (installPhase != 0)
{
progressPercentage = installPhase * 33;
}
}
/// <summary>
/// 自动下载文件。
/// </summary>
/// <param name="Url">网址</param>
/// <param name="Path">下载到的地址</param>
/// <returns></returns>
public async Task DownloadFileAsync(string Url, string Path)
{
logger.Info($"下载 {Url} 到 {Path}");
var downloadOpt = new DownloadConfiguration()
{
BufferBlockSize = 10240,
ChunkCount = 8,
MaxTryAgainOnFailover = 5,
};
var downloader = new DownloadService(downloadOpt);
downloader.DownloadProgressChanged += NewOnDownloadProgressChanged;
downloader.DownloadFileCompleted += NewOnDownloadProgressCompleted;
await downloader.DownloadFileTaskAsync(Url, Path);
}
public async Task DownloadFileAutoAsync(string File, string Path)
{
logger.Info($"自动选择下载节点式下载文件 文件: {File} 路径: {Path}");
if (!string.IsNullOrEmpty(useEndPoint))
{
string DownloadUrl = useEndPoint + File;
await DownloadFileAsync(DownloadUrl, Path);
}
else
{
string DownloadUrl = defaultEndPoint + File;
await DownloadFileAsync(DownloadUrl, Path);
}
}
/// <summary>
/// 获取最新汉化模组标签。
/// </summary>
/// <returns>返回模组标签</returns>
private static async Task<string> GetLatestLimbusLocalizeVersion(bool useGithub)
{
logger.Info("获取模组标签。");
string raw;
if (!useGithub)
{
raw = await GetURLText(useAPIEndPoint + "Mod_Release.json");
}
else
{
raw = await GetURLText("https://api.github.com/repos/LocalizeLimbusCompany/LocalizeLimbusCompany/releases");
}
var output = JArray.Parse(raw)[0].Value<JObject>();
if (output.TryGetValue("tag_name", out var jtag))
{
var latestVersionTag= jtag.Value<string>();
logger.Info($"汉化模组最后标签为: {latestVersionTag}");
return latestVersionTag;
}
logger.Info("未能获取到汉化模组最后标签。");
return string.Empty;
}
/// <summary>
/// 获取该网址的文本,通常用于API。
/// </summary>
/// <param name="Url">网址</param>
/// <returns></returns>
public static async Task<string> GetURLText(string Url)
{
try
{
logger.Info($"获取 {Url} 文本内容。");
using HttpClient client = new();
client.DefaultRequestHeaders.Add("User-Agent", "LLC_MOD_Toolbox");
string raw = string.Empty;
raw = await client.GetStringAsync(Url);
return raw;
}
catch (Exception ex)
{
ErrorReport(ex, false);
return string.Empty;
}
}
/// <summary>
/// 打开指定网址。
/// </summary>
/// <param name="Url">网址</param>
public static void OpenUrl(string Url)
{
logger.Info("打开了网址:" + Url);
ProcessStartInfo psi = new(Url)
{
UseShellExecute = true
};
Process.Start(psi);
}
/// <summary>
/// 用于错误处理。
/// </summary>
/// <param name="ex"></param>
/// <param name="CloseWindow">是否关闭窗体。</param>
/// <param name="advice">提供建议</param>
public static void ErrorReport(Exception ex, bool CloseWindow, string advice = "")
{
logger.Error("出现了问题:\n", ex);
System.Windows.MessageBox.Show($"运行中出现了问题。\n{advice}若要反馈,请带上链接或日志。\n——————————\n{ex}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
if (CloseWindow)
{
System.Windows.Application.Current.Shutdown();
}
}
/// <summary>
/// 检查工具箱更新
/// </summary>
/// <param name="version">当前版本</param>
/// <param name="IsGithub">是否使用Github</param>
/// <returns>是否存在更新</returns>
private static async void CheckToolboxUpdate()
{
try
{
logger.Info("正在检查工具箱更新。");
string raw = await GetURLText(useAPIEndPoint + "Toolbox_Release.json");
var JsonObject = JObject.Parse(raw);
string latestReleaseTagRaw = JsonObject["tag_name"].Value<string>();
string latestReleaseTag = latestReleaseTagRaw.Remove(0, 1);
logger.Info("最新安装器tag:" + latestReleaseTag);
if (new Version(latestReleaseTag) > Assembly.GetExecutingAssembly().GetName().Version)
{
logger.Info("安装器存在更新。");
System.Windows.MessageBox.Show("安装器存在更新。\n点击确定进入官网下载最新版本工具箱", "更新提醒", MessageBoxButton.OK, MessageBoxImage.Warning);
OpenUrl("https://www.zeroasso.top/docs/install/autoinstall");
System.Windows.Application.Current.Shutdown();
}
logger.Info("没有更新。");
}
catch (Exception ex)
{
logger.Error("检查安装器更新出现问题。", ex);
return;
}
}
public record FontUpdateResult(string? Tag, bool IsNotLatestVersion);
/// <summary>
/// 获取tmp字体最新标签以及是否为最新版
/// </summary>
/// <param name="version">当前版本</param>
/// <param name="IsGithub">是否使用Github</param>
/// <param name="tag">返回tmp字体tag</param>
/// <returns>是否不是最新版</returns>
public static async Task<FontUpdateResult> CheckChineseFontAssetUpdate(string version, bool IsGithub)
{
string tag;
try
{
string raw = string.Empty;
if (IsGithub == true)
{
raw = await GetURLText("https://api.github.com/repos/LocalizeLimbusCompany/LLC_ChineseFontAsset/releases/latest");
}
else
{
raw = await GetURLText(useAPIEndPoint + "LatestTmp_Release.json");
}
var JsonObject = JObject.Parse(raw);
string latestReleaseTag = JsonObject["tag_name"].Value<string>();
if (latestReleaseTag != version)
{
tag = latestReleaseTag;
return new FontUpdateResult(tag, true);
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("出现了问题。\n" + ex.ToString());
logger.Error("出现了问题。\n" + ex.ToString());
}
return new FontUpdateResult(null, false);
}
#endregion
#region 进度条系统
public async void ProgressTime_Tick(object? sender, EventArgs e)
{
await ChangeProgressValue(progressPercentage);
}
public void StartProgressTimer()
{
progressPercentage = 0;
progressTimer.Start();
}
public void StopProgressTimer()
{
progressTimer.Stop();
}
#endregion
#region 卸载功能
private void UninstallButtonClick(object sender, RoutedEventArgs e)
{
logger.Info("点击删除模组");
MessageBoxResult result = System.Windows.MessageBox.Show("删除后你需要重新安装汉化补丁。\n确定继续吗?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
logger.Info("确定删除模组。");
try
{
DeleteBepInEx();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("删除过程中出现了一些问题: " + ex.ToString(), "警告");
logger.Error("删除过程中出现了一些问题: ", ex);
}
System.Windows.MessageBox.Show("删除完成。", "提示");
logger.Info("删除完成。");
}
}
/// <summary>
/// 删除目录。
/// </summary>
/// <param name="path"></param>
public static void DeleteDir(string path)
{
if (Directory.Exists(path))
{
logger.Info("删除目录: " + path);
Directory.Delete(path, true);
}
}
/// <summary>
/// 删除文件。
/// </summary>
/// <param name="path"></param>
public static void DeleteFile(string path)
{
if (File.Exists(path))
{
logger.Info("删除文件: " + path);
File.Delete(path);
}
}
/// <summary>
/// 删除BepInEx版本汉化补丁。
/// </summary>
public static void DeleteBepInEx()
{
DeleteDir(limbusCompanyDir + "/BepInEx");
DeleteDir(limbusCompanyDir + "/dotnet");
DeleteFile(limbusCompanyDir + "/doorstop_config.ini");
DeleteFile(limbusCompanyDir + "/Latest(框架日志).log");
DeleteFile(limbusCompanyDir + "/Player(游戏日志).log");
DeleteFile(limbusCompanyDir + "/winhttp.dll");
DeleteFile(limbusCompanyDir + "/winhttp.dll.disabled");
DeleteFile(limbusCompanyDir + "/changelog.txt");
DeleteFile(limbusCompanyDir + "/BepInEx-IL2CPP-x64.7z");
DeleteFile(limbusCompanyDir + "/LimbusLocalize_BIE.7z");
DeleteFile(limbusCompanyDir + "/tmpchinese_BIE.7z");
}
#endregion
#region 灰度测试
private async void StartGreytestButtonClick(object sender, RoutedEventArgs e)
{
logger.Info("Z-TECH 灰度测试客户端程序 v2.0 启动。(并不是");
if (!greytestStatus)
{
string token = await GetGreytestBoxText();
if (token == string.Empty || token == "请输入秘钥")
{
logger.Info("Token为空。");
System.Windows.MessageBox.Show("请输入有效的Token。", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
logger.Info("Token为:" + token);
string tokenUrl = $"https://dev.zeroasso.top/api/{token}.json";
using (HttpClient client = new())
{
try
{
HttpResponseMessage response = await client.GetAsync(tokenUrl);
if (response.StatusCode != System.Net.HttpStatusCode.NotFound)
{
logger.Info("秘钥有效。");
}
else
{
logger.Info("秘钥无效。");
System.Windows.MessageBox.Show("请输入有效的Token。", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
catch (Exception ex)
{
ErrorReport(ex, false);
return;
}
}
try
{
string tokenJson = await GetURLText(tokenUrl);
var tokenObject = JObject.Parse(tokenJson);
string runStatus = tokenObject["status"].Value<string>();
if (runStatus == "test")
{
logger.Info("Token状态正常。");
}
else
{
logger.Info("Token已停止测试。");
System.Windows.MessageBox.Show("Token已停止测试。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
string fileName = tokenObject["file_name"].Value<string>();
string note = tokenObject["note"].Value<string>();
logger.Info($"Token信息:{token}\n混淆文件名:{fileName}\n备注:{note}");
await ChangeLogoToTest();
var a = $"""目前Token有效。\n-------------\nToken信息:\n秘钥:{token}\n混淆文件名:{fileName}\n备注:{note}\n-------------\n灰度测试模式已开启。\n请在自动安装安装此秘钥对应版本汉化。\n秘钥信息请勿外传。""";
System.Windows.MessageBox.Show(
$"目前Token有效。\n-------------\nToken信息:\n秘钥:{token}\n混淆文件名:{fileName}\n备注:{note}\n-------------\n灰度测试模式已开启。\n请在自动安装安装此秘钥对应版本汉化。\n秘钥信息请勿外传。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
greytestStatus = true;
greytestUrl = "https://dev.zeroasso.top/files/LimbusLocalize_Dev_" + fileName + ".7z";
}
catch (Exception ex)
{
ErrorReport(ex, false);
return;
}
}
else
{
System.Windows.MessageBox.Show("灰度测试模式已开启。\n请在自动安装安装此秘钥对应版本汉化。\n若需要正常使用或更换秘钥,请重启工具箱。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
}
private async Task<string> GetGreytestBoxText()
{
string? text = string.Empty;