Skip to content

Commit

Permalink
Fix ?!
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 18, 2024
1 parent 073eaa9 commit 243dbab
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
13 changes: 10 additions & 3 deletions v2rayN/ServiceLib/Common/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ public SemanticVersion(int major, int minor, int patch)
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)
{
Expand All @@ -43,7 +51,6 @@ public SemanticVersion(string version)
this.major = 0;
this.minor = 0;
this.patch = 0;
//this.version = "0.0.0";
}
}

Expand Down
7 changes: 4 additions & 3 deletions v2rayN/ServiceLib/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ public static string Base64Encode(string plainText)
/// </summary>
/// <param name="plainText"></param>
/// <returns></returns>
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", "")
Expand Down Expand Up @@ -365,7 +366,7 @@ public static string GetPunycode(string url)
}
}

public static bool IsBase64String(string plainText)
public static bool IsBase64String(string? plainText)
{
if (plainText.IsNullOrEmpty()) return false;
var buffer = new Span<byte>(new byte[plainText.Length]);
Expand Down Expand Up @@ -812,7 +813,7 @@ public static string GetBinPath(string filename, string? coreType = null)
}
if (coreType != null)
{
_tempPath = Path.Combine(_tempPath, coreType.ToString()!);
_tempPath = Path.Combine(_tempPath, coreType.ToString());
if (!Directory.Exists(_tempPath))
{
Directory.CreateDirectory(_tempPath);
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig)
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)
{
Expand All @@ -878,7 +878,7 @@ private int GenMoreOutbounds(ProfileItem node, SingboxConfig singboxConfig)
}

//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)
{
Expand Down Expand Up @@ -956,7 +956,7 @@ private int GenRouting(SingboxConfig singboxConfig)
if (routing != null)
{
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.ruleSet);
foreach (var item in rules!)
foreach (var item in rules ?? [])
{
if (item.enabled)
{
Expand All @@ -971,7 +971,7 @@ private int GenRouting(SingboxConfig singboxConfig)
if (lockedItem != null)
{
var rules = JsonUtils.Deserialize<List<RulesItem>>(lockedItem.ruleSet);
foreach (var item in rules!)
foreach (var item in rules ?? [])
{
GenRoutingUserRule(item, singboxConfig.route.rules);
}
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig)
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
Expand All @@ -1223,7 +1223,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig)
}

//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
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/Handler/LazyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ from t33 in t3b.DefaultIfEmpty()
return SQLiteHelper.Instance.Table<ProfileItem>().FirstOrDefault(it => it.indexId == indexId);
}

public ProfileItem? GetProfileItemViaRemarks(string remarks)
public ProfileItem? GetProfileItemViaRemarks(string? remarks)
{
if (Utils.IsNullOrEmpty(remarks))
{
Expand Down
6 changes: 3 additions & 3 deletions v2rayN/ServiceLib/Handler/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy,
//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);
}
Expand All @@ -212,7 +212,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy,
}
if (Utils.IsNotEmpty(result2))
{
if (Utils.IsBase64String(result2!))
if (Utils.IsBase64String(result2))
{
result += Utils.Base64Decode(result2);
}
Expand Down Expand Up @@ -368,7 +368,7 @@ private async Task<ResultEventArgs> ParseDownloadUrl(ECoreType type, string gitH
{
var gitHubReleases = JsonUtils.Deserialize<List<GitHubRelease>>(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);
Expand Down

0 comments on commit 243dbab

Please sign in to comment.