Project Reference v2rayN PacLib

This commit is contained in:
2dust
2023-02-01 08:54:52 +08:00
parent bd5a9bb76e
commit 1ae6baac91
5 changed files with 10 additions and 6107 deletions

View File

@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clashN", "clashN\clashN.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clashUpgrade", "clashUpgrade\clashUpgrade.csproj", "{59E0AF2B-9915-47F2-9F5F-9008F47DAE5F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PacLib", "..\..\v2rayN\v2rayN\PacLib\PacLib.csproj", "{E27F1C24-9A0A-47D5-8723-B17D00F264FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{59E0AF2B-9915-47F2-9F5F-9008F47DAE5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59E0AF2B-9915-47F2-9F5F-9008F47DAE5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59E0AF2B-9915-47F2-9F5F-9008F47DAE5F}.Release|Any CPU.Build.0 = Release|Any CPU
{E27F1C24-9A0A-47D5-8723-B17D00F264FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E27F1C24-9A0A-47D5-8723-B17D00F264FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E27F1C24-9A0A-47D5-8723-B17D00F264FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E27F1C24-9A0A-47D5-8723-B17D00F264FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,82 +0,0 @@
using clashN.Mode;
using clashN.Properties;
using System.IO;
using System.Net.Sockets;
using System.Text;
using File = System.IO.File;
namespace clashN.Handler;
public class HttpHandler
{
private static TcpListener _tcpListener;
private static string _pacText;
private static bool _isRunning;
public static void Start(Config config)
{
var path = Path.Combine(Utils.GetConfigPath(), "pac.txt");
if (!File.Exists(path))
{
File.AppendAllText(path, Resources.ResourceManager.GetString("pac"));
}
_pacText = File.ReadAllText(path).Replace("__PROXY__", $"PROXY 127.0.0.1:{config.httpPort};DIRECT;");
Stop();
_tcpListener = TcpListener.Create(config.PacPort);
_isRunning = true;
_tcpListener.Start();
Task.Factory.StartNew(() =>
{
while (_isRunning)
{
try
{
if (!_tcpListener.Pending())
{
Thread.Sleep(10);
continue;
}
var client = _tcpListener.AcceptTcpClient();
Task.Factory.StartNew(() =>
{
var stream = client.GetStream();
var sb = new StringBuilder();
sb.AppendLine("HTTP/1.0 200 OK");
sb.AppendLine("Content-type:application/x-ns-proxy-autoconfig");
sb.AppendLine("Connection:close");
sb.AppendLine("Content-Length:" + Encoding.UTF8.GetByteCount(_pacText));
sb.AppendLine();
sb.Append(_pacText);
var content = Encoding.UTF8.GetBytes(sb.ToString());
stream.Write(content, 0, content.Length);
stream.Flush();
});
}
catch (Exception e)
{
}
}
});
}
public static void Stop()
{
if (_tcpListener != null)
{
try
{
_isRunning = false;
_tcpListener.Stop();
_tcpListener = null;
}
catch (Exception e)
{
}
}
}
}

View File

@@ -1,6 +1,7 @@
using clashN.Mode;
using clashN.Properties;
using clashN.Tool;
using PacLib;
using System.Diagnostics;
using System.IO;
using System.Text;
@@ -77,14 +78,14 @@ namespace clashN.Handler
}
else if (type == ESysProxyType.Pac)
{
HttpHandler.Start(config);
PacHandler.Start(Utils.GetConfigPath(), port, config.PacPort);
var strProxy = $"{Global.httpProtocol}{Global.Loopback}:{config.PacPort}/pac?t={DateTime.Now.Ticks}";
SetIEProxy(false, strProxy, "");
}
if (type != ESysProxyType.Pac)
{
HttpHandler.Stop();
PacHandler.Stop();
}
}
catch (Exception ex)

File diff suppressed because it is too large Load Diff

View File

@@ -38,6 +38,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Sample\SampleMixin.yaml" />
<EmbeddedResource Include="Sample\SampleTun.yaml" />
<ProjectReference Include="..\..\..\v2rayN\v2rayN\PacLib\PacLib.csproj" />
<Resource Include="clashN.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>