Bug fix and remove adjust core

This commit is contained in:
2dust
2024-01-01 18:09:34 +08:00
parent ba36b621e5
commit 141943d11a
9 changed files with 57 additions and 125 deletions

View File

@@ -105,7 +105,7 @@
"" ""
}; };
public static readonly List<string> coreTypes = new List<string> { "Clash", "ClashPremium", "ClashMeta", }; public static readonly List<string> coreTypes = new List<string> { "Clash", "ClashPremium", "ClashMeta", "Mihomo" };
public static readonly List<string> allowSelectType = new List<string> { "selector", "urltest", "loadbalance", "fallback" }; public static readonly List<string> allowSelectType = new List<string> { "selector", "urltest", "loadbalance", "fallback" };

View File

@@ -498,7 +498,7 @@ namespace ClashN.Handler
} }
if (profileItem.coreType is null) if (profileItem.coreType is null)
{ {
profileItem.coreType = CoreKind.ClashMeta; profileItem.coreType = CoreKind.Mihomo;
} }
if (!config.ProfileItems.Exists(it => it.indexId == profileItem.indexId)) if (!config.ProfileItems.Exists(it => it.indexId == profileItem.indexId))
{ {
@@ -558,7 +558,7 @@ namespace ClashN.Handler
{ {
groupId = groupId, groupId = groupId,
url = clipboardData, url = clipboardData,
coreType = CoreKind.ClashMeta, coreType = CoreKind.Mihomo,
address = string.Empty, address = string.Empty,
enabled = true, enabled = true,
remarks = "clash_subscription" remarks = "clash_subscription"
@@ -582,7 +582,7 @@ namespace ClashN.Handler
{ {
groupId = groupId, groupId = groupId,
url = query["url"] ?? string.Empty, url = query["url"] ?? string.Empty,
coreType = CoreKind.ClashMeta, coreType = CoreKind.Mihomo,
address = string.Empty, address = string.Empty,
enabled = true, enabled = true,
remarks = "clash_subscription" remarks = "clash_subscription"
@@ -600,7 +600,7 @@ namespace ClashN.Handler
{ {
groupId = groupId, groupId = groupId,
url = "", url = "",
coreType = CoreKind.ClashMeta, coreType = CoreKind.Mihomo,
address = string.Empty, address = string.Empty,
enabled = false, enabled = false,
remarks = "clash_local_file" remarks = "clash_local_file"

View File

@@ -302,12 +302,12 @@ namespace ClashN.Handler
}); });
} }
public List<ProxiesItem> GetClashProxyGroups() public List<ProxiesItem>? GetClashProxyGroups()
{ {
try try
{ {
var fileContent = LazyConfig.Instance.ProfileContent; var fileContent = LazyConfig.Instance.ProfileContent;
if (!fileContent.ContainsKey("proxy-groups")) if (fileContent is null || fileContent?.ContainsKey("proxy-groups") == false)
{ {
return null; return null;
} }

View File

@@ -106,8 +106,9 @@ namespace ClashN.Handler
if (!string.IsNullOrEmpty(result)) if (!string.IsNullOrEmpty(result))
{ {
var serverStatItem = config_.GetProfileItem(config_.IndexId); var serverStatItem = config_.GetProfileItem(config_.IndexId);
ParseOutput(result, out ulong up, out ulong down); ParseOutput(result, out ulong up, out ulong down);
if (up + down > 0) if (serverStatItem != null && (up + down) > 0)
{ {
serverStatItem.uploadRemote += up; serverStatItem.uploadRemote += up;
serverStatItem.downloadRemote += down; serverStatItem.downloadRemote += down;

View File

@@ -86,16 +86,19 @@ namespace ClashN
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="strJson"></param> /// <param name="strJson"></param>
/// <returns></returns> /// <returns></returns>
public static T FromJson<T>(string strJson) public static T? FromJson<T>(string? strJson)
{ {
try try
{ {
T obj = JsonConvert.DeserializeObject<T>(strJson); if (string.IsNullOrEmpty(strJson))
return obj; {
return default;
}
return JsonConvert.DeserializeObject<T>(strJson);
} }
catch catch
{ {
return JsonConvert.DeserializeObject<T>(""); return default;
} }
} }
@@ -104,14 +107,25 @@ namespace ClashN
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
public static string ToJson(Object obj) public static string ToJson(object? obj, bool indented = true)
{ {
string result = string.Empty; string result = string.Empty;
try try
{ {
result = JsonConvert.SerializeObject(obj, if (obj == null)
{
return result;
}
if (indented)
{
result = JsonConvert.SerializeObject(obj,
Formatting.Indented, Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
else
{
result = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -895,18 +909,7 @@ namespace ClashN
/// <returns></returns> /// <returns></returns>
public static T DeepCopy<T>(T obj) public static T DeepCopy<T>(T obj)
{ {
object retval; return FromJson<T>(ToJson(obj, false))!;
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
//序列化成流
bf.Serialize(ms, obj);
ms.Seek(0, SeekOrigin.Begin);
//反序列化成对象
retval = bf.Deserialize(ms);
ms.Close();
}
return (T)retval;
} }
/// <summary> /// <summary>

View File

@@ -14,9 +14,9 @@ namespace ClashN.ViewModels
private NoticeHandler? _noticeHandler; private NoticeHandler? _noticeHandler;
public ReactiveCommand<Unit, Unit> CheckUpdateCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashCoreCmd { get; } //public ReactiveCommand<Unit, Unit> CheckUpdateClashCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateMihomoCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateMihomoCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateGeoDataCmd { get; } //public ReactiveCommand<Unit, Unit> CheckUpdateGeoDataCmd { get; }
public HelpViewModel() public HelpViewModel()
{ {
@@ -27,34 +27,34 @@ namespace ClashN.ViewModels
{ {
CheckUpdateN(); CheckUpdateN();
}); });
CheckUpdateClashCoreCmd = ReactiveCommand.Create(() => //CheckUpdateClashCoreCmd = ReactiveCommand.Create(() =>
{ //{
CheckUpdateCore(CoreKind.Clash); // CheckUpdateCore(CoreKind.Clash);
}); //});
CheckUpdateMihomoCoreCmd = ReactiveCommand.Create(() => CheckUpdateMihomoCoreCmd = ReactiveCommand.Create(() =>
{ {
CheckUpdateCore(CoreKind.Mihomo); CheckUpdateCore(CoreKind.Mihomo);
}); });
CheckUpdateGeoDataCmd = ReactiveCommand.Create(() => //CheckUpdateGeoDataCmd = ReactiveCommand.Create(() =>
{ //{
CheckUpdateGeoData(); // CheckUpdateGeoData();
}); //});
} }
private void CheckUpdateGeoData() //private void CheckUpdateGeoData()
{ //{
void _updateUI(bool success, string msg) // void _updateUI(bool success, string msg)
{ // {
_noticeHandler?.SendMessage(msg); // _noticeHandler?.SendMessage(msg);
if (success) // if (success)
{ // {
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExit(false); // Locator.Current.GetService<MainWindowViewModel>()?.MyAppExit(false);
} // }
}; // };
UpdateHandle update = new UpdateHandle(); // UpdateHandle update = new UpdateHandle();
update.UpdateGeoFile(GeoKind.GEO_IP, _config, _updateUI); // update.UpdateGeoFile(GeoKind.GEO_IP, _config, _updateUI);
update.UpdateGeoFile(GeoKind.GEO_SITE, _config, _updateUI); // update.UpdateGeoFile(GeoKind.GEO_SITE, _config, _updateUI);
} //}
private void CheckUpdateN() private void CheckUpdateN()
{ {

View File

@@ -162,7 +162,7 @@ namespace ClashN.ViewModels
{ {
item = new() item = new()
{ {
coreType = CoreKind.ClashMeta coreType = CoreKind.Mihomo
}; };
} }
else else

View File

@@ -96,42 +96,6 @@
</DockPanel> </DockPanel>
</materialDesign:Card> </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 Clash Core" />
<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="btnCheckUpdateClashCore"
Width="100"
Content="{x:Static resx:ResUI.TbHelpCheck}"
DockPanel.Dock="Right"
Style="{StaticResource DefButton}" />
</DockPanel>
</Grid>
</DockPanel>
</materialDesign:Card>
<materialDesign:Card <materialDesign:Card
Width="300" Width="300"
@@ -171,42 +135,6 @@
</materialDesign:Card> </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"
Style="{StaticResource DefButton}" />
</DockPanel>
</Grid>
</DockPanel>
</materialDesign:Card>
</WrapPanel> </WrapPanel>
</ScrollViewer> </ScrollViewer>
</DockPanel> </DockPanel>

View File

@@ -17,9 +17,9 @@ namespace ClashN.Views
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
this.BindCommand(ViewModel, vm => vm.CheckUpdateCmd, v => v.btnCheckUpdateN).DisposeWith(disposables); 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.CheckUpdateClashCoreCmd, v => v.btnCheckUpdateClashCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateMihomoCoreCmd, v => v.btnCheckUpdateMihomoCore).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.CheckUpdateMihomoCoreCmd, v => v.btnCheckUpdateMihomoCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateGeoDataCmd, v => v.btnCheckUpdateGeo).DisposeWith(disposables); //this.BindCommand(ViewModel, vm => vm.CheckUpdateGeoDataCmd, v => v.btnCheckUpdateGeo).DisposeWith(disposables);
}); });
} }