mirror of https://github.com/2dust/v2rayN
commit
300f5ef949
|
@ -63,7 +63,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
|
@ -124,7 +124,7 @@ namespace v2rayN.Forms
|
|||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||
if (vmessItem == null)
|
||||
{
|
||||
UI.Show(msg);
|
||||
UI.ShowWarning(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
|
@ -113,7 +113,7 @@ namespace v2rayN.Forms
|
|||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||
if (vmessItem == null)
|
||||
{
|
||||
UI.Show(msg);
|
||||
UI.ShowWarning(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
if (vmessItem == null)
|
||||
{
|
||||
UI.Show(msg);
|
||||
UI.ShowWarning(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ namespace v2rayN.Forms
|
|||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||
if (vmessItem == null)
|
||||
{
|
||||
UI.Show(msg);
|
||||
UI.ShowWarning(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -804,7 +804,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("FailedImportedCustomServer"));
|
||||
UI.ShowWarning(UIRes.I18N("FailedImportedCustomServer"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1197,7 +1197,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
downloadHandle.DownloadFileAsync(config, url, null, -1);
|
||||
downloadHandle.DownloadFileAsync(url, null, -1);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -1237,7 +1237,7 @@ namespace v2rayN.Forms
|
|||
};
|
||||
}
|
||||
|
||||
AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
|
||||
AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN"));
|
||||
downloadHandle.CheckUpdateAsync("v2rayN");
|
||||
}
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
downloadHandle.DownloadFileAsync(config, url, null, -1);
|
||||
downloadHandle.DownloadFileAsync(url, null, -1);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -1310,7 +1310,7 @@ namespace v2rayN.Forms
|
|||
};
|
||||
}
|
||||
|
||||
AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
|
||||
AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayCore"));
|
||||
downloadHandle.CheckUpdateAsync("Core");
|
||||
}
|
||||
|
||||
|
@ -1391,7 +1391,7 @@ namespace v2rayN.Forms
|
|||
string result = Convert.ToString(e.UserState);
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
UI.Show(UIRes.I18N("NoValidQRcodeFound"));
|
||||
UI.ShowWarning(UIRes.I18N("NoValidQRcodeFound"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,15 +389,19 @@ namespace v2rayN.Forms
|
|||
txtUserblock.Text = Utils.GetEmbedText(Global.CustomRoutingFileName + Global.blockTag);
|
||||
cmbroutingMode.SelectedIndex = 3;
|
||||
|
||||
List<string> lstUrl = new List<string>();
|
||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.agentTag);
|
||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.directTag);
|
||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.blockTag);
|
||||
List<string> lstUrl = new List<string>
|
||||
{
|
||||
Global.CustomRoutingListUrl + Global.agentTag,
|
||||
Global.CustomRoutingListUrl + Global.directTag,
|
||||
Global.CustomRoutingListUrl + Global.blockTag
|
||||
};
|
||||
|
||||
List<TextBox> lstTxt = new List<TextBox>();
|
||||
lstTxt.Add(txtUseragent);
|
||||
lstTxt.Add(txtUserdirect);
|
||||
lstTxt.Add(txtUserblock);
|
||||
List<TextBox> lstTxt = new List<TextBox>
|
||||
{
|
||||
txtUseragent,
|
||||
txtUserdirect,
|
||||
txtUserblock
|
||||
};
|
||||
|
||||
for (int k = 0; k < lstUrl.Count; k++)
|
||||
{
|
||||
|
|
|
@ -226,7 +226,7 @@
|
|||
<value>23</value>
|
||||
</data>
|
||||
<data name="chkAutoRun.Text" xml:space="preserve">
|
||||
<value>Boot automatically</value>
|
||||
<value>Automatically start at system startup</value>
|
||||
</data>
|
||||
<data name="chkEnableStatistics.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -244,7 +244,7 @@
|
|||
<value>29</value>
|
||||
</data>
|
||||
<data name="chkEnableStatistics.Text" xml:space="preserve">
|
||||
<value>Enable Statistics(Realtime net speed and traffic data amount. Need restart v2rayN client)</value>
|
||||
<value>Enable Statistics (Realtime netspeed and traffic records. Require restart the v2rayN client)</value>
|
||||
</data>
|
||||
<data name="chkKcpcongestion.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace v2rayN.Forms
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(UIRes.I18N("OperationFailed"));
|
||||
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,6 +221,10 @@ namespace v2rayN
|
|||
{
|
||||
get; set;
|
||||
}
|
||||
public static System.Threading.Mutex mutexObj
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -540,8 +540,7 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int AddCustomServer(ref Config config, string fileName)
|
||||
{
|
||||
string newFileName = string.Empty;
|
||||
newFileName = string.Format("{0}.json", Utils.GetGUID());
|
||||
string newFileName = string.Format("{0}.json", Utils.GetGUID());
|
||||
//newFileName = Path.Combine(Utils.GetTempPath(), newFileName);
|
||||
|
||||
try
|
||||
|
|
|
@ -172,12 +172,12 @@ namespace v2rayN.Handler
|
|||
|
||||
#region Download
|
||||
|
||||
public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int downloadTimeout)
|
||||
public void DownloadFileAsync(string url, WebProxy webProxy, int downloadTimeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol();
|
||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, "Downloading..."));
|
||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, UIRes.I18N("Downloading")));
|
||||
|
||||
progressPercentage = -1;
|
||||
totalBytesToReceive = 0;
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace v2rayN.Handler
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(string.Format(UIRes.I18N("SaveClientConfigurationIn"), fileName));
|
||||
UI.ShowWarning(string.Format(UIRes.I18N("SaveClientConfigurationIn"), fileName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ namespace v2rayN.Handler
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show(string.Format(UIRes.I18N("SaveServerConfigurationIn"), fileName));
|
||||
UI.ShowWarning(string.Format(UIRes.I18N("SaveServerConfigurationIn"), fileName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,14 +100,14 @@ namespace v2rayN.Handler
|
|||
|
||||
private void RunRealPing()
|
||||
{
|
||||
int pid = -1;
|
||||
try
|
||||
{
|
||||
string msg = string.Empty;
|
||||
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
||||
pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
|
||||
|
||||
Thread.Sleep(5000);
|
||||
//Thread.Sleep(5000);
|
||||
int httpPort = _config.GetLocalPort("speedtest");
|
||||
Task[] tasks = new Task[_selecteds.Count];
|
||||
int i = -1;
|
||||
|
@ -119,7 +119,8 @@ namespace v2rayN.Handler
|
|||
}
|
||||
|
||||
i++;
|
||||
tasks[i] = Task.Run(() => {
|
||||
tasks[i] = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
|
||||
|
@ -137,28 +138,28 @@ namespace v2rayN.Handler
|
|||
}
|
||||
Task.WaitAll(tasks);
|
||||
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config);
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pid > 0) _v2rayHandler.V2rayStopPid(pid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void RunSpeedTest()
|
||||
{
|
||||
int pid = -1;
|
||||
|
||||
if (_config.vmess.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
||||
|
||||
Thread.Sleep(5000);
|
||||
pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
|
||||
|
||||
string url = _config.speedTestUrl;
|
||||
testCounter = 0;
|
||||
|
@ -167,53 +168,35 @@ namespace v2rayN.Handler
|
|||
downloadHandle2 = new DownloadHandle();
|
||||
downloadHandle2.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
_updateFunc(ItemIndex, args.Msg);
|
||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateFunc(ItemIndex, args.Msg);
|
||||
}
|
||||
_updateFunc(ItemIndex, args.Msg);
|
||||
if (args.Success) StartNext();
|
||||
};
|
||||
downloadHandle2.Error += (sender2, args) =>
|
||||
{
|
||||
_updateFunc(ItemIndex, args.GetException().Message);
|
||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StartNext();
|
||||
};
|
||||
}
|
||||
|
||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
||||
StartNext();
|
||||
|
||||
void StartNext()
|
||||
{
|
||||
return;
|
||||
if (testCounter >= _selecteds.Count)
|
||||
{
|
||||
if (pid > 0) _v2rayHandler.V2rayStopPid(pid);
|
||||
return;
|
||||
}
|
||||
|
||||
int httpPort = _config.GetLocalPort("speedtest");
|
||||
int index = _selecteds[testCounter];
|
||||
|
||||
testCounter++;
|
||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
||||
downloadHandle2.DownloadFileAsync(url, webProxy, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private int ServerSpeedTestSub(int index, string url)
|
||||
{
|
||||
if (index >= _selecteds.Count)
|
||||
{
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int httpPort = _config.GetLocalPort("speedtest");
|
||||
index = _selecteds[index];
|
||||
|
||||
testCounter++;
|
||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
||||
downloadHandle2.DownloadFileAsync(_config, url, webProxy, 20);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int GetTcpingTime(string url, int port)
|
||||
{
|
||||
|
|
|
@ -27,8 +27,6 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int GenerateClientConfig(Config config, string fileName, bool blExport, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
//检查GUI设置
|
||||
|
@ -713,8 +711,6 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int GenerateClientCustomConfig(Config config, string fileName, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
//检查GUI设置
|
||||
|
@ -768,8 +764,6 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int GenerateServerConfig(Config config, string fileName, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
//检查GUI设置
|
||||
|
@ -1358,7 +1352,6 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int Export2ClientConfig(Config config, string fileName, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
return GenerateClientConfig(config, fileName, true, out msg);
|
||||
}
|
||||
|
||||
|
@ -1371,7 +1364,6 @@ namespace v2rayN.Handler
|
|||
/// <returns></returns>
|
||||
public static int Export2ServerConfig(Config config, string fileName, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
return GenerateServerConfig(config, fileName, out msg);
|
||||
}
|
||||
|
||||
|
@ -1419,10 +1411,8 @@ namespace v2rayN.Handler
|
|||
#region Gen speedtest config
|
||||
|
||||
|
||||
public static int GenerateClientSpeedtestConfig(Config config, List<int> selecteds, string fileName, out string msg)
|
||||
public static string GenerateClientSpeedtestConfigString(Config config, List<int> selecteds, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
if (config == null
|
||||
|
@ -1432,7 +1422,7 @@ namespace v2rayN.Handler
|
|||
)
|
||||
{
|
||||
msg = UIRes.I18N("CheckServerSettings");
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
|
||||
msg = UIRes.I18N("InitialConfiguration");
|
||||
|
@ -1443,20 +1433,21 @@ namespace v2rayN.Handler
|
|||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
msg = UIRes.I18N("FailedGetDefaultConfiguration");
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
|
||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||
if (v2rayConfig == null)
|
||||
{
|
||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
|
||||
log(configCopy, ref v2rayConfig, false);
|
||||
//routing(config, ref v2rayConfig);
|
||||
dns(configCopy, ref v2rayConfig);
|
||||
|
||||
v2rayConfig.inbounds.RemoveAt(0); // Remove "proxy" service for speedtest, avoiding port conflicts.
|
||||
|
||||
int httpPort = configCopy.GetLocalPort("speedtest");
|
||||
foreach (int index in selecteds)
|
||||
|
@ -1492,16 +1483,14 @@ namespace v2rayN.Handler
|
|||
v2rayConfig.routing.rules.Add(rule);
|
||||
}
|
||||
|
||||
Utils.ToJsonFile(v2rayConfig, fileName);
|
||||
|
||||
msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), configCopy.getSummary());
|
||||
return Utils.ToJson(v2rayConfig);
|
||||
}
|
||||
catch
|
||||
{
|
||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -28,9 +28,11 @@ namespace v2rayN.Handler
|
|||
|
||||
public V2rayHandler()
|
||||
{
|
||||
lstV2ray = new List<string>();
|
||||
lstV2ray.Add("wv2ray");
|
||||
lstV2ray.Add("v2ray");
|
||||
lstV2ray = new List<string>
|
||||
{
|
||||
"wv2ray",
|
||||
"v2ray"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -40,9 +42,8 @@ namespace v2rayN.Handler
|
|||
{
|
||||
if (Global.reloadV2ray)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
||||
if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out msg) != 0)
|
||||
if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out string msg) != 0)
|
||||
{
|
||||
ShowMsg(false, msg);
|
||||
}
|
||||
|
@ -55,24 +56,25 @@ namespace v2rayN.Handler
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 载入V2ray
|
||||
/// 新建进程,载入V2ray配置文件字符串
|
||||
/// 返回新进程pid。
|
||||
/// </summary>
|
||||
public void LoadV2ray(Config config, List<int> _selecteds)
|
||||
public int LoadV2rayConfigString(Config config, List<int> _selecteds)
|
||||
{
|
||||
if (Global.reloadV2ray)
|
||||
int pid = -1;
|
||||
string configStr = V2rayConfigHandler.GenerateClientSpeedtestConfigString(config, _selecteds, out string msg);
|
||||
if (configStr == "")
|
||||
{
|
||||
string msg = string.Empty;
|
||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
||||
if (V2rayConfigHandler.GenerateClientSpeedtestConfig(config, _selecteds, fileName, out msg) != 0)
|
||||
{
|
||||
ShowMsg(false, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMsg(true, msg);
|
||||
V2rayRestart();
|
||||
}
|
||||
ShowMsg(false, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMsg(true, msg);
|
||||
pid = V2rayStartNew(configStr);
|
||||
//V2rayRestart();
|
||||
// start with -config
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -140,6 +142,43 @@ namespace v2rayN.Handler
|
|||
Utils.SaveLog(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// V2ray停止
|
||||
/// </summary>
|
||||
public void V2rayStopPid(int pid)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process _p = Process.GetProcessById(pid);
|
||||
KillProcess(_p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private string V2rayFindexe() {
|
||||
//查找v2ray文件是否存在
|
||||
string fileName = string.Empty;
|
||||
lstV2ray.Reverse();
|
||||
foreach (string name in lstV2ray)
|
||||
{
|
||||
string vName = string.Format("{0}.exe", name);
|
||||
vName = Utils.GetPath(vName);
|
||||
if (File.Exists(vName))
|
||||
{
|
||||
fileName = vName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
|
||||
ShowMsg(true, msg);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// V2ray启动
|
||||
|
@ -150,32 +189,21 @@ namespace v2rayN.Handler
|
|||
|
||||
try
|
||||
{
|
||||
//查找v2ray文件是否存在
|
||||
string fileName = string.Empty;
|
||||
foreach (string name in lstV2ray)
|
||||
{
|
||||
string vName = string.Format("{0}.exe", name);
|
||||
vName = Utils.GetPath(vName);
|
||||
if (File.Exists(vName))
|
||||
{
|
||||
fileName = vName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
|
||||
ShowMsg(true, msg);
|
||||
return;
|
||||
}
|
||||
string fileName = V2rayFindexe();
|
||||
if (fileName == "") return;
|
||||
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = fileName;
|
||||
p.StartInfo.WorkingDirectory = Utils.StartupPath();
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
|
||||
Process p = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
WorkingDirectory = Utils.StartupPath(),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
}
|
||||
};
|
||||
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||
{
|
||||
if (!String.IsNullOrEmpty(e.Data))
|
||||
|
@ -198,6 +226,57 @@ namespace v2rayN.Handler
|
|||
ShowMsg(true, msg);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// V2ray启动,新建进程,传入配置字符串
|
||||
/// </summary>
|
||||
private int V2rayStartNew(string configStr)
|
||||
{
|
||||
ShowMsg(false, string.Format(UIRes.I18N("StartService"), DateTime.Now.ToString()));
|
||||
|
||||
try
|
||||
{
|
||||
string fileName = V2rayFindexe();
|
||||
if (fileName == "") return -1;
|
||||
|
||||
Process p = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = "-config stdin:",
|
||||
WorkingDirectory = Utils.StartupPath(),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
}
|
||||
};
|
||||
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||
{
|
||||
if (!String.IsNullOrEmpty(e.Data))
|
||||
{
|
||||
string msg = e.Data + Environment.NewLine;
|
||||
ShowMsg(false, msg);
|
||||
}
|
||||
});
|
||||
p.Start();
|
||||
p.BeginOutputReadLine();
|
||||
|
||||
p.StandardInput.Write(configStr);
|
||||
p.StandardInput.Close();
|
||||
|
||||
Global.processJob.AddProcess(p.Handle);
|
||||
return p.Id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
string msg = ex.Message;
|
||||
ShowMsg(true, msg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息委托
|
||||
|
|
|
@ -172,8 +172,10 @@ namespace v2rayN.HttpProxyHandler
|
|||
}
|
||||
try
|
||||
{
|
||||
List<string> lstProxy = new List<string>();
|
||||
lstProxy.Add(string.Format("PROXY {0}:{1};", address, port));
|
||||
List<string> lstProxy = new List<string>
|
||||
{
|
||||
string.Format("PROXY {0}:{1};", address, port)
|
||||
};
|
||||
string proxy = string.Join("", lstProxy.ToArray());
|
||||
|
||||
string strPacfile = Utils.GetPath(Global.pacFILE);
|
||||
|
|
|
@ -384,10 +384,9 @@ namespace v2rayN.Mode
|
|||
|
||||
public string getSummary()
|
||||
{
|
||||
string summary = string.Empty;
|
||||
summary = string.Format("{0}-", ((EConfigType)configType).ToString());
|
||||
string summary = string.Format("{0}-", ((EConfigType)configType).ToString());
|
||||
string[] arrAddr = address.Split('.');
|
||||
string addr = string.Empty;
|
||||
string addr;
|
||||
if (arrAddr.Length > 2)
|
||||
{
|
||||
addr = $"{arrAddr[0]}***{arrAddr[arrAddr.Length - 1]}";
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Forms;
|
||||
|
@ -32,13 +31,11 @@ namespace v2rayN
|
|||
|
||||
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
|
||||
Thread.Sleep(300); // 尽量避免切换语言后提示“已经运行”
|
||||
Process instance = RunningInstance();
|
||||
if (instance == null)
|
||||
if (!IsDuplicateInstance())
|
||||
{
|
||||
if (!UnzipLibs())
|
||||
{
|
||||
UI.Show($"Error preparing the environment(准备运行环境出错)");
|
||||
UI.ShowError($"Error preparing the environment(准备运行环境出错)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,7 +51,7 @@ namespace v2rayN
|
|||
}
|
||||
else
|
||||
{
|
||||
UI.Show($"v2rayN is already running(v2rayN已经运行)");
|
||||
UI.ShowWarning($"v2rayN is already running(v2rayN已经运行)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,23 +78,17 @@ namespace v2rayN
|
|||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取正在运行的实例,没有运行的实例返回null;
|
||||
/// 检查是否已在运行
|
||||
/// </summary>
|
||||
public static Process RunningInstance()
|
||||
public static bool IsDuplicateInstance()
|
||||
{
|
||||
Process current = Process.GetCurrentProcess();
|
||||
Process[] processes = Process.GetProcessesByName(current.ProcessName);
|
||||
foreach (Process process in processes)
|
||||
{
|
||||
if (process.Id != current.Id)
|
||||
{
|
||||
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == process.MainModule.FileName)
|
||||
{
|
||||
return process;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
//string name = "v2rayN";
|
||||
|
||||
string name = Utils.GetExePath(); // Allow different locations to run
|
||||
name = name.Replace("\\", "/"); // https://stackoverflow.com/questions/20714120/could-not-find-a-part-of-the-path-error-while-creating-mutex
|
||||
|
||||
Global.mutexObj = new Mutex(false, name, out bool bCreatedNew);
|
||||
return !bCreatedNew;
|
||||
}
|
||||
|
||||
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||
|
|
|
@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyTitle("v2rayN")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("v2rayN")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019-2020 (GPLv3)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
|
|
@ -105,6 +105,15 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Downloading... 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string Downloading {
|
||||
get {
|
||||
return ResourceManager.GetString("Downloading", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 DOWN 的本地化字符串。
|
||||
/// </summary>
|
||||
|
@ -492,6 +501,15 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Start updating {0}... 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string MsgStartUpdating {
|
||||
get {
|
||||
return ResourceManager.GetString("MsgStartUpdating", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Start updating PAC... 的本地化字符串。
|
||||
/// </summary>
|
||||
|
@ -501,15 +519,6 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Start updating V2ray... 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string MsgStartUpdatingV2rayCore {
|
||||
get {
|
||||
return ResourceManager.GetString("MsgStartUpdatingV2rayCore", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Subscription content decoding failed (non-BASE64 code) 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -132,6 +132,9 @@
|
|||
<data name="CustomServerTips" xml:space="preserve">
|
||||
<value>Note that custom configuration relies entirely on your own configuration and does not work with all settings. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound.</value>
|
||||
</data>
|
||||
<data name="Downloading" xml:space="preserve">
|
||||
<value>Downloading...</value>
|
||||
</data>
|
||||
<data name="downloadSpeed" xml:space="preserve">
|
||||
<value>DOWN</value>
|
||||
</data>
|
||||
|
@ -264,8 +267,8 @@
|
|||
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
||||
<value>Start updating PAC...</value>
|
||||
</data>
|
||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
||||
<value>Start updating V2ray...</value>
|
||||
<data name="MsgStartUpdating" xml:space="preserve">
|
||||
<value>Start updating {0}...</value>
|
||||
</data>
|
||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||
<value>Subscription content decoding failed (non-BASE64 code)</value>
|
||||
|
|
|
@ -132,6 +132,9 @@
|
|||
<data name="CustomServerTips" xml:space="preserve">
|
||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时,系统代理才可用</value>
|
||||
</data>
|
||||
<data name="Downloading" xml:space="preserve">
|
||||
<value>下载开始...</value>
|
||||
</data>
|
||||
<data name="downloadSpeed" xml:space="preserve">
|
||||
<value>下载</value>
|
||||
</data>
|
||||
|
@ -262,10 +265,10 @@
|
|||
<value>开始获取订阅内容</value>
|
||||
</data>
|
||||
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
||||
<value>开始更新PAC...</value>
|
||||
<value>开始更新 PAC...</value>
|
||||
</data>
|
||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
||||
<value>开始更新V2ray...</value>
|
||||
<data name="MsgStartUpdating" xml:space="preserve">
|
||||
<value>开始更新 {0}...</value>
|
||||
</data>
|
||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||
<value>订阅内容解码失败(非BASE64码)</value>
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace v2rayN
|
|||
if (extendedInfoPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(extendedInfoPtr);
|
||||
extendedInfoPtr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,18 @@ namespace v2rayN
|
|||
{
|
||||
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
public static void ShowWarning(string msg)
|
||||
{
|
||||
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
public static void ShowError(string msg)
|
||||
{
|
||||
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
public static DialogResult ShowYesNo(string msg)
|
||||
{
|
||||
return MessageBox.Show(msg, "YesNo", MessageBoxButtons.YesNo);
|
||||
return MessageBox.Show(msg, "v2rayN", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
}
|
||||
|
||||
//public static string GetResourseString(string key)
|
||||
|
|
|
@ -121,7 +121,7 @@ namespace v2rayN
|
|||
/// <returns></returns>
|
||||
public static int ToJsonFile(Object obj, string filePath)
|
||||
{
|
||||
int result = -1;
|
||||
int result;
|
||||
try
|
||||
{
|
||||
using (StreamWriter file = File.CreateText(filePath))
|
||||
|
@ -485,24 +485,16 @@ namespace v2rayN
|
|||
/// </summary>
|
||||
/// <param name="run"></param>
|
||||
/// <returns></returns>
|
||||
public static int SetAutoRun(bool run)
|
||||
public static void SetAutoRun(bool run)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
string exePath = GetExePath();
|
||||
RegWriteValue(autoRunRegPath, autoRunName, exePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegWriteValue(autoRunRegPath, autoRunName, "");
|
||||
}
|
||||
string exePath = GetExePath();
|
||||
RegWriteValue(autoRunRegPath, autoRunName, run ? exePath : "");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -551,15 +543,7 @@ namespace v2rayN
|
|||
|
||||
public static string StartupPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
string exePath = GetExePath();
|
||||
return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Application.StartupPath;
|
||||
}
|
||||
return Application.StartupPath;
|
||||
}
|
||||
|
||||
public static string RegReadValue(string path, string name, string def)
|
||||
|
@ -625,7 +609,7 @@ namespace v2rayN
|
|||
long roundtripTime = -1;
|
||||
try
|
||||
{
|
||||
int timeout = 120;
|
||||
int timeout = 30;
|
||||
int echoNum = 2;
|
||||
Ping pingSender = new Ping();
|
||||
for (int i = 0; i < echoNum; i++)
|
||||
|
@ -883,7 +867,6 @@ namespace v2rayN
|
|||
|
||||
public static string ScanScreen()
|
||||
{
|
||||
string ret = string.Empty;
|
||||
try
|
||||
{
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
|
@ -921,7 +904,7 @@ namespace v2rayN
|
|||
Result result = reader.decode(bitmap);
|
||||
if (result != null)
|
||||
{
|
||||
ret = result.Text;
|
||||
string ret = result.Text;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
this.btnClose.Location = new System.Drawing.Point(367, 118);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(184, 89);
|
||||
this.btnClose.TabIndex = 6;
|
||||
this.btnClose.TabIndex = 1;
|
||||
this.btnClose.Text = "&Exit(退出)";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
|
@ -52,7 +52,7 @@
|
|||
this.btnOK.Location = new System.Drawing.Point(81, 118);
|
||||
this.btnOK.Name = "btnOK";
|
||||
this.btnOK.Size = new System.Drawing.Size(184, 89);
|
||||
this.btnOK.TabIndex = 7;
|
||||
this.btnOK.TabIndex = 0;
|
||||
this.btnOK.Text = "&Upgrade(升级)";
|
||||
this.btnOK.UseVisualStyleBackColor = true;
|
||||
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
|
||||
|
@ -89,7 +89,6 @@
|
|||
this.Name = "MainForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "v2rayUpgrade";
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
|
|
@ -8,28 +8,24 @@ namespace v2rayUpgrade
|
|||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private string[] _args;
|
||||
private string _tempFileName = "v2rayUpgradeTemp.zip";
|
||||
|
||||
private readonly string defaultFilename = "v2ray-windows.zip";
|
||||
private string fileName;
|
||||
|
||||
public MainForm(string[] args)
|
||||
{
|
||||
InitializeComponent();
|
||||
_args = args;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
fileName = args[0];
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
private void showWarn(string message)
|
||||
{
|
||||
|
||||
MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
private void btnOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_args.Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Process[] existing = Process.GetProcessesByName("v2rayN");
|
||||
|
@ -45,19 +41,24 @@ namespace v2rayUpgrade
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace);
|
||||
showWarn("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace);
|
||||
return;
|
||||
}
|
||||
|
||||
string fileName = GetPath(_tempFileName);
|
||||
try
|
||||
{
|
||||
File.Delete(fileName);
|
||||
File.Copy(_args[0], fileName);
|
||||
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
MessageBox.Show("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
|
||||
return;
|
||||
if (File.Exists(defaultFilename))
|
||||
{
|
||||
fileName = defaultFilename;
|
||||
}
|
||||
else
|
||||
{
|
||||
showWarn("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string startKey = "v2rayN/";
|
||||
|
@ -86,23 +87,13 @@ namespace v2rayUpgrade
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Upgrade Failed(升级失败)." + ex.StackTrace);
|
||||
showWarn("Upgrade Failed(升级失败)." + ex.StackTrace);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
MessageBox.Show("Upgrade successed(升级成功)");
|
||||
Process.Start("v2rayN.exe");
|
||||
MessageBox.Show("Upgrade successed(升级成功)", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start("v2rayN.exe");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
|
@ -118,15 +109,7 @@ namespace v2rayUpgrade
|
|||
|
||||
public static string StartupPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
string exePath = GetExePath();
|
||||
return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Application.StartupPath;
|
||||
}
|
||||
return Application.StartupPath;
|
||||
}
|
||||
public static string GetPath(string fileName)
|
||||
{
|
||||
|
|
|
@ -11,12 +11,6 @@ namespace v2rayUpgrade
|
|||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length <= 0)
|
||||
{
|
||||
MessageBox.Show("Please use v2rayN to upgrade(请用v2rayN升级)");
|
||||
return;
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm(args));
|
||||
|
|
|
@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("v2rayUpgrade")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019-2020 (GPLv3)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
@ -31,5 +31,4 @@ using System.Runtime.InteropServices;
|
|||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
|
|
Loading…
Reference in New Issue