diff --git a/clashN/clashN/Global.cs b/clashN/clashN/Global.cs index ae38ec6..7aa1cb1 100644 --- a/clashN/clashN/Global.cs +++ b/clashN/clashN/Global.cs @@ -105,7 +105,7 @@ internal class Global "" }; - public static readonly List coreTypes = new List { "Clash", "ClashPremium", "ClashMeta", }; + public static readonly List coreTypes = new List { "Clash", "ClashPremium", "ClashMeta", "Mihomo" }; public static readonly List allowSelectType = new List { "selector", "urltest", "loadbalance", "fallback" }; diff --git a/clashN/clashN/Handler/ConfigProc.cs b/clashN/clashN/Handler/ConfigProc.cs index c6a7e80..78b87cd 100644 --- a/clashN/clashN/Handler/ConfigProc.cs +++ b/clashN/clashN/Handler/ConfigProc.cs @@ -498,7 +498,7 @@ public static int AddProfileCommon(ref Config config, ProfileItem profileItem) } if (profileItem.coreType is null) { - profileItem.coreType = CoreKind.ClashMeta; + profileItem.coreType = CoreKind.Mihomo; } if (!config.ProfileItems.Exists(it => it.indexId == profileItem.indexId)) { @@ -558,7 +558,7 @@ public static int AddBatchProfiles(ref Config config, string clipboardData, stri { groupId = groupId, url = clipboardData, - coreType = CoreKind.ClashMeta, + coreType = CoreKind.Mihomo, address = string.Empty, enabled = true, remarks = "clash_subscription" @@ -582,7 +582,7 @@ public static int AddBatchProfiles(ref Config config, string clipboardData, stri { groupId = groupId, url = query["url"] ?? string.Empty, - coreType = CoreKind.ClashMeta, + coreType = CoreKind.Mihomo, address = string.Empty, enabled = true, remarks = "clash_subscription" @@ -600,7 +600,7 @@ public static int AddBatchProfiles(ref Config config, string clipboardData, stri { groupId = groupId, url = "", - coreType = CoreKind.ClashMeta, + coreType = CoreKind.Mihomo, address = string.Empty, enabled = false, remarks = "clash_local_file" diff --git a/clashN/clashN/Handler/MainFormHandler.cs b/clashN/clashN/Handler/MainFormHandler.cs index c8519f0..ccf2455 100644 --- a/clashN/clashN/Handler/MainFormHandler.cs +++ b/clashN/clashN/Handler/MainFormHandler.cs @@ -302,12 +302,12 @@ public void InitRegister(Config config) }); } - public List GetClashProxyGroups() + public List? GetClashProxyGroups() { try { var fileContent = LazyConfig.Instance.ProfileContent; - if (!fileContent.ContainsKey("proxy-groups")) + if (fileContent is null || fileContent?.ContainsKey("proxy-groups") == false) { return null; } diff --git a/clashN/clashN/Handler/StatisticsHandler.cs b/clashN/clashN/Handler/StatisticsHandler.cs index 4c99913..c98da78 100644 --- a/clashN/clashN/Handler/StatisticsHandler.cs +++ b/clashN/clashN/Handler/StatisticsHandler.cs @@ -106,8 +106,9 @@ public async void Run() if (!string.IsNullOrEmpty(result)) { var serverStatItem = config_.GetProfileItem(config_.IndexId); + ParseOutput(result, out ulong up, out ulong down); - if (up + down > 0) + if (serverStatItem != null && (up + down) > 0) { serverStatItem.uploadRemote += up; serverStatItem.downloadRemote += down; diff --git a/clashN/clashN/Tool/Utils.cs b/clashN/clashN/Tool/Utils.cs index ac2883f..9f61b6c 100644 --- a/clashN/clashN/Tool/Utils.cs +++ b/clashN/clashN/Tool/Utils.cs @@ -86,16 +86,19 @@ public static string LoadResource(string res) /// /// /// - public static T FromJson(string strJson) + public static T? FromJson(string? strJson) { try { - T obj = JsonConvert.DeserializeObject(strJson); - return obj; + if (string.IsNullOrEmpty(strJson)) + { + return default; + } + return JsonConvert.DeserializeObject(strJson); } catch { - return JsonConvert.DeserializeObject(""); + return default; } } @@ -104,14 +107,25 @@ public static T FromJson(string strJson) /// /// /// - public static string ToJson(Object obj) + public static string ToJson(object? obj, bool indented = true) { string result = string.Empty; try { - result = JsonConvert.SerializeObject(obj, + if (obj == null) + { + return result; + } + if (indented) + { + result = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + } + else + { + result = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + } } catch (Exception ex) { @@ -895,18 +909,7 @@ public static string GetVersion(bool blFull = true) /// public static T DeepCopy(T obj) { - object retval; - 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; + return FromJson(ToJson(obj, false))!; } /// diff --git a/clashN/clashN/ViewModels/HelpViewModel.cs b/clashN/clashN/ViewModels/HelpViewModel.cs index 753952b..590f83c 100644 --- a/clashN/clashN/ViewModels/HelpViewModel.cs +++ b/clashN/clashN/ViewModels/HelpViewModel.cs @@ -14,9 +14,9 @@ public class HelpViewModel : ReactiveObject private NoticeHandler? _noticeHandler; public ReactiveCommand CheckUpdateCmd { get; } - public ReactiveCommand CheckUpdateClashCoreCmd { get; } + //public ReactiveCommand CheckUpdateClashCoreCmd { get; } public ReactiveCommand CheckUpdateMihomoCoreCmd { get; } - public ReactiveCommand CheckUpdateGeoDataCmd { get; } + //public ReactiveCommand CheckUpdateGeoDataCmd { get; } public HelpViewModel() { @@ -27,34 +27,34 @@ public HelpViewModel() { CheckUpdateN(); }); - CheckUpdateClashCoreCmd = ReactiveCommand.Create(() => - { - CheckUpdateCore(CoreKind.Clash); - }); + //CheckUpdateClashCoreCmd = ReactiveCommand.Create(() => + //{ + // CheckUpdateCore(CoreKind.Clash); + //}); CheckUpdateMihomoCoreCmd = ReactiveCommand.Create(() => { CheckUpdateCore(CoreKind.Mihomo); }); - CheckUpdateGeoDataCmd = ReactiveCommand.Create(() => - { - CheckUpdateGeoData(); - }); + //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 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/ViewModels/ProfilesViewModel.cs b/clashN/clashN/ViewModels/ProfilesViewModel.cs index 47a939e..9bd44e8 100644 --- a/clashN/clashN/ViewModels/ProfilesViewModel.cs +++ b/clashN/clashN/ViewModels/ProfilesViewModel.cs @@ -162,7 +162,7 @@ public void EditProfile(bool blNew) { item = new() { - coreType = CoreKind.ClashMeta + coreType = CoreKind.Mihomo }; } else diff --git a/clashN/clashN/Views/HelpView.xaml b/clashN/clashN/Views/HelpView.xaml index 924aba1..b38a7c0 100644 --- a/clashN/clashN/Views/HelpView.xaml +++ b/clashN/clashN/Views/HelpView.xaml @@ -96,42 +96,6 @@ - - - - - - - - - - - - - - -