1. 替换ClashMeta更新,替换为Mihomo

2. 增加Geo Data的更新按钮
This commit is contained in:
PctAIGM
2023-12-14 17:04:50 +08:00
parent da1234c5fc
commit 8296ce2d40
8 changed files with 115 additions and 8 deletions

View File

@@ -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";
/// <summary>

View File

@@ -90,6 +90,18 @@ namespace ClashN.Handler
match = "Clash Meta"
});
coreInfos.Add(new CoreInfo
{
coreType = CoreKind.Mihomo,
coreExes = new List<string> { $"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,

View File

@@ -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();

View File

@@ -5,6 +5,7 @@
Clash = 1,
ClashMeta = 2,
ClashPremium = 3,
Mihomo = 4,
ClashN = 99
}
}

View File

@@ -600,6 +600,27 @@ namespace ClashN
return Path.Combine(startupPath, fileName);
}
/// <summary>
/// 获取启动了应用程序的数据文件的路径
/// </summary>
/// <returns></returns>
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);
}
}
/// <summary>
/// 获取启动了应用程序的可执行文件的路径及文件名
/// </summary>

View File

@@ -15,7 +15,8 @@ namespace ClashN.ViewModels
public ReactiveCommand<Unit, Unit> CheckUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateMihomoCoreCmd { get; }
public ReactiveCommand<Unit, Unit> 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<MainWindowViewModel>()?.MyAppExit(false);
}
};
UpdateHandle update = new UpdateHandle();
update.UpdateGeoFile(GeoKind.GEO_IP, _config, _updateUI);
update.UpdateGeoFile(GeoKind.GEO_SITE, _config, _updateUI);
}
private void CheckUpdateN()

View File

@@ -149,7 +149,7 @@
Grid.Row="0"
Margin="16,16,16,4"
Style="{StaticResource TabItemTitle}"
Text="Update Clash.Meta Core" />
Text="Update Mihomo Core" />
<Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}" />
@@ -160,7 +160,45 @@
Style="{StaticResource MaterialDesignCaptionTextBlock}"
Text="" />
<Button
x:Name="btnCheckUpdateClashMetaCore"
x:Name="btnCheckUpdateMihomoCore"
Width="100"
Content="{x:Static resx:ResUI.TbHelpCheck}"
DockPanel.Dock="Right"
Style="{StaticResource DefButton}" />
</DockPanel>
</Grid>
</DockPanel>
</materialDesign:Card>
<materialDesign:Card
Width="300"
Margin="8"
Padding="16"
materialDesign:UniformCornerRadius="8">
<DockPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Margin="16,16,16,4"
Style="{StaticResource TabItemTitle}"
Text="Update Geo Data" />
<Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}" />
<DockPanel Grid.Row="2" HorizontalAlignment="Right">
<TextBlock
Grid.Row="0"
Margin="8"
Style="{StaticResource MaterialDesignCaptionTextBlock}"
Text="" />
<Button
x:Name="btnCheckUpdateGeo"
Width="100"
Content="{x:Static resx:ResUI.TbHelpCheck}"
DockPanel.Dock="Right"

View File

@@ -18,7 +18,8 @@ namespace ClashN.Views
{
this.BindCommand(ViewModel, vm => vm.CheckUpdateCmd, v => v.btnCheckUpdateN).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateClashCoreCmd, v => v.btnCheckUpdateClashCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateClashMetaCoreCmd, v => v.btnCheckUpdateClashMetaCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateMihomoCoreCmd, v => v.btnCheckUpdateMihomoCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateGeoDataCmd, v => v.btnCheckUpdateGeo).DisposeWith(disposables);
});
}