public void Save(ArcticFoxConfiguration.Profile profile) { profile.Flags.IsEnabled = ProfileEnabledCheckBox.Checked; profile.Name = ProfileNameTextBox.Text; profile.Power = (ushort)(PowerUpDown.Value * 10); profile.PreheatType = PreheatTypeComboBox.GetSelectedItem <ArcticFoxConfiguration.PreheatType>(); if (profile.PreheatType == ArcticFoxConfiguration.PreheatType.Watts) { profile.PreheatPower = (ushort)(PreheatPowerUpDown.Value * 10); } else if (profile.PreheatType == ArcticFoxConfiguration.PreheatType.Percents) { profile.PreheatPower = (ushort)PreheatPowerUpDown.Value; } else if (profile.PreheatType == ArcticFoxConfiguration.PreheatType.Curve) { profile.SelectedCurve = (byte)PowerCurveComboBox.SelectedIndex; } profile.PreheatTime = (byte)(PreheatTimeUpDown.Value * 100); profile.PreheatDelay = (byte)PreheatDelayUpDown.Value; profile.Flags.IsCelcius = TemperatureTypeComboBox.GetSelectedItem <bool>(); profile.Temperature = (ushort)TemperatureUpDown.Value; profile.Flags.IsTemperatureDominant = TemperatureDominantCheckBox.Checked; var mode = ModeComboBox.GetSelectedItem <Mode>(); profile.Flags.Material = mode == Mode.TemperatureControl ? MaterialComboBox.GetSelectedItem <ArcticFoxConfiguration.Material>() : ArcticFoxConfiguration.Material.VariWatt; profile.TCR = (ushort)TCRUpDown.Value; profile.Resistance = (ushort)(ResistanceUpDown.Value * 1000); profile.Flags.IsResistanceLocked = ResistanceLockedCheckBox.Checked; }
private void LoadProfile(int index) { var p = Global.Settings.Profiles[index]; ProfileNameText.Text = p.ProfileName; ModeComboBox.ResetCompletionList(); if (p.IsDummy) { throw new Exception("Profile not found."); } var server = ServerComboBox.Items.Cast <Server>().FirstOrDefault(s => s.Remark.Equals(p.ServerRemark)); var mode = ModeComboBox.Items.Cast <Models.Mode>().FirstOrDefault(m => m.Remark.Equals(p.ModeRemark)); if (server == null) { throw new Exception("Server not found."); } if (mode == null) { throw new Exception("Mode not found."); } ServerComboBox.SelectedItem = server; ModeComboBox.SelectedItem = mode; }
private async Task ControlFun() { Configuration.Save(); if (State == State.Waiting || State == State.Stopped) { // 服务器、模式 需选择 if (!(ServerComboBox.SelectedItem is Server server)) { MessageBoxX.Show(i18N.Translate("Please select a server first")); return; } if (!(ModeComboBox.SelectedItem is Models.Mode mode)) { MessageBoxX.Show(i18N.Translate("Please select a mode first")); return; } // 清除模式搜索框文本选择 ModeComboBox.Select(0, 0); State = State.Starting; if (await MainController.Start(server, mode)) { State = State.Started; _ = Task.Run(() => { Bandwidth.NetTraffic(); }); // 如果勾选启动后最小化 if (Global.Settings.MinimizeWhenStarted) { WindowState = FormWindowState.Minimized; if (_isFirstCloseWindow) { // 显示提示语 NotifyTip(i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore.")); _isFirstCloseWindow = false; } Hide(); } } else { State = State.Stopped; StatusText(i18N.Translate("Start failed")); } } else { // 停止 State = State.Stopping; await MainController.Stop(); State = State.Stopped; } }
public void Initialize([NotNull] ArcticFoxConfiguration configuration, int profileIndex) { if (configuration == null) { throw new ArgumentNullException("configuration"); } m_configuration = configuration; m_profile = configuration.General.Profiles[profileIndex]; ProfileEnabledCheckBox.Checked = m_profile.Flags.IsEnabled; ProfileNameTextBox.Text = m_profile.Name; PowerUpDown.Maximum = configuration.Info.MaxDevicePower / 10m; PowerUpDown.SetValue(m_profile.Power / 10m); var selectedPreheatType = PreheatTypeComboBox.SelectedItem as NamedItemContainer <ArcticFoxConfiguration.PreheatType>; if (selectedPreheatType != null && selectedPreheatType.Data == m_profile.PreheatType) { PreheatTypeComboBox_SelectedValueChanged(null, EventArgs.Empty); } else { PreheatTypeComboBox.SelectItem(m_profile.PreheatType); } PowerCurveComboBox.SelectItem(m_profile.SelectedCurve); PreheatTimeUpDown.SetValue(m_profile.PreheatTime / 100m); PreheatDelayUpDown.SetValue(m_profile.PreheatDelay); ResistanceLockedCheckBox_CheckedChanged(null, EventArgs.Empty); TemperatureTypeComboBox.SelectItem(m_profile.Flags.IsCelcius); TemperatureUpDown.SetValue(m_profile.Temperature); TemperatureDominantCheckBox.Checked = m_profile.Flags.IsTemperatureDominant; if (m_profile.Flags.Material == ArcticFoxConfiguration.Material.VariWatt) { MaterialComboBox.SelectedIndex = 0; ModeComboBox.SelectItem(Mode.Power); } else { MaterialComboBox.SelectItem(m_profile.Flags.Material); ModeComboBox.SelectItem(Mode.TemperatureControl); } TCRUpDown.SetValue(m_profile.TCR); ResistanceUpDown.SetValue(m_profile.Resistance / 1000m); ResistanceLockedCheckBox.Checked = m_profile.Flags.IsResistanceLocked; }
private async void ControlFun() { if (State == State.Waiting || State == State.Stopped) { // 服务器、模式 需选择 if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); return; } if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a mode first")); return; } // 清除模式搜索框文本选择 ModeComboBox.Select(0, 0); State = State.Starting; var server = ServerComboBox.SelectedItem as Models.Server; var mode = ModeComboBox.SelectedItem as Models.Mode; if (await _mainController.Start(server, mode)) { State = State.Started; _ = Task.Run(() => { Bandwidth.NetTraffic(server, mode, ref _mainController); }); // 如果勾选启动后最小化 if (Global.Settings.MinimizeWhenStarted) { WindowState = FormWindowState.Minimized; if (_isFirstCloseWindow) { // 显示提示语 NotifyTip(i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore.")); _isFirstCloseWindow = false; } Hide(); } if (Global.Settings.StartedTcping) { // 自动检测延迟 _ = Task.Run(() => { while (State == State.Started) { server.Test(); // 重载服务器列表 InitServer(); Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000); } }); } } else { State = State.Stopped; StatusText(i18N.Translate("Start failed")); } } else { // 停止 State = State.Stopping; await _mainController.Stop(); State = State.Stopped; _ = Task.Run(TestServer); } }
private void InitializeControls() { ProfileNameTextBox.TextChanged += (s, e) => { var position = ProfileNameTextBox.SelectionStart; var input = ProfileNameTextBox.Text; var matches = s_blackList.Matches(input); foreach (Match match in matches) { if (!match.Success) { continue; } input = input.Replace(match.Value, string.Empty); } ProfileNameTextBox.Text = input; ProfileNameTextBox.SelectionStart = position; }; PowerUpDown.Minimum = MinimumWatts; PowerUpDown.Maximum = 60; PreheatTypeComboBox.Fill(PredefinedData.ArcticFox.Profile.PreheatTypes); PreheatTypeComboBox.SelectedValueChanged += PreheatTypeComboBox_SelectedValueChanged; PowerCurveComboBox.Fill(PredefinedData.ArcticFox.Profile.PowerCurves); TemperatureTypeComboBox.Fill(PredefinedData.ArcticFox.Profile.TemperatureTypes); TemperatureTypeComboBox.SelectedValueChanged += (s, e) => { var isCelcius = TemperatureTypeComboBox.GetSelectedItem <bool>(); if (isCelcius) { TemperatureUpDown.Minimum = 100; TemperatureUpDown.Maximum = 315; } else { TemperatureUpDown.Minimum = 200; TemperatureUpDown.Maximum = 600; } }; ModeComboBox.Items.Clear(); ModeComboBox.Items.AddRange(new object[] { new NamedItemContainer <Mode>(LocalizableStrings.VapeModePower, Mode.Power), new NamedItemContainer <Mode>(LocalizableStrings.VapeModeTempControl, Mode.TemperatureControl) }); ModeComboBox.SelectedValueChanged += (s, e) => { var isTemperatureSensing = ModeComboBox.GetSelectedItem <Mode>() == Mode.TemperatureControl; SetupTempControlButton.Visible = isTemperatureSensing; MaterialComboBox.Visible = isTemperatureSensing; MaterialLabel.Visible = isTemperatureSensing; ResistanceLabel.Visible = isTemperatureSensing; ResistanceUpDown.Visible = isTemperatureSensing; ResistanceLockedCheckBox.Visible = isTemperatureSensing; OhmLabel.Visible = isTemperatureSensing; TemperatureLabel.Visible = isTemperatureSensing; TemperatureUpDown.Visible = isTemperatureSensing; TemperatureTypeComboBox.Visible = isTemperatureSensing; TemperatureDominantCheckBox.Visible = isTemperatureSensing; var selectedMaterial = MaterialComboBox.GetSelectedItem <ArcticFoxConfiguration.Material>(); TCRUpDown.Visible = isTemperatureSensing && selectedMaterial == ArcticFoxConfiguration.Material.TCR; TFRCurveEditButton.Visible = isTemperatureSensing && (int)selectedMaterial >= (int)ArcticFoxConfiguration.Material.TFR1 && (int)selectedMaterial <= (int)ArcticFoxConfiguration.Material.TFR8; }; MaterialComboBox.Fill(PredefinedData.ArcticFox.Profile.Materials); MaterialComboBox.SelectedValueChanged += (s, e) => { if (MaterialComboBox.SelectedItem == null) { return; } var selectedMaterial = MaterialComboBox.GetSelectedItem <ArcticFoxConfiguration.Material>(); TCRUpDown.Visible = selectedMaterial == ArcticFoxConfiguration.Material.TCR; TFRCurveEditButton.Visible = (int)selectedMaterial >= (int)ArcticFoxConfiguration.Material.TFR1 && (int)selectedMaterial <= (int)ArcticFoxConfiguration.Material.TFR8; }; PowerCurveEditButton.Click += PowerCurveEditButton_Click; TFRCurveEditButton.Click += TFRCurveEditButton_Click; SetupTempControlButton.Click += SetupTempControlButton_Click; }
private void ControlFun() { if (State == State.Waiting || State == State.Stopped) { // 服务器、模式 需选择 if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); return; } if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a mode first")); return; } State = State.Starting; // 清除模式搜索框文本选择 ModeComboBox.Select(0, 0); Task.Run(() => { Task.Run(Firewall.AddNetchFwRules); var server = ServerComboBox.SelectedItem as Models.Server; var mode = ModeComboBox.SelectedItem as Models.Mode; var result = false; try { // TODO 完善控制器异常处理 result = _mainController.Start(server, mode); } catch (Exception e) { if (e is DllNotFoundException || e is FileNotFoundException) { MessageBoxX.Show(e.Message + "\n\n" + i18N.Translate("Missing File or runtime components"), owner: this); } Netch.Application_OnException(this, new ThreadExceptionEventArgs(e)); } if (result) { Task.Run(() => { State = State.Started; StatusTextAppend(LocalPortText(server.Type, mode.Type)); Bandwidth.NetTraffic(server, mode, _mainController); }); // 如果勾选启动后最小化 if (Global.Settings.MinimizeWhenStarted) { WindowState = FormWindowState.Minimized; if (_isFirstCloseWindow) { // 显示提示语 NotifyTip(i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore.")); _isFirstCloseWindow = false; } Hide(); } if (Global.Settings.StartedTcping) { // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Started) { server.Test(); // 重载服务器列表 InitServer(); Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000); } else { break; } } }); } } else { State = State.Stopped; StatusText(i18N.Translate("Start failed")); } }); } else { State = State.Stopping; Task.Run(() => { // 停止 _mainController.Stop(); State = State.Stopped; Task.Run(TestServer); }); } }
private void ControlFun() { if (State == State.Waiting || State == State.Stopped) { // 服务器、模式 需选择 if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); return; } if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a mode first")); return; } State = State.Starting; // 清除模式搜索框文本选择 ModeComboBox.Select(0, 0); Task.Run(() => { Task.Run(Firewall.AddNetchFwRules); var server = ServerComboBox.SelectedItem as Models.Server; var mode = ModeComboBox.SelectedItem as Models.Mode; if (_mainController.Start(server, mode)) { Task.Run(() => { State = State.Started; StatusTextAppend(LocalPortText(server.Type, mode.Type)); Bandwidth.NetTraffic(server, mode, _mainController); }); // 如果勾选启动后最小化 if (Global.Settings.MinimizeWhenStarted) { WindowState = FormWindowState.Minimized; if (_isFirstCloseWindow) { // 显示提示语 NotifyIcon.ShowBalloonTip(5, UpdateChecker.Name, i18N.Translate( "Netch is now minimized to the notification bar, double click this icon to restore."), ToolTipIcon.Info); _isFirstCloseWindow = false; } Hide(); } if (Global.Settings.StartedTcping) { // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Started) { server.Test(); // 重载服务器列表 InitServer(); Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000); } else { break; } } }); } } else { State = State.Stopped; StatusText(i18N.Translate("Start failed")); } }); } else { Task.Run(() => { // 停止 State = State.Stopping; _mainController.Stop(); State = State.Stopped; }); Task.Run(TestServer); } }
private void ControlButton_Click(object sender, EventArgs e) { //防止模式选择框变成蓝色:D ModeComboBox.Select(0, 0); ControlFun(); }
private void ControlFun() { //防止模式选择框变成蓝色:D ModeComboBox.Select(0, 0); if (State == State.Waiting || State == State.Stopped) { #region 务器、模式 需选择 if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); return; } if (ModeComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select an mode first")); return; } #endregion #region 检查端口是否被占用 if (PortHelper.PortInUse(Global.Settings.Socks5LocalPort)) { MessageBoxX.Show("The Socks5 port is in use. Click OK to modify it."); SettingsButton.PerformClick(); return; } if (PortHelper.PortInUse(Global.Settings.HTTPLocalPort)) { MessageBoxX.Show("The HTTP port is in use. Click OK to modify it."); SettingsButton.PerformClick(); return; } if (PortHelper.PortInUse(Global.Settings.RedirectorTCPPort, PortType.TCP)) { MessageBoxX.Show("The RedirectorTCP port is in use. Click OK to modify it."); SettingsButton.PerformClick(); return; } #endregion UpdateStatus(State.Starting); Task.Run(() => { Task.Run(Firewall.AddNetchFwRules); var server = ServerComboBox.SelectedItem as Models.Server; var mode = ModeComboBox.SelectedItem as Models.Mode; if (_mainController.Start(server, mode)) { Task.Run(() => { UpdateStatus(State.Started, i18N.Translate(StateExtension.GetStatusString(State.Started)) + PortText(server.Type, mode.Type)); Bandwidth.NetTraffic(server, mode, _mainController); }); // 如果勾选启动后最小化 if (Global.Settings.MinimizeWhenStarted) { WindowState = FormWindowState.Minimized; NotifyIcon.Visible = true; if (_isFirstCloseWindow) { // 显示提示语 NotifyIcon.ShowBalloonTip(5, UpdateChecker.Name, i18N.Translate( "Netch is now minimized to the notification bar, double click this icon to restore."), ToolTipIcon.Info); _isFirstCloseWindow = false; } Hide(); } if (Global.Settings.StartedTcping) { // 自动检测延迟 Task.Run(() => { while (true) { if (State == State.Started) { server.Test(); // 重载服务器列表 InitServer(); Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000); } else { break; } } }); } } else { UpdateStatus(State.Stopped, i18N.Translate("Start failed")); } }); } else { // 停止 UpdateStatus(State.Stopping); Task.Run(() => { _mainController.Stop(); UpdateStatus(State.Stopped); TestServer(); }); } }