diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 8ba6d9b5..93b3d66d 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -98,8 +98,10 @@ namespace Netch.Controllers { MainForm.Instance.NatTypeStatusText(i18N.Translate("Starting NatTester")); // Thread.Sleep(1000); - var (nttResult, natType, _, _) = pNTTController.Start(); - if (nttResult) MainForm.Instance.NatTypeStatusText(natType); + var (nttResult, natType, localEnd, publicEnd) = pNTTController.Start(); + var country = Utils.Utils.GetCityCode(publicEnd); + + if (nttResult) MainForm.Instance.NatTypeStatusText(natType, country); }); break; } diff --git a/Netch/Controllers/Mode/NFController.cs b/Netch/Controllers/Mode/NFController.cs index afeff92c..a77ece6c 100644 --- a/Netch/Controllers/Mode/NFController.cs +++ b/Netch/Controllers/Mode/NFController.cs @@ -30,9 +30,6 @@ namespace Netch.Controllers { MainFile = "Redirector"; InitCheck(); - - // 驱动版本 - _systemDriverVersion = FileVersionInfo.GetVersionInfo(_driverPath).FileVersion; // 生成系统版本 var winNTver = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}"; var driverName = ""; @@ -56,6 +53,13 @@ namespace Netch.Controllers } _binDriverPath = "bin\\" + driverName; + + if (!File.Exists(_driverPath)) + { + InstallDriver(); + } + // 驱动版本 + _systemDriverVersion = FileVersionInfo.GetVersionInfo(_driverPath).FileVersion; } /// diff --git a/Netch/Forms/MainForm.MenuStrip.cs b/Netch/Forms/MainForm.MenuStrip.cs index f0364bad..1ad44637 100644 --- a/Netch/Forms/MainForm.MenuStrip.cs +++ b/Netch/Forms/MainForm.MenuStrip.cs @@ -1,4 +1,5 @@ using System; +using System.Data; using System.Linq; using System.Net; using System.ServiceProcess; @@ -99,6 +100,9 @@ namespace Netch.Forms private void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e) { + var bak_State = State; + var bak_StateText = StatusLabel.Text; + if (Global.Settings.UseProxyToUpdateSubscription && ServerComboBox.SelectedIndex == -1) Global.Settings.UseProxyToUpdateSubscription = false; @@ -161,8 +165,8 @@ namespace Netch.Forms } catch (Exception) { - // ignored - } + // ignored + } Global.Settings.Server = Global.Settings.Server.Where(server => server.Group != item.Remark).ToList(); var result = ShareLink.Parse(response); @@ -205,6 +209,11 @@ namespace Netch.Forms Configuration.Save(); StatusText(i18N.Translate("Subscription updated")); + + MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true; + UpdateStatus(bak_State); + StatusLabel.Text = bak_StateText; + }).ContinueWith(task => { BeginInvoke(new Action(() => { UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = true; })); }); NotifyIcon.ShowBalloonTip(5, @@ -215,6 +224,7 @@ namespace Netch.Forms else { MessageBoxX.Show(i18N.Translate("No subscription link")); + } } @@ -295,15 +305,23 @@ namespace Netch.Forms private void CleanDNSCacheToolStripMenuItem_Click(object sender, EventArgs e) { - Enabled = false; - Task.Run(() => + var bak_State = State; + var bak_StateText = StatusLabel.Text; + + try { + Enabled = false; DNS.Cache.Clear(); MessageBoxX.Show(i18N.Translate("DNS cache cleanup succeeded"), owner: this); StatusText(i18N.Translate("DNS cache cleanup succeeded")); Enabled = true; - }); + } + finally + { + UpdateStatus(bak_State); + StatusLabel.Text = bak_StateText; + } } private void OpenDirectoryToolStripMenuItem_Click(object sender, EventArgs e) @@ -415,6 +433,9 @@ namespace Netch.Forms private void updateACLToolStripMenuItem_Click(object sender, EventArgs e) { + var bak_State = State; + var bak_StateText = StatusLabel.Text; + StatusText(i18N.Translate("Starting update ACL")); using var client = new WebClient(); @@ -437,7 +458,8 @@ namespace Netch.Forms } finally { - UpdateStatus(State.Waiting); + UpdateStatus(bak_State); + StatusLabel.Text = bak_StateText; } }); } diff --git a/Netch/Forms/MainForm.Status.cs b/Netch/Forms/MainForm.Status.cs index 8081b288..d70879ef 100644 --- a/Netch/Forms/MainForm.Status.cs +++ b/Netch/Forms/MainForm.Status.cs @@ -16,7 +16,7 @@ namespace Netch.Forms /// public State State { get; private set; } = State.Waiting; - public void NatTypeStatusText(string text = "") + public void NatTypeStatusText(string text = "",string Country = "") { if (State != State.Started) { @@ -27,7 +27,14 @@ namespace Netch.Forms if (!string.IsNullOrEmpty(text)) { - NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + text.Trim(); + if (Country != "") + { + NatTypeStatusLabel.Text = String.Format("NAT{0}{1}[{2}]", i18N.Translate(": "), text, Country); + } + else + { + NatTypeStatusLabel.Text = String.Format("NAT{0}{1}", i18N.Translate(": "), text); + } if (Enum.TryParse(text, false, out STUN_Client.NatType natType)) { NatTypeStatusLightLabel.Visible = true; @@ -61,7 +68,7 @@ namespace Netch.Forms c = Color.LimeGreen; break; default: - c = Color.Red; + c = Color.Black; break; } diff --git a/Netch/Models/Server.cs b/Netch/Models/Server.cs index a70eec89..b5240604 100644 --- a/Netch/Models/Server.cs +++ b/Netch/Models/Server.cs @@ -156,32 +156,7 @@ namespace Netch.Models if (Country == null) { - try - { - var databaseReader = new DatabaseReader("bin\\GeoLite2-Country.mmdb"); - - if (IPAddress.TryParse(Hostname, out _) == true) - { - Country = databaseReader.Country(Hostname).Country.IsoCode; - } - else - { - var DnsResult = DNS.Lookup(Hostname); - - if (DnsResult != null) - { - Country = databaseReader.Country(DnsResult).Country.IsoCode; - } - else - { - Country = "UN"; - } - } - } - catch (Exception) - { - Country = "UN"; - } + Country = Utils.Utils.GetCityCode(Hostname); } Group = Group.Equals("None") || Group.Equals("") ? "NONE" : Group; diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index efe0f693..03f7bda5 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -1,4 +1,5 @@ -using System; +using MaxMind.GeoIP2; +using System; using System.Diagnostics; using System.IO; using System.Net; @@ -64,5 +65,41 @@ namespace Netch.Utils } return timeout; } + + public static string GetCityCode(string Hostname) + { + if (Hostname.Contains(":")) + { + Hostname = Hostname.Split(':')[0]; + } + string Country; + try + { + var databaseReader = new DatabaseReader("bin\\GeoLite2-Country.mmdb"); + + if (IPAddress.TryParse(Hostname, out _) == true) + { + Country = databaseReader.Country(Hostname).Country.IsoCode; + } + else + { + var DnsResult = DNS.Lookup(Hostname); + + if (DnsResult != null) + { + Country = databaseReader.Country(Hostname).Country.IsoCode; + } + else + { + Country = "Unknown"; + } + } + } + catch (Exception) + { + Country = "Unknown"; + } + return Country == null ? "Unknown" : Country; + } } } diff --git a/binaries b/binaries index 066bbd0a..c2f9c329 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 066bbd0a477a6936741c8961a7242e56ec79fb56 +Subproject commit c2f9c3291ef05c0173aaa6ab5de5fd8b0d0fba3b