From 243dbab06a40313279ef45687c5ae7d254ce339f Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Wed, 18 Sep 2024 19:54:38 +0800
Subject: [PATCH] Fix ?!
---
v2rayN/ServiceLib/Common/SemanticVersion.cs | 13 ++++++++++---
v2rayN/ServiceLib/Common/Utils.cs | 7 ++++---
.../Handler/CoreConfig/CoreConfigSingbox.cs | 8 ++++----
.../Handler/CoreConfig/CoreConfigV2ray.cs | 4 ++--
v2rayN/ServiceLib/Handler/LazyConfig.cs | 2 +-
v2rayN/ServiceLib/Handler/UpdateHandler.cs | 6 +++---
6 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/v2rayN/ServiceLib/Common/SemanticVersion.cs b/v2rayN/ServiceLib/Common/SemanticVersion.cs
index c631de5b..beea6acc 100644
--- a/v2rayN/ServiceLib/Common/SemanticVersion.cs
+++ b/v2rayN/ServiceLib/Common/SemanticVersion.cs
@@ -15,11 +15,19 @@
this.version = $"{major}.{minor}.{patch}";
}
- public SemanticVersion(string version)
+ public SemanticVersion(string? version)
{
- this.version = version.RemovePrefix('v');
try
{
+ if (version.IsNullOrEmpty())
+ {
+ this.major = 0;
+ this.minor = 0;
+ this.patch = 0;
+ return;
+ }
+ this.version = version.RemovePrefix('v');
+
string[] parts = this.version.Split('.');
if (parts.Length == 2)
{
@@ -43,7 +51,6 @@
this.major = 0;
this.minor = 0;
this.patch = 0;
- //this.version = "0.0.0";
}
}
diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index 8e2fb956..f642a423 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -158,10 +158,11 @@ namespace ServiceLib.Common
///
///
///
- public static string Base64Decode(string plainText)
+ public static string Base64Decode(string? plainText)
{
try
{
+ if (plainText.IsNullOrEmpty()) return "";
plainText = plainText.Trim()
.Replace(Environment.NewLine, "")
.Replace("\n", "")
@@ -365,7 +366,7 @@ namespace ServiceLib.Common
}
}
- public static bool IsBase64String(string plainText)
+ public static bool IsBase64String(string? plainText)
{
if (plainText.IsNullOrEmpty()) return false;
var buffer = new Span(new byte[plainText.Length]);
@@ -812,7 +813,7 @@ namespace ServiceLib.Common
}
if (coreType != null)
{
- _tempPath = Path.Combine(_tempPath, coreType.ToString()!);
+ _tempPath = Path.Combine(_tempPath, coreType.ToString());
if (!Directory.Exists(_tempPath))
{
Directory.CreateDirectory(_tempPath);
diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs
index b30d41a0..32fc70e6 100644
--- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs
+++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs
@@ -865,7 +865,7 @@ namespace ServiceLib.Handler.CoreConfig
var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);
//Previous proxy
- var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile!);
+ var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
if (prevNode is not null
&& prevNode.configType != EConfigType.Custom)
{
@@ -878,7 +878,7 @@ namespace ServiceLib.Handler.CoreConfig
}
//Next proxy
- var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile!);
+ var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
if (nextNode is not null
&& nextNode.configType != EConfigType.Custom)
{
@@ -956,7 +956,7 @@ namespace ServiceLib.Handler.CoreConfig
if (routing != null)
{
var rules = JsonUtils.Deserialize>(routing.ruleSet);
- foreach (var item in rules!)
+ foreach (var item in rules ?? [])
{
if (item.enabled)
{
@@ -971,7 +971,7 @@ namespace ServiceLib.Handler.CoreConfig
if (lockedItem != null)
{
var rules = JsonUtils.Deserialize>(lockedItem.ruleSet);
- foreach (var item in rules!)
+ foreach (var item in rules ?? [])
{
GenRoutingUserRule(item, singboxConfig.route.rules);
}
diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs
index 72f3f8ff..4e34ac4c 100644
--- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs
+++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs
@@ -1204,7 +1204,7 @@ namespace ServiceLib.Handler.CoreConfig
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
//Previous proxy
- var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile!);
+ var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile);
if (prevNode is not null
&& prevNode.configType != EConfigType.Custom
&& prevNode.configType != EConfigType.Hysteria2
@@ -1223,7 +1223,7 @@ namespace ServiceLib.Handler.CoreConfig
}
//Next proxy
- var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile!);
+ var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile);
if (nextNode is not null
&& nextNode.configType != EConfigType.Custom
&& nextNode.configType != EConfigType.Hysteria2
diff --git a/v2rayN/ServiceLib/Handler/LazyConfig.cs b/v2rayN/ServiceLib/Handler/LazyConfig.cs
index 4830ba92..afc1f729 100644
--- a/v2rayN/ServiceLib/Handler/LazyConfig.cs
+++ b/v2rayN/ServiceLib/Handler/LazyConfig.cs
@@ -168,7 +168,7 @@
return SQLiteHelper.Instance.Table().FirstOrDefault(it => it.indexId == indexId);
}
- public ProfileItem? GetProfileItemViaRemarks(string remarks)
+ public ProfileItem? GetProfileItemViaRemarks(string? remarks)
{
if (Utils.IsNullOrEmpty(remarks))
{
diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
index dc097966..49703f1c 100644
--- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs
+++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
@@ -191,7 +191,7 @@ namespace ServiceLib.Handler
//more url
if (Utils.IsNullOrEmpty(item.convertTarget) && Utils.IsNotEmpty(item.moreUrl.TrimEx()))
{
- if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result!))
+ if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result))
{
result = Utils.Base64Decode(result);
}
@@ -212,7 +212,7 @@ namespace ServiceLib.Handler
}
if (Utils.IsNotEmpty(result2))
{
- if (Utils.IsBase64String(result2!))
+ if (Utils.IsBase64String(result2))
{
result += Utils.Base64Decode(result2);
}
@@ -368,7 +368,7 @@ namespace ServiceLib.Handler
{
var gitHubReleases = JsonUtils.Deserialize>(gitHubReleaseApi);
var gitHubRelease = preRelease ? gitHubReleases?.First() : gitHubReleases?.First(r => r.Prerelease == false);
- var version = new SemanticVersion(gitHubRelease?.TagName!);
+ var version = new SemanticVersion(gitHubRelease?.TagName);
var body = gitHubRelease?.Body;
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);