Skip to content

Commit

Permalink
Merge branch '2dust:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fonaix authored Dec 1, 2024
2 parents e3a9044 + 9326b45 commit d8b0363
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 212 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/winget-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: WinGet submission on release
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml
# inspired by https://github.com/microsoft/PowerToys/blob/main/.github/workflows/package-submissions.yml
# Modified by @MerrickZ https://github.com/anpho

on:
workflow_dispatch:
release:
types: [released]

jobs:
winget:
name: Publish winget package
runs-on: windows-latest
steps:
- name: Submit v2ray package to Windows Package Manager Community Repository
run: |
$wingetPackage = "2dust.v2rayN"
$gitToken = "${{ secrets.PT_WINGET }}"
$github = Invoke-RestMethod -uri "https://api.github.com/repos/2dust/v2rayN/releases"
$targetRelease = $github | Where-Object -Property prerelease -match 'False' | Select -First 1
$installerUrl = $targetRelease | Select -ExpandProperty assets -First 1 | Where-Object -Property name -match 'v2rayN-windows-64-With-Core\.zip*' | Select -ExpandProperty browser_download_url
$ver = $targetRelease.tag_name
# getting latest wingetcreate file
iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
.\wingetcreate.exe update $wingetPackage -s -v $ver -u "$installerUrl|x64" -t $gitToken
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Common/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public SemanticVersion(string? version)
var parts = this.version.Split('.');
if (parts.Length == 2)
{
this.major = int.Parse(parts[0]);
this.minor = int.Parse(parts[1]);
this.major = int.Parse(parts.First());
this.minor = int.Parse(parts.Last());
this.patch = 0;
}
else if (parts.Length is 3 or 4)
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Common/StringEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool IsNotEmpty([NotNullWhen(false)] this string? value)
public static bool BeginWithAny(this string s, IEnumerable<char> chars)
{
if (s.IsNullOrEmpty()) return false;
return chars.Contains(s[0]);
return chars.Contains(s.First());
}

private static bool IsWhiteSpace(this string value)
Expand Down Expand Up @@ -61,7 +61,7 @@ public static string UpperFirstChar(this string value)
return string.Empty;
}

return char.ToUpper(value[0]) + value[1..];
return char.ToUpper(value.First()) + value[1..];
}

public static string AppendQuotes(this string value)
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/ServiceLib/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ public static NameValueCollection ParseQueryString(string query)
continue;
}

var key = Uri.UnescapeDataString(keyValue[0]);
var val = Uri.UnescapeDataString(keyValue[1]);
var key = Uri.UnescapeDataString(keyValue.First());
var val = Uri.UnescapeDataString(keyValue.Last());

if (result[key] is null)
{
Expand Down Expand Up @@ -622,8 +622,8 @@ public static Dictionary<string, string> GetSystemHosts()
{
if (host.StartsWith("#")) continue;
var hostItem = host.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (hostItem.Length < 2) continue;
systemHosts.Add(hostItem[1], hostItem[0]);
if (hostItem.Length != 2) continue;
systemHosts.Add(hostItem.Last(), hostItem.First());
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public class ConfigHandler
{
if (config.Inbound.Count > 0)
{
config.Inbound[0].Protocol = EInboundProtocol.socks.ToString();
config.Inbound.First().Protocol = EInboundProtocol.socks.ToString();
}
}

config.RoutingBasicItem ??= new();

if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy))
{
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies[0];//"IPIfNonMatch";
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();//"IPIfNonMatch";
}

config.KcpItem ??= new KcpItem
Expand Down Expand Up @@ -111,7 +111,7 @@ public class ConfigHandler
{
if (Thread.CurrentThread.CurrentCulture.Name.Equals("zh-cn", StringComparison.CurrentCultureIgnoreCase))
{
config.UiItem.CurrentLanguage = Global.Languages[0];
config.UiItem.CurrentLanguage = Global.Languages.First();
}
else
{
Expand All @@ -132,7 +132,7 @@ public class ConfigHandler
}
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl))
{
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls[0];
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First();
}
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl))
{
Expand All @@ -148,7 +148,7 @@ public class ConfigHandler

config.Mux4SboxItem ??= new()
{
Protocol = Global.SingboxMuxs[0],
Protocol = Global.SingboxMuxs.First(),
MaxConnections = 8
};

Expand Down Expand Up @@ -429,7 +429,7 @@ public static async Task<int> MoveServer(Config config, List<ProfileItem> lstPro
{
return 0;
}
sort = ProfileExHandler.Instance.GetSort(lstProfile[0].IndexId) - 1;
sort = ProfileExHandler.Instance.GetSort(lstProfile.First().IndexId) - 1;

break;
}
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public class ShadowsocksFmt : BaseFmt
{
return null;
}
item.Security = userInfoParts[0];
item.Id = Utils.UrlDecode(userInfoParts[1]);
item.Security = userInfoParts.First();
item.Id = Utils.UrlDecode(userInfoParts.Last());
}
else
{
Expand All @@ -111,8 +111,8 @@ public class ShadowsocksFmt : BaseFmt
{
return null;
}
item.Security = userInfoParts[0];
item.Id = userInfoParts[1];
item.Security = userInfoParts.First();
item.Id = userInfoParts.Last();
}

var queryParameters = Utils.ParseQueryString(parsedUrl.Query);
Expand Down
30 changes: 11 additions & 19 deletions v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ public class SocksFmt : BaseFmt
public static ProfileItem? Resolve(string str, out string msg)
{
msg = ResUI.ConfigurationFormatIncorrect;
ProfileItem? item;

item = ResolveSocksNew(str) ?? ResolveSocks(str);
var item = ResolveSocksNew(str) ?? ResolveSocks(str);
if (item == null)
{
return null;
Expand All @@ -25,19 +24,13 @@ public class SocksFmt : BaseFmt
public static string? ToUri(ProfileItem? item)
{
if (item == null) return null;
string url = string.Empty;
var url = string.Empty;

string remark = string.Empty;
var remark = string.Empty;
if (Utils.IsNotEmpty(item.Remarks))
{
remark = "#" + Utils.UrlEncode(item.Remarks);
}
//url = string.Format("{0}:{1}@{2}:{3}",
// item.security,
// item.id,
// item.address,
// item.port);
//url = Utile.Base64Encode(url);
//new
var pw = Utils.Base64Encode($"{item.Security}:{item.Id}");
return ToUri(EConfigType.SOCKS, item.Address, item.Port, pw, null, remark);
Expand All @@ -51,7 +44,7 @@ public class SocksFmt : BaseFmt
};
result = result[Global.ProtocolShares[EConfigType.SOCKS].Length..];
//remark
int indexRemark = result.IndexOf("#");
var indexRemark = result.IndexOf("#");
if (indexRemark > 0)
{
try
Expand All @@ -62,7 +55,7 @@ public class SocksFmt : BaseFmt
result = result[..indexRemark];
}
//part decode
int indexS = result.IndexOf("@");
var indexS = result.IndexOf("@");
if (indexS > 0)
{
}
Expand All @@ -71,21 +64,20 @@ public class SocksFmt : BaseFmt
result = Utils.Base64Decode(result);
}

string[] arr1 = result.Split('@');
var arr1 = result.Split('@');
if (arr1.Length != 2)
{
return null;
}
string[] arr21 = arr1[0].Split(':');
//string[] arr22 = arr1[1].Split(':');
int indexPort = arr1[1].LastIndexOf(":");
var arr21 = arr1.First().Split(':');
var indexPort = arr1.Last().LastIndexOf(":");
if (arr21.Length != 2 || indexPort < 0)
{
return null;
}
item.Address = arr1[1][..indexPort];
item.Port = Utils.ToInt(arr1[1][(indexPort + 1)..]);
item.Security = arr21[0];
item.Security = arr21.First();
item.Id = arr21[1];

return item;
Expand All @@ -106,10 +98,10 @@ public class SocksFmt : BaseFmt
// parse base64 UserInfo
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
var userInfo = Utils.Base64Decode(rawUserInfo);
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
var userInfoParts = userInfo.Split([':'], 2);
if (userInfoParts.Length == 2)
{
item.Security = userInfoParts[0];
item.Security = userInfoParts.First();
item.Id = userInfoParts[1];
}

Expand Down
4 changes: 2 additions & 2 deletions v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class TuicFmt : BaseFmt
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
if (userInfoParts.Length == 2)
{
item.Id = userInfoParts[0];
item.Security = userInfoParts[1];
item.Id = userInfoParts.First();
item.Security = userInfoParts.Last();
}

var query = Utils.ParseQueryString(url.Query);
Expand Down
1 change: 0 additions & 1 deletion v2rayN/ServiceLib/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public class ClashUIItem
public int ProxiesSorting { get; set; }
public bool ProxiesAutoRefresh { get; set; }
public int ProxiesAutoDelayTestInterval { get; set; } = 10;
public int ConnectionsSorting { get; set; }
public bool ConnectionsAutoRefresh { get; set; }
public int ConnectionsRefreshInterval { get; set; } = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task<RetResult> GenerateClientCustomConfig(ProfileItem node, string
//external-controller
fileContent["external-controller"] = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}";
//allow-lan
if (_config.Inbound[0].AllowLANConn)
if (_config.Inbound.First().AllowLANConn)
{
fileContent["allow-lan"] = "true";
fileContent["bind-address"] = "*";
Expand Down
28 changes: 14 additions & 14 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<RetResult> GenerateClientConfigContent(ProfileItem node)

await GenInbounds(singboxConfig);

await GenOutbound(node, singboxConfig.outbounds[0]);
await GenOutbound(node, singboxConfig.outbounds.First());

await GenMoreOutbounds(node, singboxConfig);

Expand Down Expand Up @@ -495,8 +495,8 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
singboxConfig.inbounds.Add(inbound);

inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
inbound.sniff = _config.Inbound[0].SniffingEnabled;
inbound.sniff_override_destination = _config.Inbound[0].RouteOnly ? false : _config.Inbound[0].SniffingEnabled;
inbound.sniff = _config.Inbound.First().SniffingEnabled;
inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled;
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;

var routing = await ConfigHandler.GetDefaultRouting(_config);
Expand All @@ -509,9 +509,9 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
var inbound2 = GetInbound(inbound, EInboundProtocol.http, false);
singboxConfig.inbounds.Add(inbound2);

if (_config.Inbound[0].AllowLANConn)
if (_config.Inbound.First().AllowLANConn)
{
if (_config.Inbound[0].NewPort4LAN)
if (_config.Inbound.First().NewPort4LAN)
{
var inbound3 = GetInbound(inbound, EInboundProtocol.socks2, true);
inbound3.listen = listen;
Expand All @@ -522,10 +522,10 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
singboxConfig.inbounds.Add(inbound4);

//auth
if (Utils.IsNotEmpty(_config.Inbound[0].User) && Utils.IsNotEmpty(_config.Inbound[0].Pass))
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
{
inbound3.users = new() { new() { username = _config.Inbound[0].User, password = _config.Inbound[0].Pass } };
inbound4.users = new() { new() { username = _config.Inbound[0].User, password = _config.Inbound[0].Pass } };
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
inbound4.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
}
}
else
Expand All @@ -540,20 +540,20 @@ private async Task<int> GenInbounds(SingboxConfig singboxConfig)
{
if (_config.TunModeItem.Mtu <= 0)
{
_config.TunModeItem.Mtu = Utils.ToInt(Global.TunMtus[0]);
_config.TunModeItem.Mtu = Utils.ToInt(Global.TunMtus.First());
}
if (Utils.IsNullOrEmpty(_config.TunModeItem.Stack))
{
_config.TunModeItem.Stack = Global.TunStacks[0];
_config.TunModeItem.Stack = Global.TunStacks.First();
}

var tunInbound = JsonUtils.Deserialize<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { };
tunInbound.interface_name = Utils.IsOSX() ? $"utun{new Random().Next(99)}" : "singbox_tun";
tunInbound.mtu = _config.TunModeItem.Mtu;
tunInbound.strict_route = _config.TunModeItem.StrictRoute;
tunInbound.stack = _config.TunModeItem.Stack;
tunInbound.sniff = _config.Inbound[0].SniffingEnabled;
//tunInbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled;
tunInbound.sniff = _config.Inbound.First().SniffingEnabled;
//tunInbound.sniff_override_destination = _config.inbound.First().routeOnly ? false : _config.inbound.First().sniffingEnabled;
if (_config.TunModeItem.EnableIPv6Address == false)
{
tunInbound.address = ["172.18.0.1/30"];
Expand Down Expand Up @@ -867,7 +867,7 @@ private async Task<int> GenMoreOutbounds(ProfileItem node, SingboxConfig singbox
}

//current proxy
var outbound = singboxConfig.outbounds[0];
var outbound = singboxConfig.outbounds.First();
var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);

//Previous proxy
Expand Down Expand Up @@ -910,7 +910,7 @@ private async Task<int> GenRouting(SingboxConfig singboxConfig)
try
{
var dnsOutbound = "dns_out";
if (!_config.Inbound[0].SniffingEnabled)
if (!_config.Inbound.First().SniffingEnabled)
{
singboxConfig.route.rules.Add(new()
{
Expand Down
Loading

0 comments on commit d8b0363

Please sign in to comment.