mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
parent
d7c5161431
commit
22f0d04f01
6 changed files with 29 additions and 24 deletions
|
@ -85,13 +85,19 @@ public class Utils
|
|||
/// Base64 Encode
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <param name="removePadding"></param>
|
||||
/// <returns></returns>
|
||||
public static string Base64Encode(string plainText)
|
||||
public static string Base64Encode(string plainText, bool removePadding = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
|
||||
return Convert.ToBase64String(plainTextBytes);
|
||||
var base64 = Convert.ToBase64String(plainTextBytes);
|
||||
if (removePadding)
|
||||
{
|
||||
base64 = base64.TrimEnd('=');
|
||||
}
|
||||
return base64;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -112,7 +118,7 @@ public class Utils
|
|||
{
|
||||
if (plainText.IsNullOrEmpty())
|
||||
{
|
||||
return "";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
plainText = plainText.Trim()
|
||||
|
@ -947,7 +953,7 @@ public class Utils
|
|||
if (SetUnixFileMode(fileName))
|
||||
{
|
||||
Logging.SaveLog($"Successfully set the file execution permission, {fileName}");
|
||||
return "";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (fileName.Contains(' '))
|
||||
|
|
|
@ -27,7 +27,7 @@ public class FmtHandler
|
|||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
return "";
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ShadowsocksFmt : BaseFmt
|
|||
// item.port);
|
||||
//url = Utile.Base64Encode(url);
|
||||
//new Sip002
|
||||
var pw = Utils.Base64Encode($"{item.Security}:{item.Id}");
|
||||
var pw = Utils.Base64Encode($"{item.Security}:{item.Id}", true);
|
||||
return ToUri(EConfigType.Shadowsocks, item.Address, item.Port, pw, null, remark);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SocksFmt : BaseFmt
|
|||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
//new
|
||||
var pw = Utils.Base64Encode($"{item.Security}:{item.Id}");
|
||||
var pw = Utils.Base64Encode($"{item.Security}:{item.Id}", true);
|
||||
return ToUri(EConfigType.SOCKS, item.Address, item.Port, pw, null, remark);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ public sealed class AppManager
|
|||
private Config _config;
|
||||
private int? _statePort;
|
||||
private int? _statePort2;
|
||||
private WindowsJob? _processJob;
|
||||
public static AppManager Instance => _instance.Value;
|
||||
public Config Config => _config;
|
||||
|
||||
|
@ -136,21 +135,6 @@ public sealed class AppManager
|
|||
return localPort + (int)protocol;
|
||||
}
|
||||
|
||||
public void AddProcess(nint processHandle)
|
||||
{
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
_processJob ??= new();
|
||||
try
|
||||
{
|
||||
_processJob?.AddProcess(processHandle);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Config
|
||||
|
||||
#region SqliteHelper
|
||||
|
|
|
@ -8,6 +8,7 @@ public class CoreManager
|
|||
private static readonly Lazy<CoreManager> _instance = new(() => new());
|
||||
public static CoreManager Instance => _instance.Value;
|
||||
private Config _config;
|
||||
private WindowsJob? _processJob;
|
||||
private ProcessService? _processService;
|
||||
private ProcessService? _processPreService;
|
||||
private bool _linuxSudo = false;
|
||||
|
@ -264,14 +265,28 @@ public class CoreManager
|
|||
await procService.StartAsync();
|
||||
|
||||
await Task.Delay(100);
|
||||
AppManager.Instance.AddProcess(procService.Handle);
|
||||
|
||||
if (procService is null or { HasExited: true })
|
||||
{
|
||||
throw new Exception(ResUI.FailedToRunCore);
|
||||
}
|
||||
AddProcessJob(procService.Handle);
|
||||
|
||||
return procService;
|
||||
}
|
||||
|
||||
private void AddProcessJob(nint processHandle)
|
||||
{
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
_processJob ??= new();
|
||||
try
|
||||
{
|
||||
_processJob?.AddProcess(processHandle);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Process
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue