From b4ae31fc8376575a01cf4a8355b0197b65f6de02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=96=B5?= <478688389@qq.com> Date: Thu, 10 Dec 2020 06:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=80=80=E5=87=BA=E6=97=B6?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E8=87=AA=E5=AE=9A=E4=B9=89=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN/Forms/MainForm.cs | 22 +++++++++++++++++++++- v2rayN/v2rayN/Mode/Config.cs | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 90977fd0..f1993515 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -49,7 +49,8 @@ namespace v2rayN.Forms ConfigHandler.LoadConfig(ref config); v2rayHandler = new V2rayHandler(); v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; - + string command = config.Event.open; + ExecCmd(command); if (config.enableStatistics) { statistics = new StatisticsHandler(config, UpdateStatisticsHandler); @@ -85,9 +86,11 @@ namespace v2rayN.Forms { if (e.CloseReason == CloseReason.UserClosing) { + string command = config.Event.close; StorageUI(); e.Cancel = true; HideForm(); + ExecCmd(command); return; } } @@ -151,6 +154,23 @@ namespace v2rayN.Forms } } + private void ExecCmd(string cmd) + { + if (!cmd.Equals("")) + { + Process p = new Process(); + p.StartInfo.FileName = "cmd.exe"; + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardInput = true; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.RedirectStandardError = true; + p.StartInfo.CreateNoWindow = true; + p.Start(); + p.StandardInput.WriteLine(cmd + "&exit"); + p.Close(); + } + } + #endregion #region 显示服务器 listview 和 menu diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index fb737942..30115a66 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -206,6 +206,10 @@ namespace v2rayN.Mode { get; set; } + public Event Event + { + get; set; + } #region 函数 @@ -737,4 +741,17 @@ namespace v2rayN.Mode get; set; } } + [Serializable] + public class Event + { + public string open + { + get; set; + } + + public string close + { + get; set; + } + } }