private void ExitToolStripButton_Click(object sender, EventArgs e) { // 当前状态如果不是已停止状态 if (State != Models.State.Waiting && State != Models.State.Stopped) { // 如果未勾选退出时停止,要求先点击停止按钮 if (!Global.Settings.StopWhenExited) { MessageBox.Show(Utils.i18N.Translate("Please press Stop button first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); this.Visible = true; this.ShowInTaskbar = true; // 显示在系统任务栏 this.WindowState = FormWindowState.Normal; // 还原窗体 this.NotifyIcon.Visible = true; // 托盘图标隐藏 return; } // 否则自动点击停止按钮 else { ControlButton.PerformClick(); } } Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex; Global.Settings.ModeComboBoxSelectedIndex = ModeComboBox.SelectedIndex; Utils.Configuration.Save(); State = Models.State.Terminating; this.NotifyIcon.Visible = false; this.Close(); this.Dispose(); System.Environment.Exit(System.Environment.ExitCode); }
public void OnExited(object sender, EventArgs e) { if (State == Objects.State.Started) { ControlButton.PerformClick(); } }
private void MainForm_Load(object sender, EventArgs e) { OnlyInstance.Called += OnCalled; // 计算 ComboBox绘制 目标宽度 _eWidth = ServerComboBox.Width / 10; Modes.Load(); ServerComboBox.DataSource = Global.Settings.Server; SaveSelectIndex = true; SelectLastMode(); SelectLastServer(); // 加载翻译 InitText(); // 隐藏 NatTypeStatusLabel NatTypeStatusText(); _sizeHeight = Size.Height; _configurationGroupBoxHeight = ConfigurationGroupBox.Height; _profileConfigurationHeight = ConfigurationGroupBox.Controls[0].Height / 3; // 因为 AutoSize, 所以得到的是Controls的总高度 _profileGroupboxHeight = ProfileGroupBox.Height; // 加载快速配置 InitProfile(); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Waiting || State == State.Stopped) { TestServer(); Thread.Sleep(10000); } else { Thread.Sleep(200); } } }); Task.Run(() => { // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) { CheckUpdate(); } }); }
private void MainForm_Load(object sender, EventArgs e) { AddAddServerToolStripMenuItems(); #region i18N Translations _mainFormText.Add(UninstallServiceToolStripMenuItem.Name, new[] { "Uninstall {0}", "NF Service" }); _mainFormText.Add(UninstallTapDriverToolStripMenuItem.Name, new[] { "Uninstall {0}", "TUN/TAP driver" }); #endregion OnlyInstance.Called += OnCalled; // 计算 ComboBox绘制 目标宽度 _eWidth = ServerComboBox.Width / 10; ModeHelper.Load(); InitMode(); InitServer(); _comboBoxInitialized = true; // 加载翻译 InitText(); // 隐藏 NatTypeStatusLabel NatTypeStatusText(); _configurationGroupBoxHeight = ConfigurationGroupBox.Height; _profileConfigurationHeight = ConfigurationGroupBox.Controls[0].Height / 3; // 因为 AutoSize, 所以得到的是Controls的总高度 // 加载快速配置 InitProfile(); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } Task.Run(() => { // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) { CheckUpdate(); } }); Task.Run(async() => { // 检查订阅更新 if (Global.Settings.UpdateSubscribeatWhenOpened) { await UpdateServersFromSubscribe(); } }); }
private void MainForm_Load(object sender, EventArgs e) { // 加载服务器 InitServer(); // 加载模式 InitMode(); // 加载翻译 InitText(); // NatTypeStatusText(); // 加载快速配置 _sizeHeight = Size.Height; _controlHeight = ConfigurationGroupBox.Controls[0].Height / 3; _profileBoxHeight = ProfileGroupBox.Height; _configurationGroupBoxHeight = ConfigurationGroupBox.Height; InitProfile(); // 为 ComboBox绘制 收集宽度数据 _eWidth = ServerComboBox.Width / 10; // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Waiting || State == State.Stopped) { TestServer(); Thread.Sleep(10000); } else { Thread.Sleep(200); } } }); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) { CheckUpdate(); } }
private void ProfileButton_Click(object sender, EventArgs e) { int index = ProfileButtons.IndexOf((Button)sender); //Utils.Logging.Info(String.Format("Button no.{0} clicked", index)); if (Control.ModifierKeys == Keys.Control) { SaveProfile(index); ProfileButtons[index].Text = ProfileNameText.Text; } else { try { ProfileNameText.Text = LoadProfile(index); // start the profile bool need2ndStart = true; if (State == Models.State.Waiting || State == Models.State.Stopped) { need2ndStart = false; } ControlButton.PerformClick(); if (need2ndStart) { Task.Run(() => { while (State != Models.State.Stopped) { Thread.Sleep(200); } ControlButton.PerformClick(); }); } } catch (Exception ee) { Task.Run(() => { Utils.Logging.Info(ee.Message); ProfileButtons[index].Text = Utils.i18N.Translate("Error"); Thread.Sleep(1200); ProfileButtons[index].Text = Utils.i18N.Translate("None"); }); } } }
private void MainForm_Load(object sender, EventArgs e) { // 加载配置 Utils.Configuration.Load(); // 加载服务器 InitServer(); // 加载模式 InitMode(); // 加载翻译 ServerToolStripMenuItem.Text = Utils.i18N.Translate(ServerToolStripMenuItem.Text); ImportServersFromClipboardToolStripMenuItem.Text = Utils.i18N.Translate(ImportServersFromClipboardToolStripMenuItem.Text); AddSocks5ServerToolStripMenuItem.Text = Utils.i18N.Translate(AddSocks5ServerToolStripMenuItem.Text); AddShadowsocksServerToolStripMenuItem.Text = Utils.i18N.Translate(AddShadowsocksServerToolStripMenuItem.Text); AddShadowsocksRServerToolStripMenuItem.Text = Utils.i18N.Translate(AddShadowsocksRServerToolStripMenuItem.Text); AddVMessServerToolStripMenuItem.Text = Utils.i18N.Translate(AddVMessServerToolStripMenuItem.Text); ModeToolStripMenuItem.Text = Utils.i18N.Translate(ModeToolStripMenuItem.Text); CreateProcessModeToolStripMenuItem.Text = Utils.i18N.Translate(CreateProcessModeToolStripMenuItem.Text); SubscribeToolStripMenuItem.Text = Utils.i18N.Translate(SubscribeToolStripMenuItem.Text); ManageSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(ManageSubscribeLinksToolStripMenuItem.Text); UpdateServersFromSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate(UpdateServersFromSubscribeLinksToolStripMenuItem.Text); OptionsToolStripMenuItem.Text = Utils.i18N.Translate(OptionsToolStripMenuItem.Text); RestartServiceToolStripMenuItem.Text = Utils.i18N.Translate(RestartServiceToolStripMenuItem.Text); UninstallServiceToolStripMenuItem.Text = Utils.i18N.Translate(UninstallServiceToolStripMenuItem.Text); ReloadModesToolStripMenuItem.Text = Utils.i18N.Translate(ReloadModesToolStripMenuItem.Text); CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate(CleanDNSCacheToolStripMenuItem.Text); AboutToolStripButton.Text = Utils.i18N.Translate(AboutToolStripButton.Text); ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text); ServerLabel.Text = Utils.i18N.Translate(ServerLabel.Text); ModeLabel.Text = Utils.i18N.Translate(ModeLabel.Text); ProfileLabel.Text = Utils.i18N.Translate(ProfileLabel.Text); ProfileGroupBox.Text = Utils.i18N.Translate(ProfileGroupBox.Text); SettingsButton.Text = Utils.i18N.Translate(SettingsButton.Text); ControlButton.Text = Utils.i18N.Translate(ControlButton.Text); UsedBandwidthLabel.Text = $@"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}0 KB"; StatusLabel.Text = $@"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"; ShowMainFormToolStripButton.Text = Utils.i18N.Translate(ShowMainFormToolStripButton.Text); ExitToolStripButton.Text = Utils.i18N.Translate(ExitToolStripButton.Text); InitProfile(); // 自动检测延迟 Task.Run(() => { while (true) { if (State == Models.State.Waiting || State == Models.State.Stopped) { TestServer(); Thread.Sleep(10000); } else { Thread.Sleep(200); } } }); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) { CheckUpdate(); } }
private void MainForm_Load(object sender, EventArgs e) { AddAddServerToolStripMenuItems(); OnlyInstance.Called += OnCalled; // 计算 ComboBox绘制 目标宽度 _eWidth = ServerComboBox.Width / 10; Modes.Load(); InitMode(); InitServer(); _comboBoxInitialized = true; // 加载翻译 InitText(); // 隐藏 NatTypeStatusLabel NatTypeStatusText(); _sizeHeight = Size.Height; _configurationGroupBoxHeight = ConfigurationGroupBox.Height; _profileConfigurationHeight = ConfigurationGroupBox.Controls[0].Height / 3; // 因为 AutoSize, 所以得到的是Controls的总高度 _profileGroupboxHeight = ProfileGroupBox.Height; // 加载快速配置 InitProfile(); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Waiting || State == State.Stopped) { TestServer(); Thread.Sleep(10000); } else { Thread.Sleep(200); } } }); Task.Run(() => { // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) { CheckUpdate(); } }); Task.Run(async() => { // 检查订阅更新 if (Global.Settings.UpdateSubscribeatWhenOpened) { await UpdateServersFromSubscribe(); } }); }
private void ProfileButton_Click(object sender, EventArgs e) { var index = ProfileButtons.IndexOf((Button)sender); //Utils.Logging.Info(String.Format("Button no.{0} clicked", index)); if (ModifierKeys == Keys.Control) { if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); } else if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select an mode first")); } else if (ProfileNameText.Text == "") { MessageBoxX.Show(i18N.Translate("Please enter a profile name first")); } else { SaveProfile(index); ProfileButtons[index].Text = ProfileNameText.Text; } } else { if (ProfileButtons[index].Text == i18N.Translate("Error") || ProfileButtons[index].Text == i18N.Translate("None")) { MessageBoxX.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button")); } try { ProfileNameText.Text = LoadProfile(index); // start the profile var need2ndStart = true; if (State == State.Waiting || State == State.Stopped) { need2ndStart = false; } ControlButton.PerformClick(); if (need2ndStart) { Task.Run(() => { while (State != State.Stopped) { Thread.Sleep(200); } ControlButton.PerformClick(); }); } } catch (Exception ee) { Task.Run(() => { Logging.Info(ee.Message); ProfileButtons[index].Text = i18N.Translate("Error"); Thread.Sleep(1200); ProfileButtons[index].Text = i18N.Translate("None"); }); } } }
private void ProfileButton_Click(object sender, EventArgs e) { var index = ProfileButtons.IndexOf((Button)sender); if (ModifierKeys == Keys.Control) { if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); } else if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select an mode first")); } else if (ProfileNameText.Text == "") { MessageBoxX.Show(i18N.Translate("Please enter a profile name first")); } else { SaveProfile(index); ProfileButtons[index].Text = ProfileNameText.Text; } } else if (ModifierKeys == Keys.Shift) { if (MessageBoxX.Show(i18N.Translate("Remove this Profile?"), confirm: true) == DialogResult.OK) { RemoveProfile(index); ProfileButtons[index].Text = i18N.Translate("None"); MessageBoxX.Show(i18N.Translate("Profile Removed!")); } } else { if (Global.Settings.Profiles[index].IsDummy) { MessageBoxX.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button")); return; } try { ProfileNameText.Text = LoadProfile(index); // start the profile ControlFun(); if (State == State.Stopping || State == State.Stopped) { Task.Run(() => { while (State != State.Stopped) { Thread.Sleep(250); } ControlButton.PerformClick(); }); } } catch (Exception ee) { Task.Run(() => { Logging.Info(ee.Message); ProfileButtons[index].Text = i18N.Translate("Error"); Thread.Sleep(1200); ProfileButtons[index].Text = i18N.Translate("None"); }); } } }
public void PerformClick() { ControlButton.PerformClick(); }
private void MainForm_Load(object sender, EventArgs e) { // 加载配置 Utils.Configuration.Load(); // 加载服务器 InitServer(); // 加载模式 InitMode(); // 加载翻译 ServerToolStripMenuItem.Text = Utils.i18N.Translate("Server"); ImportServersFromClipboardToolStripMenuItem.Text = Utils.i18N.Translate("Import Servers From Clipboard"); AddSocks5ServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [Socks5] Server"); AddShadowsocksServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [Shadowsocks] Server"); AddShadowsocksRServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [ShadowsocksR] Server"); AddVMessServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [VMess] Server"); ModeToolStripMenuItem.Text = Utils.i18N.Translate("Mode"); CreateProcessModeToolStripMenuItem.Text = Utils.i18N.Translate("Create Process Mode"); SubscribeToolStripMenuItem.Text = Utils.i18N.Translate("Subscribe"); ManageSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate("Manage Subscribe Links"); UpdateServersFromSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate("Update Servers From Subscribe Links"); OptionsToolStripMenuItem.Text = Utils.i18N.Translate("Options"); RestartServiceToolStripMenuItem.Text = Utils.i18N.Translate("Restart Service"); UninstallServiceToolStripMenuItem.Text = Utils.i18N.Translate("Uninstall Service"); ReloadModesToolStripMenuItem.Text = Utils.i18N.Translate("Reload Modes"); CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate("Clean DNS Cache"); AboutToolStripButton.Text = Utils.i18N.Translate("About"); ConfigurationGroupBox.Text = Utils.i18N.Translate("Configuration"); ServerLabel.Text = Utils.i18N.Translate("Server"); ModeLabel.Text = Utils.i18N.Translate("Mode"); SettingsButton.Text = Utils.i18N.Translate("Settings"); ControlButton.Text = Utils.i18N.Translate("Start"); UsedBandwidthLabel.Text = $"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}0 KB"; StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"; NotifyIcon.BalloonTipText = Utils.i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."); ShowMainFormToolStripButton.Text = Utils.i18N.Translate("Show"); ExitToolStripButton.Text = Utils.i18N.Translate("Exit"); // 自动检测延迟 Task.Run(() => { while (true) { if (State == Models.State.Waiting || State == Models.State.Stopped) { TestServer(); Thread.Sleep(10000); } else { Thread.Sleep(200); } } }); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) { ControlButton.PerformClick(); } }