diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs index 8d112758..426672d0 100644 --- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs @@ -60,8 +60,8 @@ this.menuExport2ServerConfig = new System.Windows.Forms.ToolStripMenuItem(); this.menuExport2ShareUrl = new System.Windows.Forms.ToolStripMenuItem(); this.menuExport2SubContent = new System.Windows.Forms.ToolStripMenuItem(); - this.qrCodeControl = new v2rayN.Forms.QRCodeControl(); this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton(); + this.qrCodeControl = new v2rayN.Forms.QRCodeControl(); this.notifyMain = new System.Windows.Forms.NotifyIcon(this.components); this.cmsMain = new System.Windows.Forms.ContextMenuStrip(this.components); this.menuSysAgentMode = new System.Windows.Forms.ToolStripMenuItem(); @@ -70,6 +70,8 @@ this.menuGlobalPAC = new System.Windows.Forms.ToolStripMenuItem(); this.menuKeep = new System.Windows.Forms.ToolStripMenuItem(); this.menuKeepPAC = new System.Windows.Forms.ToolStripMenuItem(); + this.menuKeepNothing = new System.Windows.Forms.ToolStripMenuItem(); + this.menuKeepPACNothing = new System.Windows.Forms.ToolStripMenuItem(); this.menuServers = new System.Windows.Forms.ToolStripMenuItem(); this.menuAddServers2 = new System.Windows.Forms.ToolStripMenuItem(); this.menuScanScreen2 = new System.Windows.Forms.ToolStripMenuItem(); @@ -111,8 +113,8 @@ this.tsbCheckClearPACList = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator10 = new System.Windows.Forms.ToolStripSeparator(); this.tsbHelp = new System.Windows.Forms.ToolStripDropDownButton(); - this.tsbV2rayWebsite = new System.Windows.Forms.ToolStripMenuItem(); this.tsbAbout = new System.Windows.Forms.ToolStripMenuItem(); + this.tsbV2rayWebsite = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator12 = new System.Windows.Forms.ToolStripSeparator(); this.tsbLanguageDef = new System.Windows.Forms.ToolStripMenuItem(); this.tsbLanguageZhHans = new System.Windows.Forms.ToolStripMenuItem(); @@ -358,11 +360,6 @@ resources.ApplyResources(this.menuExport2SubContent, "menuExport2SubContent"); this.menuExport2SubContent.Click += new System.EventHandler(this.menuExport2SubContent_Click); // - // qrCodeControl - // - resources.ApplyResources(this.qrCodeControl, "qrCodeControl"); - this.qrCodeControl.Name = "qrCodeControl"; - // // tsbServer // this.tsbServer.DropDown = this.cmsLv; @@ -370,6 +367,11 @@ resources.ApplyResources(this.tsbServer, "tsbServer"); this.tsbServer.Name = "tsbServer"; // + // qrCodeControl + // + resources.ApplyResources(this.qrCodeControl, "qrCodeControl"); + this.qrCodeControl.Name = "qrCodeControl"; + // // notifyMain // this.notifyMain.ContextMenuStrip = this.cmsMain; @@ -400,7 +402,9 @@ this.menuGlobal, this.menuGlobalPAC, this.menuKeep, - this.menuKeepPAC}); + this.menuKeepPAC, + this.menuKeepNothing, + this.menuKeepPACNothing}); this.menuSysAgentMode.Name = "menuSysAgentMode"; resources.ApplyResources(this.menuSysAgentMode, "menuSysAgentMode"); // @@ -434,6 +438,18 @@ resources.ApplyResources(this.menuKeepPAC, "menuKeepPAC"); this.menuKeepPAC.Click += new System.EventHandler(this.menuKeepPAC_Click); // + // menuKeepNothing + // + this.menuKeepNothing.Name = "menuKeepNothing"; + resources.ApplyResources(this.menuKeepNothing, "menuKeepNothing"); + this.menuKeepNothing.Click += new System.EventHandler(this.menuKeepNothing_Click); + // + // menuKeepPACNothing + // + this.menuKeepPACNothing.Name = "menuKeepPACNothing"; + resources.ApplyResources(this.menuKeepPACNothing, "menuKeepPACNothing"); + this.menuKeepPACNothing.Click += new System.EventHandler(this.menuKeepPACNothing_Click); + // // menuServers // this.menuServers.Name = "menuServers"; @@ -713,18 +729,18 @@ resources.ApplyResources(this.tsbHelp, "tsbHelp"); this.tsbHelp.Name = "tsbHelp"; // - // tsbV2rayWebsite - // - this.tsbV2rayWebsite.Name = "tsbV2rayWebsite"; - resources.ApplyResources(this.tsbV2rayWebsite, "tsbV2rayWebsite"); - this.tsbV2rayWebsite.Click += new System.EventHandler(this.tsbV2rayWebsite_Click); - // // tsbAbout // this.tsbAbout.Name = "tsbAbout"; resources.ApplyResources(this.tsbAbout, "tsbAbout"); this.tsbAbout.Click += new System.EventHandler(this.tsbAbout_Click); // + // tsbV2rayWebsite + // + this.tsbV2rayWebsite.Name = "tsbV2rayWebsite"; + resources.ApplyResources(this.tsbV2rayWebsite, "tsbV2rayWebsite"); + this.tsbV2rayWebsite.Click += new System.EventHandler(this.tsbV2rayWebsite_Click); + // // toolStripSeparator12 // this.toolStripSeparator12.Name = "toolStripSeparator12"; @@ -886,6 +902,8 @@ private System.Windows.Forms.ToolStripMenuItem menuNotEnabledHttp; private System.Windows.Forms.ToolStripSeparator toolStripSeparator13; private System.Windows.Forms.ToolStripMenuItem tsbV2rayWebsite; + private System.Windows.Forms.ToolStripMenuItem menuKeepNothing; + private System.Windows.Forms.ToolStripMenuItem menuKeepPACNothing; } } diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 4c69f799..af4b26d1 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -1,1500 +1,1496 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.IO.Compression; -using System.Text; -using System.Windows.Forms; -using v2rayN.Handler; -using v2rayN.HttpProxyHandler; -using v2rayN.Mode; -using v2rayN.Base; -using v2rayN.Tool; -using System.Diagnostics; -using v2rayN.Properties; -using Newtonsoft.Json; - -namespace v2rayN.Forms -{ - public partial class MainForm : BaseForm - { - private V2rayHandler v2rayHandler; - private List lvSelecteds = new List(); - private StatisticsHandler statistics = null; - - #region Window 事件 - - public MainForm() - { - InitializeComponent(); - this.ShowInTaskbar = false; - this.WindowState = FormWindowState.Minimized; - HideForm(); - this.Text = Utils.GetVersion(); - Global.processJob = new Job(); - - Application.ApplicationExit += (sender, args) => - { - v2rayHandler.V2rayStop(); - - HttpProxyHandle.CloseHttpAgent(config); - PACServerHandle.Stop(); - - ConfigHandler.SaveConfig(ref config); - statistics?.SaveToFile(); - statistics?.Close(); - }; - } - - private void MainForm_Load(object sender, EventArgs e) - { - ConfigHandler.LoadConfig(ref config); - v2rayHandler = new V2rayHandler(); - v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; - - if (config.enableStatistics) - { - statistics = new StatisticsHandler(config, UpdateStatisticsHandler); - } - } - - private void MainForm_VisibleChanged(object sender, EventArgs e) - { - if (statistics == null || !statistics.Enable) return; - if ((sender as Form).Visible) - { - statistics.UpdateUI = true; - } - else - { - statistics.UpdateUI = false; - } - } - - private void MainForm_Shown(object sender, EventArgs e) - { - InitServersView(); - RefreshServers(); - lvServers.AutoResizeColumns(); - - LoadV2ray(); - - HideForm(); - - } - - private void MainForm_FormClosing(object sender, FormClosingEventArgs e) - { - if (e.CloseReason == CloseReason.UserClosing) - { - e.Cancel = true; - HideForm(); - return; - } - } - - private void MainForm_Resize(object sender, EventArgs e) - { - //if (this.WindowState == FormWindowState.Minimized) - //{ - // HideForm(); - //} - //else - //{ - // //this.splitContainer1.SplitterDistance = config.uiItem.mainQRCodeWidth; - //} - } - - private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e) - { - //config.uiItem.mainQRCodeWidth = splitContainer1.SplitterDistance; - } - - //private const int WM_QUERYENDSESSION = 0x0011; - //protected override void WndProc(ref Message m) - //{ - // switch (m.Msg) - // { - // case WM_QUERYENDSESSION: - // Utils.SaveLog("Windows shutdown UnsetProxy"); - - // ConfigHandler.ToJsonFile(config); - // statistics?.SaveToFile(); - // ProxySetting.UnsetProxy(); - // m.Result = (IntPtr)1; - // break; - // default: - // base.WndProc(ref m); - // break; - // } - //} - #endregion - - #region 显示服务器 listview 和 menu - - /// - /// 刷新服务器 - /// - private void RefreshServers() - { - RefreshServersView(); - RefreshServersMenu(); - } - - /// - /// 初始化服务器列表 - /// - private void InitServersView() - { - lvServers.Items.Clear(); - - lvServers.GridLines = true; - lvServers.FullRowSelect = true; - lvServers.View = View.Details; - lvServers.Scrollable = true; - lvServers.MultiSelect = true; - lvServers.HeaderStyle = ColumnHeaderStyle.Nonclickable; - - lvServers.Columns.Add("", 30, HorizontalAlignment.Center); - lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvAlias"), 100, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvAddress"), 120, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvPort"), 50, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvEncryptionMethod"), 90, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvTransportProtocol"), 70, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvSubscription"), 50, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvTestResults"), 70, HorizontalAlignment.Left); - - if (statistics != null && statistics.Enable) - { - lvServers.Columns.Add(UIRes.I18N("LvTodayDownloadDataAmount"), 70, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvTodayUploadDataAmount"), 70, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvTotalDownloadDataAmount"), 70, HorizontalAlignment.Left); - lvServers.Columns.Add(UIRes.I18N("LvTotalUploadDataAmount"), 70, HorizontalAlignment.Left); - } - } - - /// - /// 刷新服务器列表 - /// - private void RefreshServersView() - { - lvServers.Items.Clear(); - - for (int k = 0; k < config.vmess.Count; k++) - { - string def = string.Empty; - string totalUp = string.Empty, - totalDown = string.Empty, - todayUp = string.Empty, - todayDown = string.Empty; - if (config.index.Equals(k)) - { - def = "√"; - } - - VmessItem item = config.vmess[k]; - - ListViewItem lvItem = null; - if (statistics != null && statistics.Enable) - { - var sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId()); - if (sItem != null) - { - totalUp = Utils.HumanFy(sItem.totalUp); - totalDown = Utils.HumanFy(sItem.totalDown); - todayUp = Utils.HumanFy(sItem.todayUp); - todayDown = Utils.HumanFy(sItem.todayDown); - } - - lvItem = new ListViewItem(new string[] - { - def, - ((EConfigType)item.configType).ToString(), - item.remarks, - item.address, - item.port.ToString(), - //item.id, - //item.alterId.ToString(), - item.security, - item.network, - item.getSubRemarks(config), - item.testResult, - todayDown, - todayUp, - totalDown, - totalUp - }); - } - else - { - lvItem = new ListViewItem(new string[] - { - def, - ((EConfigType)item.configType).ToString(), - item.remarks, - item.address, - item.port.ToString(), - //item.id, - //item.alterId.ToString(), - item.security, - item.network, - item.getSubRemarks(config), - item.testResult - }); - } - - if (lvItem != null) lvServers.Items.Add(lvItem); - } - - //if (lvServers.Items.Count > 0) - //{ - // if (lvServers.Items.Count <= testConfigIndex) - // { - // testConfigIndex = lvServers.Items.Count - 1; - // } - // lvServers.Items[testConfigIndex].Selected = true; - // lvServers.Select(); - //} - } - - /// - /// 刷新托盘服务器菜单 - /// - private void RefreshServersMenu() - { - menuServers.DropDownItems.Clear(); - - List lst = new List(); - for (int k = 0; k < config.vmess.Count; k++) - { - VmessItem item = config.vmess[k]; - string name = item.getSummary(); - - ToolStripMenuItem ts = new ToolStripMenuItem(name); - ts.Tag = k; - if (config.index.Equals(k)) - { - ts.Checked = true; - } - ts.Click += new EventHandler(ts_Click); - lst.Add(ts); - } - menuServers.DropDownItems.AddRange(lst.ToArray()); - } - - private void ts_Click(object sender, EventArgs e) - { - try - { - ToolStripItem ts = (ToolStripItem)sender; - int index = Utils.ToInt(ts.Tag); - SetDefaultServer(index); - } - catch - { - } - } - - private void lvServers_SelectedIndexChanged(object sender, EventArgs e) - { - int index = -1; - try - { - if (lvServers.SelectedIndices.Count > 0) - { - index = lvServers.SelectedIndices[0]; - } - } - catch - { - } - if (index < 0) - { - return; - } - //qrCodeControl.showQRCode(index, config); - } - - private void DisplayToolStatus() - { - toolSslSocksPort.Text = - toolSslHttpPort.Text = - toolSslPacPort.Text = "OFF"; - - toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}"; - - if (config.listenerType != 0) - { - toolSslHttpPort.Text = $"{Global.Loopback}:{Global.httpPort}"; - if (config.listenerType == 2 || config.listenerType == 4) - { - if (PACServerHandle.IsRunning) - { - toolSslPacPort.Text = $"{HttpProxyHandle.GetPacUrl()}"; - } - else - { - toolSslPacPort.Text = UIRes.I18N("StartPacFailed"); - } - } - } - - notifyMain.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon); - } - private void ssMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - if (!Utils.IsNullOrEmpty(e.ClickedItem.Text)) - { - Utils.SetClipboardData(e.ClickedItem.Text); - } +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.IO.Compression; +using System.Text; +using System.Windows.Forms; +using v2rayN.Handler; +using v2rayN.HttpProxyHandler; +using v2rayN.Mode; +using v2rayN.Base; +using v2rayN.Tool; +using System.Diagnostics; +using v2rayN.Properties; +using Newtonsoft.Json; + +namespace v2rayN.Forms +{ + public partial class MainForm : BaseForm + { + private V2rayHandler v2rayHandler; + private List lvSelecteds = new List(); + private StatisticsHandler statistics = null; + + #region Window 事件 + + public MainForm() + { + InitializeComponent(); + this.ShowInTaskbar = false; + this.WindowState = FormWindowState.Minimized; + HideForm(); + this.Text = Utils.GetVersion(); + Global.processJob = new Job(); + + Application.ApplicationExit += (sender, args) => + { + v2rayHandler.V2rayStop(); + + HttpProxyHandle.CloseHttpAgent(config); + PACServerHandle.Stop(); + + ConfigHandler.SaveConfig(ref config); + statistics?.SaveToFile(); + statistics?.Close(); + }; } - #endregion - - #region http proxy 操作 - private void RestartHttpProxy() + private void MainForm_Load(object sender, EventArgs e) { - HttpProxyHandle.RestartHttpAgent(config, true); - } - #endregion - - #region v2ray 操作 + ConfigHandler.LoadConfig(ref config); + v2rayHandler = new V2rayHandler(); + v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; - /// - /// 载入V2ray - /// - private void LoadV2ray() - { - tsbReload.Enabled = false; - - if (Global.reloadV2ray) - { - ClearMsg(); - } - v2rayHandler.LoadV2ray(config); - Global.reloadV2ray = false; - ConfigHandler.SaveConfig(ref config, false); - statistics?.SaveToFile(); - - ChangePACButtonStatus(config.listenerType); - - tsbReload.Enabled = true; - } - - /// - /// 关闭V2ray - /// - private void CloseV2ray() - { - ConfigHandler.SaveConfig(ref config, false); - statistics?.SaveToFile(); - - ChangePACButtonStatus(0); - - v2rayHandler.V2rayStop(); - } - - #endregion - - #region 功能按钮 - - private void lvServers_Click(object sender, EventArgs e) - { - int index = -1; - try - { - if (lvServers.SelectedIndices.Count > 0) - { - index = lvServers.SelectedIndices[0]; - } - } - catch - { - } - if (index < 0) - { - return; - } - qrCodeControl.showQRCode(index, config); - } - - private void lvServers_DoubleClick(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - - if (config.vmess[index].configType == (int)EConfigType.Vmess) - { - var fm = new AddServerForm(); - fm.EditIndex = index; - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - } - else if (config.vmess[index].configType == (int)EConfigType.Shadowsocks) - { - var fm = new AddServer3Form(); - fm.EditIndex = index; - if (fm.ShowDialog() == DialogResult.OK) - { - RefreshServers(); - LoadV2ray(); - } - } - else if (config.vmess[index].configType == (int)EConfigType.Socks) - { - var fm = new AddServer4Form(); - fm.EditIndex = index; - if (fm.ShowDialog() == DialogResult.OK) - { - RefreshServers(); - LoadV2ray(); - } - } - else - { - var fm2 = new AddServer2Form(); - fm2.EditIndex = index; - if (fm2.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - } - } - - private void lvServers_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control) - { - switch (e.KeyCode) - { - case Keys.A: - menuSelectAll_Click(null, null); - break; - case Keys.C: - menuExport2ShareUrl_Click(null, null); - break; - case Keys.V: - menuAddServers_Click(null, null); - break; - case Keys.P: - menuPingServer_Click(null, null); - break; - case Keys.O: - menuTcpingServer_Click(null, null); - break; - case Keys.R: - menuRealPingServer_Click(null, null); - break; - case Keys.S: - menuScanScreen_Click(null, null); - break; - case Keys.T: - menuSpeedServer_Click(null, null); - break; - } - } - else - { - switch (e.KeyCode) - { - case Keys.Enter: - menuSetDefaultServer_Click(null, null); - break; - case Keys.Delete: - menuRemoveServer_Click(null, null); - break; - case Keys.T: - menuMoveTop_Click(null, null); - break; - case Keys.B: - menuMoveBottom_Click(null, null); - break; - case Keys.U: - menuMoveUp_Click(null, null); - break; - case Keys.D: - menuMoveDown_Click(null, null); - break; - } - } - } - - private void menuAddVmessServer_Click(object sender, EventArgs e) - { - AddServerForm fm = new AddServerForm(); - fm.EditIndex = -1; - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - } - - private void menuRemoveServer_Click(object sender, EventArgs e) - { - - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - if (UI.ShowYesNo(UIRes.I18N("RemoveServer")) == DialogResult.No) - { - return; - } - for (int k = lvSelecteds.Count - 1; k >= 0; k--) - { - ConfigHandler.RemoveServer(ref config, lvSelecteds[k]); - } - //刷新 - RefreshServers(); - LoadV2ray(); - - } - - private void menuRemoveDuplicateServer_Click(object sender, EventArgs e) - { - List servers = null; - Utils.DedupServerList(config.vmess, out servers); - int oldCount = config.vmess.Count; - int newCount = servers.Count; - if (servers != null) - { - config.vmess = servers; - } - //刷新 - RefreshServers(); - LoadV2ray(); - UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount)); - } - - private void menuCopyServer_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - if (ConfigHandler.CopyServer(ref config, index) == 0) - { - //刷新 - RefreshServers(); - } - } - - private void menuSetDefaultServer_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - SetDefaultServer(index); - } - - - private void menuPingServer_Click(object sender, EventArgs e) - { - Speedtest("ping"); - } - private void menuTcpingServer_Click(object sender, EventArgs e) - { - Speedtest("tcping"); - } - - private void menuRealPingServer_Click(object sender, EventArgs e) - { - //if (!config.sysAgentEnabled) - //{ - // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); - // return; - //} - - //UI.Show(UIRes.I18N("SpeedServerTips")); - - Speedtest("realping"); - } - - private void menuSpeedServer_Click(object sender, EventArgs e) - { - //if (!config.sysAgentEnabled) - //{ - // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); - // return; - //} - - //UI.Show(UIRes.I18N("SpeedServerTips")); - - Speedtest("speedtest"); - } - private void Speedtest(string actionType) - { - GetLvSelectedIndex(); - ClearTestResult(); - var statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, actionType, UpdateSpeedtestHandler); - } - - private void menuExport2ClientConfig_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - MainFormHandler.Instance.Export2ClientConfig(index, config); - } - - private void menuExport2ServerConfig_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - MainFormHandler.Instance.Export2ServerConfig(index, config); - } - - private void menuExport2ShareUrl_Click(object sender, EventArgs e) - { - GetLvSelectedIndex(); - - StringBuilder sb = new StringBuilder(); - foreach (int v in lvSelecteds) - { - string url = ConfigHandler.GetVmessQRCode(config, v); - if (Utils.IsNullOrEmpty(url)) - { - continue; - } - sb.Append(url); - sb.AppendLine(); - } - if (sb.Length > 0) - { - Utils.SetClipboardData(sb.ToString()); - AppendText(false, UIRes.I18N("BatchExportURLSuccessfully")); - //UI.Show(UIRes.I18N("BatchExportURLSuccessfully")); - } - } - - private void menuExport2SubContent_Click(object sender, EventArgs e) - { - GetLvSelectedIndex(); - - StringBuilder sb = new StringBuilder(); - foreach (int v in lvSelecteds) - { - string url = ConfigHandler.GetVmessQRCode(config, v); - if (Utils.IsNullOrEmpty(url)) - { - continue; - } - sb.Append(url); - sb.AppendLine(); - } - if (sb.Length > 0) - { - Utils.SetClipboardData(Utils.Base64Encode(sb.ToString())); - UI.Show(UIRes.I18N("BatchExportSubscriptionSuccessfully")); - } - } - - private void tsbOptionSetting_Click(object sender, EventArgs e) - { - OptionSettingForm fm = new OptionSettingForm(); - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - RestartHttpProxy(); - } - } - - private void tsbReload_Click(object sender, EventArgs e) - { - Global.reloadV2ray = true; - LoadV2ray(); - } - - private void tsbClose_Click(object sender, EventArgs e) - { - HideForm(); - //this.WindowState = FormWindowState.Minimized; - } - - /// - /// 设置活动服务器 - /// - /// - /// - private int SetDefaultServer(int index) - { - if (index < 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return -1; - } - if (ConfigHandler.SetDefaultServer(ref config, index) == 0) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - return 0; - } - - /// - /// 取得ListView选中的行 - /// - /// - private int GetLvSelectedIndex() - { - int index = -1; - lvSelecteds.Clear(); - try - { - if (lvServers.SelectedIndices.Count <= 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return index; - } - - index = lvServers.SelectedIndices[0]; - foreach (int i in lvServers.SelectedIndices) - { - lvSelecteds.Add(i); - } - return index; - } - catch - { - return index; - } - } - - private void menuAddCustomServer_Click(object sender, EventArgs e) - { - UI.Show(UIRes.I18N("CustomServerTips")); - - OpenFileDialog fileDialog = new OpenFileDialog(); - fileDialog.Multiselect = false; - fileDialog.Filter = "Config|*.json|All|*.*"; - if (fileDialog.ShowDialog() != DialogResult.OK) - { - return; - } - string fileName = fileDialog.FileName; - if (Utils.IsNullOrEmpty(fileName)) - { - return; - } - - if (ConfigHandler.AddCustomServer(ref config, fileName) == 0) - { - //刷新 - RefreshServers(); - LoadV2ray(); - UI.Show(UIRes.I18N("SuccessfullyImportedCustomServer")); - } - else - { - UI.Show(UIRes.I18N("FailedImportedCustomServer")); - } - } - - private void menuAddShadowsocksServer_Click(object sender, EventArgs e) - { - var fm = new AddServer3Form(); - fm.EditIndex = -1; - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - ShowForm(); - } - - private void menuAddSocksServer_Click(object sender, EventArgs e) - { - var fm = new AddServer4Form(); - fm.EditIndex = -1; - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - ShowForm(); - } - - private void menuAddServers_Click(object sender, EventArgs e) - { - string clipboardData = Utils.GetClipboardData(); - int result = AddBatchServers(clipboardData); - if (result > 0) - { - UI.Show(string.Format(UIRes.I18N("SuccessfullyImportedServerViaClipboard"), result)); - } - } - - private void menuScanScreen_Click(object sender, EventArgs e) - { - HideForm(); - bgwScan.RunWorkerAsync(); - } - - private int AddBatchServers(string clipboardData, string subid = "") - { - int counter; - int _Add() - { - return ConfigHandler.AddBatchServers(ref config, clipboardData, subid); - } - counter = _Add(); - if (counter < 1) - { - clipboardData = Utils.Base64Decode(clipboardData); - counter = _Add(); - } - RefreshServers(); - return counter; - } - - #endregion - - - #region 提示信息 - - /// - /// 消息委托 - /// - /// - /// - void v2rayHandler_ProcessEvent(bool notify, string msg) - { - AppendText(notify, msg); - } - - delegate void AppendTextDelegate(string text); - void AppendText(bool notify, string msg) - { - try - { - AppendText(msg); - if (notify) - { - notifyMsg(msg); - } - } - catch - { - } - } - - void AppendText(string text) - { - if (this.txtMsgBox.InvokeRequired) - { - Invoke(new AppendTextDelegate(AppendText), new object[] { text }); - } - else - { - //this.txtMsgBox.AppendText(text); - ShowMsg(text); - } - } - - /// - /// 提示信息 - /// - /// - private void ShowMsg(string msg) - { - if (txtMsgBox.Lines.Length > 999) - { - ClearMsg(); - } - this.txtMsgBox.AppendText(msg); - if (!msg.EndsWith(Environment.NewLine)) - { - this.txtMsgBox.AppendText(Environment.NewLine); - } - } - - /// - /// 清除信息 - /// - private void ClearMsg() - { - this.txtMsgBox.Clear(); - } - - /// - /// 托盘信息 - /// - /// - private void notifyMsg(string msg) - { - notifyMain.Text = msg; - } - - #endregion - - - #region 托盘事件 - - private void notifyMain_MouseClick(object sender, MouseEventArgs e) - { - if (e.Button == System.Windows.Forms.MouseButtons.Left) - { - ShowForm(); - } - } - - private void menuExit_Click(object sender, EventArgs e) - { - - this.Visible = false; - this.Close(); - - Application.Exit(); - } - - - private void ShowForm() - { - this.Show(); - this.WindowState = FormWindowState.Normal; - this.Activate(); - //this.notifyIcon1.Visible = false; - this.ShowInTaskbar = true; - this.txtMsgBox.ScrollToCaret(); - - SetVisibleCore(true); - } - - private void HideForm() - { - //this.WindowState = FormWindowState.Minimized; - this.Hide(); - //this.notifyMain.Icon = this.Icon; - this.notifyMain.Visible = true; - this.ShowInTaskbar = false; - - SetVisibleCore(false); - } - - #endregion - - #region 后台测速 - - private void SetTestResult(int k, string txt) - { - config.vmess[k].testResult = txt; - lvServers.Items[k].SubItems[8].Text = txt; - } - private void ClearTestResult() - { - foreach (int s in lvSelecteds) - { - SetTestResult(s, ""); - } - } - private void UpdateSpeedtestHandler(int index, string msg) - { - lvServers.Invoke((MethodInvoker)delegate - { - lvServers.SuspendLayout(); - - SetTestResult(index, msg); - - lvServers.ResumeLayout(); - }); - } - - private void UpdateStatisticsHandler(ulong up, ulong down, List statistics) - { - try - { - up /= (ulong)(config.statisticsFreshRate / 1000f); - down /= (ulong)(config.statisticsFreshRate / 1000f); - toolSslServerSpeed.Text = string.Format("{0}/s↑ | {1}/s↓", Utils.HumanFy(up), Utils.HumanFy(down)); - - List datas = new List(); - for (int i = 0; i < config.vmess.Count; i++) - { - var index = statistics.FindIndex(item_ => item_.itemId == config.vmess[i].getItemId()); - if (index != -1) - { - lvServers.Invoke((MethodInvoker)delegate - { - lvServers.SuspendLayout(); - - var indexStart = 9; - lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayDown); - lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayUp); - lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalDown); - lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalUp); - - lvServers.ResumeLayout(); - }); - } - } - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - } - - #endregion - - #region 移动服务器 - - private void menuMoveTop_Click(object sender, EventArgs e) - { - MoveServer(EMove.Top); - } - - private void menuMoveUp_Click(object sender, EventArgs e) - { - MoveServer(EMove.Up); - } - - private void menuMoveDown_Click(object sender, EventArgs e) - { - MoveServer(EMove.Down); - } - - private void menuMoveBottom_Click(object sender, EventArgs e) - { - MoveServer(EMove.Bottom); - } - - private void MoveServer(EMove eMove) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return; - } - if (ConfigHandler.MoveServer(ref config, index, eMove) == 0) - { - //TODO: reload is not good. - RefreshServers(); - LoadV2ray(); - } - } - private void menuSelectAll_Click(object sender, EventArgs e) - { - foreach (ListViewItem item in lvServers.Items) - { - item.Selected = true; - } - } - - #endregion - - #region 系统代理相关 - - private void menuCopyPACUrl_Click(object sender, EventArgs e) - { - Utils.SetClipboardData(HttpProxyHandle.GetPacUrl()); - } - - private void menuNotEnabledHttp_Click(object sender, EventArgs e) - { - SetListenerType(0); - } - - private void menuGlobal_Click(object sender, EventArgs e) - { - SetListenerType(1); - } - - private void menuGlobalPAC_Click(object sender, EventArgs e) - { - SetListenerType(2); - } - - private void menuKeep_Click(object sender, EventArgs e) - { - SetListenerType(3); - } - - private void menuKeepPAC_Click(object sender, EventArgs e) - { - SetListenerType(4); - } - - private void SetListenerType(int type) - { - config.listenerType = type; - ChangePACButtonStatus(type); - } - - private void ChangePACButtonStatus(int type) - { - if (type != 0) - { - HttpProxyHandle.RestartHttpAgent(config, false); - } - else - { - HttpProxyHandle.CloseHttpAgent(config); - } - - for (int k = 0; k < menuSysAgentMode.DropDownItems.Count; k++) - { - var item = ((ToolStripMenuItem)menuSysAgentMode.DropDownItems[k]); - item.Checked = (type == k); - } - - ConfigHandler.SaveConfig(ref config, false); - DisplayToolStatus(); - } - - #endregion - - - #region CheckUpdate - - private void tsbCheckUpdateN_Click(object sender, EventArgs e) - { - //System.Diagnostics.Process.Start(Global.UpdateUrl); - DownloadHandle downloadHandle = null; - if (downloadHandle == null) - { - downloadHandle = new DownloadHandle(); - downloadHandle.AbsoluteCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); - - string url = args.Msg; - this.Invoke((MethodInvoker)(delegate - { - - if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) - { - return; - } - else - { - downloadHandle.DownloadFileAsync(config, url, null, -1); - } - })); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); - - try - { - var fileName = Utils.GetPath(downloadHandle.DownloadFileName); - var process = Process.Start("v2rayUpgrade.exe", fileName); - if (process.Id > 0) - { - menuExit_Click(null, null); - } - } - catch (Exception ex) - { - AppendText(false, ex.Message); - } - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - } - - AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); - downloadHandle.CheckUpdateAsync("v2rayN"); - } - - private void tsbCheckUpdateCore_Click(object sender, EventArgs e) - { - DownloadHandle downloadHandle = null; - if (downloadHandle == null) - { - downloadHandle = new DownloadHandle(); - downloadHandle.AbsoluteCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); - - string url = args.Msg; - this.Invoke((MethodInvoker)(delegate - { - - if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) - { - return; - } - else - { - downloadHandle.DownloadFileAsync(config, url, null, -1); - } - })); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); - AppendText(false, UIRes.I18N("MsgUnpacking")); - - try - { - CloseV2ray(); - - string fileName = downloadHandle.DownloadFileName; - fileName = Utils.GetPath(fileName); - FileManager.ZipExtractToFile(fileName); - - AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); - - Global.reloadV2ray = true; - LoadV2ray(); - - AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); - } - catch (Exception ex) - { - AppendText(false, ex.Message); - } - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - } - - AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); - downloadHandle.CheckUpdateAsync("Core"); - } - - private void tsbCheckUpdatePACList_Click(object sender, EventArgs e) - { - DownloadHandle pacListHandle = null; - if (pacListHandle == null) - { - pacListHandle = new DownloadHandle(); - pacListHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - var result = args.Msg; - if (Utils.IsNullOrEmpty(result)) - { - return; - } - pacListHandle.GenPacFile(result); - - AppendText(false, UIRes.I18N("MsgPACUpdateSuccessfully")); - } - else - { - AppendText(false, UIRes.I18N("MsgPACUpdateFailed")); - } - }; - pacListHandle.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - } - AppendText(false, UIRes.I18N("MsgStartUpdatingPAC")); - pacListHandle.WebDownloadString(config.urlGFWList); - } - - private void tsbCheckClearPACList_Click(object sender, EventArgs e) - { - try - { - File.WriteAllText(Utils.GetPath(Global.pacFILE), Utils.GetEmbedText(Global.BlankPacFileName), Encoding.UTF8); - AppendText(false, UIRes.I18N("MsgSimplifyPAC")); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - } - #endregion - - #region Help - - - private void tsbAbout_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start(Global.AboutUrl); - } - - private void tsbPromotion_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}"); - } - #endregion - - #region ScanScreen - - - private void bgwScan_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) - { - string ret = Utils.ScanScreen(); - bgwScan.ReportProgress(0, ret); - } - - private void bgwScan_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) - { - ShowForm(); - - string result = Convert.ToString(e.UserState); - if (Utils.IsNullOrEmpty(result)) - { - UI.Show(UIRes.I18N("NoValidQRcodeFound")); - } - else - { - if (AddBatchServers(result) > 0) - { - UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan")); - } - } - } - - #endregion - - #region 订阅 - private void tsbSubSetting_Click(object sender, EventArgs e) - { - SubSettingForm fm = new SubSettingForm(); - if (fm.ShowDialog() == DialogResult.OK) - { - RefreshServers(); - } - } - - private void tsbSubUpdate_Click(object sender, EventArgs e) - { - AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); - - if (config.subItem == null || config.subItem.Count <= 0) - { - AppendText(false, UIRes.I18N("MsgNoValidSubscription")); - return; - } - - for (int k = 1; k <= config.subItem.Count; k++) - { - string id = config.subItem[k - 1].id.TrimEx(); - string url = config.subItem[k - 1].url.TrimEx(); - string hashCode = $"{k}->"; - if (config.subItem[k - 1].enabled == false) - { - continue; - } - if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); - continue; - } - - DownloadHandle downloadHandle3 = new DownloadHandle(); - downloadHandle3.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); - var result = Utils.Base64Decode(args.Msg); - if (Utils.IsNullOrEmpty(result)) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); - return; - } - - ConfigHandler.RemoveServerViaSubid(ref config, id); - AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); - RefreshServers(); - if (AddBatchServers(result, id) > 0) - { - } - else - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); - } - AppendText(false, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle3.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - - downloadHandle3.WebDownloadString(url); - AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); - } - } - - #endregion - - #region Language - - private void tsbLanguageDef_Click(object sender, EventArgs e) - { - SetCurrentLanguage("en"); - } - - private void tsbLanguageZhHans_Click(object sender, EventArgs e) - { - SetCurrentLanguage("zh-Hans"); - } - private void SetCurrentLanguage(string value) - { - Utils.RegWriteValue(Global.MyRegPath, Global.MyRegKeyLanguage, value); - Application.Restart(); - } - - - #endregion - - private void tsbV2rayWebsite_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start(Global.v2rayWebsiteUrl); - } - } -} + if (config.enableStatistics) + { + statistics = new StatisticsHandler(config, UpdateStatisticsHandler); + } + } + + private void MainForm_VisibleChanged(object sender, EventArgs e) + { + if (statistics == null || !statistics.Enable) return; + if ((sender as Form).Visible) + { + statistics.UpdateUI = true; + } + else + { + statistics.UpdateUI = false; + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + InitServersView(); + RefreshServers(); + lvServers.AutoResizeColumns(); + + LoadV2ray(); + + HideForm(); + + } + + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (e.CloseReason == CloseReason.UserClosing) + { + e.Cancel = true; + HideForm(); + return; + } + } + + private void MainForm_Resize(object sender, EventArgs e) + { + //if (this.WindowState == FormWindowState.Minimized) + //{ + // HideForm(); + //} + //else + //{ + // //this.splitContainer1.SplitterDistance = config.uiItem.mainQRCodeWidth; + //} + } + + private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e) + { + //config.uiItem.mainQRCodeWidth = splitContainer1.SplitterDistance; + } + + //private const int WM_QUERYENDSESSION = 0x0011; + //protected override void WndProc(ref Message m) + //{ + // switch (m.Msg) + // { + // case WM_QUERYENDSESSION: + // Utils.SaveLog("Windows shutdown UnsetProxy"); + + // ConfigHandler.ToJsonFile(config); + // statistics?.SaveToFile(); + // ProxySetting.UnsetProxy(); + // m.Result = (IntPtr)1; + // break; + // default: + // base.WndProc(ref m); + // break; + // } + //} + #endregion + + #region 显示服务器 listview 和 menu + + /// + /// 刷新服务器 + /// + private void RefreshServers() + { + RefreshServersView(); + RefreshServersMenu(); + } + + /// + /// 初始化服务器列表 + /// + private void InitServersView() + { + lvServers.Items.Clear(); + + lvServers.GridLines = true; + lvServers.FullRowSelect = true; + lvServers.View = View.Details; + lvServers.Scrollable = true; + lvServers.MultiSelect = true; + lvServers.HeaderStyle = ColumnHeaderStyle.Nonclickable; + + lvServers.Columns.Add("", 30, HorizontalAlignment.Center); + lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvAlias"), 100, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvAddress"), 120, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvPort"), 50, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvEncryptionMethod"), 90, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvTransportProtocol"), 70, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvSubscription"), 50, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvTestResults"), 70, HorizontalAlignment.Left); + + if (statistics != null && statistics.Enable) + { + lvServers.Columns.Add(UIRes.I18N("LvTodayDownloadDataAmount"), 70, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvTodayUploadDataAmount"), 70, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvTotalDownloadDataAmount"), 70, HorizontalAlignment.Left); + lvServers.Columns.Add(UIRes.I18N("LvTotalUploadDataAmount"), 70, HorizontalAlignment.Left); + } + } + + /// + /// 刷新服务器列表 + /// + private void RefreshServersView() + { + lvServers.Items.Clear(); + + for (int k = 0; k < config.vmess.Count; k++) + { + string def = string.Empty; + string totalUp = string.Empty, + totalDown = string.Empty, + todayUp = string.Empty, + todayDown = string.Empty; + if (config.index.Equals(k)) + { + def = "√"; + } + + VmessItem item = config.vmess[k]; + + ListViewItem lvItem = null; + if (statistics != null && statistics.Enable) + { + var sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId()); + if (sItem != null) + { + totalUp = Utils.HumanFy(sItem.totalUp); + totalDown = Utils.HumanFy(sItem.totalDown); + todayUp = Utils.HumanFy(sItem.todayUp); + todayDown = Utils.HumanFy(sItem.todayDown); + } + + lvItem = new ListViewItem(new string[] + { + def, + ((EConfigType)item.configType).ToString(), + item.remarks, + item.address, + item.port.ToString(), + //item.id, + //item.alterId.ToString(), + item.security, + item.network, + item.getSubRemarks(config), + item.testResult, + todayDown, + todayUp, + totalDown, + totalUp + }); + } + else + { + lvItem = new ListViewItem(new string[] + { + def, + ((EConfigType)item.configType).ToString(), + item.remarks, + item.address, + item.port.ToString(), + //item.id, + //item.alterId.ToString(), + item.security, + item.network, + item.getSubRemarks(config), + item.testResult + }); + } + + if (lvItem != null) lvServers.Items.Add(lvItem); + } + + //if (lvServers.Items.Count > 0) + //{ + // if (lvServers.Items.Count <= testConfigIndex) + // { + // testConfigIndex = lvServers.Items.Count - 1; + // } + // lvServers.Items[testConfigIndex].Selected = true; + // lvServers.Select(); + //} + } + + /// + /// 刷新托盘服务器菜单 + /// + private void RefreshServersMenu() + { + menuServers.DropDownItems.Clear(); + + List lst = new List(); + for (int k = 0; k < config.vmess.Count; k++) + { + VmessItem item = config.vmess[k]; + string name = item.getSummary(); + + ToolStripMenuItem ts = new ToolStripMenuItem(name); + ts.Tag = k; + if (config.index.Equals(k)) + { + ts.Checked = true; + } + ts.Click += new EventHandler(ts_Click); + lst.Add(ts); + } + menuServers.DropDownItems.AddRange(lst.ToArray()); + } + + private void ts_Click(object sender, EventArgs e) + { + try + { + ToolStripItem ts = (ToolStripItem)sender; + int index = Utils.ToInt(ts.Tag); + SetDefaultServer(index); + } + catch + { + } + } + + private void lvServers_SelectedIndexChanged(object sender, EventArgs e) + { + int index = -1; + try + { + if (lvServers.SelectedIndices.Count > 0) + { + index = lvServers.SelectedIndices[0]; + } + } + catch + { + } + if (index < 0) + { + return; + } + //qrCodeControl.showQRCode(index, config); + } + + private void DisplayToolStatus() + { + toolSslSocksPort.Text = + toolSslHttpPort.Text = + toolSslPacPort.Text = "OFF"; + + toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}"; + + if (config.listenerType != 0) + { + toolSslHttpPort.Text = $"{Global.Loopback}:{Global.httpPort}"; + if (config.listenerType % 2 == 0) + { + if (PACServerHandle.IsRunning) + { + toolSslPacPort.Text = $"{HttpProxyHandle.GetPacUrl()}"; + } + else + { + toolSslPacPort.Text = UIRes.I18N("StartPacFailed"); + } + } + } + + notifyMain.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon); + } + private void ssMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + if (!Utils.IsNullOrEmpty(e.ClickedItem.Text)) + { + Utils.SetClipboardData(e.ClickedItem.Text); + } + } + + #endregion + + #region v2ray 操作 + + /// + /// 载入V2ray + /// + private void LoadV2ray() + { + tsbReload.Enabled = false; + + if (Global.reloadV2ray) + { + ClearMsg(); + } + v2rayHandler.LoadV2ray(config); + Global.reloadV2ray = false; + ConfigHandler.SaveConfig(ref config, false); + statistics?.SaveToFile(); + + ChangePACButtonStatus(config.listenerType); + + tsbReload.Enabled = true; + } + + /// + /// 关闭V2ray + /// + private void CloseV2ray() + { + ConfigHandler.SaveConfig(ref config, false); + statistics?.SaveToFile(); + + ChangePACButtonStatus(0); + + v2rayHandler.V2rayStop(); + } + + #endregion + + #region 功能按钮 + + private void lvServers_Click(object sender, EventArgs e) + { + int index = -1; + try + { + if (lvServers.SelectedIndices.Count > 0) + { + index = lvServers.SelectedIndices[0]; + } + } + catch + { + } + if (index < 0) + { + return; + } + qrCodeControl.showQRCode(index, config); + } + + private void lvServers_DoubleClick(object sender, EventArgs e) + { + int index = GetLvSelectedIndex(); + if (index < 0) + { + return; + } + + if (config.vmess[index].configType == (int)EConfigType.Vmess) + { + var fm = new AddServerForm(); + fm.EditIndex = index; + if (fm.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + } + else if (config.vmess[index].configType == (int)EConfigType.Shadowsocks) + { + var fm = new AddServer3Form(); + fm.EditIndex = index; + if (fm.ShowDialog() == DialogResult.OK) + { + RefreshServers(); + LoadV2ray(); + } + } + else if (config.vmess[index].configType == (int)EConfigType.Socks) + { + var fm = new AddServer4Form(); + fm.EditIndex = index; + if (fm.ShowDialog() == DialogResult.OK) + { + RefreshServers(); + LoadV2ray(); + } + } + else + { + var fm2 = new AddServer2Form(); + fm2.EditIndex = index; + if (fm2.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + } + } + + private void lvServers_KeyDown(object sender, KeyEventArgs e) + { + if (e.Control) + { + switch (e.KeyCode) + { + case Keys.A: + menuSelectAll_Click(null, null); + break; + case Keys.C: + menuExport2ShareUrl_Click(null, null); + break; + case Keys.V: + menuAddServers_Click(null, null); + break; + case Keys.P: + menuPingServer_Click(null, null); + break; + case Keys.O: + menuTcpingServer_Click(null, null); + break; + case Keys.R: + menuRealPingServer_Click(null, null); + break; + case Keys.S: + menuScanScreen_Click(null, null); + break; + case Keys.T: + menuSpeedServer_Click(null, null); + break; + } + } + else + { + switch (e.KeyCode) + { + case Keys.Enter: + menuSetDefaultServer_Click(null, null); + break; + case Keys.Delete: + menuRemoveServer_Click(null, null); + break; + case Keys.T: + menuMoveTop_Click(null, null); + break; + case Keys.B: + menuMoveBottom_Click(null, null); + break; + case Keys.U: + menuMoveUp_Click(null, null); + break; + case Keys.D: + menuMoveDown_Click(null, null); + break; + } + } + } + + private void menuAddVmessServer_Click(object sender, EventArgs e) + { + AddServerForm fm = new AddServerForm(); + fm.EditIndex = -1; + if (fm.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + } + + private void menuRemoveServer_Click(object sender, EventArgs e) + { + + int index = GetLvSelectedIndex(); + if (index < 0) + { + return; + } + if (UI.ShowYesNo(UIRes.I18N("RemoveServer")) == DialogResult.No) + { + return; + } + for (int k = lvSelecteds.Count - 1; k >= 0; k--) + { + ConfigHandler.RemoveServer(ref config, lvSelecteds[k]); + } + //刷新 + RefreshServers(); + LoadV2ray(); + + } + + private void menuRemoveDuplicateServer_Click(object sender, EventArgs e) + { + List servers = null; + Utils.DedupServerList(config.vmess, out servers); + int oldCount = config.vmess.Count; + int newCount = servers.Count; + if (servers != null) + { + config.vmess = servers; + } + //刷新 + RefreshServers(); + LoadV2ray(); + UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount)); + } + + private void menuCopyServer_Click(object sender, EventArgs e) + { + int index = GetLvSelectedIndex(); + if (index < 0) + { + return; + } + if (ConfigHandler.CopyServer(ref config, index) == 0) + { + //刷新 + RefreshServers(); + } + } + + private void menuSetDefaultServer_Click(object sender, EventArgs e) + { + int index = GetLvSelectedIndex(); + if (index < 0) + { + return; + } + SetDefaultServer(index); + } + + + private void menuPingServer_Click(object sender, EventArgs e) + { + Speedtest("ping"); + } + private void menuTcpingServer_Click(object sender, EventArgs e) + { + Speedtest("tcping"); + } + + private void menuRealPingServer_Click(object sender, EventArgs e) + { + //if (!config.sysAgentEnabled) + //{ + // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); + // return; + //} + + //UI.Show(UIRes.I18N("SpeedServerTips")); + + Speedtest("realping"); + } + + private void menuSpeedServer_Click(object sender, EventArgs e) + { + //if (!config.sysAgentEnabled) + //{ + // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); + // return; + //} + + //UI.Show(UIRes.I18N("SpeedServerTips")); + + Speedtest("speedtest"); + } + private void Speedtest(string actionType) + { + GetLvSelectedIndex(); + ClearTestResult(); + var statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, actionType, UpdateSpeedtestHandler); + } + + private void menuExport2ClientConfig_Click(object sender, EventArgs e) + { + int index = GetLvSelectedIndex(); + MainFormHandler.Instance.Export2ClientConfig(index, config); + } + + private void menuExport2ServerConfig_Click(object sender, EventArgs e) + { + int index = GetLvSelectedIndex(); + MainFormHandler.Instance.Export2ServerConfig(index, config); + } + + private void menuExport2ShareUrl_Click(object sender, EventArgs e) + { + GetLvSelectedIndex(); + + StringBuilder sb = new StringBuilder(); + foreach (int v in lvSelecteds) + { + string url = ConfigHandler.GetVmessQRCode(config, v); + if (Utils.IsNullOrEmpty(url)) + { + continue; + } + sb.Append(url); + sb.AppendLine(); + } + if (sb.Length > 0) + { + Utils.SetClipboardData(sb.ToString()); + AppendText(false, UIRes.I18N("BatchExportURLSuccessfully")); + //UI.Show(UIRes.I18N("BatchExportURLSuccessfully")); + } + } + + private void menuExport2SubContent_Click(object sender, EventArgs e) + { + GetLvSelectedIndex(); + + StringBuilder sb = new StringBuilder(); + foreach (int v in lvSelecteds) + { + string url = ConfigHandler.GetVmessQRCode(config, v); + if (Utils.IsNullOrEmpty(url)) + { + continue; + } + sb.Append(url); + sb.AppendLine(); + } + if (sb.Length > 0) + { + Utils.SetClipboardData(Utils.Base64Encode(sb.ToString())); + UI.Show(UIRes.I18N("BatchExportSubscriptionSuccessfully")); + } + } + + private void tsbOptionSetting_Click(object sender, EventArgs e) + { + OptionSettingForm fm = new OptionSettingForm(); + if (fm.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + HttpProxyHandle.RestartHttpAgent(config, true); + } + } + + private void tsbReload_Click(object sender, EventArgs e) + { + Global.reloadV2ray = true; + LoadV2ray(); + } + + private void tsbClose_Click(object sender, EventArgs e) + { + HideForm(); + //this.WindowState = FormWindowState.Minimized; + } + + /// + /// 设置活动服务器 + /// + /// + /// + private int SetDefaultServer(int index) + { + if (index < 0) + { + UI.Show(UIRes.I18N("PleaseSelectServer")); + return -1; + } + if (ConfigHandler.SetDefaultServer(ref config, index) == 0) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + return 0; + } + + /// + /// 取得ListView选中的行 + /// + /// + private int GetLvSelectedIndex() + { + int index = -1; + lvSelecteds.Clear(); + try + { + if (lvServers.SelectedIndices.Count <= 0) + { + UI.Show(UIRes.I18N("PleaseSelectServer")); + return index; + } + + index = lvServers.SelectedIndices[0]; + foreach (int i in lvServers.SelectedIndices) + { + lvSelecteds.Add(i); + } + return index; + } + catch + { + return index; + } + } + + private void menuAddCustomServer_Click(object sender, EventArgs e) + { + UI.Show(UIRes.I18N("CustomServerTips")); + + OpenFileDialog fileDialog = new OpenFileDialog(); + fileDialog.Multiselect = false; + fileDialog.Filter = "Config|*.json|All|*.*"; + if (fileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + string fileName = fileDialog.FileName; + if (Utils.IsNullOrEmpty(fileName)) + { + return; + } + + if (ConfigHandler.AddCustomServer(ref config, fileName) == 0) + { + //刷新 + RefreshServers(); + LoadV2ray(); + UI.Show(UIRes.I18N("SuccessfullyImportedCustomServer")); + } + else + { + UI.Show(UIRes.I18N("FailedImportedCustomServer")); + } + } + + private void menuAddShadowsocksServer_Click(object sender, EventArgs e) + { + var fm = new AddServer3Form(); + fm.EditIndex = -1; + if (fm.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + ShowForm(); + } + + private void menuAddSocksServer_Click(object sender, EventArgs e) + { + var fm = new AddServer4Form(); + fm.EditIndex = -1; + if (fm.ShowDialog() == DialogResult.OK) + { + //刷新 + RefreshServers(); + LoadV2ray(); + } + ShowForm(); + } + + private void menuAddServers_Click(object sender, EventArgs e) + { + string clipboardData = Utils.GetClipboardData(); + int result = AddBatchServers(clipboardData); + if (result > 0) + { + UI.Show(string.Format(UIRes.I18N("SuccessfullyImportedServerViaClipboard"), result)); + } + } + + private void menuScanScreen_Click(object sender, EventArgs e) + { + HideForm(); + bgwScan.RunWorkerAsync(); + } + + private int AddBatchServers(string clipboardData, string subid = "") + { + int counter; + int _Add() + { + return ConfigHandler.AddBatchServers(ref config, clipboardData, subid); + } + counter = _Add(); + if (counter < 1) + { + clipboardData = Utils.Base64Decode(clipboardData); + counter = _Add(); + } + RefreshServers(); + return counter; + } + + #endregion + + + #region 提示信息 + + /// + /// 消息委托 + /// + /// + /// + void v2rayHandler_ProcessEvent(bool notify, string msg) + { + AppendText(notify, msg); + } + + delegate void AppendTextDelegate(string text); + void AppendText(bool notify, string msg) + { + try + { + AppendText(msg); + if (notify) + { + notifyMsg(msg); + } + } + catch + { + } + } + + void AppendText(string text) + { + if (this.txtMsgBox.InvokeRequired) + { + Invoke(new AppendTextDelegate(AppendText), new object[] { text }); + } + else + { + //this.txtMsgBox.AppendText(text); + ShowMsg(text); + } + } + + /// + /// 提示信息 + /// + /// + private void ShowMsg(string msg) + { + if (txtMsgBox.Lines.Length > 999) + { + ClearMsg(); + } + this.txtMsgBox.AppendText(msg); + if (!msg.EndsWith(Environment.NewLine)) + { + this.txtMsgBox.AppendText(Environment.NewLine); + } + } + + /// + /// 清除信息 + /// + private void ClearMsg() + { + this.txtMsgBox.Clear(); + } + + /// + /// 托盘信息 + /// + /// + private void notifyMsg(string msg) + { + notifyMain.Text = msg; + } + + #endregion + + + #region 托盘事件 + + private void notifyMain_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + ShowForm(); + } + } + + private void menuExit_Click(object sender, EventArgs e) + { + + this.Visible = false; + this.Close(); + + Application.Exit(); + } + + + private void ShowForm() + { + this.Show(); + this.WindowState = FormWindowState.Normal; + this.Activate(); + //this.notifyIcon1.Visible = false; + this.ShowInTaskbar = true; + this.txtMsgBox.ScrollToCaret(); + + SetVisibleCore(true); + } + + private void HideForm() + { + //this.WindowState = FormWindowState.Minimized; + this.Hide(); + //this.notifyMain.Icon = this.Icon; + this.notifyMain.Visible = true; + this.ShowInTaskbar = false; + + SetVisibleCore(false); + } + + #endregion + + #region 后台测速 + + private void SetTestResult(int k, string txt) + { + config.vmess[k].testResult = txt; + lvServers.Items[k].SubItems[8].Text = txt; + } + private void ClearTestResult() + { + foreach (int s in lvSelecteds) + { + SetTestResult(s, ""); + } + } + private void UpdateSpeedtestHandler(int index, string msg) + { + lvServers.Invoke((MethodInvoker)delegate + { + lvServers.SuspendLayout(); + + SetTestResult(index, msg); + + lvServers.ResumeLayout(); + }); + } + + private void UpdateStatisticsHandler(ulong up, ulong down, List statistics) + { + try + { + up /= (ulong)(config.statisticsFreshRate / 1000f); + down /= (ulong)(config.statisticsFreshRate / 1000f); + toolSslServerSpeed.Text = string.Format("{0}/s↑ | {1}/s↓", Utils.HumanFy(up), Utils.HumanFy(down)); + + List datas = new List(); + for (int i = 0; i < config.vmess.Count; i++) + { + var index = statistics.FindIndex(item_ => item_.itemId == config.vmess[i].getItemId()); + if (index != -1) + { + lvServers.Invoke((MethodInvoker)delegate + { + lvServers.SuspendLayout(); + + var indexStart = 9; + lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayDown); + lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayUp); + lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalDown); + lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalUp); + + lvServers.ResumeLayout(); + }); + } + } + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + } + } + + #endregion + + #region 移动服务器 + + private void menuMoveTop_Click(object sender, EventArgs e) + { + MoveServer(EMove.Top); + } + + private void menuMoveUp_Click(object sender, EventArgs e) + { + MoveServer(EMove.Up); + } + + private void menuMoveDown_Click(object sender, EventArgs e) + { + MoveServer(EMove.Down); + } + + private void menuMoveBottom_Click(object sender, EventArgs e) + { + MoveServer(EMove.Bottom); + } + + private void MoveServer(EMove eMove) + { + int index = GetLvSelectedIndex(); + if (index < 0) + { + UI.Show(UIRes.I18N("PleaseSelectServer")); + return; + } + if (ConfigHandler.MoveServer(ref config, index, eMove) == 0) + { + //TODO: reload is not good. + RefreshServers(); + LoadV2ray(); + } + } + private void menuSelectAll_Click(object sender, EventArgs e) + { + foreach (ListViewItem item in lvServers.Items) + { + item.Selected = true; + } + } + + #endregion + + #region 系统代理相关 + + private void menuCopyPACUrl_Click(object sender, EventArgs e) + { + Utils.SetClipboardData(HttpProxyHandle.GetPacUrl()); + } + + private void menuNotEnabledHttp_Click(object sender, EventArgs e) + { + SetListenerType(0); + } + private void menuGlobal_Click(object sender, EventArgs e) + { + SetListenerType(1); + } + private void menuGlobalPAC_Click(object sender, EventArgs e) + { + SetListenerType(2); + } + private void menuKeep_Click(object sender, EventArgs e) + { + SetListenerType(3); + } + private void menuKeepPAC_Click(object sender, EventArgs e) + { + SetListenerType(4); + } + private void menuKeepNothing_Click(object sender, EventArgs e) + { + SetListenerType(5); + } + private void menuKeepPACNothing_Click(object sender, EventArgs e) + { + SetListenerType(6); + } + private void SetListenerType(int type) + { + config.listenerType = type; + ChangePACButtonStatus(type); + } + + private void ChangePACButtonStatus(int type) + { + if (type != 0) + { + HttpProxyHandle.RestartHttpAgent(config, false); + } + else + { + HttpProxyHandle.CloseHttpAgent(config); + } + + for (int k = 0; k < menuSysAgentMode.DropDownItems.Count; k++) + { + var item = ((ToolStripMenuItem)menuSysAgentMode.DropDownItems[k]); + item.Checked = (type == k); + } + + ConfigHandler.SaveConfig(ref config, false); + DisplayToolStatus(); + } + + #endregion + + + #region CheckUpdate + + private void tsbCheckUpdateN_Click(object sender, EventArgs e) + { + //System.Diagnostics.Process.Start(Global.UpdateUrl); + DownloadHandle downloadHandle = null; + if (downloadHandle == null) + { + downloadHandle = new DownloadHandle(); + downloadHandle.AbsoluteCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); + + string url = args.Msg; + this.Invoke((MethodInvoker)(delegate + { + + if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) + { + return; + } + else + { + downloadHandle.DownloadFileAsync(config, url, null, -1); + } + })); + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.UpdateCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); + + try + { + var fileName = Utils.GetPath(downloadHandle.DownloadFileName); + var process = Process.Start("v2rayUpgrade.exe", fileName); + if (process.Id > 0) + { + menuExit_Click(null, null); + } + } + catch (Exception ex) + { + AppendText(false, ex.Message); + } + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.Error += (sender2, args) => + { + AppendText(true, args.GetException().Message); + }; + } + + AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); + downloadHandle.CheckUpdateAsync("v2rayN"); + } + + private void tsbCheckUpdateCore_Click(object sender, EventArgs e) + { + DownloadHandle downloadHandle = null; + if (downloadHandle == null) + { + downloadHandle = new DownloadHandle(); + downloadHandle.AbsoluteCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); + + string url = args.Msg; + this.Invoke((MethodInvoker)(delegate + { + + if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) + { + return; + } + else + { + downloadHandle.DownloadFileAsync(config, url, null, -1); + } + })); + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.UpdateCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); + AppendText(false, UIRes.I18N("MsgUnpacking")); + + try + { + CloseV2ray(); + + string fileName = downloadHandle.DownloadFileName; + fileName = Utils.GetPath(fileName); + FileManager.ZipExtractToFile(fileName); + + AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); + + Global.reloadV2ray = true; + LoadV2ray(); + + AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); + } + catch (Exception ex) + { + AppendText(false, ex.Message); + } + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.Error += (sender2, args) => + { + AppendText(true, args.GetException().Message); + }; + } + + AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); + downloadHandle.CheckUpdateAsync("Core"); + } + + private void tsbCheckUpdatePACList_Click(object sender, EventArgs e) + { + DownloadHandle pacListHandle = null; + if (pacListHandle == null) + { + pacListHandle = new DownloadHandle(); + pacListHandle.UpdateCompleted += (sender2, args) => + { + if (args.Success) + { + var result = args.Msg; + if (Utils.IsNullOrEmpty(result)) + { + return; + } + pacListHandle.GenPacFile(result); + + AppendText(false, UIRes.I18N("MsgPACUpdateSuccessfully")); + } + else + { + AppendText(false, UIRes.I18N("MsgPACUpdateFailed")); + } + }; + pacListHandle.Error += (sender2, args) => + { + AppendText(true, args.GetException().Message); + }; + } + AppendText(false, UIRes.I18N("MsgStartUpdatingPAC")); + pacListHandle.WebDownloadString(config.urlGFWList); + } + + private void tsbCheckClearPACList_Click(object sender, EventArgs e) + { + try + { + File.WriteAllText(Utils.GetPath(Global.pacFILE), Utils.GetEmbedText(Global.BlankPacFileName), Encoding.UTF8); + AppendText(false, UIRes.I18N("MsgSimplifyPAC")); + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + } + } + #endregion + + #region Help + + + private void tsbAbout_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start(Global.AboutUrl); + } + + private void tsbPromotion_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}"); + } + #endregion + + #region ScanScreen + + + private void bgwScan_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) + { + string ret = Utils.ScanScreen(); + bgwScan.ReportProgress(0, ret); + } + + private void bgwScan_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) + { + ShowForm(); + + string result = Convert.ToString(e.UserState); + if (Utils.IsNullOrEmpty(result)) + { + UI.Show(UIRes.I18N("NoValidQRcodeFound")); + } + else + { + if (AddBatchServers(result) > 0) + { + UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan")); + } + } + } + + #endregion + + #region 订阅 + private void tsbSubSetting_Click(object sender, EventArgs e) + { + SubSettingForm fm = new SubSettingForm(); + if (fm.ShowDialog() == DialogResult.OK) + { + RefreshServers(); + } + } + + private void tsbSubUpdate_Click(object sender, EventArgs e) + { + AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); + + if (config.subItem == null || config.subItem.Count <= 0) + { + AppendText(false, UIRes.I18N("MsgNoValidSubscription")); + return; + } + + for (int k = 1; k <= config.subItem.Count; k++) + { + string id = config.subItem[k - 1].id.TrimEx(); + string url = config.subItem[k - 1].url.TrimEx(); + string hashCode = $"{k}->"; + if (config.subItem[k - 1].enabled == false) + { + continue; + } + if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) + { + AppendText(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); + continue; + } + + DownloadHandle downloadHandle3 = new DownloadHandle(); + downloadHandle3.UpdateCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); + var result = Utils.Base64Decode(args.Msg); + if (Utils.IsNullOrEmpty(result)) + { + AppendText(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); + return; + } + + ConfigHandler.RemoveServerViaSubid(ref config, id); + AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); + RefreshServers(); + if (AddBatchServers(result, id) > 0) + { + } + else + { + AppendText(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); + } + AppendText(false, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle3.Error += (sender2, args) => + { + AppendText(true, args.GetException().Message); + }; + + downloadHandle3.WebDownloadString(url); + AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); + } + } + + #endregion + + #region Language + + private void tsbLanguageDef_Click(object sender, EventArgs e) + { + SetCurrentLanguage("en"); + } + + private void tsbLanguageZhHans_Click(object sender, EventArgs e) + { + SetCurrentLanguage("zh-Hans"); + } + private void SetCurrentLanguage(string value) + { + Utils.RegWriteValue(Global.MyRegPath, Global.MyRegKeyLanguage, value); + Application.Restart(); + } + + + #endregion + + private void tsbV2rayWebsite_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start(Global.v2rayWebsiteUrl); + } + } +} diff --git a/v2rayN/v2rayN/Forms/MainForm.resx b/v2rayN/v2rayN/Forms/MainForm.resx index c8a36583..7cf2c348 100644 --- a/v2rayN/v2rayN/Forms/MainForm.resx +++ b/v2rayN/v2rayN/Forms/MainForm.resx @@ -423,34 +423,46 @@ NoControl - 547, 22 + 411, 22 Not Enabled Http Proxy - 547, 22 + 411, 22 - Open Http proxy and automatically configure proxy server (global mode) + Open Http proxy and set the system proxy (global mode) - 547, 22 + 411, 22 - Open PAC and automatically configure PAC (PAC mode) + Open PAC and set the system proxy (PAC mode) - 547, 22 + 411, 22 - Only open Http proxy, do not automatically configure proxy server (direct mode) + Only open Http proxy and clear the proxy settings - 547, 22 + 411, 22 - Only open PAC, do not automatically configure PAC + Only open PAC and clear the proxy settings + + + 411, 22 + + + Only open Http proxy and do nothing + + + 411, 22 + + + Only open PAC and do nothing 264, 22 @@ -492,7 +504,7 @@ Exit - 265, 142 + 265, 164 cmsMain @@ -1163,6 +1175,18 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + menuKeepNothing + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + menuKeepPACNothing + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + menuServers @@ -1373,18 +1397,18 @@ System.Windows.Forms.ToolStripDropDownButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsbV2rayWebsite - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tsbAbout System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsbV2rayWebsite + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripSeparator12 diff --git a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx index a89539cb..1fdca7f8 100644 --- a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx @@ -119,151 +119,151 @@ - 278, 22 + 300, 22 添加[VMess]服务器 - 278, 22 + 300, 22 添加[Shadowsocks]服务器 - 278, 22 + 300, 22 添加[Socks]服务器 - 278, 22 + 300, 22 添加自定义配置服务器 - 278, 22 + 300, 22 从剪贴板导入批量URL (Ctrl+V) - 278, 22 + 300, 22 扫描屏幕上的二维码 (Ctrl+S) - 275, 6 + 297, 6 - 278, 22 + 300, 22 移除所选服务器(多选) (Delete) - 278, 22 + 300, 22 移除重复的服务器 - 278, 22 + 300, 22 克隆所选服务器 - 278, 22 + 300, 22 设为活动服务器 (Enter) - 275, 6 + 297, 6 - 278, 22 + 300, 22 上移至顶 (T) - 278, 22 + 300, 22 上移 (U) - 278, 22 + 300, 22 下移 (D) - 278, 22 + 300, 22 下移至底 (B) - 278, 22 + 300, 22 全选 (Ctrl+A) - 275, 6 + 297, 6 - 278, 22 + 300, 22 测试服务器延迟Ping(多选) (Ctrl+P) - 278, 22 + 300, 22 测试服务器延迟Tcping(多选) (Ctrl+O) - 278, 22 + 300, 22 测试服务器真连接延迟(多选) (Ctrl+R) - 278, 22 + 300, 22 测试服务器速度(多选) (Ctrl+T) - 275, 6 + 297, 6 - 278, 22 + 300, 22 导出所选服务器为客户端配置 - 278, 22 + 300, 22 导出所选服务器为服务端配置 - 278, 22 + 300, 22 批量导出分享URL至剪贴板(多选) (Ctrl+C) - 278, 22 + 300, 22 批量导出订阅内容至剪贴板(多选) @@ -275,7 +275,7 @@ 服务器 - 279, 534 + 301, 534 @@ -295,34 +295,46 @@ - 340, 22 + 316, 22 关闭Http代理 - 340, 22 + 316, 22 - 开启Http代理,并自动配置代理服务器(全局模式) + 开启Http代理,并自动配置系统代理(全局模式) - 340, 22 + 316, 22 - 开启PAC,并自动配置PAC(PAC模式) + 开启PAC,并自动配置系统代理(PAC模式) - 340, 22 + 316, 22 - 仅开启Http代理,不自动配置代理服务器(直连模式) + 仅开启Http代理,并清除系统代理 - 340, 22 + 316, 22 - 仅开启PAC,不自动配置PAC + 仅开启PAC,并清除系统代理 + + + 316, 22 + + + 仅开启Http代理,不改变系统代理 + + + 316, 22 + + + 仅开启PAC,不改变系统代理 195, 22 @@ -402,7 +414,7 @@ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAE3SURBVFhH7ZaBDQIhDEVvBEdwBDfQDXQER3AD3cARdAPd + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAE3SURBVFhH7ZaBDQIhDEVvBEdwBDfQDXQER3AD3cARdAPd QDfSDbQvuSb1AicFjJrwkxcN0FIolOuamv5VE2E+gLaPayWchEcE+hhTXVPhIoQmDcFYbKpoJtwEdX4X jgIrXfTwnzb6dBw22BaJVdjJmWQs1/SdBRtE0U5cBXW2oSFRO0HtSEeW2FZ1wsq9sjuRdTDVAXnNuWLY 6JnAl0sYa/Q5q1dhq35ci+Bkq2HJvbZpxGeybAAuw4Fq+cnW1wPITgHFYxvBUw+qHEIL1yq1vDKhVlH3 @@ -417,25 +429,28 @@ 重启服务 - 232, 22 + 223, 22 v2rayN - 232, 22 + 223, 22 v2rayCore - 232, 22 + 223, 22 PAC + + 220, 6 + - 232, 22 + 223, 22 简化PAC (请设置Core路由) @@ -446,12 +461,12 @@ 检查更新 - - V2Ray 官网 - v2rayN 项目 + + V2Ray 官网 + 69, 53 @@ -467,10 +482,13 @@ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAAySURBVFhH7c6xDQAgCEVBRnVTHU2ZABuMxV3yOvJDAAA/ + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAySURBVFhH7c6xDQAgCEVBRnVTHU2ZABuMxV3yOvJDAAA/ GqfZVG6X8mg1dfUAAPBQxAZd0SJruVXHWwAAAABJRU5ErkJggg== + + 76, 53 + 关闭窗口 diff --git a/v2rayN/v2rayN/Forms/OptionSettingForm.Designer.cs b/v2rayN/v2rayN/Forms/OptionSettingForm.Designer.cs index 5e00b7e5..8799a79c 100644 --- a/v2rayN/v2rayN/Forms/OptionSettingForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/OptionSettingForm.Designer.cs @@ -118,32 +118,33 @@ // // btnClose // - this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; resources.ApplyResources(this.btnClose, "btnClose"); + this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnClose.Name = "btnClose"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // tabControl1 // + resources.ApplyResources(this.tabControl1, "tabControl1"); this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Controls.Add(this.tabPage6); this.tabControl1.Controls.Add(this.tabPage7); this.tabControl1.Controls.Add(this.tabPage9); - resources.ApplyResources(this.tabControl1, "tabControl1"); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; // // tabPage1 // - this.tabPage1.Controls.Add(this.groupBox1); resources.ApplyResources(this.tabPage1, "tabPage1"); + this.tabPage1.Controls.Add(this.groupBox1); this.tabPage1.Name = "tabPage1"; this.tabPage1.UseVisualStyleBackColor = true; // // groupBox1 // + resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Controls.Add(this.label16); this.groupBox1.Controls.Add(this.cmblistenerType); this.groupBox1.Controls.Add(this.chksniffingEnabled2); @@ -164,7 +165,6 @@ this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.txtlocalPort); this.groupBox1.Controls.Add(this.label2); - resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // @@ -175,6 +175,7 @@ // // cmblistenerType // + resources.ApplyResources(this.cmblistenerType, "cmblistenerType"); this.cmblistenerType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmblistenerType.FormattingEnabled = true; this.cmblistenerType.Items.AddRange(new object[] { @@ -182,8 +183,9 @@ resources.GetString("cmblistenerType.Items1"), resources.GetString("cmblistenerType.Items2"), resources.GetString("cmblistenerType.Items3"), - resources.GetString("cmblistenerType.Items4")}); - resources.ApplyResources(this.cmblistenerType, "cmblistenerType"); + resources.GetString("cmblistenerType.Items4"), + resources.GetString("cmblistenerType.Items5"), + resources.GetString("cmblistenerType.Items6")}); this.cmblistenerType.Name = "cmblistenerType"; // // chksniffingEnabled2 @@ -229,12 +231,12 @@ // // cmbprotocol2 // + resources.ApplyResources(this.cmbprotocol2, "cmbprotocol2"); this.cmbprotocol2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbprotocol2.FormattingEnabled = true; this.cmbprotocol2.Items.AddRange(new object[] { resources.GetString("cmbprotocol2.Items"), resources.GetString("cmbprotocol2.Items1")}); - resources.ApplyResources(this.cmbprotocol2, "cmbprotocol2"); this.cmbprotocol2.Name = "cmbprotocol2"; // // label3 @@ -249,8 +251,8 @@ // // cmbprotocol // - this.cmbprotocol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; resources.ApplyResources(this.cmbprotocol, "cmbprotocol"); + this.cmbprotocol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbprotocol.FormattingEnabled = true; this.cmbprotocol.Items.AddRange(new object[] { resources.GetString("cmbprotocol.Items"), @@ -276,6 +278,7 @@ // // cmbloglevel // + resources.ApplyResources(this.cmbloglevel, "cmbloglevel"); this.cmbloglevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbloglevel.FormattingEnabled = true; this.cmbloglevel.Items.AddRange(new object[] { @@ -284,7 +287,6 @@ resources.GetString("cmbloglevel.Items2"), resources.GetString("cmbloglevel.Items3"), resources.GetString("cmbloglevel.Items4")}); - resources.ApplyResources(this.cmbloglevel, "cmbloglevel"); this.cmbloglevel.Name = "cmbloglevel"; // // label5 @@ -304,33 +306,33 @@ // // tabPage2 // - this.tabPage2.Controls.Add(this.groupBox2); resources.ApplyResources(this.tabPage2, "tabPage2"); + this.tabPage2.Controls.Add(this.groupBox2); this.tabPage2.Name = "tabPage2"; this.tabPage2.UseVisualStyleBackColor = true; // // groupBox2 // + resources.ApplyResources(this.groupBox2, "groupBox2"); this.groupBox2.Controls.Add(this.tabControl2); this.groupBox2.Controls.Add(this.panel3); - resources.ApplyResources(this.groupBox2, "groupBox2"); this.groupBox2.Name = "groupBox2"; this.groupBox2.TabStop = false; // // tabControl2 // + resources.ApplyResources(this.tabControl2, "tabControl2"); this.tabControl2.Controls.Add(this.tabPage3); this.tabControl2.Controls.Add(this.tabPage4); this.tabControl2.Controls.Add(this.tabPage5); this.tabControl2.Controls.Add(this.tabPage8); - resources.ApplyResources(this.tabControl2, "tabControl2"); this.tabControl2.Name = "tabControl2"; this.tabControl2.SelectedIndex = 0; // // tabPage3 // - this.tabPage3.Controls.Add(this.txtUseragent); resources.ApplyResources(this.tabPage3, "tabPage3"); + this.tabPage3.Controls.Add(this.txtUseragent); this.tabPage3.Name = "tabPage3"; this.tabPage3.UseVisualStyleBackColor = true; // @@ -341,8 +343,8 @@ // // tabPage4 // - this.tabPage4.Controls.Add(this.txtUserdirect); resources.ApplyResources(this.tabPage4, "tabPage4"); + this.tabPage4.Controls.Add(this.txtUserdirect); this.tabPage4.Name = "tabPage4"; this.tabPage4.UseVisualStyleBackColor = true; // @@ -353,8 +355,8 @@ // // tabPage5 // - this.tabPage5.Controls.Add(this.txtUserblock); resources.ApplyResources(this.tabPage5, "tabPage5"); + this.tabPage5.Controls.Add(this.txtUserblock); this.tabPage5.Name = "tabPage5"; this.tabPage5.UseVisualStyleBackColor = true; // @@ -365,13 +367,14 @@ // // tabPage8 // - this.tabPage8.Controls.Add(this.cmbroutingMode); resources.ApplyResources(this.tabPage8, "tabPage8"); + this.tabPage8.Controls.Add(this.cmbroutingMode); this.tabPage8.Name = "tabPage8"; this.tabPage8.UseVisualStyleBackColor = true; // // cmbroutingMode // + resources.ApplyResources(this.cmbroutingMode, "cmbroutingMode"); this.cmbroutingMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbroutingMode.FormattingEnabled = true; this.cmbroutingMode.Items.AddRange(new object[] { @@ -379,16 +382,15 @@ resources.GetString("cmbroutingMode.Items1"), resources.GetString("cmbroutingMode.Items2"), resources.GetString("cmbroutingMode.Items3")}); - resources.ApplyResources(this.cmbroutingMode, "cmbroutingMode"); this.cmbroutingMode.Name = "cmbroutingMode"; // // panel3 // + resources.ApplyResources(this.panel3, "panel3"); this.panel3.Controls.Add(this.btnSetDefRountingRule); this.panel3.Controls.Add(this.labRoutingTips); this.panel3.Controls.Add(this.cmbdomainStrategy); this.panel3.Controls.Add(this.label15); - resources.ApplyResources(this.panel3, "panel3"); this.panel3.Name = "panel3"; // // btnSetDefRountingRule @@ -400,19 +402,19 @@ // // labRoutingTips // - this.labRoutingTips.ForeColor = System.Drawing.Color.Brown; resources.ApplyResources(this.labRoutingTips, "labRoutingTips"); + this.labRoutingTips.ForeColor = System.Drawing.Color.Brown; this.labRoutingTips.Name = "labRoutingTips"; // // cmbdomainStrategy // + resources.ApplyResources(this.cmbdomainStrategy, "cmbdomainStrategy"); this.cmbdomainStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbdomainStrategy.FormattingEnabled = true; this.cmbdomainStrategy.Items.AddRange(new object[] { resources.GetString("cmbdomainStrategy.Items"), resources.GetString("cmbdomainStrategy.Items1"), resources.GetString("cmbdomainStrategy.Items2")}); - resources.ApplyResources(this.cmbdomainStrategy, "cmbdomainStrategy"); this.cmbdomainStrategy.Name = "cmbdomainStrategy"; // // label15 @@ -422,6 +424,7 @@ // // tabPage6 // + resources.ApplyResources(this.tabPage6, "tabPage6"); this.tabPage6.Controls.Add(this.chkKcpcongestion); this.tabPage6.Controls.Add(this.txtKcpwriteBufferSize); this.tabPage6.Controls.Add(this.label10); @@ -435,7 +438,6 @@ this.tabPage6.Controls.Add(this.label7); this.tabPage6.Controls.Add(this.txtKcpmtu); this.tabPage6.Controls.Add(this.label6); - resources.ApplyResources(this.tabPage6, "tabPage6"); this.tabPage6.Name = "tabPage6"; this.tabPage6.UseVisualStyleBackColor = true; // @@ -507,6 +509,7 @@ // // tabPage7 // + resources.ApplyResources(this.tabPage7, "tabPage7"); this.tabPage7.Controls.Add(this.cbFreshrate); this.tabPage7.Controls.Add(this.lbFreshrate); this.tabPage7.Controls.Add(this.chkEnableStatistics); @@ -514,15 +517,14 @@ this.tabPage7.Controls.Add(this.txturlGFWList); this.tabPage7.Controls.Add(this.label13); this.tabPage7.Controls.Add(this.chkAutoRun); - resources.ApplyResources(this.tabPage7, "tabPage7"); this.tabPage7.Name = "tabPage7"; this.tabPage7.UseVisualStyleBackColor = true; // // cbFreshrate // + resources.ApplyResources(this.cbFreshrate, "cbFreshrate"); this.cbFreshrate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbFreshrate.FormattingEnabled = true; - resources.ApplyResources(this.cbFreshrate, "cbFreshrate"); this.cbFreshrate.Name = "cbFreshrate"; // // lbFreshrate @@ -560,9 +562,9 @@ // // tabPage9 // + resources.ApplyResources(this.tabPage9, "tabPage9"); this.tabPage9.Controls.Add(this.txtuserPacRule); this.tabPage9.Controls.Add(this.panel4); - resources.ApplyResources(this.tabPage9, "tabPage9"); this.tabPage9.Name = "tabPage9"; this.tabPage9.UseVisualStyleBackColor = true; // @@ -573,21 +575,21 @@ // // panel4 // - this.panel4.Controls.Add(this.label4); resources.ApplyResources(this.panel4, "panel4"); + this.panel4.Controls.Add(this.label4); this.panel4.Name = "panel4"; // // label4 // - this.label4.ForeColor = System.Drawing.Color.Brown; resources.ApplyResources(this.label4, "label4"); + this.label4.ForeColor = System.Drawing.Color.Brown; this.label4.Name = "label4"; // // panel2 // + resources.ApplyResources(this.panel2, "panel2"); this.panel2.Controls.Add(this.btnClose); this.panel2.Controls.Add(this.btnOK); - resources.ApplyResources(this.panel2, "panel2"); this.panel2.Name = "panel2"; // // btnOK diff --git a/v2rayN/v2rayN/Forms/OptionSettingForm.resx b/v2rayN/v2rayN/Forms/OptionSettingForm.resx index d6938a98..0bf6ffbf 100644 --- a/v2rayN/v2rayN/Forms/OptionSettingForm.resx +++ b/v2rayN/v2rayN/Forms/OptionSettingForm.resx @@ -117,1415 +117,31 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 355, 16 - - - 75, 23 - - - 7 - - - &Cancel - - - btnClose - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 0 - - + True - - - NoControl - - - 42, 98 - - - 65, 12 - - - 34 - - - Http proxy - - - label16 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 0 - - - Not Enabled Http Proxy - - - Open Http proxy and automatically configure proxy server (global mode) - - - Open PAC and automatically configure PAC (PAC mode) - - - Only open Http proxy, do not automatically configure proxy server (direct mode) - - - Only open PAC, do not automatically configure PAC - - - 124, 94 - - - 464, 20 - - - 33 - - - cmblistenerType - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 1 - - - True - - - NoControl - - - 468, 60 - - - 120, 16 - - - 32 - - - Turn on Sniffing - - - False - - - chksniffingEnabled2 - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 2 - - - True - - - NoControl - - - 468, 27 - - - 120, 16 - - - 31 - - - Turn on Sniffing - - - chksniffingEnabled - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 3 - - - 33, 228 - - - True - - - 555, 100 - - - 30 - - - txtremoteDNS + + 11 System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - groupBox1 - - - 4 - - - True - - - 33, 204 - - - 281, 12 - - - 29 - - - Custom DNS (multiple, separated by commas (,)) - - - label14 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 5 - - - True - - - 15, 129 - - - 174, 16 - - - 20 - - - Turn on Mux Multiplexing - - - chkmuxEnabled - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 6 - - - True - - - 15, 63 - - - 120, 16 - - - 19 - - - listening port 2 - - - False - - - chkAllowIn2 - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 7 - - - True - - - 369, 62 - - - 84, 16 - - - 18 - - - Enable UDP - - - False - - - chkudpEnabled2 - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 8 - - - socks - - - http - - - 257, 60 - - - 97, 20 - - - 17 - - - False - - - cmbprotocol2 - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 9 - - - True - - - 206, 64 - - - 53, 12 - - - 16 - - - protocol - - - False - - - label3 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 10 - - - 124, 60 - - - 78, 21 - - - 14 - - - False - - - txtlocalPort2 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 11 - - - False - - - socks - - - http - - - 257, 25 - - - 97, 20 - - - 12 - - - cmbprotocol - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 12 - - - True - - - 206, 29 - - - 53, 12 - - - 11 - - - protocol - - - label1 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 13 - - - True - - - 369, 27 - - - 84, 16 - - - 10 - - - Enable UDP - - - chkudpEnabled - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 14 - - - True - - - 15, 160 - - - 126, 16 - - - 9 - - - Record local logs - - - chklogEnabled - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 15 - - - debug - - - info - - - warning - - - error - - - none - - - 257, 158 - - - 97, 20 - - - 6 - - - cmbloglevel - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 16 - - - True - - - 193, 162 - - - 59, 12 - - - 8 - - - Log level - - - label5 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 17 - - - 124, 25 - - - 78, 21 - - - 3 - - - txtlocalPort - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 18 - - - True - - - 33, 29 - - - 89, 12 - - - 2 - - - Listening port - - - label2 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 19 - - - Fill - - - 3, 3 - - - 648, 573 - - - 6 - - - groupBox1 - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage1 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 654, 579 - - - 0 - - - Core: basic settings - - - tabPage1 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl1 - - - 0 - - - Fill - - - 3, 3 - - - 0 - - - True - - - Vertical - - - 628, 454 - - - 0 - - - txtUseragent - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage3 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 634, 460 - - - 0 - - - 1.Proxy Domain or IP - - - tabPage3 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl2 - - - 0 - - - Fill - - - 3, 3 - - - 0 - - - True - - - Vertical - - - 628, 454 - - - 1 - - - txtUserdirect - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage4 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 634, 460 - - - 1 - - - 2.Direct Domain or IP - - - tabPage4 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl2 - - - 1 - - - Fill - - - 3, 3 - - - 0 - - - True - - - Vertical - - - 628, 454 - - - 1 - - - txtUserblock - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage5 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 634, 460 - - - 2 - - - 3.Block Domain or IP - - - tabPage5 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl2 - - - 2 - - - Global - - - Bypassing the LAN address - - - Bypass mainland address - - - Bypassing LAN and mainland address - - - 21, 17 - - - 255, 20 - - - 14 - - - cmbroutingMode - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage8 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 634, 460 - - - 3 - - - 4.Pre-defined rules - - - tabPage8 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl2 - - - 3 - - - Fill - - - 3, 84 - - - 642, 486 - - - 12 - - - tabControl2 - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - groupBox2 - - 0 - - - 322, 10 - - - 229, 23 - - - 18 - - - Set default custom routing rules - - - btnSetDefRountingRule - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 0 - - - 5, 45 - - - 598, 16 - - - 13 - - - *Set the rules, separated by commas (,); support Domain (pure string / regular / subdomain) and IP - - - labRoutingTips - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - 1 - - AsIs + + + 30, 176 - - IPIfNonMatch + + Record local logs - - IPOnDemand - - - 115, 10 - - - 165, 20 - - - 16 - - - cmbdomainStrategy - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 2 - - - True - - - NoControl - - - 5, 14 - - - 95, 12 - - - 17 - - - Domain strategy - - - label15 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel3 - - - 3 - - - Top - - - 3, 17 - - - 642, 67 - - - 19 - - - panel3 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox2 - - - 1 - - - Fill - - - 3, 3 - - - 648, 573 - - - 12 - - - groupBox2 - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage2 - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 654, 579 - - - 1 - - - Core: Routing settings - - - tabPage2 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl1 - - - 1 - - - True - - - 20, 143 - - - 84, 16 - - - 20 - - - congestion - - - chkKcpcongestion - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 0 - - - 345, 100 - - - 94, 21 - - - 15 - - - txtKcpwriteBufferSize - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 1 - - - True - - - 236, 104 - - - 95, 12 - - - 14 - - - writeBufferSize - - - label10 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 2 - - - 111, 100 - - - 94, 21 - - - 13 - - - txtKcpreadBufferSize - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 3 - - - True - - - 18, 104 - - - 89, 12 - - - 12 - - - readBufferSize - - - label11 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 4 - - - 345, 62 - - - 94, 21 - - - 11 - - - txtKcpdownlinkCapacity - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 5 - - - True - - - 236, 66 - - - 101, 12 - - - 10 - - - downlinkCapacity - - - label8 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 6 - - - 111, 62 - - - 94, 21 - - - 9 - - - txtKcpuplinkCapacity - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 7 - - - True - - - 18, 66 - - - 89, 12 - - - 8 - - - uplinkCapacity - - - label9 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 8 - - - 345, 24 - - - 94, 21 - - - 7 - - - txtKcptti - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 9 - - - True - - - 236, 28 - - - 23, 12 - - - 6 - - - tti - - - label7 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 10 - - - 111, 24 - - - 94, 21 - - - 5 - - - txtKcpmtu - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 - - - 11 - - - True - - - 18, 28 - - - 23, 12 - - - 4 - - - mtu - - - label6 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage6 + + 634, 460 12 @@ -1533,469 +149,1859 @@ 4, 22 - - 3, 3, 3, 3 + + txtKcpwriteBufferSize - - 654, 579 + + groupBox1 - - 2 + + 1 - - Core: KCP settings + + False - - tabPage6 + + 17 - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 tabControl1 - - 2 + + groupBox1 - - 161, 84 + + 5 - - 58, 20 + + 94, 21 - - 32 + + 9 - - cbFreshrate + + groupBox1 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + label15 - - tabPage7 + + tabPage9 - + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 13 + + + 468, 60 + + + + Top + + + 15, 16 + + + 6 + + + txtKcptti + + + tabPage3 + + + 4, 22 + + + cmblistenerType + + 0 - + + 634, 460 + + + 0 + + + 111, 100 + + True - - NoControl + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 30, 92 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 125, 12 + + 3, 3 - - 30 + + 598, 16 - - Statistics freshrate + + Core: basic settings + + + True + + + 120, 16 + + + 281, 12 + + + panel3 + + + True + + + tti + + + tabPage6 + + + 84, 16 + + + tabPage9 + + + 628, 454 + + + tabPage7 + + + Only open PAC, do not automatically configure PAC + + + 12 + + + 662, 60 + + + 20 + + + http + + + 7 + + + label5 + + + 648, 573 + + + Core: KCP settings + + + 206, 64 + + + 95, 12 + + + tabPage6 + + + 14 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Only open PAC and do nothing + + + 15, 63 + + + tabControl2 + + + 16 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Fill + + + Enable UDP + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Fill + + + &Cancel + + + label10 + + + 648, 573 + + + Vertical + + + groupBox1 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + 1 + + + Bypassing the LAN address + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Bypassing LAN and mainland address + + + Bypass mainland address + + + Top + + + 12 + + + txtKcpmtu lbFreshrate - + + 1 + + + label11 + + + 29 + + + 1 + + + NoControl + + + tabPage6 + + + Only open Http proxy, do not automatically configure proxy server (direct mode) + + + 4 + + + tabPage6 + + + False + + + tabControl2 + + + 0 + + + $this + + + 6 + + + 2 + + + 3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + 0 + + + tabPage6 + + + 3 + + + 18 + + + True + + + Fill + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + congestion + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + panel3 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 3, 3, 3, 3 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 89, 12 + + + info + + + txtUseragent + + + 1 + + + tabPage7 + + + v2rayN settings + + + 19 + + + 15 + + + Not Enabled Http Proxy + + + 13 + + + 32 + + + 628, 454 + + + 6, 12 + + + groupBox1 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + txtKcpdownlinkCapacity + + + Boot automatically + + + 654, 579 + + + 3, 3, 3, 3 + + + 1 + + + Http proxy + + + 4 + + + Turn on Sniffing + + + tabPage6 + + + 355, 16 + + + 3, 3, 3, 3 + + + 97, 20 + + + 3 + + + 5, 14 + + + 662, 605 + + + 33, 29 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 78, 21 + + + 5, 45 + + + Custom DNS (multiple, separated by commas (,)) + + + tabControl1 + + + 9 + + + 598, 16 + + + 654, 579 + + + v2rayN.Forms.BaseForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + warning + + + groupBox1 + + + 0 + + + tabPage7 + + + True + + + Statistics freshrate + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 120, 16 + + + 20 + + + 89, 12 + + + Only open Http proxy and do nothing + + + 120, 16 + + + 18, 66 + + + 20, 143 + + + 11 + + + 4, 4, 4, 4 + + + tabPage6 + + + btnClose + + + Turn on Sniffing + + + cmbloglevel + + + groupBox1 + + + 18, 28 + + + 34 + + + 20 + + + 29 + + + 0 + + + 21, 17 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 1 + + + label16 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 14 + + + 19 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + *Set user pac rules, separated by commas (,) + + + True + + + chksniffingEnabled + + + 5 + + + 174, 16 + + + 16 + + + 30, 92 + + + groupBox1 + + + 18, 104 + + + tabPage2 + + + 97, 20 + + + socks + + + tabPage5 + + + 558, 16 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 464, 20 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage6 + + + *Set the rules, separated by commas (,); support Domain (pure string / regular / subdomain) and IP + + + tabPage3 + + + 30 + + + 53, 12 + + + 16 + + + label8 + + + 468, 27 + + + label13 + + + chkAutoRun + + + 65, 12 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 3 + + + 14 + + + 12 + + + 15, 129 + + + chkudpEnabled + + + 345, 24 + + + True + + + 33, 204 + + + tabPage1 + + + 5 + + + tabPage6 + + + 2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 4 + + + btnSetDefRountingRule + + + True + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + label1 + + + 84, 16 + + + tabPage8 + + + True + + + False + + + label7 + + + 4, 22 + + + txtlocalPort + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage7 + + + 3, 17 + + + 4, 22 + + + labRoutingTips + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 3, 3, 3, 3 + + + 124, 25 + + + protocol + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabControl2 + + + 84, 16 + + + Turn on Mux Multiplexing + + + 23, 12 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 97, 20 + + + 555, 100 + + + socks + + + 3, 3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + chkAllowLANConn + + + 4, 22 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabControl1 + + + 1 + + + True + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 15, 38 + + + 2 + + + 10 + + + 369, 62 + + + 12 + + + 1.Proxy Domain or IP + + + panel3 + + + NoControl + + + 654, 579 + + + tabControl2 + + + 7 + + + 7 + + + http + + + 53, 12 + + + 1 + + + 2 + + + 0 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage6 + + + label2 + + + 165, 20 + + + False + + + 0 + + + 3, 3 + + + 9 + + + groupBox1 + + + 4.Pre-defined rules + + + 101, 12 + + + 2 + + + 12 + + + 431, 12 + + + cmbprotocol + + + 648, 37 + + + True + + + Enable Statistics(Realtime net speed and traffic data amount. Need restart v2rayN client) + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 4 + + + Listening port + + + Vertical + + + Fill + + + 1 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Vertical + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 28 + + + 257, 60 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabControl1 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + cmbprotocol2 + + + Open Http proxy and automatically configure proxy server (global mode) + + + groupBox2 + + + True + + + 94, 21 + + + mtu + + + True + + + panel4 + + + True + + + chkKcpcongestion + + + 0 + + + 0 + + + 257, 25 + + + 3, 84 + + + groupBox1 + + + Top + + + listening port 2 + + + 11 + + + chkAllowIn2 + + + tabPage2 + + + 14 + + + True + + + True + + + 19 + + + 3 + + + tabPage4 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 4 + + + 541, 100 + + + panel3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + error + + + True + + + txtuserPacRule + + + 59, 12 + + + groupBox1 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 634, 460 + + + 11 + + + tabControl1 + + + 662, 10 + + + txtlocalPort2 + + + True + + + tabPage7 + + + True + + + Fill + + + groupBox1 + + + 654, 579 + + + 7 + + + 27 + + + 10 + + + False + + + Vertical + + + 206, 29 + + + 8 + + + txtUserdirect + + + chkudpEnabled2 + + + 0 + + + 0 + + + 648, 536 + + + Allow connections from the LAN + + + 161, 84 + + + panel3 + + + tabPage6 + + + tabControl2 + + + txtKcpreadBufferSize + + + 3 + + + panel2 + + + 30 + + + 8 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + User PAC settings + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 tabPage7 - - 1 + + 9 - - True + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + Log level + + + tabControl1 + + + protocol + + + 6 + + + tabPage4 + + NoControl - - 15, 62 - - - 558, 16 - - - 29 - - - Enable Statistics(Realtime net speed and traffic data amount. Need restart v2rayN client) - - - chkEnableStatistics - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage7 - - + 2 - - True - - - 15, 38 - - - 204, 16 - - - 29 - - - Allow connections from the LAN - - - chkAllowLANConn - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage7 - - - 3 - - - 32, 205 - - - True - - - 541, 100 - - - 28 - - - txturlGFWList - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage7 - - - 4 - - - True - - - 30, 176 - - - 431, 12 - - - 27 - - - Custom GFWList address (please fill in the blank without customization) - - - label13 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage7 - - - 5 - - - True - - - 15, 16 - - - 132, 16 - - - 23 - - - Boot automatically - - - chkAutoRun - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tabPage7 + + AsIs + + + 15, 62 6 - - 4, 22 - - - 3, 3, 3, 3 - - - 654, 579 - - - 3 - - - v2rayN settings - - + tabPage7 - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 642, 486 - - tabControl1 - - - 3 - - - Fill - - - 3, 40 - - - 0 - - - True - - - Vertical - - - 648, 536 - - - 21 - - - txtuserPacRule - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage9 - - - 0 - - - NoControl - - - 5, 11 - - - 598, 16 - - - 13 - - - *Set user pac rules, separated by commas (,) - - - label4 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel4 - - - 0 - - - Top - - - 3, 3 - - - 648, 37 - - - 20 - - - panel4 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabPage9 - - - 1 - - + 4, 22 - - 3, 3, 3, 3 - - - 654, 579 - - - 4 - - - User PAC settings - - - tabPage9 - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tabControl1 - - - 4 - - - Fill - - - 0, 10 - - - 662, 605 - - - 10 - - - tabControl1 - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - 267, 16 - - - 75, 23 - - - 8 - - - &OK - - - btnOK - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 1 - - - Bottom - - - 0, 615 - - - 662, 60 - - - 11 - - - panel2 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this + + 58, 20 1 - - Top + + 42, 98 - - 0, 0 + + 13 - - 662, 10 + + 13 - - 9 - - - panel1 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - + 2 - + + downlinkCapacity + + + 78, 21 + + True - - - 6, 12 - - 662, 675 + + True - - 4, 4, 4, 4 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Settings + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + cmbroutingMode + + + 3, 3 + + + 1 + + + 23, 12 + + + True + + + 8 + + + True + + + 3, 3, 3, 3 + + + 17 + + + 345, 100 + + + 94, 21 + + + 75, 23 + + + True + + + 10 + + + 204, 16 + + + 17 + + + 94, 21 + + + debug + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 5 + + + 0, 615 + + + txtUserblock + + + 229, 23 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage1 + + + 15 + + + 2 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + Custom GFWList address (please fill in the blank without customization) + + + 18 + + + 255, 20 + + + NoControl + + + 4, 22 + + + cmbdomainStrategy OptionSettingForm - - v2rayN.Forms.BaseForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + NoControl + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + &OK + + + 10 + + + 3, 40 + + + panel2 + + + txtKcpuplinkCapacity + + + 115, 10 + + + 23 + + + chklogEnabled + + + chksniffingEnabled2 + + + 1 + + + 642, 67 + + + 0 + + + 4, 22 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Domain strategy + + + tabPage5 + + + 8 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + IPIfNonMatch + + + groupBox1 + + + groupBox1 + + + 0 + + + 3.Block Domain or IP + + + label3 + + + 6 + + + 236, 66 + + + tabPage7 + + + $this + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + $this + + + 8 + + + txtremoteDNS + + + 654, 579 + + + True + + + 33 + + + 3 + + + writeBufferSize + + + 11 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 89, 12 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + 31 + + + 369, 27 + + + 193, 162 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Fill + + + groupBox1 + + + groupBox1 + + + 32 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel4 + + + Core: Routing settings + + + 29 + + + Fill + + + True + + + 3, 3 + + + 257, 158 + + + tabPage8 + + + 2 + + + 236, 104 + + + 4 + + + Open PAC and automatically configure PAC (PAC mode) + + + 125, 12 + + + NoControl + + + tabPage9 + + + 94, 21 + + + 75, 23 + + + True + + + 33, 228 + + + 345, 62 + + + uplinkCapacity + + + 662, 675 + + + chkEnableStatistics + + + IPOnDemand + + + True + + + 6 + + + 0 + + + 0 + + + Settings + + + 0 + + + 3, 3, 3, 3 + + + 3, 3 + + + 32, 205 + + + 634, 460 + + + 111, 62 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + label4 + + + 628, 454 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox2 + + + 124, 94 + + + btnOK + + + Set default custom routing rules + + + tabPage6 + + + txturlGFWList + + + chkmuxEnabled + + + none + + + tabPage6 + + + False + + + 4, 22 + + + 5, 11 + + + 0 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0, 0 + + + Enable UDP + + + 15, 160 + + + 3, 3, 3, 3 + + + groupBox1 + + + 18 + + + 126, 16 + + + 267, 16 + + + Global + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 95, 12 + + + groupBox1 + + + Fill + + + False + + + readBufferSize + + + 9 + + + 0 + + + 322, 10 + + + groupBox1 + + + 0 + + + 94, 21 + + + 3 + + + 3 + + + 3, 3, 3, 3 + + + 236, 28 + + + Bottom + + + 2.Direct Domain or IP + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + NoControl + + + 3, 3, 3, 3 + + + 10 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 124, 60 + + + cbFreshrate + + + 132, 16 + + + tabPage6 + + + label6 + + + 111, 24 + + + panel2 + + + 21 + + + label9 + + + 0, 10 + + + panel1 + + + 2 + + + label14 + + + True + \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/OptionSettingForm.zh-Hans.resx b/v2rayN/v2rayN/Forms/OptionSettingForm.zh-Hans.resx index 5c60abe0..97b2cf9d 100644 --- a/v2rayN/v2rayN/Forms/OptionSettingForm.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/OptionSettingForm.zh-Hans.resx @@ -131,16 +131,22 @@ 关闭Http代理 - 开启Http代理,并自动配置代理服务器(全局模式) + 开启Http代理,并自动配置系统代理(全局模式) - 开启PAC,并自动配置PAC(PAC模式) + 开启PAC,并自动配置系统代理(PAC模式) - 仅开启Http代理,不自动配置代理服务器(直连模式) + 仅开启Http代理,并清除系统代理 - 仅开启PAC,不自动配置PAC + 仅开启PAC,并清除系统代理 + + + 仅开启Http代理,不改变系统代理 + + + 仅开启PAC,不改变系统代理 96, 16 diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index d03a2cb6..26b7afb0 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -42,7 +42,7 @@ namespace v2rayN.Handler var index = config.listenerType; if (index > 0) { - color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange })[index - 1]; + color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1]; //color = ColorTranslator.FromHtml(new string[] { "#CC0066", "#CC6600", "#99CC99", "#666699" }[index - 1]); } @@ -150,6 +150,6 @@ namespace v2rayN.Handler } } - + } } diff --git a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs index 88009e5d..897b4f03 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs @@ -1,156 +1,170 @@ -using System; -using v2rayN.Mode; - -namespace v2rayN.HttpProxyHandler -{ - /// - /// 系统代理(http)总处理 - /// 启动privoxy提供http协议 - /// 设置IE系统代理或者PAC模式 - /// - class HttpProxyHandle - { - private static bool Update(Config config, bool forceDisable) - { - int type = config.listenerType; - - if (forceDisable) - { - type = 0; - } - - try - { - if (type != 0) - { - var port = Global.httpPort; - if (port <= 0) - { - return false; - } - if (type == 1) - { - //PACServerHandle.Stop(); - ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2); - } - else if (type == 2) - { - string pacUrl = GetPacUrl(); - ProxySetting.SetProxy(pacUrl, "", 4); - //PACServerHandle.Stop(); - PACServerHandle.Init(config); - } - else if (type == 3) - { - //PACServerHandle.Stop(); - ProxySetting.UnsetProxy(); - } - else if (type == 4) - { - string pacUrl = GetPacUrl(); - ProxySetting.UnsetProxy(); - //PACServerHandle.Stop(); - PACServerHandle.Init(config); - } - } - else - { - ProxySetting.UnsetProxy(); - //PACServerHandle.Stop(); - } - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - return true; - } - - /// - /// 启用系统代理(http) - /// - /// - private static void StartHttpAgent(Config config) - { - try - { - int localPort = config.GetLocalPort(Global.InboundSocks); - if (localPort > 0) - { - PrivoxyHandler.Instance.Restart(localPort, config); - if (PrivoxyHandler.Instance.RunningPort > 0) - { - Global.sysAgent = true; - Global.socksPort = localPort; - Global.httpPort = PrivoxyHandler.Instance.RunningPort; - Global.pacPort = config.GetLocalPort("pac"); - } - } - } - catch - { - } - } - - /// - /// 关闭系统代理 - /// - /// - public static void CloseHttpAgent(Config config) - { - try - { - Update(config, true); - - PrivoxyHandler.Instance.Stop(); - - Global.sysAgent = false; - Global.socksPort = 0; - Global.httpPort = 0; - } - catch - { - } - } - - /// - /// 重启系统代理(http) - /// - /// - /// - public static void RestartHttpAgent(Config config, bool forced) - { - bool isRestart = false; +using System; +using v2rayN.Mode; + +namespace v2rayN.HttpProxyHandler +{ + /// + /// 系统代理(http)总处理 + /// 启动privoxy提供http协议 + /// 设置IE系统代理或者PAC模式 + /// + class HttpProxyHandle + { + private static bool Update(Config config, bool forceDisable) + { + int type = config.listenerType; + + if (forceDisable) + { + type = 0; + } + + try + { + if (type != 0) + { + var port = Global.httpPort; + if (port <= 0) + { + return false; + } + if (type == 1) + { + //PACServerHandle.Stop(); + //ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2); + SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}"); + } + else if (type == 2) + { + string pacUrl = GetPacUrl(); + //ProxySetting.SetProxy(pacUrl, "", 4); + SysProxyHandle.SetIEProxy(true, false, pacUrl); + //PACServerHandle.Stop(); + PACServerHandle.Init(config); + } + else if (type == 3) + { + //PACServerHandle.Stop(); + SysProxyHandle.ResetIEProxy(); + } + else if (type == 4) + { + string pacUrl = GetPacUrl(); + SysProxyHandle.ResetIEProxy(); + //PACServerHandle.Stop(); + PACServerHandle.Init(config); + } + else if (type == 5) + { + //PACServerHandle.Stop(); + //SysProxyHandle.ResetIEProxy(); + } + else if (type == 6) + { + string pacUrl = GetPacUrl(); + //SysProxyHandle.ResetIEProxy(); + //PACServerHandle.Stop(); + PACServerHandle.Init(config); + } + } + else + { + SysProxyHandle.ResetIEProxy(); + //PACServerHandle.Stop(); + } + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + } + return true; + } + + /// + /// 启用系统代理(http) + /// + /// + private static void StartHttpAgent(Config config) + { + try + { + int localPort = config.GetLocalPort(Global.InboundSocks); + if (localPort > 0) + { + PrivoxyHandler.Instance.Restart(localPort, config); + if (PrivoxyHandler.Instance.RunningPort > 0) + { + Global.sysAgent = true; + Global.socksPort = localPort; + Global.httpPort = PrivoxyHandler.Instance.RunningPort; + Global.pacPort = config.GetLocalPort("pac"); + } + } + } + catch + { + } + } + + /// + /// 关闭系统代理 + /// + /// + public static void CloseHttpAgent(Config config) + { + try + { + Update(config, true); + + PrivoxyHandler.Instance.Stop(); + + Global.sysAgent = false; + Global.socksPort = 0; + Global.httpPort = 0; + } + catch + { + } + } + + /// + /// 重启系统代理(http) + /// + /// + /// + public static void RestartHttpAgent(Config config, bool forced) + { + bool isRestart = false; if (config.listenerType == 0) { // 关闭http proxy时,直接返回 return; - } - //强制重启或者socks端口变化 - if (forced) - { - isRestart = true; - } - else - { - int localPort = config.GetLocalPort(Global.InboundSocks); - if (localPort != Global.socksPort) - { - isRestart = true; - } - } - if (isRestart) - { - CloseHttpAgent(config); - StartHttpAgent(config); - } - Update(config, false); - } - - public static string GetPacUrl() - { - string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={ DateTime.Now.ToString("HHmmss")}"; - return pacUrl; - } - } -} + } + //强制重启或者socks端口变化 + if (forced) + { + isRestart = true; + } + else + { + int localPort = config.GetLocalPort(Global.InboundSocks); + if (localPort != Global.socksPort) + { + isRestart = true; + } + } + if (isRestart) + { + CloseHttpAgent(config); + StartHttpAgent(config); + } + Update(config, false); + } + + public static string GetPacUrl() + { + string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={ DateTime.Now.ToString("HHmmss")}"; + return pacUrl; + } + } +} diff --git a/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs new file mode 100644 index 00000000..e79e5a4d --- /dev/null +++ b/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs @@ -0,0 +1,193 @@ + +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Threading; +using v2rayN.Base; +using v2rayN.Mode; +using v2rayN.Properties; +using v2rayN.Tool; + +namespace v2rayN.HttpProxyHandler +{ + public static class SysProxyHandle + { + //private const string _userWininetConfigFile = "user-wininet.json"; + + //private static string _queryStr; + + // In general, this won't change + // format: + // + // + // + // + private static SysproxyConfig _userSettings = null; + + enum RET_ERRORS : int + { + RET_NO_ERROR = 0, + INVALID_FORMAT = 1, + NO_PERMISSION = 2, + SYSCALL_FAILED = 3, + NO_MEMORY = 4, + INVAILD_OPTION_COUNT = 5, + }; + + static SysProxyHandle() + { + try + { + FileManager.UncompressFile(Utils.GetTempPath("sysproxy.exe"), + Environment.Is64BitOperatingSystem ? Resources.sysproxy64_exe : Resources.sysproxy_exe); + } + catch (IOException ex) + { + Utils.SaveLog(ex.Message, ex); + } + } + + public static void SetIEProxy(bool enable, bool global, string strProxy) + { + //Read(); + + //if (!_userSettings.UserSettingsRecorded) + //{ + // // record user settings + // ExecSysproxy("query"); + // //ParseQueryStr(_queryStr); + //} + + string arguments; + if (enable) + { + arguments = global + ? $"global {strProxy} {Global.IEProxyExceptions}" + : $"pac {strProxy}"; + } + else + { + // restore user settings + var flags = _userSettings.Flags; + var proxy_server = _userSettings.ProxyServer ?? "-"; + var bypass_list = _userSettings.BypassList ?? "-"; + var pac_url = _userSettings.PacUrl ?? "-"; + arguments = $"set {flags} {proxy_server} {bypass_list} {pac_url}"; + + // have to get new settings + _userSettings.UserSettingsRecorded = false; + } + + //Save(); + ExecSysproxy(arguments); + } + + // set system proxy to 1 (null) (null) (null) + public static bool ResetIEProxy() + { + try + { + // clear user-wininet.json + //_userSettings = new SysproxyConfig(); + //Save(); + // clear system setting + ExecSysproxy("set 1 - - -"); + } + catch (Exception) + { + return false; + } + + return true; + } + + private static void ExecSysproxy(string arguments) + { + // using event to avoid hanging when redirect standard output/error + // ref: https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why + // and http://blog.csdn.net/zhangweixing0/article/details/7356841 + using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) + using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) + { + using (var process = new Process()) + { + // Configure the process using the StartInfo properties. + process.StartInfo.FileName = Utils.GetTempPath("sysproxy.exe"); + process.StartInfo.Arguments = arguments; + process.StartInfo.WorkingDirectory = Utils.GetTempPath(); + process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.RedirectStandardOutput = true; + + // Need to provide encoding info, or output/error strings we got will be wrong. + process.StartInfo.StandardOutputEncoding = Encoding.Unicode; + process.StartInfo.StandardErrorEncoding = Encoding.Unicode; + + process.StartInfo.CreateNoWindow = true; + + StringBuilder output = new StringBuilder(); + StringBuilder error = new StringBuilder(); + + process.OutputDataReceived += (sender, e) => + { + if (e.Data == null) + { + outputWaitHandle.Set(); + } + else + { + output.AppendLine(e.Data); + } + }; + process.ErrorDataReceived += (sender, e) => + { + if (e.Data == null) + { + errorWaitHandle.Set(); + } + else + { + error.AppendLine(e.Data); + } + }; + try + { + process.Start(); + + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + + process.WaitForExit(); + } + catch (System.ComponentModel.Win32Exception e) + { + + // log the arguments + throw new Exception(process.StartInfo.Arguments); + } + var stderr = error.ToString(); + var stdout = output.ToString(); + + var exitCode = process.ExitCode; + if (exitCode != (int)RET_ERRORS.RET_NO_ERROR) + { + throw new Exception(stderr); + } + + //if (arguments == "query") + //{ + // if (stdout.IsNullOrWhiteSpace() || stdout.IsNullOrEmpty()) + // { + // throw new Exception("failed to query wininet settings"); + // } + // _queryStr = stdout; + //} + } + } + } + + + } +} diff --git a/v2rayN/v2rayN/Properties/AssemblyInfo.cs b/v2rayN/v2rayN/Properties/AssemblyInfo.cs index 371903c0..32fb1a67 100644 --- a/v2rayN/v2rayN/Properties/AssemblyInfo.cs +++ b/v2rayN/v2rayN/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Microsoft")] [assembly: AssemblyProduct("v2rayN")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2019")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,4 +33,4 @@ using System.Runtime.InteropServices; // 方法是按如下所示使用“*”: //[assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("3.7")] +[assembly: AssemblyFileVersion("3.8")] diff --git a/v2rayN/v2rayN/Properties/Resources.Designer.cs b/v2rayN/v2rayN/Properties/Resources.Designer.cs index ec86047f..be8f6a6d 100644 --- a/v2rayN/v2rayN/Properties/Resources.Designer.cs +++ b/v2rayN/v2rayN/Properties/Resources.Designer.cs @@ -216,5 +216,25 @@ namespace v2rayN.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] sysproxy_exe { + get { + object obj = ResourceManager.GetObject("sysproxy_exe", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] sysproxy64_exe { + get { + object obj = ResourceManager.GetObject("sysproxy64_exe", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/v2rayN/v2rayN/Properties/Resources.resx b/v2rayN/v2rayN/Properties/Resources.resx index 72e8e12c..cd38282a 100644 --- a/v2rayN/v2rayN/Properties/Resources.resx +++ b/v2rayN/v2rayN/Properties/Resources.resx @@ -163,4 +163,10 @@ ..\resources\sub.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\sysproxy64.exe.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\resources\sysproxy.exe.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resources/sysproxy.exe.gz b/v2rayN/v2rayN/Resources/sysproxy.exe.gz new file mode 100644 index 00000000..980d304b Binary files /dev/null and b/v2rayN/v2rayN/Resources/sysproxy.exe.gz differ diff --git a/v2rayN/v2rayN/Resources/sysproxy64.exe.gz b/v2rayN/v2rayN/Resources/sysproxy64.exe.gz new file mode 100644 index 00000000..c5ff36af Binary files /dev/null and b/v2rayN/v2rayN/Resources/sysproxy64.exe.gz differ diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 002d99e3..ff7e5c38 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -195,6 +195,7 @@ Component + @@ -345,6 +346,8 @@ + +