Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 10, 2024
1 parent 5135afc commit 6762f35
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions v2rayN/v2rayN/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static int ToInt(object obj)
{
return Convert.ToInt32(obj);
}
catch (Exception ex)
catch //(Exception ex)
{
//SaveLog(ex.Message, ex);
return 0;
Expand All @@ -219,7 +219,7 @@ public static bool ToBool(object obj)
{
return Convert.ToBoolean(obj);
}
catch (Exception ex)
catch //(Exception ex)
{
//SaveLog(ex.Message, ex);
return false;
Expand All @@ -232,7 +232,7 @@ public static string ToString(object obj)
{
return obj?.ToString() ?? string.Empty;
}
catch (Exception ex)
catch// (Exception ex)
{
//SaveLog(ex.Message, ex);
return string.Empty;
Expand Down Expand Up @@ -546,7 +546,7 @@ public static string GetPath(string fileName)
/// <returns></returns>
public static string GetExePath()
{
return Environment.ProcessPath;
return Environment.ProcessPath ?? string.Empty;
}

public static string StartupPath()
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private int GenInbounds(SingboxConfig singboxConfig)
_config.tunModeItem.stack = Global.TunStacks[0];
}

var tunInbound = JsonUtils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName));
var tunInbound = JsonUtils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { };
tunInbound.mtu = _config.tunModeItem.mtu;
tunInbound.strict_route = _config.tunModeItem.strictRoute;
tunInbound.stack = _config.tunModeItem.stack;
Expand All @@ -196,7 +196,7 @@ private int GenInbounds(SingboxConfig singboxConfig)
return 0;
}

private Inbound4Sbox? GetInbound(Inbound4Sbox inItem, string tag, int offset, bool bSocks)
private Inbound4Sbox GetInbound(Inbound4Sbox inItem, string tag, int offset, bool bSocks)
{
var inbound = JsonUtils.DeepCopy(inItem);
inbound.tag = tag;
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/DownloadHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int down

responseTime = timer.Elapsed.Milliseconds;
}
catch (Exception ex)
catch //(Exception ex)
{
//Utils.SaveLog(ex.Message, ex);
}
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Handler/SpeedtestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private async Task RunPingSubAsync(Action<ServerTestItem> updateFun)
{
try
{
Task.Run(() => updateFun(it));
_ = Task.Run(() => updateFun(it));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -349,7 +349,7 @@ private int GetTcpingTime(string url, int port)

try
{
if (!IPAddress.TryParse(url, out IPAddress ipAddress))
if (!IPAddress.TryParse(url, out IPAddress? ipAddress))
{
IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry(url);
ipAddress = ipHostInfo.AddressList[0];
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Handler/UpdateHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy,
//more url
if (Utils.IsNullOrEmpty(item.convertTarget) && !Utils.IsNullOrEmpty(item.moreUrl.TrimEx()))
{
if (!Utils.IsNullOrEmpty(result) && Utils.IsBase64String(result))
if (!Utils.IsNullOrEmpty(result) && Utils.IsBase64String(result!))
{
result = Utils.Base64Decode(result);
}
Expand All @@ -245,7 +245,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy,
}
if (!Utils.IsNullOrEmpty(result2))
{
if (Utils.IsBase64String(result2))
if (Utils.IsBase64String(result2!))
{
result += Utils.Base64Decode(result2);
}
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ public async void ShareServer()
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
return;
}
string url = ShareHandler.GetShareUrl(item);
var url = ShareHandler.GetShareUrl(item);
if (Utils.IsNullOrEmpty(url))
{
return;
Expand Down
6 changes: 3 additions & 3 deletions v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public RoutingRuleSettingViewModel(RoutingItem routingItem, Window view)
{
ImportRulesFromClipboard();
});
ImportRulesFromUrlCmd = ReactiveCommand.Create(() =>
ImportRulesFromUrlCmd = ReactiveCommand.CreateFromTask(() =>
{
ImportRulesFromUrl();
return ImportRulesFromUrl();
});

RuleRemoveCmd = ReactiveCommand.Create(() =>
Expand Down Expand Up @@ -142,7 +142,7 @@ public void RefreshRulesItems()

public void RuleEdit(bool blNew)
{
RulesItem item;
RulesItem? item;
if (blNew)
{
item = new();
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/ViewModels/SubSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void DeleteSub()

foreach (var it in SelectedSources)
{
ConfigHandler.DeleteSubItem(_config, it?.id);
ConfigHandler.DeleteSubItem(_config, it.id);
}
RefreshSubItems();
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
Expand Down

0 comments on commit 6762f35

Please sign in to comment.