mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-27 18:42:52 +00:00
Compare commits
No commits in common. "3f0f895424fe5ca0cc1e3cc8cb9ee9a77513e088" and "78fde575d7f76edba4284505ad283b396cff2a2b" have entirely different histories.
3f0f895424
...
78fde575d7
83 changed files with 793 additions and 765 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>7.10.4</Version>
|
||||
<Version>7.10.3</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit ef73fa22c46cfc7d1ec192ffe8497f6e61b4f0db
|
||||
Subproject commit b3b635ef46b7aed3ee9e27abe7ec1f2688695bfb
|
||||
|
|
@ -10,7 +10,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public async Task<string?> DownloadStringAsync(IWebProxy? webProxy, string url, string? userAgent, int timeout)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ namespace ServiceLib.Common
|
|||
Uri uri = new(url);
|
||||
//Authorization Header
|
||||
var headers = new WebHeaderCollection();
|
||||
if (uri.UserInfo.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(uri.UserInfo))
|
||||
{
|
||||
headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgress<string> progress, int timeout)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ namespace ServiceLib.Common
|
|||
//};
|
||||
downloader.DownloadProgressChanged += (sender, value) =>
|
||||
{
|
||||
var ts = DateTime.Now - totalDatetime;
|
||||
var ts = (DateTime.Now - totalDatetime);
|
||||
if (progress != null && ts.Seconds > totalSecond)
|
||||
{
|
||||
hasValue = true;
|
||||
|
|
@ -119,11 +119,11 @@ namespace ServiceLib.Common
|
|||
|
||||
public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string fileName, IProgress<double> progress, int timeout)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
|
@ -146,7 +146,10 @@ namespace ServiceLib.Common
|
|||
var progressPercentage = 0;
|
||||
var hasValue = false;
|
||||
await using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||
downloader.DownloadStarted += (sender, value) => progress?.Report(0);
|
||||
downloader.DownloadStarted += (sender, value) =>
|
||||
{
|
||||
progress?.Report(0);
|
||||
};
|
||||
downloader.DownloadProgressChanged += (sender, value) =>
|
||||
{
|
||||
hasValue = true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Formats.Tar;
|
||||
using System.Formats.Tar;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ namespace ServiceLib.Common
|
|||
}
|
||||
try
|
||||
{
|
||||
if (ignoredName.IsNotEmpty() && entry.Name.Contains(ignoredName))
|
||||
if (Utils.IsNotEmpty(ignoredName) && entry.Name.Contains(ignoredName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -163,20 +163,18 @@ namespace ServiceLib.Common
|
|||
|
||||
// Check if the source directory exists
|
||||
if (!dir.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
||||
}
|
||||
|
||||
// Cache directories before we start copying
|
||||
var dirs = dir.GetDirectories();
|
||||
|
||||
// Create the destination directory
|
||||
_ = Directory.CreateDirectory(destinationDir);
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
|
||||
// Get the files in the source directory and copy to the destination directory
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
if (ignoredName.IsNotEmpty() && file.Name.Contains(ignoredName))
|
||||
if (Utils.IsNotEmpty(ignoredName) && file.Name.Contains(ignoredName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -189,7 +187,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
continue;
|
||||
}
|
||||
_ = file.CopyTo(targetFilePath, overwrite);
|
||||
file.CopyTo(targetFilePath, overwrite);
|
||||
}
|
||||
|
||||
// If recursive and copying subdirectories, recursively call this method
|
||||
|
|
|
|||
|
|
@ -18,17 +18,12 @@ namespace ServiceLib.Common
|
|||
public static HttpClientHelper Instance => _instance.Value;
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
private HttpClientHelper(HttpClient httpClient)
|
||||
{
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
private HttpClientHelper(HttpClient httpClient) => this.httpClient = httpClient;
|
||||
|
||||
public async Task<string?> TryGetAsync(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -43,19 +38,15 @@ namespace ServiceLib.Common
|
|||
|
||||
public async Task<string?> GetAsync(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
return null;
|
||||
}
|
||||
return await httpClient.GetStringAsync(url);
|
||||
}
|
||||
|
||||
public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token = default)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
return null;
|
||||
}
|
||||
return await client.GetStringAsync(url, token);
|
||||
}
|
||||
|
||||
|
|
@ -64,13 +55,13 @@ namespace ServiceLib.Common
|
|||
var jsonContent = JsonUtils.Serialize(headers);
|
||||
var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||
|
||||
await httpClient.PutAsync(url, content);
|
||||
var result = await httpClient.PutAsync(url, content);
|
||||
}
|
||||
|
||||
public async Task PatchAsync(string url, Dictionary<string, string> headers)
|
||||
{
|
||||
var myContent = JsonUtils.Serialize(headers);
|
||||
var buffer = Encoding.UTF8.GetBytes(myContent);
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
|
||||
var byteContent = new ByteArrayContent(buffer);
|
||||
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
|
|
@ -87,16 +78,12 @@ namespace ServiceLib.Common
|
|||
ArgumentNullException.ThrowIfNull(url);
|
||||
ArgumentNullException.ThrowIfNull(fileName);
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(response.StatusCode.ToString());
|
||||
}
|
||||
|
||||
var total = response.Content.Headers.ContentLength ?? -1L;
|
||||
var canReportProgress = total != -1 && progress != null;
|
||||
|
|
@ -115,9 +102,7 @@ namespace ServiceLib.Common
|
|||
totalRead += read;
|
||||
|
||||
if (read == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await file.WriteAsync(buffer.AsMemory(0, read), token);
|
||||
|
||||
if (canReportProgress)
|
||||
|
|
@ -138,7 +123,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<string> progress, CancellationToken token = default)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
|
|
@ -188,7 +173,7 @@ namespace ServiceLib.Common
|
|||
|
||||
totalRead += read;
|
||||
|
||||
var ts = DateTime.Now - totalDatetime;
|
||||
var ts = (DateTime.Now - totalDatetime);
|
||||
if (progress != null && ts.Seconds > totalSecond)
|
||||
{
|
||||
totalSecond = ts.Seconds;
|
||||
|
|
|
|||
|
|
@ -15,30 +15,28 @@ namespace ServiceLib.Common
|
|||
public Job()
|
||||
{
|
||||
handle = CreateJobObject(IntPtr.Zero, null);
|
||||
var extendedInfoPtr = IntPtr.Zero;
|
||||
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||
IntPtr extendedInfoPtr = IntPtr.Zero;
|
||||
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new()
|
||||
{
|
||||
LimitFlags = 0x2000
|
||||
};
|
||||
|
||||
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new()
|
||||
{
|
||||
BasicLimitInformation = info
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
||||
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
||||
extendedInfoPtr = Marshal.AllocHGlobal(length);
|
||||
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
|
||||
|
||||
if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr,
|
||||
(uint)length))
|
||||
{
|
||||
throw new Exception(string.Format("Unable to set information. Error: {0}",
|
||||
Marshal.GetLastWin32Error()));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (extendedInfoPtr != IntPtr.Zero)
|
||||
|
|
@ -50,7 +48,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public bool AddProcess(IntPtr processHandle)
|
||||
{
|
||||
var succ = AssignProcessToJobObject(handle, processHandle);
|
||||
bool succ = AssignProcessToJobObject(handle, processHandle);
|
||||
|
||||
if (!succ)
|
||||
{
|
||||
|
|
@ -78,9 +76,7 @@ namespace ServiceLib.Common
|
|||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
disposed = true;
|
||||
|
||||
if (disposing)
|
||||
|
|
@ -108,7 +104,7 @@ namespace ServiceLib.Common
|
|||
private static extern IntPtr CreateJobObject(IntPtr a, string? lpName);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
|
||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
||||
|
|
@ -125,34 +121,34 @@ namespace ServiceLib.Common
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct IO_COUNTERS
|
||||
{
|
||||
public ulong ReadOperationCount;
|
||||
public ulong WriteOperationCount;
|
||||
public ulong OtherOperationCount;
|
||||
public ulong ReadTransferCount;
|
||||
public ulong WriteTransferCount;
|
||||
public ulong OtherTransferCount;
|
||||
public UInt64 ReadOperationCount;
|
||||
public UInt64 WriteOperationCount;
|
||||
public UInt64 OtherOperationCount;
|
||||
public UInt64 ReadTransferCount;
|
||||
public UInt64 WriteTransferCount;
|
||||
public UInt64 OtherTransferCount;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
||||
{
|
||||
public long PerProcessUserTimeLimit;
|
||||
public long PerJobUserTimeLimit;
|
||||
public uint LimitFlags;
|
||||
public Int64 PerProcessUserTimeLimit;
|
||||
public Int64 PerJobUserTimeLimit;
|
||||
public UInt32 LimitFlags;
|
||||
public UIntPtr MinimumWorkingSetSize;
|
||||
public UIntPtr MaximumWorkingSetSize;
|
||||
public uint ActiveProcessLimit;
|
||||
public UInt32 ActiveProcessLimit;
|
||||
public UIntPtr Affinity;
|
||||
public uint PriorityClass;
|
||||
public uint SchedulingClass;
|
||||
public UInt32 PriorityClass;
|
||||
public UInt32 SchedulingClass;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public uint nLength;
|
||||
public UInt32 nLength;
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
public int bInheritHandle;
|
||||
public Int32 bInheritHandle;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ namespace ServiceLib.Common
|
|||
public static void SaveLog(string strContent)
|
||||
{
|
||||
if (!LogManager.IsLoggingEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.GetLogger("Log1").Info(strContent);
|
||||
}
|
||||
|
|
@ -38,9 +36,7 @@ namespace ServiceLib.Common
|
|||
public static void SaveLog(string strTitle, Exception ex)
|
||||
{
|
||||
if (!LogManager.IsLoggingEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var logger = LogManager.GetLogger("Log2");
|
||||
logger.Debug($"{strTitle},{ex.Message}");
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public static class ProcUtils
|
|||
|
||||
public static void ProcessStart(string? fileName, string arguments = "")
|
||||
{
|
||||
_ = ProcessStart(fileName, arguments, null);
|
||||
ProcessStart(fileName, arguments, null);
|
||||
}
|
||||
|
||||
public static int? ProcessStart(string? fileName, string arguments, string? dir)
|
||||
|
|
@ -38,7 +38,7 @@ public static class ProcUtils
|
|||
WorkingDirectory = dir ?? string.Empty
|
||||
}
|
||||
};
|
||||
_ = proc.Start();
|
||||
proc.Start();
|
||||
return dir is null ? null : proc.Id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -60,7 +60,7 @@ public static class ProcUtils
|
|||
FileName = Utils.GetExePath().AppendQuotes(),
|
||||
Verb = blAdmin ? "runas" : null,
|
||||
};
|
||||
_ = Process.Start(startInfo);
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -138,9 +138,7 @@ public static class ProcUtils
|
|||
fileName = null;
|
||||
processName = null;
|
||||
if (!review)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
procId = proc?.Id;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace ServiceLib.Common
|
|||
var reader = new BarcodeReader();
|
||||
var result = reader.Decode(bitmap);
|
||||
|
||||
if (result != null && result.Text.IsNotEmpty())
|
||||
if (result != null && Utils.IsNotEmpty(result.Text))
|
||||
{
|
||||
return result.Text;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
namespace ServiceLib.Common
|
||||
namespace ServiceLib.Common
|
||||
{
|
||||
public class SemanticVersion
|
||||
{
|
||||
private readonly int major;
|
||||
private readonly int minor;
|
||||
private readonly int patch;
|
||||
private readonly string version;
|
||||
private int major;
|
||||
private int minor;
|
||||
private int patch;
|
||||
private string version;
|
||||
|
||||
public SemanticVersion(int major, int minor, int patch)
|
||||
{
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
version = $"{major}.{minor}.{patch}";
|
||||
this.version = $"{major}.{minor}.{patch}";
|
||||
}
|
||||
|
||||
public SemanticVersion(string? version)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(version))
|
||||
if (version.IsNullOrEmpty())
|
||||
{
|
||||
major = 0;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
this.major = 0;
|
||||
this.minor = 0;
|
||||
this.patch = 0;
|
||||
return;
|
||||
}
|
||||
this.version = version.RemovePrefix('v');
|
||||
|
|
@ -31,15 +31,15 @@ namespace ServiceLib.Common
|
|||
var parts = this.version.Split('.');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
major = int.Parse(parts.First());
|
||||
minor = int.Parse(parts.Last());
|
||||
patch = 0;
|
||||
this.major = int.Parse(parts.First());
|
||||
this.minor = int.Parse(parts.Last());
|
||||
this.patch = 0;
|
||||
}
|
||||
else if (parts.Length is 3 or 4)
|
||||
{
|
||||
major = int.Parse(parts[0]);
|
||||
minor = int.Parse(parts[1]);
|
||||
patch = int.Parse(parts[2]);
|
||||
this.major = int.Parse(parts[0]);
|
||||
this.minor = int.Parse(parts[1]);
|
||||
this.patch = int.Parse(parts[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -48,9 +48,9 @@ namespace ServiceLib.Common
|
|||
}
|
||||
catch
|
||||
{
|
||||
major = 0;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
this.major = 0;
|
||||
this.minor = 0;
|
||||
this.patch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
if (obj is SemanticVersion other)
|
||||
{
|
||||
return major == other.major && minor == other.minor && patch == other.patch;
|
||||
return this.major == other.major && this.minor == other.minor && this.patch == other.patch;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return major.GetHashCode() ^ minor.GetHashCode() ^ patch.GetHashCode();
|
||||
return this.major.GetHashCode() ^ this.minor.GetHashCode() ^ this.patch.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -77,18 +77,18 @@ namespace ServiceLib.Common
|
|||
/// <returns>major.minor.patch</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return version;
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public string ToVersionString(string? prefix = null)
|
||||
{
|
||||
if (prefix == null)
|
||||
{
|
||||
return version;
|
||||
return this.version;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{prefix}{version}";
|
||||
return $"{prefix}{this.version}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,31 +108,31 @@ namespace ServiceLib.Common
|
|||
|
||||
private bool GreaterEquals(SemanticVersion other)
|
||||
{
|
||||
if (major < other.major)
|
||||
if (this.major < other.major)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (major > other.major)
|
||||
else if (this.major > other.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minor < other.minor)
|
||||
if (this.minor < other.minor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (minor > other.minor)
|
||||
else if (this.minor > other.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (patch < other.patch)
|
||||
if (this.patch < other.patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (patch > other.patch)
|
||||
else if (this.patch > other.patch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -146,31 +146,31 @@ namespace ServiceLib.Common
|
|||
|
||||
private bool LessEquals(SemanticVersion other)
|
||||
{
|
||||
if (major < other.major)
|
||||
if (this.major < other.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (major > other.major)
|
||||
else if (this.major > other.major)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minor < other.minor)
|
||||
if (this.minor < other.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (minor > other.minor)
|
||||
else if (this.minor > other.minor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (patch < other.patch)
|
||||
if (this.patch < other.patch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (patch > other.patch)
|
||||
else if (this.patch > other.patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
private static readonly Lazy<SQLiteHelper> _instance = new(() => new());
|
||||
public static SQLiteHelper Instance => _instance.Value;
|
||||
private readonly string _connstr;
|
||||
private string _connstr;
|
||||
private SQLiteConnection _db;
|
||||
private SQLiteAsyncConnection _dbAsync;
|
||||
private readonly string _configDB = "guiNDB.db";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? value)
|
||||
{
|
||||
return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value);
|
||||
return string.IsNullOrEmpty(value);
|
||||
}
|
||||
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value)
|
||||
|
|
@ -22,9 +22,7 @@ namespace ServiceLib.Common
|
|||
public static bool BeginWithAny(this string s, IEnumerable<char> chars)
|
||||
{
|
||||
if (s.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return chars.Contains(s.First());
|
||||
}
|
||||
|
||||
|
|
@ -38,9 +36,7 @@ namespace ServiceLib.Common
|
|||
while (reader.ReadLine() is { } line)
|
||||
{
|
||||
if (line.IsWhiteSpace())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
|
|
@ -74,10 +70,5 @@ namespace ServiceLib.Common
|
|||
{
|
||||
return string.IsNullOrEmpty(value) ? string.Empty : $"\"{value}\"";
|
||||
}
|
||||
|
||||
public static int ToInt(this string? value, int defaultValue = 0)
|
||||
{
|
||||
return int.TryParse(value, out var result) ? result : defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,69 +20,85 @@ namespace ServiceLib.Common
|
|||
#region 转换函数
|
||||
|
||||
/// <summary>
|
||||
/// Convert to comma-separated string
|
||||
/// 转逗号分隔的字符串
|
||||
/// </summary>
|
||||
/// <param name="lst"></param>
|
||||
/// <param name="wrap"></param>
|
||||
/// <returns></returns>
|
||||
public static string List2String(List<string>? lst, bool wrap = false)
|
||||
{
|
||||
if (lst == null || lst.Count == 0)
|
||||
try
|
||||
{
|
||||
if (lst == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var separator = wrap ? "," + Environment.NewLine : ",";
|
||||
|
||||
try
|
||||
if (wrap)
|
||||
{
|
||||
return string.Join(separator, lst);
|
||||
return string.Join("," + Environment.NewLine, lst);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Join(",", lst);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comma-separated string
|
||||
/// 逗号分隔的字符串
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string>? String2List(string? str)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
try
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, string.Empty);
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comma-separated string, sorted and then converted to List
|
||||
/// 逗号分隔的字符串,先排序后转List
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string>? String2ListSorted(string str)
|
||||
{
|
||||
var lst = String2List(str);
|
||||
lst?.Sort();
|
||||
return lst;
|
||||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
list.Sort();
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64 Encode
|
||||
/// Base64编码
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -102,7 +118,7 @@ namespace ServiceLib.Common
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base64 Decode
|
||||
/// Base64解码
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -111,10 +127,7 @@ namespace ServiceLib.Common
|
|||
try
|
||||
{
|
||||
if (plainText.IsNullOrEmpty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
plainText = plainText.Trim()
|
||||
.Replace(Environment.NewLine, "")
|
||||
.Replace("\n", "")
|
||||
|
|
@ -139,6 +152,18 @@ namespace ServiceLib.Common
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
public static int ToInt(object? obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(obj ?? string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ToBool(object obj)
|
||||
{
|
||||
try
|
||||
|
|
@ -163,25 +188,55 @@ namespace ServiceLib.Common
|
|||
}
|
||||
}
|
||||
|
||||
private static void ToHumanReadable(long amount, out double result, out string unit)
|
||||
{
|
||||
var factor = 1024u;
|
||||
//long KBs = amount / factor;
|
||||
var KBs = amount;
|
||||
if (KBs > 0)
|
||||
{
|
||||
// multi KB
|
||||
var MBs = KBs / factor;
|
||||
if (MBs > 0)
|
||||
{
|
||||
// multi MB
|
||||
var GBs = MBs / factor;
|
||||
if (GBs > 0)
|
||||
{
|
||||
// multi GB
|
||||
var TBs = GBs / factor;
|
||||
if (TBs > 0)
|
||||
{
|
||||
result = TBs + ((GBs % factor) / (factor + 0.0));
|
||||
unit = "TB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = GBs + ((MBs % factor) / (factor + 0.0));
|
||||
unit = "GB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = MBs + ((KBs % factor) / (factor + 0.0));
|
||||
unit = "MB";
|
||||
return;
|
||||
}
|
||||
|
||||
result = KBs + ((amount % factor) / (factor + 0.0));
|
||||
unit = "KB";
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = amount;
|
||||
unit = "B";
|
||||
}
|
||||
}
|
||||
|
||||
public static string HumanFy(long amount)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
return $"{amount:f1} B";
|
||||
}
|
||||
|
||||
string[] units = ["KB", "MB", "GB", "TB", "PB"];
|
||||
var unitIndex = 0;
|
||||
double size = amount;
|
||||
|
||||
// Loop and divide by 1024 until a suitable unit is found
|
||||
while (size >= 1024 && unitIndex < units.Length - 1)
|
||||
{
|
||||
size /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
return $"{size:f1} {units[unitIndex]}";
|
||||
ToHumanReadable(amount, out var result, out var unit);
|
||||
return $"{result:f1} {unit}";
|
||||
}
|
||||
|
||||
public static string UrlEncode(string url)
|
||||
|
|
@ -197,7 +252,7 @@ namespace ServiceLib.Common
|
|||
public static NameValueCollection ParseQueryString(string query)
|
||||
{
|
||||
var result = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
|
||||
if (query.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(query))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -243,7 +298,7 @@ namespace ServiceLib.Common
|
|||
/// <returns></returns>
|
||||
public static string GetPunycode(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
|
@ -276,7 +331,7 @@ namespace ServiceLib.Common
|
|||
|
||||
public static string Convert2Comma(string text)
|
||||
{
|
||||
if (text.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(text))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
|
@ -289,7 +344,7 @@ namespace ServiceLib.Common
|
|||
#region 数据检查
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the input is a number
|
||||
/// 判断输入的是否是数字
|
||||
/// </summary>
|
||||
/// <param name="oText"></param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -298,13 +353,28 @@ namespace ServiceLib.Common
|
|||
return oText.All(char.IsNumber);
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return text == "null";
|
||||
}
|
||||
|
||||
public static bool IsNotEmpty(string? text)
|
||||
{
|
||||
return !string.IsNullOrEmpty(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate if the domain address is valid
|
||||
/// 验证Domain地址是否合法
|
||||
/// </summary>
|
||||
/// <param name="domain"></param>
|
||||
public static bool IsDomain(string? domain)
|
||||
{
|
||||
if (domain.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(domain))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -421,7 +491,7 @@ namespace ServiceLib.Common
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get version
|
||||
/// 取得版本
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetVersion(bool blFull = true)
|
||||
|
|
@ -459,7 +529,7 @@ namespace ServiceLib.Common
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// GUID
|
||||
/// 取得GUID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetGuid(bool full = true)
|
||||
|
|
@ -590,7 +660,7 @@ namespace ServiceLib.Common
|
|||
public static string GetPath(string fileName)
|
||||
{
|
||||
var startupPath = StartupPath();
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(fileName))
|
||||
{
|
||||
return startupPath;
|
||||
}
|
||||
|
|
@ -626,7 +696,7 @@ namespace ServiceLib.Common
|
|||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
@ -655,7 +725,7 @@ namespace ServiceLib.Common
|
|||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
@ -682,7 +752,7 @@ namespace ServiceLib.Common
|
|||
}
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
@ -700,7 +770,7 @@ namespace ServiceLib.Common
|
|||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
@ -718,7 +788,7 @@ namespace ServiceLib.Common
|
|||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
@ -736,7 +806,7 @@ namespace ServiceLib.Common
|
|||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
if (filename.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(filename))
|
||||
{
|
||||
return tempPath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace ServiceLib.Common
|
|||
{
|
||||
regKey = Registry.CurrentUser.OpenSubKey(path, false);
|
||||
var value = regKey?.GetValue(name) as string;
|
||||
return value.IsNullOrEmpty() ? def : value;
|
||||
return Utils.IsNullOrEmpty(value) ? def : value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -34,7 +34,7 @@ namespace ServiceLib.Common
|
|||
try
|
||||
{
|
||||
regKey = Registry.CurrentUser.CreateSubKey(path);
|
||||
if (value.ToString().IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(value.ToString()))
|
||||
{
|
||||
regKey?.DeleteValue(name, false);
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ namespace ServiceLib.Common
|
|||
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
||||
|
||||
// Try to remove the device
|
||||
_ = await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||
await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
|
|
@ -62,6 +62,9 @@ namespace ServiceLib.Common
|
|||
|
||||
public static string? PreprocessYaml(string str)
|
||||
{
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
try
|
||||
{
|
||||
var mergingParser = new MergingParser(new Parser(new StringReader(str)));
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public async Task<List<ProfileItem>?> ProfileItems(string subid)
|
||||
{
|
||||
if (subid.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().ToListAsync();
|
||||
}
|
||||
|
|
@ -153,11 +153,11 @@ namespace ServiceLib.Handler
|
|||
from ProfileItem a
|
||||
left join SubItem b on a.subid = b.id
|
||||
where 1=1 ";
|
||||
if (subid.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(subid))
|
||||
{
|
||||
sql += $" and a.subid = '{subid}'";
|
||||
}
|
||||
if (filter.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(filter))
|
||||
{
|
||||
if (filter.Contains('\''))
|
||||
{
|
||||
|
|
@ -171,7 +171,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public async Task<ProfileItem?> GetProfileItem(string indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks)
|
||||
{
|
||||
if (remarks.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(remarks))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ namespace ServiceLib.Handler
|
|||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static void AutoStartTaskService(string taskName, string fileName, string description)
|
||||
{
|
||||
if (taskName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(taskName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ namespace ServiceLib.Handler
|
|||
var logonUser = WindowsIdentity.GetCurrent().Name;
|
||||
using var taskService = new Microsoft.Win32.TaskScheduler.TaskService();
|
||||
var tasks = taskService.RootFolder.GetTasks(new Regex(taskName));
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
foreach (var t in tasks)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> updateFunc)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (blAll)
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
break;
|
||||
}
|
||||
await Task.Delay(5000);
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
if (_proxies == null)
|
||||
{
|
||||
|
|
@ -90,8 +90,9 @@ namespace ServiceLib.Handler
|
|||
updateFunc?.Invoke(it, result);
|
||||
}));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
await Task.Delay(1000);
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
|
||||
Task.Delay(1000).Wait();
|
||||
updateFunc?.Invoke(null, "");
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
Config? config = null;
|
||||
var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes));
|
||||
if (result.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result))
|
||||
{
|
||||
config = JsonUtils.Deserialize<Config>(result);
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
|
||||
config.RoutingBasicItem ??= new();
|
||||
if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy))
|
||||
{
|
||||
config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ namespace ServiceLib.Handler
|
|||
};
|
||||
config.UiItem.MainColumnItem ??= new();
|
||||
|
||||
if (config.UiItem.CurrentLanguage.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(config.UiItem.CurrentLanguage))
|
||||
{
|
||||
config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase)
|
||||
? Global.Languages.First()
|
||||
|
|
@ -117,11 +117,11 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
config.SpeedTestItem.SpeedTestTimeout = 10;
|
||||
}
|
||||
if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl))
|
||||
{
|
||||
config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First();
|
||||
}
|
||||
if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl))
|
||||
{
|
||||
config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrl;
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ namespace ServiceLib.Handler
|
|||
/// <returns></returns>
|
||||
public static async Task<int> SetDefaultServerIndex(Config config, string? indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -506,7 +506,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
profileItem.Address = newFileName;
|
||||
profileItem.ConfigType = EConfigType.Custom;
|
||||
if (profileItem.Remarks.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.Remarks))
|
||||
{
|
||||
profileItem.Remarks = $"import custom@{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}";
|
||||
}
|
||||
|
|
@ -624,7 +624,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
profileItem.Address = profileItem.Address.TrimEx();
|
||||
profileItem.Id = profileItem.Id.TrimEx();
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
|
|
@ -654,7 +654,7 @@ namespace ServiceLib.Handler
|
|||
profileItem.Path = profileItem.Path.TrimEx();
|
||||
profileItem.Network = string.Empty;
|
||||
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
|
|
@ -689,11 +689,11 @@ namespace ServiceLib.Handler
|
|||
profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!;
|
||||
}
|
||||
|
||||
if (profileItem.StreamSecurity.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.StreamSecurity))
|
||||
{
|
||||
profileItem.StreamSecurity = Global.StreamSecurity;
|
||||
}
|
||||
if (profileItem.Alpn.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.Alpn))
|
||||
{
|
||||
profileItem.Alpn = "h3";
|
||||
}
|
||||
|
|
@ -858,7 +858,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
if (profileItem.Security.IsNotEmpty() && profileItem.Security != Global.None)
|
||||
if (Utils.IsNotEmpty(profileItem.Security) && profileItem.Security != Global.None)
|
||||
{
|
||||
profileItem.Security = Global.None;
|
||||
}
|
||||
|
|
@ -897,7 +897,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
profileItem.ConfigVersion = 2;
|
||||
|
||||
if (profileItem.StreamSecurity.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(profileItem.StreamSecurity))
|
||||
{
|
||||
if (profileItem.StreamSecurity != Global.StreamSecurity
|
||||
&& profileItem.StreamSecurity != Global.StreamSecurityReality)
|
||||
|
|
@ -906,24 +906,24 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
else
|
||||
{
|
||||
if (profileItem.AllowInsecure.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.AllowInsecure))
|
||||
{
|
||||
profileItem.AllowInsecure = config.CoreBasicItem.DefAllowInsecure.ToString().ToLower();
|
||||
}
|
||||
if (profileItem.Fingerprint.IsNullOrEmpty() && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
||||
if (Utils.IsNullOrEmpty(profileItem.Fingerprint) && profileItem.StreamSecurity == Global.StreamSecurityReality)
|
||||
{
|
||||
profileItem.Fingerprint = config.CoreBasicItem.DefFingerprint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (profileItem.Network.IsNotEmpty() && !Global.Networks.Contains(profileItem.Network))
|
||||
if (Utils.IsNotEmpty(profileItem.Network) && !Global.Networks.Contains(profileItem.Network))
|
||||
{
|
||||
profileItem.Network = Global.DefaultNetwork;
|
||||
}
|
||||
|
||||
var maxSort = -1;
|
||||
if (profileItem.IndexId.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(profileItem.IndexId))
|
||||
{
|
||||
profileItem.IndexId = Utils.GetGuid(false);
|
||||
maxSort = ProfileExHandler.Instance.GetMaxSort();
|
||||
|
|
@ -1084,14 +1084,14 @@ namespace ServiceLib.Handler
|
|||
/// <returns>成功导入的数量</returns>
|
||||
private static async Task<int> AddBatchServersCommon(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var subFilter = string.Empty;
|
||||
//remove sub items
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
|
||||
|
|
@ -1122,7 +1122,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
|
||||
//exist sub items //filter
|
||||
if (isSub && subid.IsNotEmpty() && subFilter.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid) && Utils.IsNotEmpty(subFilter))
|
||||
{
|
||||
if (!Regex.IsMatch(profileItem.Remarks, subFilter))
|
||||
{
|
||||
|
|
@ -1163,7 +1163,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
private static async Task<int> AddBatchServers4Custom(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1185,7 +1185,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
if (lstProfiles != null && lstProfiles.Count > 0)
|
||||
{
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
|
|
@ -1236,12 +1236,12 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
profileItem = NaiveproxyFmt.ResolveFull(strData, subRemarks);
|
||||
}
|
||||
if (profileItem is null || profileItem.Address.IsNullOrEmpty())
|
||||
if (profileItem is null || Utils.IsNullOrEmpty(profileItem.Address))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
|
|
@ -1261,12 +1261,12 @@ namespace ServiceLib.Handler
|
|||
|
||||
private static async Task<int> AddBatchServers4SsSIP008(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
await RemoveServersViaSubid(config, subid, isSub);
|
||||
}
|
||||
|
|
@ -1293,13 +1293,13 @@ namespace ServiceLib.Handler
|
|||
|
||||
public static async Task<int> AddBatchServers(Config config, string strData, string subid, bool isSub)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
List<ProfileItem>? lstOriSub = null;
|
||||
ProfileItem? activeProfile = null;
|
||||
if (isSub && subid.IsNotEmpty())
|
||||
if (isSub && Utils.IsNotEmpty(subid))
|
||||
{
|
||||
lstOriSub = await AppHandler.Instance.ProfileItems(subid);
|
||||
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);
|
||||
|
|
@ -1424,7 +1424,7 @@ namespace ServiceLib.Handler
|
|||
item.Memo = subItem.Memo;
|
||||
}
|
||||
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
|
||||
|
|
@ -1457,7 +1457,7 @@ namespace ServiceLib.Handler
|
|||
/// <returns></returns>
|
||||
public static async Task<int> RemoveServersViaSubid(Config config, string subid, bool isSub)
|
||||
{
|
||||
if (subid.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1508,7 +1508,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public static async Task<int> SaveRoutingItem(Config config, RoutingItem item)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
}
|
||||
|
|
@ -1531,7 +1531,7 @@ namespace ServiceLib.Handler
|
|||
/// <returns></returns>
|
||||
public static async Task<int> AddBatchRoutingRules(RoutingItem routingItem, string strData)
|
||||
{
|
||||
if (strData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(strData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1549,7 +1549,7 @@ namespace ServiceLib.Handler
|
|||
routingItem.RuleNum = lstRules.Count;
|
||||
routingItem.RuleSet = JsonUtils.Serialize(lstRules, false);
|
||||
|
||||
if (routingItem.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(routingItem.Id))
|
||||
{
|
||||
routingItem.Id = Utils.GetGuid(false);
|
||||
}
|
||||
|
|
@ -1668,7 +1668,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public static async Task<int> InitRouting(Config config, bool blImportAdvancedRules = false)
|
||||
{
|
||||
if (config.ConstItem.RouteRulesTemplateSourceUrl.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(config.ConstItem.RouteRulesTemplateSourceUrl))
|
||||
{
|
||||
await InitBuiltinRouting(config, blImportAdvancedRules);
|
||||
}
|
||||
|
|
@ -1684,7 +1684,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
var downloadHandle = new DownloadService();
|
||||
var templateContent = await downloadHandle.TryDownloadString(config.ConstItem.RouteRulesTemplateSourceUrl, true, "");
|
||||
if (templateContent.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(templateContent))
|
||||
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
|
||||
|
||||
var template = JsonUtils.Deserialize<RoutingTemplate>(templateContent);
|
||||
|
|
@ -1701,14 +1701,14 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
var item = template.RoutingItems[i];
|
||||
|
||||
if (item.Url.IsNullOrEmpty() && item.RuleSet.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(item.Url) && string.IsNullOrEmpty(item.RuleSet))
|
||||
continue;
|
||||
|
||||
var ruleSetsString = !item.RuleSet.IsNullOrEmpty()
|
||||
var ruleSetsString = !string.IsNullOrEmpty(item.RuleSet)
|
||||
? item.RuleSet
|
||||
: await downloadHandle.TryDownloadString(item.Url, true, "");
|
||||
|
||||
if (ruleSetsString.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(ruleSetsString))
|
||||
continue;
|
||||
|
||||
item.Remarks = $"{template.Version}-{item.Remarks}";
|
||||
|
|
@ -1820,7 +1820,7 @@ namespace ServiceLib.Handler
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(item.Id))
|
||||
{
|
||||
item.Id = Utils.GetGuid(false);
|
||||
}
|
||||
|
|
@ -1841,17 +1841,17 @@ namespace ServiceLib.Handler
|
|||
|
||||
var downloadHandle = new DownloadService();
|
||||
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
|
||||
if (templateContent.IsNullOrEmpty())
|
||||
if (string.IsNullOrEmpty(templateContent))
|
||||
return currentItem;
|
||||
|
||||
var template = JsonUtils.Deserialize<DNSItem>(templateContent);
|
||||
if (template == null)
|
||||
return currentItem;
|
||||
|
||||
if (!template.NormalDNS.IsNullOrEmpty())
|
||||
if (!string.IsNullOrEmpty(template.NormalDNS))
|
||||
template.NormalDNS = await downloadHandle.TryDownloadString(template.NormalDNS, true, "");
|
||||
|
||||
if (!template.TunDNS.IsNullOrEmpty())
|
||||
if (!string.IsNullOrEmpty(template.TunDNS))
|
||||
template.TunDNS = await downloadHandle.TryDownloadString(template.TunDNS, true, "");
|
||||
|
||||
template.Id = currentItem.Id;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
return result;
|
||||
}
|
||||
if (fileName.IsNotEmpty() && result.Data != null)
|
||||
if (Utils.IsNotEmpty(fileName) && result.Data != null)
|
||||
{
|
||||
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ namespace ServiceLib.Handler
|
|||
private async Task<Process?> RunProcess(CoreInfo? coreInfo, string configPath, bool displayLog, bool mayNeedSudo)
|
||||
{
|
||||
var fileName = CoreInfoHandler.Instance.GetCoreExecFile(coreInfo, out var msg);
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
UpdateFunc(false, msg);
|
||||
return null;
|
||||
|
|
@ -274,13 +274,13 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(e.Data))
|
||||
return;
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
};
|
||||
proc.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(e.Data))
|
||||
return;
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||
{
|
||||
if (item.Flow.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Flow))
|
||||
{
|
||||
dicQuery.Add("flow", item.Flow);
|
||||
}
|
||||
|
||||
if (item.StreamSecurity.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.StreamSecurity))
|
||||
{
|
||||
dicQuery.Add("security", item.StreamSecurity);
|
||||
}
|
||||
|
|
@ -32,27 +32,27 @@ namespace ServiceLib.Handler.Fmt
|
|||
dicQuery.Add("security", securityDef);
|
||||
}
|
||||
}
|
||||
if (item.Sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
if (item.Fingerprint.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Fingerprint))
|
||||
{
|
||||
dicQuery.Add("fp", Utils.UrlEncode(item.Fingerprint));
|
||||
}
|
||||
if (item.PublicKey.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.PublicKey))
|
||||
{
|
||||
dicQuery.Add("pbk", Utils.UrlEncode(item.PublicKey));
|
||||
}
|
||||
if (item.ShortId.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.ShortId))
|
||||
{
|
||||
dicQuery.Add("sid", Utils.UrlEncode(item.ShortId));
|
||||
}
|
||||
if (item.SpiderX.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.SpiderX))
|
||||
{
|
||||
dicQuery.Add("spx", Utils.UrlEncode(item.SpiderX));
|
||||
}
|
||||
|
|
@ -61,21 +61,21 @@ namespace ServiceLib.Handler.Fmt
|
|||
dicQuery.Add("allowInsecure", "1");
|
||||
}
|
||||
|
||||
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
|
||||
dicQuery.Add("type", Utils.IsNotEmpty(item.Network) ? item.Network : nameof(ETransport.tcp));
|
||||
|
||||
switch (item.Network)
|
||||
{
|
||||
case nameof(ETransport.tcp):
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.kcp):
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
if (item.Path.IsNotEmpty())
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("seed", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
|
|
@ -83,30 +83,30 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
case nameof(ETransport.ws):
|
||||
case nameof(ETransport.httpupgrade):
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.xhttp):
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
if (item.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(item.HeaderType))
|
||||
if (Utils.IsNotEmpty(item.HeaderType) && Global.XhttpMode.Contains(item.HeaderType))
|
||||
{
|
||||
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType));
|
||||
}
|
||||
if (item.Extra.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Extra))
|
||||
{
|
||||
dicQuery.Add("extra", Utils.UrlEncode(item.Extra));
|
||||
}
|
||||
|
|
@ -115,24 +115,24 @@ namespace ServiceLib.Handler.Fmt
|
|||
case nameof(ETransport.http):
|
||||
case nameof(ETransport.h2):
|
||||
dicQuery["type"] = nameof(ETransport.http);
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
{
|
||||
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("path", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.quic):
|
||||
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
|
||||
dicQuery.Add("headerType", Utils.IsNotEmpty(item.HeaderType) ? item.HeaderType : Global.None);
|
||||
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
|
||||
dicQuery.Add("key", Utils.UrlEncode(item.Path));
|
||||
break;
|
||||
|
||||
case nameof(ETransport.grpc):
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost));
|
||||
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path));
|
||||
|
|
@ -215,10 +215,8 @@ namespace ServiceLib.Handler.Fmt
|
|||
foreach (var item in s)
|
||||
{
|
||||
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
try
|
||||
{
|
||||
string str = config.TrimEx();
|
||||
if (str.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(str))
|
||||
{
|
||||
msg = ResUI.FailedReadConfiguration;
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -36,26 +36,26 @@ namespace ServiceLib.Handler.Fmt
|
|||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.Sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("obfs", "salamander");
|
||||
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
||||
if (item.Ports.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Ports))
|
||||
{
|
||||
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
|
|
@ -53,14 +53,12 @@ namespace ServiceLib.Handler.Fmt
|
|||
{
|
||||
var match = UrlFinder.Match(result);
|
||||
if (!match.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new();
|
||||
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
||||
var tag = match.Groups["tag"].Value;
|
||||
if (tag.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(tag))
|
||||
{
|
||||
item.Remarks = Utils.UrlDecode(tag);
|
||||
}
|
||||
|
|
@ -74,13 +72,11 @@ namespace ServiceLib.Handler.Fmt
|
|||
return null;
|
||||
}
|
||||
if (!details.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
item.Security = details.Groups["method"].Value;
|
||||
item.Id = details.Groups["password"].Value;
|
||||
item.Address = details.Groups["hostname"].Value;
|
||||
item.Port = details.Groups["port"].Value.ToInt();
|
||||
item.Port = Utils.ToInt(details.Groups["port"].Value);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
@ -88,9 +84,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
{
|
||||
var parsedUrl = Utils.TryUri(result);
|
||||
if (parsedUrl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new()
|
||||
{
|
||||
|
|
@ -102,7 +96,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
//2022-blake3
|
||||
if (rawUserInfo.Contains(':'))
|
||||
{
|
||||
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||
if (userInfoParts.Length != 2)
|
||||
{
|
||||
return null;
|
||||
|
|
@ -113,8 +107,8 @@ namespace ServiceLib.Handler.Fmt
|
|||
else
|
||||
{
|
||||
// parse base64 UserInfo
|
||||
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
if (userInfoParts.Length != 2)
|
||||
{
|
||||
return null;
|
||||
|
|
@ -128,7 +122,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
{
|
||||
//obfs-host exists
|
||||
var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host"));
|
||||
if (queryParameters["plugin"].Contains("obfs=http") && obfsHost.IsNotEmpty())
|
||||
if (queryParameters["plugin"].Contains("obfs=http") && Utils.IsNotEmpty(obfsHost))
|
||||
{
|
||||
obfsHost = obfsHost?.Replace("obfs-host=", "");
|
||||
item.Network = Global.DefaultNetwork;
|
||||
|
|
@ -168,7 +162,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
Security = it.method,
|
||||
Id = it.password,
|
||||
Address = it.server,
|
||||
Port = it.server_port.ToInt()
|
||||
Port = Utils.ToInt(it.server_port)
|
||||
};
|
||||
lst.Add(ssItem);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
namespace ServiceLib.Handler.Fmt
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
public class SingboxFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
{
|
||||
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
||||
if (configObjects != null && configObjects.Length > 0)
|
||||
{
|
||||
List<ProfileItem> lstResult = [];
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var url = string.Empty;
|
||||
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
return null;
|
||||
}
|
||||
item.Address = arr1[1][..indexPort];
|
||||
item.Port = arr1[1][(indexPort + 1)..].ToInt();
|
||||
item.Port = Utils.ToInt(arr1[1][(indexPort + 1)..]);
|
||||
item.Security = arr21.First();
|
||||
item.Id = arr21[1];
|
||||
|
||||
|
|
@ -88,9 +88,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
{
|
||||
var parsedUrl = Utils.TryUri(result);
|
||||
if (parsedUrl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProfileItem item = new()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
|
|
@ -23,7 +21,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
ResolveStdTransport(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -31,16 +29,16 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
string url = string.Empty;
|
||||
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
_ = GetStdTransport(item, null, ref dicQuery);
|
||||
GetStdTransport(item, null, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
|
|
@ -38,21 +36,20 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string url = string.Empty;
|
||||
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.Sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Sni))
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Alpn))
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
namespace ServiceLib.Handler.Fmt
|
||||
namespace ServiceLib.Handler.Fmt
|
||||
{
|
||||
public class V2rayFmt : BaseFmt
|
||||
{
|
||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||
{
|
||||
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
||||
if (configObjects != null && configObjects.Length > 0)
|
||||
{
|
||||
List<ProfileItem> lstResult = [];
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
|
|
@ -26,7 +24,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
var query = Utils.ParseQueryString(url.Query);
|
||||
item.Security = query["encryption"] ?? Global.None;
|
||||
item.StreamSecurity = query["security"] ?? "";
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
ResolveStdTransport(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -34,17 +32,16 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string url = string.Empty;
|
||||
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.Security.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Security))
|
||||
{
|
||||
dicQuery.Add("encryption", item.Security);
|
||||
}
|
||||
|
|
@ -52,7 +49,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
{
|
||||
dicQuery.Add("encryption", Global.None);
|
||||
}
|
||||
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||
GetStdTransport(item, Global.None, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var vmessQRCode = new VmessQRCode
|
||||
string url = string.Empty;
|
||||
|
||||
VmessQRCode vmessQRCode = new()
|
||||
{
|
||||
v = item.ConfigVersion,
|
||||
ps = item.Remarks.TrimEx(),
|
||||
|
|
@ -42,7 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
fp = item.Fingerprint
|
||||
};
|
||||
|
||||
var url = JsonUtils.Serialize(vmessQRCode);
|
||||
url = JsonUtils.Serialize(vmessQRCode);
|
||||
url = Utils.Base64Encode(url);
|
||||
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
||||
result = Utils.Base64Decode(result);
|
||||
|
||||
var vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||
if (vmessQRCode == null)
|
||||
{
|
||||
msg = ResUI.FailedConversionConfiguration;
|
||||
|
|
@ -78,12 +78,12 @@ namespace ServiceLib.Handler.Fmt
|
|||
item.AlterId = vmessQRCode.aid;
|
||||
item.Security = Utils.ToString(vmessQRCode.scy);
|
||||
|
||||
item.Security = vmessQRCode.scy.IsNotEmpty() ? vmessQRCode.scy : Global.DefaultSecurity;
|
||||
if (vmessQRCode.net.IsNotEmpty())
|
||||
item.Security = Utils.IsNotEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity;
|
||||
if (Utils.IsNotEmpty(vmessQRCode.net))
|
||||
{
|
||||
item.Network = vmessQRCode.net;
|
||||
}
|
||||
if (vmessQRCode.type.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(vmessQRCode.type))
|
||||
{
|
||||
item.HeaderType = vmessQRCode.type;
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
public static ProfileItem? ResolveStdVmess(string str)
|
||||
{
|
||||
var item = new ProfileItem
|
||||
ProfileItem item = new()
|
||||
{
|
||||
ConfigType = EConfigType.VMess,
|
||||
Security = "auto"
|
||||
|
|
@ -108,9 +108,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
|
||||
var url = Utils.TryUri(str);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Address = url.IdnHost;
|
||||
item.Port = url.Port;
|
||||
|
|
@ -35,30 +33,29 @@ namespace ServiceLib.Handler.Fmt
|
|||
public static string? ToUri(ProfileItem? item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string url = string.Empty;
|
||||
|
||||
var remark = string.Empty;
|
||||
if (item.Remarks.IsNotEmpty())
|
||||
string remark = string.Empty;
|
||||
if (Utils.IsNotEmpty(item.Remarks))
|
||||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.PublicKey.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.PublicKey))
|
||||
{
|
||||
dicQuery.Add("publickey", Utils.UrlEncode(item.PublicKey));
|
||||
}
|
||||
if (item.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Path))
|
||||
{
|
||||
dicQuery.Add("reserved", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
if (item.RequestHost.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.RequestHost))
|
||||
{
|
||||
dicQuery.Add("address", Utils.UrlEncode(item.RequestHost));
|
||||
}
|
||||
if (item.ShortId.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.ShortId))
|
||||
{
|
||||
dicQuery.Add("mtu", Utils.UrlEncode(item.ShortId));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
public static async Task Start(string configPath, int httpPort, int pacPort)
|
||||
{
|
||||
_needRestart = configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning;
|
||||
_needRestart = (configPath != _configPath || httpPort != _httpPort || pacPort != _pacPort || !_isRunning);
|
||||
|
||||
_configPath = configPath;
|
||||
_httpPort = httpPort;
|
||||
|
|
@ -70,7 +70,7 @@ namespace ServiceLib.Handler
|
|||
}
|
||||
|
||||
var client = await _tcpListener.AcceptTcpClientAsync();
|
||||
await Task.Run(() => WriteContent(client));
|
||||
await Task.Run(() => { WriteContent(client); });
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -90,9 +90,7 @@ namespace ServiceLib.Handler
|
|||
public static void Stop()
|
||||
{
|
||||
if (_tcpListener == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_isRunning = false;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
private void IndexIdEnqueue(string indexId)
|
||||
{
|
||||
if (indexId.IsNotEmpty() && !_queIndexIds.Contains(indexId))
|
||||
if (Utils.IsNotEmpty(indexId) && !_queIndexIds.Contains(indexId))
|
||||
{
|
||||
_queIndexIds.Enqueue(indexId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace ServiceLib.Handler.SysProxy
|
|||
try
|
||||
{
|
||||
// set proxy for LAN
|
||||
var result = SetConnectionProxy(null, strProxy, exceptions, type);
|
||||
bool result = SetConnectionProxy(null, strProxy, exceptions, type);
|
||||
// set proxy for dial up connections
|
||||
var connections = EnumerateRasEntries();
|
||||
foreach (var connection in connections)
|
||||
|
|
@ -71,27 +71,27 @@ namespace ServiceLib.Handler.SysProxy
|
|||
}
|
||||
catch
|
||||
{
|
||||
_ = SetProxyFallback(strProxy, exceptions, type);
|
||||
SetProxyFallback(strProxy, exceptions, type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SetConnectionProxy(string? connectionName, string? strProxy, string? exceptions, int type)
|
||||
{
|
||||
var list = new InternetPerConnOptionList();
|
||||
InternetPerConnOptionList list = new();
|
||||
|
||||
var optionCount = 1;
|
||||
int optionCount = 1;
|
||||
if (type == 1) // No proxy
|
||||
{
|
||||
optionCount = 1;
|
||||
}
|
||||
else if (type is 2 or 4) // named proxy or autoproxy script URL
|
||||
{
|
||||
optionCount = exceptions.IsNullOrEmpty() ? 2 : 3;
|
||||
optionCount = string.IsNullOrEmpty(exceptions) ? 2 : 3;
|
||||
}
|
||||
|
||||
var m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
||||
var m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
int m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT;
|
||||
PerConnOption m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
if (type == 2) // named proxy
|
||||
{
|
||||
m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY);
|
||||
|
|
@ -103,9 +103,11 @@ namespace ServiceLib.Handler.SysProxy
|
|||
m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL;
|
||||
}
|
||||
|
||||
var options = new InternetConnectionOption[optionCount];
|
||||
//int optionCount = Utile.IsNullOrEmpty(strProxy) ? 1 : (Utile.IsNullOrEmpty(exceptions) ? 2 : 3);
|
||||
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
|
||||
// USE a proxy server ...
|
||||
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
|
||||
//options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
|
||||
options[0].m_Value.m_Int = m_Int;
|
||||
// use THIS proxy server
|
||||
if (optionCount > 1)
|
||||
|
|
@ -133,20 +135,20 @@ namespace ServiceLib.Handler.SysProxy
|
|||
list.dwOptionCount = options.Length;
|
||||
list.dwOptionError = 0;
|
||||
|
||||
var optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
||||
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
|
||||
// make a pointer out of all that ...
|
||||
var optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
||||
nint optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
|
||||
// copy the array over into that spot in memory ...
|
||||
for (var i = 0; i < options.Length; ++i)
|
||||
for (int i = 0; i < options.Length; ++i)
|
||||
{
|
||||
if (Environment.Is64BitOperatingSystem)
|
||||
{
|
||||
var opt = new nint(optionsPtr.ToInt64() + (i * optSize));
|
||||
nint opt = new(optionsPtr.ToInt64() + (i * optSize));
|
||||
Marshal.StructureToPtr(options[i], opt, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var opt = new nint(optionsPtr.ToInt32() + (i * optSize));
|
||||
nint opt = new(optionsPtr.ToInt32() + (i * optSize));
|
||||
Marshal.StructureToPtr(options[i], opt, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -154,14 +156,14 @@ namespace ServiceLib.Handler.SysProxy
|
|||
list.options = optionsPtr;
|
||||
|
||||
// and then make a pointer out of the whole list
|
||||
var ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
||||
nint ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
|
||||
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
||||
|
||||
// and finally, call the API method!
|
||||
var isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
||||
bool isSuccess = NativeMethods.InternetSetOption(nint.Zero,
|
||||
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
|
||||
ipcoListPtr, list.dwSize);
|
||||
var returnvalue = 0; // ERROR_SUCCESS
|
||||
int returnvalue = 0; // ERROR_SUCCESS
|
||||
if (!isSuccess)
|
||||
{ // get the error codes, they might be helpful
|
||||
returnvalue = Marshal.GetLastPInvokeError();
|
||||
|
|
@ -169,15 +171,13 @@ namespace ServiceLib.Handler.SysProxy
|
|||
else
|
||||
{
|
||||
// Notify the system that the registry settings have been changed and cause them to be refreshed
|
||||
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
||||
_ = NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
|
||||
NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
|
||||
}
|
||||
|
||||
// FREE the data ASAP
|
||||
if (list.szConnection != nint.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(list.szConnection); // release mem 3
|
||||
}
|
||||
if (optionCount > 1)
|
||||
{
|
||||
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
|
||||
|
|
@ -204,18 +204,18 @@ namespace ServiceLib.Handler.SysProxy
|
|||
/// <exception cref="ApplicationException">Error message with win32 error code</exception>
|
||||
private static IEnumerable<string> EnumerateRasEntries()
|
||||
{
|
||||
var entries = 0;
|
||||
int entries = 0;
|
||||
// attempt to query with 1 entry buffer
|
||||
var rasEntryNames = new RASENTRYNAME[1];
|
||||
var bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
RASENTRYNAME[] rasEntryNames = new RASENTRYNAME[1];
|
||||
int bufferSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
rasEntryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
|
||||
var result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
||||
uint result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);
|
||||
// increase buffer if the buffer is not large enough
|
||||
if (result == (uint)ErrorCode.ERROR_BUFFER_TOO_SMALL)
|
||||
{
|
||||
rasEntryNames = new RASENTRYNAME[bufferSize / Marshal.SizeOf(typeof(RASENTRYNAME))];
|
||||
for (var i = 0; i < rasEntryNames.Length; i++)
|
||||
for (int i = 0; i < rasEntryNames.Length; i++)
|
||||
{
|
||||
rasEntryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ namespace ServiceLib.Handler.SysProxy
|
|||
if (result == 0)
|
||||
{
|
||||
var entryNames = new List<string>();
|
||||
for (var i = 0; i < entries; i++)
|
||||
for (int i = 0; i < entries; i++)
|
||||
{
|
||||
entryNames.Add(rasEntryNames[i].szEntryName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
}
|
||||
|
||||
strProxy = string.Empty;
|
||||
if (config.SystemProxyItem.SystemProxyAdvancedProtocol.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(config.SystemProxyItem.SystemProxyAdvancedProtocol))
|
||||
{
|
||||
strProxy = $"{Global.Loopback}:{port}";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace ServiceLib.Handler
|
|||
private static readonly Lazy<WebDavHandler> _instance = new(() => new());
|
||||
public static WebDavHandler Instance => _instance.Value;
|
||||
|
||||
private readonly Config? _config;
|
||||
private Config? _config;
|
||||
private WebDavClient? _client;
|
||||
private string? _lastDescription;
|
||||
private string _webDir = Global.AppName + "_backup";
|
||||
|
|
@ -62,9 +62,7 @@ namespace ServiceLib.Handler
|
|||
private async Task<bool> TryCreateDir()
|
||||
{
|
||||
if (_client is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
var result2 = await _client.Mkcol(_webDir);
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ namespace ServiceLib.Models
|
|||
|
||||
public List<string>? GetAlpn()
|
||||
{
|
||||
return Alpn.IsNullOrEmpty() ? null : Utils.String2List(Alpn);
|
||||
return Utils.IsNullOrEmpty(Alpn) ? null : Utils.String2List(Alpn);
|
||||
}
|
||||
|
||||
public string GetNetwork()
|
||||
{
|
||||
if (Network.IsNullOrEmpty() || !Global.Networks.Contains(Network))
|
||||
if (Utils.IsNullOrEmpty(Network) || !Global.Networks.Contains(Network))
|
||||
{
|
||||
return Global.DefaultNetwork;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
var addressFileName = node.Address;
|
||||
if (addressFileName.IsNullOrEmpty())
|
||||
string addressFileName = node.Address;
|
||||
if (Utils.IsNullOrEmpty(addressFileName))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -60,9 +60,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||
return ret;
|
||||
}
|
||||
|
||||
var tagYamlStr1 = "!<str>";
|
||||
var tagYamlStr2 = "__strn__";
|
||||
var tagYamlStr3 = "!!str";
|
||||
string tagYamlStr1 = "!<str>";
|
||||
string tagYamlStr2 = "__strn__";
|
||||
string tagYamlStr3 = "!!str";
|
||||
var txtFile = File.ReadAllText(addressFileName);
|
||||
txtFile = txtFile.Replace(tagYamlStr1, tagYamlStr2);
|
||||
|
||||
|
|
@ -117,15 +117,13 @@ namespace ServiceLib.Services.CoreConfig
|
|||
if (_config.TunModeItem.EnableTun)
|
||||
{
|
||||
var tun = EmbedUtils.GetEmbedText(Global.ClashTunYaml);
|
||||
if (tun.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(tun))
|
||||
{
|
||||
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
|
||||
if (tunContent != null)
|
||||
{
|
||||
fileContent["tun"] = tunContent["tun"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Mixin
|
||||
try
|
||||
|
|
@ -204,8 +202,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
private void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
||||
{
|
||||
var blPrepend = false;
|
||||
var blRemoved = false;
|
||||
bool blPrepend = false;
|
||||
bool blRemoved = false;
|
||||
if (key.StartsWith("prepend-"))
|
||||
{
|
||||
blPrepend = true;
|
||||
|
|
@ -246,11 +244,17 @@ namespace ServiceLib.Services.CoreConfig
|
|||
if (blPrepend)
|
||||
{
|
||||
lstValue.Reverse();
|
||||
lstValue.ForEach(item => lstOri.Insert(0, item));
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Insert(0, item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lstValue.ForEach(item => lstOri.Add(item));
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
ret.Msg = ResUI.InitialConfiguration;
|
||||
|
||||
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||
var txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
||||
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -138,7 +138,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
ret.Msg = ResUI.InitialConfiguration;
|
||||
|
||||
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -317,7 +317,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
string result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||
string txtOutbound = EmbedUtils.GetEmbedText(Global.SingboxSampleOutbound);
|
||||
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -354,7 +354,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -443,7 +443,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
|
||||
string addressFileName = node.Address;
|
||||
if (addressFileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(addressFileName))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -560,10 +560,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||
inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
inbound.sniff = _config.Inbound.First().SniffingEnabled;
|
||||
inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled;
|
||||
inbound.domain_strategy = _config.RoutingBasicItem.DomainStrategy4Singbox.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||
inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||
|
||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||
if (routing.DomainStrategy4Singbox.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(routing.DomainStrategy4Singbox))
|
||||
{
|
||||
inbound.domain_strategy = routing.DomainStrategy4Singbox;
|
||||
}
|
||||
|
|
@ -583,7 +583,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
singboxConfig.inbounds.Add(inbound3);
|
||||
|
||||
//auth
|
||||
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
|
||||
{
|
||||
inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } };
|
||||
}
|
||||
|
|
@ -601,7 +601,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
_config.TunModeItem.Mtu = Global.TunMtus.First();
|
||||
}
|
||||
if (_config.TunModeItem.Stack.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(_config.TunModeItem.Stack))
|
||||
{
|
||||
_config.TunModeItem.Stack = Global.TunStacks.First();
|
||||
}
|
||||
|
|
@ -674,8 +674,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
case EConfigType.SOCKS:
|
||||
{
|
||||
outbound.version = "5";
|
||||
if (node.Security.IsNotEmpty()
|
||||
&& node.Id.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Security)
|
||||
&& Utils.IsNotEmpty(node.Id))
|
||||
{
|
||||
outbound.username = node.Security;
|
||||
outbound.password = node.Id;
|
||||
|
|
@ -684,8 +684,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
case EConfigType.HTTP:
|
||||
{
|
||||
if (node.Security.IsNotEmpty()
|
||||
&& node.Id.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Security)
|
||||
&& Utils.IsNotEmpty(node.Id))
|
||||
{
|
||||
outbound.username = node.Security;
|
||||
outbound.password = node.Id;
|
||||
|
|
@ -698,7 +698,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
outbound.packet_encoding = "xudp";
|
||||
|
||||
if (node.Flow.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(node.Flow))
|
||||
{
|
||||
await GenOutboundMux(node, outbound);
|
||||
}
|
||||
|
|
@ -719,7 +719,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
outbound.password = node.Id;
|
||||
|
||||
if (node.Path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Path))
|
||||
{
|
||||
outbound.obfs = new()
|
||||
{
|
||||
|
|
@ -755,7 +755,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
outbound.peer_public_key = node.PublicKey;
|
||||
outbound.reserved = Utils.String2List(node.Path)?.Select(int.Parse).ToList();
|
||||
outbound.local_address = Utils.String2List(node.RequestHost);
|
||||
outbound.mtu = node.ShortId.IsNullOrEmpty() ? Global.TunMtus.First() : node.ShortId.ToInt();
|
||||
outbound.mtu = Utils.ToInt(node.ShortId.IsNullOrEmpty() ? Global.TunMtus.First() : node.ShortId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -775,7 +775,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_config.CoreBasicItem.MuxEnabled && _config.Mux4SboxItem.Protocol.IsNotEmpty())
|
||||
if (_config.CoreBasicItem.MuxEnabled && Utils.IsNotEmpty(_config.Mux4SboxItem.Protocol))
|
||||
{
|
||||
var mux = new Multiplex4Sbox()
|
||||
{
|
||||
|
|
@ -801,11 +801,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
if (node.StreamSecurity == Global.StreamSecurityReality || node.StreamSecurity == Global.StreamSecurity)
|
||||
{
|
||||
var server_name = string.Empty;
|
||||
if (node.Sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Sni))
|
||||
{
|
||||
server_name = node.Sni;
|
||||
}
|
||||
else if (node.RequestHost.IsNotEmpty())
|
||||
else if (Utils.IsNotEmpty(node.RequestHost))
|
||||
{
|
||||
server_name = Utils.String2List(node.RequestHost)?.First();
|
||||
}
|
||||
|
|
@ -816,7 +816,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
insecure = Utils.ToBool(node.AllowInsecure.IsNullOrEmpty() ? _config.CoreBasicItem.DefAllowInsecure.ToString().ToLower() : node.AllowInsecure),
|
||||
alpn = node.GetAlpn(),
|
||||
};
|
||||
if (node.Fingerprint.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Fingerprint))
|
||||
{
|
||||
tls.utls = new Utls4Sbox()
|
||||
{
|
||||
|
|
@ -854,8 +854,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
case nameof(ETransport.h2):
|
||||
transport.type = nameof(ETransport.http);
|
||||
transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost);
|
||||
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost);
|
||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.tcp): //http
|
||||
|
|
@ -869,16 +869,16 @@ namespace ServiceLib.Services.CoreConfig
|
|||
else
|
||||
{
|
||||
transport.type = nameof(ETransport.http);
|
||||
transport.host = node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(node.RequestHost);
|
||||
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : Utils.String2List(node.RequestHost);
|
||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(ETransport.ws):
|
||||
transport.type = nameof(ETransport.ws);
|
||||
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||
if (node.RequestHost.IsNotEmpty())
|
||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
||||
if (Utils.IsNotEmpty(node.RequestHost))
|
||||
{
|
||||
transport.headers = new()
|
||||
{
|
||||
|
|
@ -889,8 +889,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
case nameof(ETransport.httpupgrade):
|
||||
transport.type = nameof(ETransport.httpupgrade);
|
||||
transport.path = node.Path.IsNullOrEmpty() ? null : node.Path;
|
||||
transport.host = node.RequestHost.IsNullOrEmpty() ? null : node.RequestHost;
|
||||
transport.path = Utils.IsNullOrEmpty(node.Path) ? null : node.Path;
|
||||
transport.host = Utils.IsNullOrEmpty(node.RequestHost) ? null : node.RequestHost;
|
||||
|
||||
break;
|
||||
|
||||
|
|
@ -1085,7 +1085,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
outbound = item.OutboundTag,
|
||||
};
|
||||
|
||||
if (item.Port.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Port))
|
||||
{
|
||||
if (item.Port.Contains("-"))
|
||||
{
|
||||
|
|
@ -1093,10 +1093,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
else
|
||||
{
|
||||
rule.port = new List<int> { item.Port.ToInt() };
|
||||
rule.port = new List<int> { Utils.ToInt(item.Port) };
|
||||
}
|
||||
}
|
||||
if (item.Network.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.Network))
|
||||
{
|
||||
rule.network = Utils.String2List(item.Network);
|
||||
}
|
||||
|
|
@ -1241,11 +1241,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
var strDNS = string.Empty;
|
||||
if (_config.TunModeItem.EnableTun)
|
||||
{
|
||||
strDNS = string.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS;
|
||||
strDNS = Utils.IsNullOrEmpty(item?.TunDNS) ? EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.TunDNS;
|
||||
}
|
||||
else
|
||||
{
|
||||
strDNS = string.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS;
|
||||
strDNS = Utils.IsNullOrEmpty(item?.NormalDNS) ? EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.NormalDNS;
|
||||
}
|
||||
|
||||
var dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(strDNS);
|
||||
|
|
@ -1274,9 +1274,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||
dns4Sbox.servers.Add(new()
|
||||
{
|
||||
tag = tag,
|
||||
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||
address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.SingboxDomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||
detour = Global.DirectTag,
|
||||
strategy = string.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
||||
strategy = Utils.IsNullOrEmpty(dNSItem?.DomainStrategy4Freedom) ? null : dNSItem?.DomainStrategy4Freedom,
|
||||
});
|
||||
dns4Sbox.rules.Insert(0, new()
|
||||
{
|
||||
|
|
@ -1290,7 +1290,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
});
|
||||
|
||||
var lstDomain = singboxConfig.outbounds
|
||||
.Where(t => t.server.IsNotEmpty() && Utils.IsDomain(t.server))
|
||||
.Where(t => Utils.IsNotEmpty(t.server) && Utils.IsDomain(t.server))
|
||||
.Select(t => t.server)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
|
@ -1394,10 +1394,10 @@ namespace ServiceLib.Services.CoreConfig
|
|||
List<Ruleset4Sbox> customRulesets = [];
|
||||
|
||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||
if (routing.CustomRulesetPath4Singbox.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(routing.CustomRulesetPath4Singbox))
|
||||
{
|
||||
var result = EmbedUtils.LoadResource(routing.CustomRulesetPath4Singbox);
|
||||
if (result.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result))
|
||||
{
|
||||
customRulesets = (JsonUtils.Deserialize<List<Ruleset4Sbox>>(result) ?? [])
|
||||
.Where(t => t.tag != null)
|
||||
|
|
@ -1414,7 +1414,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
singboxConfig.route.rule_set = [];
|
||||
foreach (var item in new HashSet<string>(ruleSets))
|
||||
{
|
||||
if (item.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(item))
|
||||
{ continue; }
|
||||
var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item));
|
||||
if (customRuleset is null)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
ret.Msg = ResUI.InitialConfiguration;
|
||||
|
||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -93,7 +93,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
string result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||
string txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
||||
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -135,7 +135,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
if (Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -216,7 +216,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||
var txtOutbound = EmbedUtils.GetEmbedText(Global.V2raySampleOutbound);
|
||||
if (result.IsNullOrEmpty() || txtOutbound.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -261,7 +261,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
if (item is null || Utils.IsNullOrEmpty(item.Id) || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -371,7 +371,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
|
||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
return ret;
|
||||
|
|
@ -465,7 +465,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
v2rayConfig.inbounds.Add(inbound3);
|
||||
|
||||
//auth
|
||||
if (_config.Inbound.First().User.IsNotEmpty() && _config.Inbound.First().Pass.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass))
|
||||
{
|
||||
inbound3.settings.auth = "password";
|
||||
inbound3.settings.accounts = new List<AccountsItem4Ray> { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } };
|
||||
|
|
@ -487,7 +487,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
|
||||
{
|
||||
string result = EmbedUtils.GetEmbedText(Global.V2raySampleInbound);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
|
@ -515,12 +515,12 @@ namespace ServiceLib.Services.CoreConfig
|
|||
if (v2rayConfig.routing?.rules != null)
|
||||
{
|
||||
v2rayConfig.routing.domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||
v2rayConfig.routing.domainMatcher = _config.RoutingBasicItem.DomainMatcher.IsNullOrEmpty() ? null : _config.RoutingBasicItem.DomainMatcher;
|
||||
v2rayConfig.routing.domainMatcher = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainMatcher) ? null : _config.RoutingBasicItem.DomainMatcher;
|
||||
|
||||
var routing = await ConfigHandler.GetDefaultRouting(_config);
|
||||
if (routing != null)
|
||||
{
|
||||
if (routing.DomainStrategy.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(routing.DomainStrategy))
|
||||
{
|
||||
v2rayConfig.routing.domainStrategy = routing.DomainStrategy;
|
||||
}
|
||||
|
|
@ -551,11 +551,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
if (rule.port.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(rule.port))
|
||||
{
|
||||
rule.port = null;
|
||||
}
|
||||
if (rule.network.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(rule.network))
|
||||
{
|
||||
rule.network = null;
|
||||
}
|
||||
|
|
@ -603,7 +603,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
}
|
||||
if (!hasDomainIp)
|
||||
{
|
||||
if (rule.port.IsNotEmpty()
|
||||
if (Utils.IsNotEmpty(rule.port)
|
||||
|| rule.protocol?.Count > 0
|
||||
|| rule.inboundTag?.Count > 0
|
||||
)
|
||||
|
|
@ -714,8 +714,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
serversItem.method = null;
|
||||
serversItem.password = null;
|
||||
|
||||
if (node.Security.IsNotEmpty()
|
||||
&& node.Id.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Security)
|
||||
&& Utils.IsNotEmpty(node.Id))
|
||||
{
|
||||
SocksUsersItem4Ray socksUsersItem = new()
|
||||
{
|
||||
|
|
@ -868,11 +868,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
alpn = node.GetAlpn(),
|
||||
fingerprint = node.Fingerprint.IsNullOrEmpty() ? _config.CoreBasicItem.DefFingerprint : node.Fingerprint
|
||||
};
|
||||
if (sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(sni))
|
||||
{
|
||||
tlsSettings.serverName = sni;
|
||||
}
|
||||
else if (host.IsNotEmpty())
|
||||
else if (Utils.IsNotEmpty(host))
|
||||
{
|
||||
tlsSettings.serverName = Utils.String2List(host)?.First();
|
||||
}
|
||||
|
|
@ -918,7 +918,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
type = node.HeaderType,
|
||||
domain = host.IsNullOrEmpty() ? null : host
|
||||
};
|
||||
if (path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(path))
|
||||
{
|
||||
kcpSettings.seed = path;
|
||||
}
|
||||
|
|
@ -929,16 +929,16 @@ namespace ServiceLib.Services.CoreConfig
|
|||
WsSettings4Ray wsSettings = new();
|
||||
wsSettings.headers = new Headers4Ray();
|
||||
|
||||
if (host.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(host))
|
||||
{
|
||||
wsSettings.host = host;
|
||||
wsSettings.headers.Host = host;
|
||||
}
|
||||
if (path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(path))
|
||||
{
|
||||
wsSettings.path = path;
|
||||
}
|
||||
if (useragent.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(useragent))
|
||||
{
|
||||
wsSettings.headers.UserAgent = useragent;
|
||||
}
|
||||
|
|
@ -949,11 +949,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
case nameof(ETransport.httpupgrade):
|
||||
HttpupgradeSettings4Ray httpupgradeSettings = new();
|
||||
|
||||
if (path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(path))
|
||||
{
|
||||
httpupgradeSettings.path = path;
|
||||
}
|
||||
if (host.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(host))
|
||||
{
|
||||
httpupgradeSettings.host = host;
|
||||
}
|
||||
|
|
@ -965,19 +965,19 @@ namespace ServiceLib.Services.CoreConfig
|
|||
streamSettings.network = ETransport.xhttp.ToString();
|
||||
XhttpSettings4Ray xhttpSettings = new();
|
||||
|
||||
if (path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(path))
|
||||
{
|
||||
xhttpSettings.path = path;
|
||||
}
|
||||
if (host.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(host))
|
||||
{
|
||||
xhttpSettings.host = host;
|
||||
}
|
||||
if (node.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(node.HeaderType))
|
||||
if (Utils.IsNotEmpty(node.HeaderType) && Global.XhttpMode.Contains(node.HeaderType))
|
||||
{
|
||||
xhttpSettings.mode = node.HeaderType;
|
||||
}
|
||||
if (node.Extra.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(node.Extra))
|
||||
{
|
||||
xhttpSettings.extra = JsonUtils.ParseJson(node.Extra);
|
||||
}
|
||||
|
|
@ -990,7 +990,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
case nameof(ETransport.h2):
|
||||
HttpSettings4Ray httpSettings = new();
|
||||
|
||||
if (host.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(host))
|
||||
{
|
||||
httpSettings.host = Utils.String2List(host);
|
||||
}
|
||||
|
|
@ -1013,7 +1013,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
streamSettings.quicSettings = quicsettings;
|
||||
if (node.StreamSecurity == Global.StreamSecurity)
|
||||
{
|
||||
if (sni.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(sni))
|
||||
{
|
||||
streamSettings.tlsSettings.serverName = sni;
|
||||
}
|
||||
|
|
@ -1027,7 +1027,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
case nameof(ETransport.grpc):
|
||||
GrpcSettings4Ray grpcSettings = new()
|
||||
{
|
||||
authority = host.IsNullOrEmpty() ? null : host,
|
||||
authority = Utils.IsNullOrEmpty(host) ? null : host,
|
||||
serviceName = path,
|
||||
multiMode = node.HeaderType == Global.GrpcMultiMode,
|
||||
idle_timeout = _config.GrpcItem.IdleTimeout,
|
||||
|
|
@ -1058,7 +1058,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
request = request.Replace("$requestUserAgent$", $"{useragent.AppendQuotes()}");
|
||||
//Path
|
||||
string pathHttp = @"/";
|
||||
if (path.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(path))
|
||||
{
|
||||
string[] arrPath = path.Split(',');
|
||||
pathHttp = string.Join(",".AppendQuotes(), arrPath);
|
||||
|
|
@ -1085,13 +1085,13 @@ namespace ServiceLib.Services.CoreConfig
|
|||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||
var normalDNS = item?.NormalDNS;
|
||||
var domainStrategy4Freedom = item?.DomainStrategy4Freedom;
|
||||
if (normalDNS.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(normalDNS))
|
||||
{
|
||||
normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
||||
}
|
||||
|
||||
//Outbound Freedom domainStrategy
|
||||
if (domainStrategy4Freedom.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(domainStrategy4Freedom))
|
||||
{
|
||||
var outbound = v2rayConfig.outbounds.FirstOrDefault(t => t is { protocol: "freedom", tag: Global.DirectTag });
|
||||
if (outbound != null)
|
||||
|
|
@ -1156,7 +1156,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
var dnsServer = new DnsServer4Ray()
|
||||
{
|
||||
address = string.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||
address = Utils.IsNullOrEmpty(dNSItem?.DomainDNSAddress) ? Global.DomainDNSAddress.FirstOrDefault() : dNSItem?.DomainDNSAddress,
|
||||
domains = [node.Address]
|
||||
};
|
||||
servers.AsArray().Add(JsonUtils.SerializeToNode(dnsServer));
|
||||
|
|
@ -1216,7 +1216,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
//fragment proxy
|
||||
if (_config.CoreBasicItem.EnableFragment
|
||||
&& v2rayConfig.outbounds.First().streamSettings?.security.IsNullOrEmpty() == false)
|
||||
&& Utils.IsNotEmpty(v2rayConfig.outbounds.First().streamSettings?.security))
|
||||
{
|
||||
var fragmentOutbound = new Outbounds4Ray
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,14 @@ namespace ServiceLib.Services
|
|||
SetSecurityProtocol(AppHandler.Instance.Config.GuiItem.EnableSecurityProtocolTls13);
|
||||
|
||||
var progress = new Progress<string>();
|
||||
progress.ProgressChanged += (sender, value) => updateFunc?.Invoke(false, $"{value}");
|
||||
progress.ProgressChanged += (sender, value) =>
|
||||
{
|
||||
if (updateFunc != null)
|
||||
{
|
||||
string msg = $"{value}";
|
||||
updateFunc?.Invoke(false, msg);
|
||||
}
|
||||
};
|
||||
|
||||
await DownloaderHelper.Instance.DownloadDataAsync4Speed(webProxy,
|
||||
url,
|
||||
|
|
@ -49,7 +56,10 @@ namespace ServiceLib.Services
|
|||
UpdateCompleted?.Invoke(this, new RetResult(false, $"{ResUI.Downloading} {url}"));
|
||||
|
||||
var progress = new Progress<double>();
|
||||
progress.ProgressChanged += (sender, value) => UpdateCompleted?.Invoke(this, new RetResult(value > 100, $"...{value}%"));
|
||||
progress.ProgressChanged += (sender, value) =>
|
||||
{
|
||||
UpdateCompleted?.Invoke(this, new RetResult(value > 100, $"...{value}%"));
|
||||
};
|
||||
|
||||
var webProxy = await GetWebProxy(blProxy);
|
||||
await DownloaderHelper.Instance.DownloadFileAsync(webProxy,
|
||||
|
|
@ -98,7 +108,7 @@ namespace ServiceLib.Services
|
|||
try
|
||||
{
|
||||
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
|
||||
if (result1.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result1))
|
||||
{
|
||||
return result1;
|
||||
}
|
||||
|
|
@ -116,7 +126,7 @@ namespace ServiceLib.Services
|
|||
try
|
||||
{
|
||||
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
|
||||
if (result2.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result2))
|
||||
{
|
||||
return result2;
|
||||
}
|
||||
|
|
@ -150,7 +160,7 @@ namespace ServiceLib.Services
|
|||
UseProxy = webProxy != null
|
||||
});
|
||||
|
||||
if (userAgent.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
userAgent = Utils.GetVersion(false);
|
||||
}
|
||||
|
|
@ -158,7 +168,7 @@ namespace ServiceLib.Services
|
|||
|
||||
Uri uri = new(url);
|
||||
//Authorization Header
|
||||
if (uri.UserInfo.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(uri.UserInfo))
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
|
||||
}
|
||||
|
|
@ -191,7 +201,7 @@ namespace ServiceLib.Services
|
|||
|
||||
var webProxy = await GetWebProxy(blProxy);
|
||||
|
||||
if (userAgent.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
userAgent = Utils.GetVersion(false);
|
||||
}
|
||||
|
|
@ -253,7 +263,7 @@ namespace ServiceLib.Services
|
|||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
var timer = Stopwatch.StartNew();
|
||||
await client.GetAsync(url, cts.Token).ConfigureAwait(false);
|
||||
await client.GetAsync(url, cts.Token);
|
||||
timer.Stop();
|
||||
oneTime.Add((int)timer.Elapsed.TotalMilliseconds);
|
||||
await Task.Delay(100);
|
||||
|
|
|
|||
|
|
@ -141,7 +141,8 @@ namespace ServiceLib.Services
|
|||
}
|
||||
}));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
Task.WaitAll([.. tasks]);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task RunRealPingBatchAsync(List<ServerTestItem> lstSelected, string exitLoopKey, int pageSize = 0)
|
||||
|
|
@ -215,7 +216,7 @@ namespace ServiceLib.Services
|
|||
await DoRealPing(downloadHandle, it);
|
||||
}));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -290,7 +291,7 @@ namespace ServiceLib.Services
|
|||
}
|
||||
}));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
|
||||
private async Task<int> DoRealPing(DownloadService downloadHandle, ServerTestItem it)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace ServiceLib.Services.Statistics
|
|||
{
|
||||
public class StatisticsSingboxService
|
||||
{
|
||||
private readonly Config _config;
|
||||
private Config _config;
|
||||
private bool _exitFlag;
|
||||
private ClientWebSocket? webSocket;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
|
|
@ -18,7 +18,7 @@ namespace ServiceLib.Services.Statistics
|
|||
_updateFunc = updateFunc;
|
||||
_exitFlag = false;
|
||||
|
||||
_ = Task.Run(Run);
|
||||
Task.Run(Run);
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
|
|
@ -68,7 +68,8 @@ namespace ServiceLib.Services.Statistics
|
|||
}
|
||||
if (webSocket != null)
|
||||
{
|
||||
if (webSocket.State is WebSocketState.Aborted or WebSocketState.Closed)
|
||||
if (webSocket.State == WebSocketState.Aborted
|
||||
|| webSocket.State == WebSocketState.Closed)
|
||||
{
|
||||
webSocket.Abort();
|
||||
webSocket = null;
|
||||
|
|
@ -86,9 +87,9 @@ namespace ServiceLib.Services.Statistics
|
|||
while (!res.CloseStatus.HasValue)
|
||||
{
|
||||
var result = Encoding.UTF8.GetString(buffer, 0, res.Count);
|
||||
if (result.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result))
|
||||
{
|
||||
ParseOutput(result, out var up, out var down);
|
||||
ParseOutput(result, out ulong up, out ulong down);
|
||||
|
||||
_updateFunc?.Invoke(new ServerSpeedItem()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace ServiceLib.Services.Statistics
|
|||
{
|
||||
private const long linkBase = 1024;
|
||||
private ServerSpeedItem _serverSpeedItem = new();
|
||||
private readonly Config _config;
|
||||
private Config _config;
|
||||
private bool _exitFlag;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
|
||||
|
|
@ -15,7 +15,7 @@ namespace ServiceLib.Services.Statistics
|
|||
_updateFunc = updateFunc;
|
||||
_exitFlag = false;
|
||||
|
||||
_ = Task.Run(Run);
|
||||
Task.Run(Run);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
|
@ -60,13 +60,11 @@ namespace ServiceLib.Services.Statistics
|
|||
}
|
||||
|
||||
ServerSpeedItem server = new();
|
||||
foreach (var key in source.stats.outbound.Keys.Cast<string>())
|
||||
foreach (string key in source.stats.outbound.Keys)
|
||||
{
|
||||
var value = source.stats.outbound[key];
|
||||
if (value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var state = JsonUtils.Deserialize<V2rayMetricsVarsLink>(value.ToString());
|
||||
|
||||
if (key.StartsWith(Global.ProxyTag))
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ namespace ServiceLib.Services
|
|||
var url = item.Url.TrimEx();
|
||||
var userAgent = item.UserAgent.TrimEx();
|
||||
var hashCode = $"{item.Remarks}->";
|
||||
if (id.IsNullOrEmpty() || url.IsNullOrEmpty() || (subId.IsNotEmpty() && item.Id != subId))
|
||||
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.Id != subId))
|
||||
{
|
||||
//_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
|
||||
continue;
|
||||
|
|
@ -149,9 +149,9 @@ namespace ServiceLib.Services
|
|||
//one url
|
||||
url = Utils.GetPunycode(url);
|
||||
//convert
|
||||
if (item.ConvertTarget.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.ConvertTarget))
|
||||
{
|
||||
var subConvertUrl = config.ConstItem.SubConvertUrl.IsNullOrEmpty() ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl;
|
||||
var subConvertUrl = Utils.IsNullOrEmpty(config.ConstItem.SubConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.ConstItem.SubConvertUrl;
|
||||
url = string.Format(subConvertUrl!, Utils.UrlEncode(url));
|
||||
if (!url.Contains("target="))
|
||||
{
|
||||
|
|
@ -163,15 +163,15 @@ namespace ServiceLib.Services
|
|||
}
|
||||
}
|
||||
var result = await downloadHandle.TryDownloadString(url, blProxy, userAgent);
|
||||
if (blProxy && result.IsNullOrEmpty())
|
||||
if (blProxy && Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
result = await downloadHandle.TryDownloadString(url, false, userAgent);
|
||||
}
|
||||
|
||||
//more url
|
||||
if (item.ConvertTarget.IsNullOrEmpty() && item.MoreUrl.TrimEx().IsNotEmpty())
|
||||
if (Utils.IsNullOrEmpty(item.ConvertTarget) && Utils.IsNotEmpty(item.MoreUrl.TrimEx()))
|
||||
{
|
||||
if (result.IsNotEmpty() && Utils.IsBase64String(result))
|
||||
if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result))
|
||||
{
|
||||
result = Utils.Base64Decode(result);
|
||||
}
|
||||
|
|
@ -180,17 +180,17 @@ namespace ServiceLib.Services
|
|||
foreach (var it in lstUrl)
|
||||
{
|
||||
var url2 = Utils.GetPunycode(it);
|
||||
if (url2.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url2))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var result2 = await downloadHandle.TryDownloadString(url2, blProxy, userAgent);
|
||||
if (blProxy && result2.IsNullOrEmpty())
|
||||
if (blProxy && Utils.IsNullOrEmpty(result2))
|
||||
{
|
||||
result2 = await downloadHandle.TryDownloadString(url2, false, userAgent);
|
||||
}
|
||||
if (result2.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result2))
|
||||
{
|
||||
if (Utils.IsBase64String(result2))
|
||||
{
|
||||
|
|
@ -204,7 +204,7 @@ namespace ServiceLib.Services
|
|||
}
|
||||
}
|
||||
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ namespace ServiceLib.Services
|
|||
{
|
||||
var url = coreInfo?.ReleaseApiUrl;
|
||||
var result = await downloadHandle.TryDownloadString(url, true, Global.AppName);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
return new RetResult(false, "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task SaveServerAsync()
|
||||
{
|
||||
var remarks = SelectedSource.Remarks;
|
||||
if (remarks.IsNullOrEmpty())
|
||||
string remarks = SelectedSource.Remarks;
|
||||
if (Utils.IsNullOrEmpty(remarks))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SelectedSource.Address.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Address))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
||||
return;
|
||||
|
|
@ -69,7 +69,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task BrowseServer(string fileName)
|
||||
{
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ namespace ServiceLib.ViewModels
|
|||
if (await ConfigHandler.AddCustomServer(_config, item, false) == 0)
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer);
|
||||
if (item.IndexId.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(item.IndexId))
|
||||
{
|
||||
SelectedSource = JsonUtils.DeepCopy(item);
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ namespace ServiceLib.ViewModels
|
|||
private async Task EditServer()
|
||||
{
|
||||
var address = SelectedSource.Address;
|
||||
if (address.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(address))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddressCustom);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -41,19 +41,19 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task SaveServerAsync()
|
||||
{
|
||||
if (SelectedSource.Remarks.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Remarks))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SelectedSource.Address.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Address))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
|
||||
return;
|
||||
}
|
||||
var port = SelectedSource.Port.ToString();
|
||||
if (port.IsNullOrEmpty() || !Utils.IsNumeric(port)
|
||||
if (Utils.IsNullOrEmpty(port) || !Utils.IsNumeric(port)
|
||||
|| SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort)
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
|
||||
|
|
@ -61,20 +61,21 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
if (SelectedSource.ConfigType == EConfigType.Shadowsocks)
|
||||
{
|
||||
if (SelectedSource.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Id))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
|
||||
return;
|
||||
}
|
||||
if (SelectedSource.Security.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Security))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
|
||||
if (SelectedSource.ConfigType != EConfigType.SOCKS
|
||||
&& SelectedSource.ConfigType != EConfigType.HTTP)
|
||||
{
|
||||
if (SelectedSource.Id.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedSource.Id))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
DisplayOperationMsg();
|
||||
_config.WebDavItem = SelectedSource;
|
||||
_ = await ConfigHandler.SaveConfig(_config);
|
||||
await ConfigHandler.SaveConfig(_config);
|
||||
|
||||
var result = await WebDavHandler.Instance.CheckConnection();
|
||||
if (result)
|
||||
|
|
@ -114,7 +114,7 @@ namespace ServiceLib.ViewModels
|
|||
public async Task LocalRestore(string fileName)
|
||||
{
|
||||
DisplayOperationMsg();
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
if (Utils.UpgradeAppExists(out var upgradeFileName))
|
||||
{
|
||||
_ = ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath());
|
||||
ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath());
|
||||
}
|
||||
}
|
||||
service?.Shutdown(true);
|
||||
|
|
@ -164,7 +164,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task<bool> CreateZipFileFromDirectory(string fileName)
|
||||
{
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
var canEditRemove = this.WhenAnyValue(
|
||||
x => x.SelectedSource,
|
||||
selectedSource => selectedSource != null && selectedSource.Id.IsNotEmpty());
|
||||
selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id));
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.AutoRefresh,
|
||||
|
|
@ -53,78 +53,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task Init()
|
||||
{
|
||||
_ = DelayTestTask();
|
||||
}
|
||||
|
||||
private async Task GetClashConnections()
|
||||
{
|
||||
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
|
||||
if (ret == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_ = _updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections);
|
||||
}
|
||||
|
||||
public void RefreshConnections(List<ConnectionItem>? connections)
|
||||
{
|
||||
_connectionItems.Clear();
|
||||
|
||||
var dtNow = DateTime.Now;
|
||||
var lstModel = new List<ClashConnectionModel>();
|
||||
foreach (var item in connections ?? new())
|
||||
{
|
||||
var host = $"{(item.metadata.host.IsNullOrEmpty() ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
|
||||
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var model = new ClashConnectionModel
|
||||
{
|
||||
Id = item.id,
|
||||
Network = item.metadata.network,
|
||||
Type = item.metadata.type,
|
||||
Host = host,
|
||||
Time = (dtNow - item.start).TotalSeconds < 0 ? 1 : (dtNow - item.start).TotalSeconds,
|
||||
Elapsed = (dtNow - item.start).ToString(@"hh\:mm\:ss"),
|
||||
Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}"
|
||||
};
|
||||
|
||||
lstModel.Add(model);
|
||||
}
|
||||
if (lstModel.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_connectionItems.AddRange(lstModel);
|
||||
}
|
||||
|
||||
public async Task ClashConnectionClose(bool all)
|
||||
{
|
||||
var id = string.Empty;
|
||||
if (!all)
|
||||
{
|
||||
var item = SelectedSource;
|
||||
if (item is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
id = item.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
_connectionItems.Clear();
|
||||
}
|
||||
await ClashApiHandler.Instance.ClashConnectionClose(id);
|
||||
await GetClashConnections();
|
||||
}
|
||||
|
||||
public async Task DelayTestTask()
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var numOfExecuted = 1;
|
||||
while (true)
|
||||
|
|
@ -151,5 +80,70 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task GetClashConnections()
|
||||
{
|
||||
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
|
||||
if (ret == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_updateView?.Invoke(EViewAction.DispatcherRefreshConnections, ret?.connections);
|
||||
}
|
||||
|
||||
public void RefreshConnections(List<ConnectionItem>? connections)
|
||||
{
|
||||
_connectionItems.Clear();
|
||||
|
||||
var dtNow = DateTime.Now;
|
||||
var lstModel = new List<ClashConnectionModel>();
|
||||
foreach (var item in connections ?? new())
|
||||
{
|
||||
var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
|
||||
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ClashConnectionModel model = new();
|
||||
|
||||
model.Id = item.id;
|
||||
model.Network = item.metadata.network;
|
||||
model.Type = item.metadata.type;
|
||||
model.Host = host;
|
||||
var sp = (dtNow - item.start);
|
||||
model.Time = sp.TotalSeconds < 0 ? 1 : sp.TotalSeconds;
|
||||
model.Elapsed = sp.ToString(@"hh\:mm\:ss");
|
||||
item.chains?.Reverse();
|
||||
model.Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}";
|
||||
|
||||
lstModel.Add(model);
|
||||
}
|
||||
if (lstModel.Count <= 0)
|
||||
{ return; }
|
||||
|
||||
_connectionItems.AddRange(lstModel);
|
||||
}
|
||||
|
||||
public async Task ClashConnectionClose(bool all)
|
||||
{
|
||||
var id = string.Empty;
|
||||
if (!all)
|
||||
{
|
||||
var item = SelectedSource;
|
||||
if (item is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
id = item.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
_connectionItems.Clear();
|
||||
}
|
||||
await ClashApiHandler.Instance.ClashConnectionClose(id);
|
||||
await GetClashConnections();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
this.WhenAnyValue(
|
||||
x => x.SelectedGroup,
|
||||
y => y != null && y.Name.IsNotEmpty())
|
||||
y => y != null && Utils.IsNotEmpty(y.Name))
|
||||
.Subscribe(c => RefreshProxyDetails(c));
|
||||
|
||||
this.WhenAnyValue(
|
||||
|
|
@ -96,6 +96,7 @@ namespace ServiceLib.ViewModels
|
|||
private async Task Init()
|
||||
{
|
||||
_ = DelayTestTask();
|
||||
await ProxiesReload();
|
||||
}
|
||||
|
||||
private async Task DoRulemodeSelected(bool c)
|
||||
|
|
@ -134,12 +135,22 @@ namespace ServiceLib.ViewModels
|
|||
RefreshProxyDetails(c);
|
||||
}
|
||||
|
||||
private void UpdateHandler(bool notify, string msg)
|
||||
{
|
||||
NoticeHandler.Instance.SendMessageEx(msg);
|
||||
}
|
||||
|
||||
public async Task ProxiesReload()
|
||||
{
|
||||
await GetClashProxies(true);
|
||||
await ProxiesDelayTest();
|
||||
}
|
||||
|
||||
public async Task ProxiesDelayTest()
|
||||
{
|
||||
await ProxiesDelayTest(true);
|
||||
}
|
||||
|
||||
#region proxy function
|
||||
|
||||
private async Task SetRuleMode(ERuleMode mode)
|
||||
|
|
@ -182,7 +193,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
foreach (var it in proxyGroups)
|
||||
{
|
||||
if (it.name.IsNullOrEmpty() || !_proxies.ContainsKey(it.name))
|
||||
if (Utils.IsNullOrEmpty(it.name) || !_proxies.ContainsKey(it.name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -207,8 +218,8 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
continue;
|
||||
}
|
||||
var item = _proxyGroups.FirstOrDefault(t => t.Name == kv.Key);
|
||||
if (item != null && item.Name.IsNotEmpty())
|
||||
var item = _proxyGroups.Where(t => t.Name == kv.Key).FirstOrDefault();
|
||||
if (item != null && Utils.IsNotEmpty(item.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -245,7 +256,7 @@ namespace ServiceLib.ViewModels
|
|||
return;
|
||||
}
|
||||
var name = SelectedGroup?.Name;
|
||||
if (name.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -330,21 +341,21 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task SetActiveProxy()
|
||||
{
|
||||
if (SelectedGroup == null || SelectedGroup.Name.IsNullOrEmpty())
|
||||
if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.Name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (SelectedDetail == null || SelectedDetail.Name.IsNullOrEmpty())
|
||||
if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.Name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var name = SelectedGroup.Name;
|
||||
if (name.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var nameNode = SelectedDetail.Name;
|
||||
if (nameNode.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(nameNode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -358,7 +369,7 @@ namespace ServiceLib.ViewModels
|
|||
await ClashApiHandler.Instance.ClashSetActiveProxy(name, nameNode);
|
||||
|
||||
selectedProxy.now = nameNode;
|
||||
var group = _proxyGroups.FirstOrDefault(it => it.Name == SelectedGroup.Name);
|
||||
var group = _proxyGroups.Where(it => it.Name == SelectedGroup.Name).FirstOrDefault();
|
||||
if (group != null)
|
||||
{
|
||||
group.Now = nameNode;
|
||||
|
|
@ -370,7 +381,7 @@ namespace ServiceLib.ViewModels
|
|||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
}
|
||||
|
||||
private async Task ProxiesDelayTest(bool blAll = true)
|
||||
private async Task ProxiesDelayTest(bool blAll)
|
||||
{
|
||||
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) =>
|
||||
{
|
||||
|
|
@ -379,7 +390,7 @@ namespace ServiceLib.ViewModels
|
|||
await GetClashProxies(true);
|
||||
return;
|
||||
}
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -392,19 +403,19 @@ namespace ServiceLib.ViewModels
|
|||
public void ProxiesDelayTestResult(SpeedTestResult result)
|
||||
{
|
||||
//UpdateHandler(false, $"{item.name}={result}");
|
||||
var detail = _proxyDetails.FirstOrDefault(it => it.Name == result.IndexId);
|
||||
var detail = _proxyDetails.Where(it => it.Name == result.IndexId).FirstOrDefault();
|
||||
if (detail != null)
|
||||
{
|
||||
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
|
||||
if (dicResult != null && dicResult.TryGetValue("delay", out var value))
|
||||
if (dicResult != null && dicResult.ContainsKey("delay"))
|
||||
{
|
||||
detail.Delay = Convert.ToInt32(value.ToString());
|
||||
detail.Delay = Convert.ToInt32(dicResult["delay"].ToString());
|
||||
detail.DelayName = $"{detail.Delay}ms";
|
||||
}
|
||||
else if (dicResult != null && dicResult.TryGetValue("message", out var value1))
|
||||
else if (dicResult != null && dicResult.ContainsKey("message"))
|
||||
{
|
||||
detail.Delay = _delayTimeout;
|
||||
detail.DelayName = $"{value1}";
|
||||
detail.DelayName = $"{dicResult["message"]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -421,7 +432,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task DelayTestTask()
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var numOfExecuted = 1;
|
||||
while (true)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
public class DNSSettingViewModel : MyReactiveObject
|
||||
{
|
||||
[Reactive] public bool UseSystemHosts { get; set; }
|
||||
[Reactive] public string DomainStrategy4Freedom { get; set; }
|
||||
[Reactive] public string DomainDNSAddress { get; set; }
|
||||
[Reactive] public string NormalDNS { get; set; }
|
||||
[Reactive] public bool useSystemHosts { get; set; }
|
||||
[Reactive] public string domainStrategy4Freedom { get; set; }
|
||||
[Reactive] public string domainDNSAddress { get; set; }
|
||||
[Reactive] public string normalDNS { get; set; }
|
||||
|
||||
[Reactive] public string DomainStrategy4Freedom2 { get; set; }
|
||||
[Reactive] public string DomainDNSAddress2 { get; set; }
|
||||
[Reactive] public string NormalDNS2 { get; set; }
|
||||
[Reactive] public string TunDNS2 { get; set; }
|
||||
[Reactive] public string domainStrategy4Freedom2 { get; set; }
|
||||
[Reactive] public string domainDNSAddress2 { get; set; }
|
||||
[Reactive] public string normalDNS2 { get; set; }
|
||||
[Reactive] public string tunDNS2 { get; set; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
|
||||
|
|
@ -31,14 +31,14 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
ImportDefConfig4V2rayCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
NormalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
||||
normalDNS = EmbedUtils.GetEmbedText(Global.DNSV2rayNormalFileName);
|
||||
await Task.CompletedTask;
|
||||
});
|
||||
|
||||
ImportDefConfig4SingboxCmd = ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
NormalDNS2 = EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName);
|
||||
TunDNS2 = EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName);
|
||||
normalDNS2 = EmbedUtils.GetEmbedText(Global.DNSSingboxNormalFileName);
|
||||
tunDNS2 = EmbedUtils.GetEmbedText(Global.TunSingboxDNSFileName);
|
||||
await Task.CompletedTask;
|
||||
});
|
||||
|
||||
|
|
@ -48,47 +48,47 @@ namespace ServiceLib.ViewModels
|
|||
private async Task Init()
|
||||
{
|
||||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||
UseSystemHosts = item.UseSystemHosts;
|
||||
DomainStrategy4Freedom = item?.DomainStrategy4Freedom ?? string.Empty;
|
||||
DomainDNSAddress = item?.DomainDNSAddress ?? string.Empty;
|
||||
NormalDNS = item?.NormalDNS ?? string.Empty;
|
||||
useSystemHosts = item.UseSystemHosts;
|
||||
domainStrategy4Freedom = item?.DomainStrategy4Freedom ?? string.Empty;
|
||||
domainDNSAddress = item?.DomainDNSAddress ?? string.Empty;
|
||||
normalDNS = item?.NormalDNS ?? string.Empty;
|
||||
|
||||
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
||||
DomainStrategy4Freedom2 = item2?.DomainStrategy4Freedom ?? string.Empty;
|
||||
DomainDNSAddress2 = item2?.DomainDNSAddress ?? string.Empty;
|
||||
NormalDNS2 = item2?.NormalDNS ?? string.Empty;
|
||||
TunDNS2 = item2?.TunDNS ?? string.Empty;
|
||||
domainStrategy4Freedom2 = item2?.DomainStrategy4Freedom ?? string.Empty;
|
||||
domainDNSAddress2 = item2?.DomainDNSAddress ?? string.Empty;
|
||||
normalDNS2 = item2?.NormalDNS ?? string.Empty;
|
||||
tunDNS2 = item2?.TunDNS ?? string.Empty;
|
||||
}
|
||||
|
||||
private async Task SaveSettingAsync()
|
||||
{
|
||||
if (NormalDNS.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(normalDNS))
|
||||
{
|
||||
var obj = JsonUtils.ParseJson(NormalDNS);
|
||||
var obj = JsonUtils.ParseJson(normalDNS);
|
||||
if (obj != null && obj["servers"] != null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NormalDNS.Contains('{') || NormalDNS.Contains('}'))
|
||||
if (normalDNS.Contains('{') || normalDNS.Contains('}'))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NormalDNS2.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(normalDNS2))
|
||||
{
|
||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(NormalDNS2);
|
||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(normalDNS2);
|
||||
if (obj2 == null)
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (TunDNS2.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(tunDNS2))
|
||||
{
|
||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(TunDNS2);
|
||||
var obj2 = JsonUtils.Deserialize<Dns4Sbox>(tunDNS2);
|
||||
if (obj2 == null)
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectDNSText);
|
||||
|
|
@ -97,21 +97,21 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
|
||||
var item = await AppHandler.Instance.GetDNSItem(ECoreType.Xray);
|
||||
item.DomainStrategy4Freedom = DomainStrategy4Freedom;
|
||||
item.DomainDNSAddress = DomainDNSAddress;
|
||||
item.UseSystemHosts = UseSystemHosts;
|
||||
item.NormalDNS = NormalDNS;
|
||||
item.DomainStrategy4Freedom = domainStrategy4Freedom;
|
||||
item.DomainDNSAddress = domainDNSAddress;
|
||||
item.UseSystemHosts = useSystemHosts;
|
||||
item.NormalDNS = normalDNS;
|
||||
await ConfigHandler.SaveDNSItems(_config, item);
|
||||
|
||||
var item2 = await AppHandler.Instance.GetDNSItem(ECoreType.sing_box);
|
||||
item2.DomainStrategy4Freedom = DomainStrategy4Freedom2;
|
||||
item2.DomainDNSAddress = DomainDNSAddress2;
|
||||
item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(NormalDNS2));
|
||||
item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(TunDNS2));
|
||||
item2.DomainStrategy4Freedom = domainStrategy4Freedom2;
|
||||
item2.DomainDNSAddress = domainDNSAddress2;
|
||||
item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
|
||||
item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
|
||||
await ConfigHandler.SaveDNSItems(_config, item2);
|
||||
|
||||
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
|
||||
_ = _updateView?.Invoke(EViewAction.CloseWindow, null);
|
||||
_updateView?.Invoke(EViewAction.CloseWindow, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task ScanImageResult(string fileName)
|
||||
{
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task AddScanResultAsync(string? result)
|
||||
{
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.NoValidQRcodeFound);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task SaveSettingAsync()
|
||||
{
|
||||
if (localPort.ToString().IsNullOrEmpty() || !Utils.IsNumeric(localPort.ToString())
|
||||
if (Utils.IsNullOrEmpty(localPort.ToString()) || !Utils.IsNumeric(localPort.ToString())
|
||||
|| localPort <= 0 || localPort >= Global.MaxPort)
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.FillLocalListeningPort);
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public void SetSpeedTestResult(SpeedTestResult result)
|
||||
{
|
||||
if (result.IndexId.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result.IndexId))
|
||||
{
|
||||
NoticeHandler.Instance.SendMessageEx(result.Delay);
|
||||
NoticeHandler.Instance.Enqueue(result.Delay);
|
||||
|
|
@ -279,13 +279,13 @@ namespace ServiceLib.ViewModels
|
|||
return;
|
||||
}
|
||||
|
||||
if (result.Delay.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result.Delay))
|
||||
{
|
||||
int.TryParse(result.Delay, out var temp);
|
||||
item.Delay = temp;
|
||||
item.DelayVal = result.Delay ?? string.Empty;
|
||||
}
|
||||
if (result.Speed.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(result.Speed))
|
||||
{
|
||||
item.SpeedVal = result.Speed ?? string.Empty;
|
||||
}
|
||||
|
|
@ -350,7 +350,7 @@ namespace ServiceLib.ViewModels
|
|||
return;
|
||||
}
|
||||
_serverFilter = ServerFilter;
|
||||
if (_serverFilter.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(_serverFilter))
|
||||
{
|
||||
RefreshServers();
|
||||
}
|
||||
|
|
@ -476,7 +476,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task EditServerAsync(EConfigType eConfigType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||
if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -557,7 +557,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task SetDefaultServer()
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||
if (Utils.IsNullOrEmpty(SelectedProfile?.IndexId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -566,7 +566,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task SetDefaultServer(string indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(indexId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -598,7 +598,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (SelectedServer.ID.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedServer.ID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -614,7 +614,7 @@ namespace ServiceLib.ViewModels
|
|||
return;
|
||||
}
|
||||
var url = FmtHandler.GetShareUri(item);
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -649,7 +649,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task SortServer(string colName)
|
||||
{
|
||||
if (colName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(colName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -776,7 +776,7 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task Export2ClientConfigResult(string fileName, ProfileItem item)
|
||||
{
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -803,7 +803,7 @@ namespace ServiceLib.ViewModels
|
|||
foreach (var it in lstSelecteds)
|
||||
{
|
||||
var url = FmtHandler.GetShareUri(it);
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ namespace ServiceLib.ViewModels
|
|||
|| SelectedSource.Ip?.Count > 0
|
||||
|| SelectedSource.Protocol?.Count > 0
|
||||
|| SelectedSource.Process?.Count > 0
|
||||
|| SelectedSource.Port.IsNotEmpty()
|
||||
|| SelectedSource.Network.IsNotEmpty();
|
||||
|| Utils.IsNotEmpty(SelectedSource.Port)
|
||||
|| Utils.IsNotEmpty(SelectedSource.Network);
|
||||
|
||||
if (!hasRule)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ namespace ServiceLib.ViewModels
|
|||
private async Task SaveRoutingAsync()
|
||||
{
|
||||
string remarks = SelectedRouting.Remarks;
|
||||
if (remarks.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(remarks))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||
return;
|
||||
|
|
@ -252,13 +252,13 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
public async Task ImportRulesFromFileAsync(string fileName)
|
||||
{
|
||||
if (fileName.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var result = EmbedUtils.LoadResource(fileName);
|
||||
if (result.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ namespace ServiceLib.ViewModels
|
|||
private async Task ImportRulesFromUrl()
|
||||
{
|
||||
var url = SelectedRouting.Url;
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.MsgNeedUrl);
|
||||
return;
|
||||
|
|
@ -311,7 +311,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
blReplace = true;
|
||||
}
|
||||
if (clipboardData.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(clipboardData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ namespace ServiceLib.ViewModels
|
|||
public IList<RoutingItemModel> SelectedSources { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string DomainStrategy { get; set; }
|
||||
public string domainStrategy { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string DomainMatcher { get; set; }
|
||||
public string domainMatcher { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string DomainStrategy4Singbox { get; set; }
|
||||
public string domainStrategy4Singbox { get; set; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> RoutingAdvancedAddCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> RoutingAdvancedRemoveCmd { get; }
|
||||
|
|
@ -74,9 +74,9 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
SelectedSource = new();
|
||||
|
||||
DomainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||
DomainMatcher = _config.RoutingBasicItem.DomainMatcher;
|
||||
DomainStrategy4Singbox = _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||
domainStrategy = _config.RoutingBasicItem.DomainStrategy;
|
||||
domainMatcher = _config.RoutingBasicItem.DomainMatcher;
|
||||
domainStrategy4Singbox = _config.RoutingBasicItem.DomainStrategy4Singbox;
|
||||
|
||||
await ConfigHandler.InitBuiltinRouting(_config);
|
||||
await RefreshRoutingItems();
|
||||
|
|
@ -91,7 +91,11 @@ namespace ServiceLib.ViewModels
|
|||
var routings = await AppHandler.Instance.RoutingItems();
|
||||
foreach (var item in routings)
|
||||
{
|
||||
var def = item.Id == _config.RoutingBasicItem.RoutingIndexId;
|
||||
bool def = false;
|
||||
if (item.Id == _config.RoutingBasicItem.RoutingIndexId)
|
||||
{
|
||||
def = true;
|
||||
}
|
||||
|
||||
var it = new RoutingItemModel()
|
||||
{
|
||||
|
|
@ -110,9 +114,9 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
private async Task SaveRoutingAsync()
|
||||
{
|
||||
_config.RoutingBasicItem.DomainStrategy = DomainStrategy;
|
||||
_config.RoutingBasicItem.DomainMatcher = DomainMatcher;
|
||||
_config.RoutingBasicItem.DomainStrategy4Singbox = DomainStrategy4Singbox;
|
||||
_config.RoutingBasicItem.DomainStrategy = domainStrategy;
|
||||
_config.RoutingBasicItem.DomainMatcher = domainMatcher;
|
||||
_config.RoutingBasicItem.DomainStrategy4Singbox = domainStrategy4Singbox;
|
||||
|
||||
if (await ConfigHandler.SaveConfig(_config) == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (SelectedServer.ID.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(SelectedServer.ID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace ServiceLib.ViewModels
|
|||
private async Task SaveSubAsync()
|
||||
{
|
||||
var remarks = SelectedSource.Remarks;
|
||||
if (remarks.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(remarks))
|
||||
{
|
||||
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public partial class App : Application
|
|||
|
||||
var ViewModel = new StatusBarViewModel(null);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
DataContext = ViewModel;
|
||||
this.DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
|
@ -65,20 +65,16 @@ public partial class App : Application
|
|||
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
if (service != null)
|
||||
{
|
||||
_ = service.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void MenuExit_Click(object? sender, EventArgs e)
|
||||
{
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
if (service != null)
|
||||
{
|
||||
await service.MyAppExitAsync(true);
|
||||
}
|
||||
service?.Shutdown(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ namespace v2rayN.Desktop.Common
|
|||
{
|
||||
var sp = GetStorageProvider(owner);
|
||||
if (sp is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Start async operation to open the dialog.
|
||||
var files = await sp.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
|
|
@ -37,9 +35,7 @@ namespace v2rayN.Desktop.Common
|
|||
{
|
||||
var sp = GetStorageProvider(owner);
|
||||
if (sp is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Start async operation to open the dialog.
|
||||
var files = await sp.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
|
|
|
|||
|
|
@ -27,9 +27,7 @@ public class AutoCompleteBox : Avalonia.Controls.AutoCompleteBox
|
|||
{
|
||||
base.OnGotFocus(e);
|
||||
if (IsDropDownOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ namespace v2rayN.Desktop.Converters
|
|||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
_ = int.TryParse(value?.ToString(), out var delay);
|
||||
int.TryParse(value?.ToString(), out var delay);
|
||||
|
||||
return delay switch
|
||||
{
|
||||
<= 0 => new SolidColorBrush(Colors.Red),
|
||||
<= 500 => new SolidColorBrush(Colors.Green),
|
||||
_ => new SolidColorBrush(Colors.IndianRed)
|
||||
};
|
||||
if (delay <= 0)
|
||||
return new SolidColorBrush(Colors.Red);
|
||||
if (delay <= 500)
|
||||
return new SolidColorBrush(Colors.Green);
|
||||
else
|
||||
return new SolidColorBrush(Colors.IndianRed);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ internal class Program
|
|||
if (Utils.IsWindows())
|
||||
{
|
||||
var exePathKey = Utils.GetMd5(Utils.GetExePath());
|
||||
var rebootas = (Args ?? []).Any(t => t == Global.RebootAs);
|
||||
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out var bCreatedNew);
|
||||
var rebootas = (Args ?? Array.Empty<string>()).Any(t => t == Global.RebootAs);
|
||||
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out bool bCreatedNew);
|
||||
if (!rebootas && !bCreatedNew)
|
||||
{
|
||||
ProgramStarted.Set();
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace v2rayN.Desktop.ViewModels
|
|||
y => y != null && !y.IsNullOrEmpty())
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (CurrentLanguage.IsNotEmpty() && _config.UiItem.CurrentLanguage != CurrentLanguage)
|
||||
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage)
|
||||
{
|
||||
_config.UiItem.CurrentLanguage = CurrentLanguage;
|
||||
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ namespace v2rayN.Desktop.Views
|
|||
cmbHeaderType.Items.Clear();
|
||||
|
||||
var network = cmbNetwork.SelectedItem.ToString();
|
||||
if (network.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(network))
|
||||
{
|
||||
cmbHeaderType.Items.Add(Global.None);
|
||||
return;
|
||||
|
|
@ -313,7 +313,7 @@ namespace v2rayN.Desktop.Views
|
|||
private void SetTips()
|
||||
{
|
||||
var network = cmbNetwork.SelectedItem.ToString();
|
||||
if (network.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(network))
|
||||
{
|
||||
network = Global.DefaultNetwork;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,15 +36,15 @@ namespace v2rayN.Desktop.Views
|
|||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.Bind(ViewModel, vm => vm.UseSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainDNSAddress, v => v.cmbdomainDNSAddress.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.NormalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.useSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainDNSAddress, v => v.cmbdomainDNSAddress.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.normalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainDNSAddress2, v => v.cmbdomainDNSAddress2.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.NormalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainDNSAddress2, v => v.cmbdomainDNSAddress2.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.normalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.tunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4V2rayCmd, v => v.btnImportDefConfig4V2ray).DisposeWith(disposables);
|
||||
|
|
|
|||
|
|
@ -461,8 +461,8 @@ namespace v2rayN.Desktop.Views
|
|||
|
||||
private void StorageUI(string? n = null)
|
||||
{
|
||||
_config.UiItem.MainWidth = this.Width;
|
||||
_config.UiItem.MainHeight = this.Height;
|
||||
_config.UiItem.MainWidth = Utils.ToInt(this.Width);
|
||||
_config.UiItem.MainHeight = Utils.ToInt(this.Height);
|
||||
|
||||
if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Horizontal)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ namespace v2rayN.Desktop.Views
|
|||
|
||||
public async Task ShareServer(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -404,7 +404,7 @@ namespace v2rayN.Desktop.Views
|
|||
lvColumnItem.Add(new()
|
||||
{
|
||||
Name = (string)item2.Tag,
|
||||
Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1),
|
||||
Width = item2.IsVisible == true ? Utils.ToInt(item2.ActualWidth) : -1,
|
||||
Index = item2.DisplayIndex
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ namespace v2rayN.Desktop.Views
|
|||
this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.lstRoutings.ItemsSource).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstRoutings.SelectedItem).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy, v => v.cmbdomainStrategy.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainMatcher, v => v.cmbdomainMatcher.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy, v => v.cmbdomainStrategy.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainMatcher, v => v.cmbdomainMatcher.SelectedValue).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.SelectedValue).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd2).DisposeWith(disposables);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace v2rayN.Desktop.Views
|
|||
|
||||
private async Task ShareSub(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace v2rayN.Converters
|
|||
try
|
||||
{
|
||||
var fontFamily = AppHandler.Instance.Config.UiItem.CurrentFontFamily;
|
||||
if (fontFamily.IsNotEmpty())
|
||||
if (Utils.IsNotEmpty(fontFamily))
|
||||
{
|
||||
var fontPath = Utils.GetFontsPath();
|
||||
MyFont = new FontFamily(new Uri(@$"file:///{fontPath}\"), $"./#{fontFamily}");
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace v2rayN.Handler
|
|||
try
|
||||
{
|
||||
var item = await ConfigHandler.GetDefaultRouting(config);
|
||||
if (item == null || item.CustomIcon.IsNullOrEmpty() || !File.Exists(item.CustomIcon))
|
||||
if (item == null || Utils.IsNullOrEmpty(item.CustomIcon) || !File.Exists(item.CustomIcon))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace v2rayN.ViewModels
|
|||
y => y != null && !y.IsNullOrEmpty())
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (CurrentLanguage.IsNotEmpty() && _config.UiItem.CurrentLanguage != CurrentLanguage)
|
||||
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage)
|
||||
{
|
||||
_config.UiItem.CurrentLanguage = CurrentLanguage;
|
||||
Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ namespace v2rayN.Views
|
|||
cmbHeaderType.Items.Clear();
|
||||
|
||||
var network = cmbNetwork.SelectedItem.ToString();
|
||||
if (network.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(network))
|
||||
{
|
||||
cmbHeaderType.Items.Add(Global.None);
|
||||
return;
|
||||
|
|
@ -308,7 +308,7 @@ namespace v2rayN.Views
|
|||
private void SetTips()
|
||||
{
|
||||
var network = cmbNetwork.SelectedItem.ToString();
|
||||
if (network.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(network))
|
||||
{
|
||||
network = Global.DefaultNetwork;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,15 +36,15 @@ namespace v2rayN.Views
|
|||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.Bind(ViewModel, vm => vm.UseSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainDNSAddress, v => v.cmbdomainDNSAddress.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.NormalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.useSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainDNSAddress, v => v.cmbdomainDNSAddress.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.normalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainDNSAddress2, v => v.cmbdomainDNSAddress2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.NormalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.TunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainDNSAddress2, v => v.cmbdomainDNSAddress2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.normalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.tunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ImportDefConfig4V2rayCmd, v => v.btnImportDefConfig4V2ray).DisposeWith(disposables);
|
||||
|
|
|
|||
|
|
@ -414,8 +414,8 @@ namespace v2rayN.Views
|
|||
|
||||
private void StorageUI(string? n = null)
|
||||
{
|
||||
_config.UiItem.MainWidth = this.Width;
|
||||
_config.UiItem.MainHeight = this.Height;
|
||||
_config.UiItem.MainWidth = Utils.ToInt(this.Width);
|
||||
_config.UiItem.MainHeight = Utils.ToInt(this.Height);
|
||||
|
||||
if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Horizontal)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -234,10 +234,10 @@ namespace v2rayN.Views
|
|||
// continue;
|
||||
//}
|
||||
var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)];
|
||||
if (fontFamily.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fontFamily))
|
||||
{
|
||||
fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)];
|
||||
if (fontFamily.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(fontFamily))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ namespace v2rayN.Views
|
|||
lvColumnItem.Add(new()
|
||||
{
|
||||
Name = item2.ExName,
|
||||
Width = (int)(item2.Visibility == Visibility.Visible ? item2.ActualWidth : -1),
|
||||
Width = item2.Visibility == Visibility.Visible ? Utils.ToInt(item2.ActualWidth) : -1,
|
||||
Index = item2.DisplayIndex
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ namespace v2rayN.Views
|
|||
this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.lstRoutings.ItemsSource).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstRoutings.SelectedItem).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy, v => v.cmbdomainStrategy.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainMatcher, v => v.cmbdomainMatcher.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.DomainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy, v => v.cmbdomainStrategy.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainMatcher, v => v.cmbdomainMatcher.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.domainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.Text).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd2).DisposeWith(disposables);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace v2rayN.Views
|
|||
|
||||
private async void ShareSub(string url)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
if (Utils.IsNullOrEmpty(url))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue