From 30daa11bfb6c9fd3a3aecaacf60c84c367ce67e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:28:03 +0200 Subject: [PATCH 1/8] bugfix: "Show on system tray" setting not saved --- src/MainForm.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index a72c31e..159a6e9 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -172,6 +172,9 @@ namespace MeshCentralRouter [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)]string lParam); + [DllImport("User32.dll")] + public static extern Int32 SetForegroundWindow(int hWnd); + private bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { if (meshcentral.ignoreCert) return true; @@ -220,6 +223,8 @@ namespace MeshCentralRouter serverNameComboBox.Text = Settings.GetRegValue("ServerName", ""); userNameTextBox.Text = Settings.GetRegValue("UserName", ""); + notifyIcon.Visible = Settings.GetRegValue("NotifyIcon", false); + title = this.Text; int argflags = 0; @@ -236,7 +241,7 @@ namespace MeshCentralRouter if (arg.ToLower() == "-ignorecert") { ignoreCert = true; } if (arg.ToLower() == "-all") { inaddrany = true; } if (arg.ToLower() == "-inaddrany") { inaddrany = true; } - if (arg.ToLower() == "-tray") { notifyIcon.Visible = true; this.ShowInTaskbar = false; this.MinimizeBox = false; } + if (arg.ToLower() == "-tray") { notifyIcon.Visible = true; } if (arg.ToLower() == "-native") { webSocketClient.nativeWebSocketFirst = true; } if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-host:") { serverNameComboBox.Text = arg.Substring(6); argflags |= 1; } if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-user:") { userNameTextBox.Text = arg.Substring(6); argflags |= 2; } @@ -249,6 +254,8 @@ namespace MeshCentralRouter if (arg.ToLower() == "-localfiles") { FileViewer fileViewer = new FileViewer(meshcentral, null); fileViewer.Show(); } } autoLogin = (argflags == 7); + this.MinimizeBox = !notifyIcon.Visible; + //this.ShowInTaskbar = !notifyIcon.Visible; if (update != null) { @@ -488,13 +495,13 @@ namespace MeshCentralRouter private void exitToolStripMenuItem_Click(object sender, EventArgs e) { - forceExit = true; + forceExit = !notifyIcon.Visible; Application.Exit(); } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - if ((notifyIcon.Visible == true) && (forceExit == false)) { e.Cancel = true; Visible = false; } + if ((notifyIcon.Visible == true && currentPanel == 4) && (forceExit == false)) { e.Cancel = true; Visible = false; } Settings.SetRegValue("Location", Location.X + "," + Location.Y); } @@ -1544,7 +1551,13 @@ namespace MeshCentralRouter private void notifyIcon_DoubleClick(object sender, EventArgs e) { - if (this.Visible == false) { this.Visible = true; } else { this.Visible = false; this.Focus(); } + if (this.Visible == false) + { + this.WindowState = FormWindowState.Normal; + this.Visible = true; + SetForegroundWindow(this.Handle.ToInt32()); + this.Focus(); + } else { this.Visible = false; } } private void exitToolStripMenuItem_Click_1(object sender, EventArgs e) @@ -1556,7 +1569,9 @@ namespace MeshCentralRouter private void openToolStripMenuItem_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; + this.ShowInTaskbar = true; this.Visible = true; + SetForegroundWindow(this.Handle.ToInt32()); this.Focus(); } @@ -2009,6 +2024,7 @@ namespace MeshCentralRouter if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 443, 2, node); // HTTPS } + private void rdpToolStripMenuItem_Click(object sender, EventArgs e) { if (devicesListView.SelectedItems.Count != 1) { return; } @@ -2167,6 +2183,7 @@ namespace MeshCentralRouter if (f.ShowDialog(this) == DialogResult.OK) { Settings.SetRegValue("CheckForUpdates", f.CheckForUpdates); + Settings.SetRegValue("NotifyIcon", f.ShowSystemTray); allowUpdates = f.CheckForUpdates; deviceDoubleClickAction = f.deviceDoubleClickAction; Settings.SetRegValue("DevDoubleClickClickAction", deviceDoubleClickAction.ToString()); @@ -2176,13 +2193,11 @@ namespace MeshCentralRouter if (f.ShowSystemTray) { notifyIcon.Visible = true; - this.ShowInTaskbar = false; this.MinimizeBox = false; } else { notifyIcon.Visible = false; - this.ShowInTaskbar = true; this.MinimizeBox = true; } } From ca18e48453209bdf43bdca5af6305e8413b2bd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:28:31 +0200 Subject: [PATCH 2/8] fixed wrong german translation (issue #36) --- MeshCentralRouter-translation.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MeshCentralRouter-translation.json b/MeshCentralRouter-translation.json index 544d889..b28ad89 100644 --- a/MeshCentralRouter-translation.json +++ b/MeshCentralRouter-translation.json @@ -1674,7 +1674,7 @@ }, { "cs": "Nastavení", - "de": "die Einstellungen", + "de": "Einstellungen", "en": "Settings", "es": "Configuraciones", "fr": "Réglages", From cf67f540f38d28421a7335f58423472a25f707b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:29:12 +0200 Subject: [PATCH 3/8] bugfix: update application stuck when "Show on system tray" is active --- src/MainForm.cs | 3 ++- src/UpdateForm.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index 159a6e9..45e4904 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -679,7 +679,8 @@ namespace MeshCentralRouter { if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.toolUpdateHandler(Meshcentral_onToolUpdate), url, hash, size, serverhash); return; } UpdateForm f = new UpdateForm(url, hash, size, args, serverhash); - if (f.ShowDialog(this) == DialogResult.OK) { } + forceExit = true; + if (f.ShowDialog(this) != DialogResult.OK) { forceExit = !notifyIcon.Visible; } } private void Meshcentral_onLoginTokenChanged() diff --git a/src/UpdateForm.cs b/src/UpdateForm.cs index 5629b8c..5c3753f 100644 --- a/src/UpdateForm.cs +++ b/src/UpdateForm.cs @@ -140,7 +140,8 @@ namespace MeshCentralRouter } else { updateMessage(Translate.T(Properties.Resources.Updating), 0); Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location + ".update.exe", "-update:" + System.Reflection.Assembly.GetEntryAssembly().Location + " " + string.Join(" ", args)); - Application.Exit(); + + if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { Application.Exit(); }); } else { Application.Exit(); } } } } From f092cba2bbea7b8434f6893aeec65c28cc84826d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:39:31 +0200 Subject: [PATCH 4/8] fixed registry path --- src/MapUserControl.cs | 4 ++-- src/MeshCentralServer.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MapUserControl.cs b/src/MapUserControl.cs index a1c75be..58f8662 100644 --- a/src/MapUserControl.cs +++ b/src/MapUserControl.cs @@ -45,11 +45,11 @@ namespace MeshCentralRouter public static void saveToRegistry(string name, string value) { - try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\OpenSource\MeshRouter", name, value); } catch (Exception) { } + try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { } } public static string loadFromRegistry(string name) { - try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\OpenSource\MeshRouter", name, "").ToString(); } catch (Exception) { return ""; } + try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, "").ToString(); } catch (Exception) { return ""; } } public MapUserControl() diff --git a/src/MeshCentralServer.cs b/src/MeshCentralServer.cs index 66ccb1b..ca0195c 100644 --- a/src/MeshCentralServer.cs +++ b/src/MeshCentralServer.cs @@ -90,11 +90,11 @@ namespace MeshCentralRouter public static void saveToRegistry(string name, string value) { - try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\OpenSource\MeshRouter", name, value); } catch (Exception) { } + try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { } } public static string loadFromRegistry(string name) { - try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\OpenSource\MeshRouter", name, "").ToString(); } catch (Exception) { return ""; } + try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, "").ToString(); } catch (Exception) { return ""; } } public static string GetProxyForUrlUsingPac(string DestinationUrl, string PacUri) From fa884a7e73a6e6427b1feabf2e97f73b22a33ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:52:17 +0200 Subject: [PATCH 5/8] allow window height change when logged in --- src/MainForm.cs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index 45e4904..46b621c 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -35,6 +35,7 @@ namespace MeshCentralRouter { public partial class MainForm : Form { + private int initialHeight; public int currentPanel = 0; public DateTime refreshTime = DateTime.Now; public MeshCentralServer meshcentral = null; @@ -108,6 +109,7 @@ namespace MeshCentralRouter } catch (Exception) { } } + public void unHookRouter() { try { Registry.ClassesRoot.DeleteSubKeyTree("mcrouter"); } catch (Exception) { } @@ -158,6 +160,7 @@ namespace MeshCentralRouter return bx.CompareTo(ax); } } + public class DeviceGroupComparer : IComparer { public int Compare(Object a, Object b) @@ -195,7 +198,6 @@ namespace MeshCentralRouter return false; } - public MainForm(string[] args) { // Set TLS 1.2 @@ -226,6 +228,7 @@ namespace MeshCentralRouter notifyIcon.Visible = Settings.GetRegValue("NotifyIcon", false); title = this.Text; + initialHeight = this.Height; int argflags = 0; string update = null; @@ -255,7 +258,11 @@ namespace MeshCentralRouter } autoLogin = (argflags == 7); this.MinimizeBox = !notifyIcon.Visible; - //this.ShowInTaskbar = !notifyIcon.Visible; + this.MinimumSize = new Size(this.Width, initialHeight); + this.MaximumSize = new Size(this.Width, 1080); + this.MaximizeBox = false; + this.ResizeEnd += MainForm_ResizeEnd; + this.devicesListView.Dock = DockStyle.Fill; if (update != null) { @@ -384,7 +391,19 @@ namespace MeshCentralRouter private void setPanel(int newPanel) { if (currentPanel == newPanel) return; - if (newPanel == 4) { updatePanel4(); } + if (newPanel == 4) + { + this.Height = Settings.GetRegValue("WindowHeight", this.Height); + this.FormBorderStyle = FormBorderStyle.Sizable; + + updatePanel4(); + } + else + { + this.Height = initialHeight; + this.FormBorderStyle = FormBorderStyle.FixedSingle; + } + panel1.Visible = (newPanel == 1); panel2.Visible = (newPanel == 2); panel3.Visible = (newPanel == 3); @@ -1570,7 +1589,6 @@ namespace MeshCentralRouter private void openToolStripMenuItem_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; - this.ShowInTaskbar = true; this.Visible = true; SetForegroundWindow(this.Handle.ToInt32()); this.Focus(); @@ -1593,13 +1611,11 @@ namespace MeshCentralRouter if (f.ShowSystemTray) { notifyIcon.Visible = true; - this.ShowInTaskbar = false; this.MinimizeBox = false; } else { notifyIcon.Visible = false; - this.ShowInTaskbar = true; this.MinimizeBox = true; } } @@ -2247,6 +2263,11 @@ namespace MeshCentralRouter } } + private void MainForm_ResizeEnd(object sender, EventArgs e) + { + Settings.SetRegValue("WindowHeight", this.Height); + } + private X509Certificate2 getClientAuthCertificate() { X509Certificate2 r = null; From 756e93a7c74964f74c5ae3392e77e5cfe45d3987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 18:59:53 +0200 Subject: [PATCH 6/8] bugfix: client-list disappears when node.mesh == null --- src/MainForm.cs | 81 +++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index 46b621c..f2cc50d 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -556,7 +556,7 @@ namespace MeshCentralRouter { string host = serverNameComboBox.Text; int i = host.IndexOf("?key="); - if (i >= 0) { host = host.Substring(0, i); } + if (i >= 0) { host = host.Substring(0, i); } i = host.IndexOf(":"); if (i >= 0) { host = host.Substring(0, i); } ok = (Program.LockToHostname == host); @@ -737,15 +737,15 @@ namespace MeshCentralRouter } } - class GroupComparer : IComparer - { - public int Compare(object objA, object objB) - { - return ((ListViewGroup)objA).Header.CompareTo(((ListViewGroup)objB).Header); - } - } + class GroupComparer : IComparer + { + public int Compare(object objA, object objB) + { + return ((ListViewGroup)objA).Header.CompareTo(((ListViewGroup)objB).Header); + } + } - private void updateDeviceList() + private void updateDeviceList() { string search = searchTextBox.Text.ToLower(); if (deviceListViewMode) @@ -784,42 +784,42 @@ namespace MeshCentralRouter device.SubItems[0].Text = node.name; } - // *** Flynn Grouping start - bool bGroupExisting = false; - for(int i = 0; i < devicesListView.Groups.Count; i++) - if(devicesListView.Groups[i].Header == node.mesh.name) - { - bGroupExisting = true; - node.listitem.Group = devicesListView.Groups[i]; - break; - } - if(!bGroupExisting) - { - ListViewGroup grp = devicesListView.Groups.Add(devicesListView.Groups.Count.ToString(), node.mesh.name); - node.listitem.Group = grp; + // *** Flynn Grouping start + bool bGroupExisting = false; + for (int i = 0; i < devicesListView.Groups.Count; i++) + if ((node.mesh != null && devicesListView.Groups[i].Header == node.mesh.name) || (node.mesh == null && devicesListView.Groups[i].Header == "")) + { + bGroupExisting = true; + node.listitem.Group = devicesListView.Groups[i]; + break; + } + if (!bGroupExisting) + { + ListViewGroup grp = devicesListView.Groups.Add(devicesListView.Groups.Count.ToString(), ((node.mesh == null) ? "" : node.mesh.name)); + node.listitem.Group = grp; - ListViewGroup[] groups = new ListViewGroup[this.devicesListView.Groups.Count]; + ListViewGroup[] groups = new ListViewGroup[this.devicesListView.Groups.Count]; - this.devicesListView.Groups.CopyTo(groups, 0); + this.devicesListView.Groups.CopyTo(groups, 0); - Array.Sort(groups, new GroupComparer()); + Array.Sort(groups, new GroupComparer()); - this.devicesListView.BeginUpdate(); - this.devicesListView.Groups.Clear(); - this.devicesListView.Groups.AddRange(groups); - this.devicesListView.EndUpdate(); + this.devicesListView.BeginUpdate(); + this.devicesListView.Groups.Clear(); + this.devicesListView.Groups.AddRange(groups); + this.devicesListView.EndUpdate(); - foreach(ListViewGroup lvg in devicesListView.Groups) - { - if(lvg.Header == "Repos") - ListViewExtended.setGrpState(lvg, ListViewGroupState.Collapsible | ListViewGroupState.Normal); - else - ListViewExtended.setGrpState(lvg, ListViewGroupState.Collapsible | ListViewGroupState.Collapsed); - } - } - // *** Flynn Groupng end + foreach (ListViewGroup lvg in devicesListView.Groups) + { + if (lvg.Header == "Repos") + ListViewExtended.setGrpState(lvg, ListViewGroupState.Collapsible | ListViewGroupState.Normal); + else + ListViewExtended.setGrpState(lvg, ListViewGroupState.Collapsible | ListViewGroupState.Collapsed); + } + } + // *** Flynn Groupng end - bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((node.conn & 1) != 0)) || (node.mtype == 3); + bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((node.conn & 1) != 0)) || (node.mtype == 3); int imageIndex = (node.icon - 1) * 2; if (((node.conn & 1) == 0) && (node.mtype != 3)) { imageIndex++; } device.ImageIndex = imageIndex; @@ -2258,7 +2258,8 @@ namespace MeshCentralRouter private void customAppsToolStripMenuItem_Click(object sender, EventArgs e) { CustomAppsForm f = new CustomAppsForm(Settings.GetApplications()); - if (f.ShowDialog(this) == DialogResult.OK) { + if (f.ShowDialog(this) == DialogResult.OK) + { Settings.SetApplications(f.getApplications()); } } From f2fe654a8e6be682608bb63546e076ffef0d4640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 20:44:06 +0200 Subject: [PATCH 7/8] clear password textbox on logout --- src/MainForm.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MainForm.cs b/src/MainForm.cs index f2cc50d..0e9d854 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -400,6 +400,9 @@ namespace MeshCentralRouter } else { + if (currentPanel == 4) + passwordTextBox.Text = ""; + this.Height = initialHeight; this.FormBorderStyle = FormBorderStyle.FixedSingle; } From 838c4eefc47db3225f9a93fb3c29c00f4e04e3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 21:31:54 +0200 Subject: [PATCH 8/8] Bugfix: clear password textbox on logout only when argument '-pass' not provided --- src/MainForm.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index 0e9d854..215b645 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -36,6 +36,7 @@ namespace MeshCentralRouter public partial class MainForm : Form { private int initialHeight; + private int argflags; public int currentPanel = 0; public DateTime refreshTime = DateTime.Now; public MeshCentralServer meshcentral = null; @@ -230,7 +231,7 @@ namespace MeshCentralRouter title = this.Text; initialHeight = this.Height; - int argflags = 0; + argflags = 0; string update = null; string delete = null; foreach (string arg in this.args) @@ -400,7 +401,7 @@ namespace MeshCentralRouter } else { - if (currentPanel == 4) + if (currentPanel == 4 && (argflags & 4) != 4) passwordTextBox.Text = ""; this.Height = initialHeight;