mirror of https://github.com/2dust/v2rayN
up job
parent
3e35882fee
commit
8bcbd34c27
|
@ -30,6 +30,7 @@ namespace v2rayN.Forms
|
||||||
this.WindowState = FormWindowState.Minimized;
|
this.WindowState = FormWindowState.Minimized;
|
||||||
HideForm();
|
HideForm();
|
||||||
this.Text = Utils.GetVersion();
|
this.Text = Utils.GetVersion();
|
||||||
|
Global.processJob = new Job();
|
||||||
|
|
||||||
Application.ApplicationExit += (sender, args) =>
|
Application.ApplicationExit += (sender, args) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -161,7 +161,7 @@ namespace v2rayN
|
||||||
slow = 3000
|
slow = 3000
|
||||||
}
|
}
|
||||||
public const string StatisticLogOverall = "StatisticLogOverall.json";
|
public const string StatisticLogOverall = "StatisticLogOverall.json";
|
||||||
|
|
||||||
public const string IEProxyExceptions = "<local>;localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;172.32.*";
|
public const string IEProxyExceptions = "<local>;localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;172.32.*";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -216,6 +216,11 @@ namespace v2rayN
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Job processJob
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using v2rayN.Mode;
|
using v2rayN.Mode;
|
||||||
|
|
||||||
namespace v2rayN.Handler
|
namespace v2rayN.Handler
|
||||||
|
@ -147,6 +148,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = fileName;
|
p.StartInfo.FileName = fileName;
|
||||||
|
p.StartInfo.WorkingDirectory = Utils.StartupPath();
|
||||||
p.StartInfo.UseShellExecute = false;
|
p.StartInfo.UseShellExecute = false;
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
p.StartInfo.CreateNoWindow = true;
|
p.StartInfo.CreateNoWindow = true;
|
||||||
|
@ -162,6 +164,8 @@ namespace v2rayN.Handler
|
||||||
p.Start();
|
p.Start();
|
||||||
p.BeginOutputReadLine();
|
p.BeginOutputReadLine();
|
||||||
processId = p.Id;
|
processId = p.Id;
|
||||||
|
|
||||||
|
Global.processJob.AddProcess(p.Handle);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace v2rayN.HttpProxyHandler
|
||||||
int localPort = config.GetLocalPort(Global.InboundSocks);
|
int localPort = config.GetLocalPort(Global.InboundSocks);
|
||||||
if (localPort > 0)
|
if (localPort > 0)
|
||||||
{
|
{
|
||||||
PrivoxyHandler.Instance.Start(localPort, config);
|
PrivoxyHandler.Instance.Restart(localPort, config);
|
||||||
if (PrivoxyHandler.Instance.RunningPort > 0)
|
if (PrivoxyHandler.Instance.RunningPort > 0)
|
||||||
{
|
{
|
||||||
Global.sysAgent = true;
|
Global.sysAgent = true;
|
||||||
|
|
|
@ -22,18 +22,17 @@ namespace v2rayN.HttpProxyHandler
|
||||||
|
|
||||||
private static int _uid;
|
private static int _uid;
|
||||||
private static string _uniqueConfigFile;
|
private static string _uniqueConfigFile;
|
||||||
private static Job _privoxyJob;
|
|
||||||
private Process _process;
|
private Process _process;
|
||||||
|
private static string _privoxyName = "v2ray_privoxy";
|
||||||
|
|
||||||
static PrivoxyHandler()
|
static PrivoxyHandler()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_uid = Application.StartupPath.GetHashCode(); // Currently we use ss's StartupPath to identify different Privoxy instance.
|
_uid = Application.StartupPath.GetHashCode();
|
||||||
_uniqueConfigFile = string.Format("privoxy_{0}.conf", _uid);
|
_uniqueConfigFile = string.Format("privoxy_{0}.conf", _uid);
|
||||||
_privoxyJob = new Job();
|
|
||||||
|
|
||||||
FileManager.UncompressFile(Utils.GetTempPath("v2ray_privoxy.exe"), Resources.privoxy_exe);
|
FileManager.UncompressFile(Utils.GetTempPath($"{_privoxyName}.exe"), Resources.privoxy_exe);
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
@ -41,11 +40,6 @@ namespace v2rayN.HttpProxyHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PrivoxyHandler()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单例
|
/// 单例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -66,17 +60,20 @@ namespace v2rayN.HttpProxyHandler
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Restart(int localPort, Config config)
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
Start(localPort, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Start(int localPort, Config config)
|
public void Start(int localPort, Config config)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_process == null)
|
if (_process == null)
|
||||||
{
|
{
|
||||||
Process[] existingPrivoxy = Process.GetProcessesByName("v2ray_privoxy");
|
|
||||||
foreach (Process p in existingPrivoxy.Where(IsChildProcess))
|
|
||||||
{
|
|
||||||
KillProcess(p);
|
|
||||||
}
|
|
||||||
string privoxyConfig = Resources.privoxy_conf;
|
string privoxyConfig = Resources.privoxy_conf;
|
||||||
RunningPort = config.GetLocalPort(Global.InboundHttp);
|
RunningPort = config.GetLocalPort(Global.InboundHttp);
|
||||||
privoxyConfig = privoxyConfig.Replace("__SOCKS_PORT__", localPort.ToString());
|
privoxyConfig = privoxyConfig.Replace("__SOCKS_PORT__", localPort.ToString());
|
||||||
|
@ -96,7 +93,7 @@ namespace v2rayN.HttpProxyHandler
|
||||||
// Configure the process using the StartInfo properties.
|
// Configure the process using the StartInfo properties.
|
||||||
StartInfo =
|
StartInfo =
|
||||||
{
|
{
|
||||||
FileName = "v2ray_privoxy.exe",
|
FileName = $"{_privoxyName}.exe",
|
||||||
Arguments = _uniqueConfigFile,
|
Arguments = _uniqueConfigFile,
|
||||||
WorkingDirectory = Utils.GetTempPath(),
|
WorkingDirectory = Utils.GetTempPath(),
|
||||||
WindowStyle = ProcessWindowStyle.Hidden,
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
|
@ -110,12 +107,13 @@ namespace v2rayN.HttpProxyHandler
|
||||||
* Add this process to job obj associated with this ss process, so that
|
* Add this process to job obj associated with this ss process, so that
|
||||||
* when ss exit unexpectedly, this process will be forced killed by system.
|
* when ss exit unexpectedly, this process will be forced killed by system.
|
||||||
*/
|
*/
|
||||||
_privoxyJob.AddProcess(_process.Handle);
|
|
||||||
|
|
||||||
|
Global.processJob.AddProcess(_process.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
RunningPort = 0;
|
||||||
Utils.SaveLog(ex.Message, ex);
|
Utils.SaveLog(ex.Message, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +127,14 @@ namespace v2rayN.HttpProxyHandler
|
||||||
_process = null;
|
_process = null;
|
||||||
RunningPort = 0;
|
RunningPort = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Process[] existingPrivoxy = Process.GetProcessesByName(_privoxyName);
|
||||||
|
foreach (Process p in existingPrivoxy.Where(IsChildProcess))
|
||||||
|
{
|
||||||
|
KillProcess(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void KillProcess(Process p)
|
private static void KillProcess(Process p)
|
||||||
|
@ -168,7 +174,7 @@ namespace v2rayN.HttpProxyHandler
|
||||||
*/
|
*/
|
||||||
var path = process.MainModule.FileName;
|
var path = process.MainModule.FileName;
|
||||||
|
|
||||||
return Utils.GetTempPath("v2ray_privoxy.exe").Equals(path);
|
return Utils.GetTempPath($"{_privoxyName}.exe").Equals(path);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace v2rayN
|
||||||
|
|
||||||
if (!succ)
|
if (!succ)
|
||||||
{
|
{
|
||||||
//Logging.Error("Failed to call AssignProcessToJobObject! GetLastError=" + Marshal.GetLastWin32Error());
|
Utils.SaveLog("Failed to call AssignProcessToJobObject! GetLastError=" + Marshal.GetLastWin32Error());
|
||||||
}
|
}
|
||||||
|
|
||||||
return succ;
|
return succ;
|
||||||
|
|
Loading…
Reference in New Issue