From 8296ce2d403fe470d004640d929849ceaa7112ff Mon Sep 17 00:00:00 2001 From: PctAIGM Date: Thu, 14 Dec 2023 17:04:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=9B=BF=E6=8D=A2ClashMeta=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=EF=BC=8C=E6=9B=BF=E6=8D=A2=E4=B8=BAMihomo=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Geo=20Data=E7=9A=84=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clashN/clashN/Global.cs | 1 + clashN/clashN/Handler/LazyConfig.cs | 12 +++++++ clashN/clashN/Handler/UpdateHandle.cs | 17 +++++++-- clashN/clashN/Mode/CoreKind.cs | 1 + clashN/clashN/Tool/Utils.cs | 21 ++++++++++++ clashN/clashN/ViewModels/HelpViewModel.cs | 26 ++++++++++++-- clashN/clashN/Views/HelpView.xaml | 42 +++++++++++++++++++++-- clashN/clashN/Views/HelpView.xaml.cs | 3 +- 8 files changed, 115 insertions(+), 8 deletions(-) diff --git a/clashN/clashN/Global.cs b/clashN/clashN/Global.cs index 09ca720..ae38ec6 100644 --- a/clashN/clashN/Global.cs +++ b/clashN/clashN/Global.cs @@ -9,6 +9,7 @@ public const string NUrl = @"https://github.com/2dust/clashN/releases"; public const string clashCoreUrl = "https://github.com/Dreamacro/clash/releases"; public const string clashMetaCoreUrl = "https://github.com/MetaCubeX/Clash.Meta/releases"; + public const string mihomoCoreUrl = "https://github.com/MetaCubeX/mihomo/releases"; public const string geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat"; /// diff --git a/clashN/clashN/Handler/LazyConfig.cs b/clashN/clashN/Handler/LazyConfig.cs index 5756e6c..64e6cfc 100644 --- a/clashN/clashN/Handler/LazyConfig.cs +++ b/clashN/clashN/Handler/LazyConfig.cs @@ -90,6 +90,18 @@ namespace ClashN.Handler match = "Clash Meta" }); + coreInfos.Add(new CoreInfo + { + coreType = CoreKind.Mihomo, + coreExes = new List { $"mihomo-windows-amd64{(Avx2.X64.IsSupported ? "" : "-compatible")}", "mihomo-windows-amd64-compatible", "mihomo-windows-amd64", "mihomo-windows-386", "mihomo", "clash" }, + arguments = "-f config.yaml", + coreUrl = Global.mihomoCoreUrl, + coreLatestUrl = Global.mihomoCoreUrl + "/latest", + coreDownloadUrl32 = Global.mihomoCoreUrl + "/download/{0}/mihomo-windows-386-{0}.zip", + coreDownloadUrl64 = Global.mihomoCoreUrl + "/download/{0}/mihomo-windows-amd64" + (Avx2.X64.IsSupported ? "" : "-compatible") + "-{0}.zip", + match = "Mihomo" + }); + coreInfos.Add(new CoreInfo { coreType = CoreKind.ClashPremium, diff --git a/clashN/clashN/Handler/UpdateHandle.cs b/clashN/clashN/Handler/UpdateHandle.cs index 9da3287..dafbf15 100644 --- a/clashN/clashN/Handler/UpdateHandle.cs +++ b/clashN/clashN/Handler/UpdateHandle.cs @@ -310,10 +310,10 @@ namespace ClashN.Handler try { - string fileName = Utils.GetPath(Utils.GetDownloadFileName(url)); + string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url)); if (File.Exists(fileName)) { - string targetPath = Utils.GetPath($"{geoName}.dat"); + string targetPath = Utils.GetDataPath($"{geoName}.dat"); if (File.Exists(targetPath)) { File.Delete(targetPath); @@ -455,6 +455,19 @@ namespace ClashN.Handler url = string.Format(coreInfo.coreDownloadUrl32, version); } } + else if (type == CoreKind.Mihomo) + { + curVersion = getCoreVersion(type); + message = string.Format(ResUI.IsLatestCore, curVersion); + if (Environment.Is64BitProcess) + { + url = string.Format(coreInfo.coreDownloadUrl64, version); + } + else + { + url = string.Format(coreInfo.coreDownloadUrl32, version); + } + } else if (type == CoreKind.ClashN) { curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString(); diff --git a/clashN/clashN/Mode/CoreKind.cs b/clashN/clashN/Mode/CoreKind.cs index d0973c2..e873e09 100644 --- a/clashN/clashN/Mode/CoreKind.cs +++ b/clashN/clashN/Mode/CoreKind.cs @@ -5,6 +5,7 @@ Clash = 1, ClashMeta = 2, ClashPremium = 3, + Mihomo = 4, ClashN = 99 } } \ No newline at end of file diff --git a/clashN/clashN/Tool/Utils.cs b/clashN/clashN/Tool/Utils.cs index e5a68bb..ac2883f 100644 --- a/clashN/clashN/Tool/Utils.cs +++ b/clashN/clashN/Tool/Utils.cs @@ -599,6 +599,27 @@ namespace ClashN } return Path.Combine(startupPath, fileName); } + + /// + /// 获取启动了应用程序的数据文件的路径 + /// + /// + public static string GetDataPath(string fileName) + { + string _tempPath = Path.Combine(StartupPath(), "data"); + if (!Directory.Exists(_tempPath)) + { + Directory.CreateDirectory(_tempPath); + } + if (string.IsNullOrEmpty(fileName)) + { + return _tempPath; + } + else + { + return Path.Combine(_tempPath, fileName); + } + } /// /// 获取启动了应用程序的可执行文件的路径及文件名 diff --git a/clashN/clashN/ViewModels/HelpViewModel.cs b/clashN/clashN/ViewModels/HelpViewModel.cs index 2682362..753952b 100644 --- a/clashN/clashN/ViewModels/HelpViewModel.cs +++ b/clashN/clashN/ViewModels/HelpViewModel.cs @@ -15,7 +15,8 @@ namespace ClashN.ViewModels public ReactiveCommand CheckUpdateCmd { get; } public ReactiveCommand CheckUpdateClashCoreCmd { get; } - public ReactiveCommand CheckUpdateClashMetaCoreCmd { get; } + public ReactiveCommand CheckUpdateMihomoCoreCmd { get; } + public ReactiveCommand CheckUpdateGeoDataCmd { get; } public HelpViewModel() { @@ -30,10 +31,29 @@ namespace ClashN.ViewModels { CheckUpdateCore(CoreKind.Clash); }); - CheckUpdateClashMetaCoreCmd = ReactiveCommand.Create(() => + CheckUpdateMihomoCoreCmd = ReactiveCommand.Create(() => { - CheckUpdateCore(CoreKind.ClashMeta); + CheckUpdateCore(CoreKind.Mihomo); }); + CheckUpdateGeoDataCmd = ReactiveCommand.Create(() => + { + CheckUpdateGeoData(); + }); + } + + private void CheckUpdateGeoData() + { + void _updateUI(bool success, string msg) + { + _noticeHandler?.SendMessage(msg); + if (success) + { + Locator.Current.GetService()?.MyAppExit(false); + } + }; + UpdateHandle update = new UpdateHandle(); + update.UpdateGeoFile(GeoKind.GEO_IP, _config, _updateUI); + update.UpdateGeoFile(GeoKind.GEO_SITE, _config, _updateUI); } private void CheckUpdateN() diff --git a/clashN/clashN/Views/HelpView.xaml b/clashN/clashN/Views/HelpView.xaml index 7e597e4..924aba1 100644 --- a/clashN/clashN/Views/HelpView.xaml +++ b/clashN/clashN/Views/HelpView.xaml @@ -149,7 +149,7 @@ Grid.Row="0" Margin="16,16,16,4" Style="{StaticResource TabItemTitle}" - Text="Update Clash.Meta Core" /> + Text="Update Mihomo Core" /> @@ -160,7 +160,45 @@ Style="{StaticResource MaterialDesignCaptionTextBlock}" Text="" />