using System; using System.Windows.Media; using Netch.Models; using Netch.Utils; using Color = System.Drawing.Color; namespace Netch.Forms { public partial class Dummy { } partial class MainForm { /// /// 当前状态 /// public State State { get; private set; } = State.Waiting; public void NatTypeStatusText(string text = "") { if (State != State.Started) { NatTypeStatusLabel.Text = ""; NatTypeStatusLabel.Visible = false; NatTypeStatusLightLabel.Visible = false; return; } if (!string.IsNullOrEmpty(text)) { NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + text.Trim(); } else { NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + i18N.Translate("Test failed"); } if (Enum.TryParse(text,false,out STUN_Client.NatType natType)) { UpdateNatTypeLight(natType); NatTypeStatusLightLabel.Visible = true; } else { NatTypeStatusLightLabel.Visible = false; } NatTypeStatusLabel.Visible = true; } private void UpdateNatTypeLight(STUN_Client.NatType natType) { Color c; switch (natType) { case STUN_Client.NatType.UdpBlocked: case STUN_Client.NatType.SymmetricUdpFirewall: case STUN_Client.NatType.Symmetric: c = Color.Red; break; case STUN_Client.NatType.RestrictedCone: case STUN_Client.NatType.PortRestrictedCone: c = Color.Yellow; break; case STUN_Client.NatType.OpenInternet: case STUN_Client.NatType.FullCone: c = Color.LimeGreen; break; default: c=Color.Red; break; } NatTypeStatusLightLabel.ForeColor=c; } public void StatusText(string text) { StatusLabel.Text = i18N.Translate("Status", ": ") + text; } /// /// Update UI, Status, Status Label /// /// public void UpdateStatus(State state) { State = state; StatusText(i18N.Translate(StateExtension.GetStatusString(state))); // TODO 补充 switch (state) { case State.Waiting: ControlButton.Enabled = true; ControlButton.Text = i18N.Translate("Start"); MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true; updateACLWithProxyToolStripMenuItem.Enabled = true; NatTypeStatusText(); break; case State.Starting: ControlButton.Enabled = false; ControlButton.Text = "..."; ServerComboBox.Enabled = false; ModeComboBox.Enabled = false; UninstallServiceToolStripMenuItem.Enabled = false; updateACLWithProxyToolStripMenuItem.Enabled = false; UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false; reinstallTapDriverToolStripMenuItem.Enabled = false; break; case State.Started: ControlButton.Enabled = true; ControlButton.Text = i18N.Translate("Stop"); break; case State.Stopping: ControlButton.Enabled = false; ControlButton.Text = "..."; ProfileGroupBox.Enabled = false; MenuStrip.Enabled = ConfigurationGroupBox.Enabled = SettingsButton.Enabled = true; UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = false; NatTypeStatusText(); break; case State.Stopped: ControlButton.Enabled = true; ControlButton.Text = i18N.Translate("Start"); LastUploadBandwidth = 0; LastDownloadBandwidth = 0; ServerComboBox.Enabled = true; ModeComboBox.Enabled = true; ProfileGroupBox.Enabled = true; UninstallServiceToolStripMenuItem.Enabled = true; updateACLWithProxyToolStripMenuItem.Enabled = true; UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = true; reinstallTapDriverToolStripMenuItem.Enabled = true; break; case State.Terminating: break; } } public void UpdateStatus() { UpdateStatus(State); } } }