启动退出时执行自定义命令

This commit is contained in:
白喵 2020-12-10 06:14:05 +08:00
parent 47dce69aa4
commit b4ae31fc83
2 changed files with 38 additions and 1 deletions

View file

@ -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

View file

@ -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;
}
}
}