Skip to content

Commit

Permalink
Bug fix and remove adjust core
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 1, 2024
1 parent ba36b62 commit 141943d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 125 deletions.
2 changes: 1 addition & 1 deletion clashN/clashN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class Global
""
};

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" };

Expand Down
8 changes: 4 additions & 4 deletions clashN/clashN/Handler/ConfigProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions clashN/clashN/Handler/MainFormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ public void InitRegister(Config config)
});
}

public List<ProxiesItem> GetClashProxyGroups()
public List<ProxiesItem>? GetClashProxyGroups()
{
try
{
var fileContent = LazyConfig.Instance.ProfileContent;
if (!fileContent.ContainsKey("proxy-groups"))
if (fileContent is null || fileContent?.ContainsKey("proxy-groups") == false)
{
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion clashN/clashN/Handler/StatisticsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 21 additions & 18 deletions clashN/clashN/Tool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ public static string LoadResource(string res)
/// <typeparam name="T"></typeparam>
/// <param name="strJson"></param>
/// <returns></returns>
public static T FromJson<T>(string strJson)
public static T? FromJson<T>(string? strJson)
{
try
{
T obj = JsonConvert.DeserializeObject<T>(strJson);
return obj;
if (string.IsNullOrEmpty(strJson))
{
return default;
}
return JsonConvert.DeserializeObject<T>(strJson);
}
catch
{
return JsonConvert.DeserializeObject<T>("");
return default;
}
}

Expand All @@ -104,14 +107,25 @@ public static T FromJson<T>(string strJson)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
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)
{
Expand Down Expand Up @@ -895,18 +909,7 @@ public static string GetVersion(bool blFull = true)
/// <returns></returns>
public static T DeepCopy<T>(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<T>(ToJson(obj, false))!;
}

/// <summary>
Expand Down
48 changes: 24 additions & 24 deletions clashN/clashN/ViewModels/HelpViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class HelpViewModel : ReactiveObject
private NoticeHandler? _noticeHandler;

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> CheckUpdateGeoDataCmd { get; }
//public ReactiveCommand<Unit, Unit> CheckUpdateGeoDataCmd { get; }

public HelpViewModel()
{
Expand All @@ -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<MainWindowViewModel>()?.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<MainWindowViewModel>()?.MyAppExit(false);
// }
// };
// UpdateHandle update = new UpdateHandle();
// update.UpdateGeoFile(GeoKind.GEO_IP, _config, _updateUI);
// update.UpdateGeoFile(GeoKind.GEO_SITE, _config, _updateUI);
//}

private void CheckUpdateN()
{
Expand Down
2 changes: 1 addition & 1 deletion clashN/clashN/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void EditProfile(bool blNew)
{
item = new()
{
coreType = CoreKind.ClashMeta
coreType = CoreKind.Mihomo
};
}
else
Expand Down
72 changes: 0 additions & 72 deletions clashN/clashN/Views/HelpView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,6 @@
</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 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
Width="300"
Expand Down Expand Up @@ -169,44 +133,8 @@
</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"
Style="{StaticResource DefButton}" />
</DockPanel>
</Grid>
</DockPanel>
</materialDesign:Card>
</WrapPanel>
</ScrollViewer>
</DockPanel>
Expand Down
4 changes: 2 additions & 2 deletions clashN/clashN/Views/HelpView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public HelpView()
this.WhenActivated(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.CheckUpdateGeoDataCmd, v => v.btnCheckUpdateGeo).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.CheckUpdateGeoDataCmd, v => v.btnCheckUpdateGeo).DisposeWith(disposables);
});
}

Expand Down

0 comments on commit 141943d

Please sign in to comment.