diff --git a/MeshCentralRouter.csproj b/MeshCentralRouter.csproj index 13b4ae0..b88f70e 100644 --- a/MeshCentralRouter.csproj +++ b/MeshCentralRouter.csproj @@ -83,6 +83,7 @@ + Form diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 35f5d66..7b0acf9 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -22,5 +22,77 @@ public static Settings Default { return defaultInstance; } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ShowInstallButton { + get { + return ((bool)(this["ShowInstallButton"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool AllowCommandArgs { + get { + return ((bool)(this["AllowCommandArgs"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool CollapseDeviceGroups { + get { + return ((bool)(this["CollapseDeviceGroups"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("2")] + public string DeviceDoubleClickAction { + get { + return ((string)(this["DeviceDoubleClickAction"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ShowLicense { + get { + return ((bool)(this["ShowLicense"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool AllowCustomizations { + get { + return ((bool)(this["AllowCustomizations"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Center")] + public global::System.Windows.Forms.HorizontalAlignment GroupHeaderAlignment { + get { + return ((global::System.Windows.Forms.HorizontalAlignment)(this["GroupHeaderAlignment"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ShowWebsiteButton { + get { + return ((bool)(this["ShowWebsiteButton"])); + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 8e615f2..1c3c272 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -1,5 +1,30 @@  - + - + + + False + + + False + + + False + + + 2 + + + False + + + False + + + Center + + + False + + \ No newline at end of file diff --git a/Settings.cs b/Settings.cs new file mode 100644 index 0000000..d7f5237 --- /dev/null +++ b/Settings.cs @@ -0,0 +1,28 @@ +namespace MeshCentralRouter.Properties { + + + // This class allows you to handle specific events on the settings class: + // The SettingChanging event is raised before a setting's value is changed. + // The PropertyChanged event is raised after a setting's value is changed. + // The SettingsLoaded event is raised after the setting values are loaded. + // The SettingsSaving event is raised before the setting values are saved. + internal sealed partial class Settings { + + public Settings() { + // // To add event handlers for saving and changing settings, uncomment the lines below: + // + // this.SettingChanging += this.SettingChangingEventHandler; + // + // this.SettingsSaving += this.SettingsSavingEventHandler; + // + } + + private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { + // Add code to handle the SettingChangingEvent event here. + } + + private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { + // Add code to handle the SettingsSaving event here. + } + } +} diff --git a/app.config b/app.config index 37bb3f3..804866e 100644 --- a/app.config +++ b/app.config @@ -5,6 +5,9 @@
+ +
+ @@ -39,4 +42,32 @@ - + + + + False + + + False + + + False + + + 2 + + + False + + + False + + + Center + + + False + + + + diff --git a/src/MainForm.cs b/src/MainForm.cs index 2a97c72..84eeba7 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -37,6 +37,7 @@ public partial class MainForm : Form { private int initialHeight; private int argflags; + private Properties.Settings appSettings = Properties.Settings.Default; public int currentPanel = 0; public DateTime refreshTime = DateTime.Now; public MeshCentralServer meshcentral = null; @@ -235,29 +236,42 @@ public MainForm(string[] args) argflags = 0; string update = null; string delete = null; - foreach (string arg in this.args) - { - if (arg.ToLower() == "-oldstyle") { deviceListViewMode = false; } - if (arg.ToLower() == "-install") { hookRouter(); forceExit = true; return; } - if (arg.ToLower() == "-uninstall") { unHookRouter(); forceExit = true; return; } - if (arg.ToLower() == "-noupdate") { allowUpdates = false; return; } - if (arg.ToLower() == "-debug") { debug = true; } - if (arg.ToLower() == "-tlsdump") { tlsdump = true; } - 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; } - 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; } - if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-pass:") { passwordTextBox.Text = arg.Substring(6); argflags |= 4; } - if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-search:") { searchTextBox.Text = arg.Substring(8); } - if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-update:") { update = arg.Substring(8); } - if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-delete:") { delete = arg.Substring(8); } - if (arg.Length > 11 && arg.Substring(0, 11).ToLower() == "mcrouter://") { authLoginUrl = new Uri(arg); } - if ((arg.Length > 1) && (arg[0] != '-') && (arg.ToLower().EndsWith(".mcrouter"))) { try { argflags |= loadMappingFile(File.ReadAllText(arg), 1); } catch (Exception) { } } - if (arg.ToLower() == "-localfiles") { FileViewer fileViewer = new FileViewer(meshcentral, null); fileViewer.Show(); } + + + + installButton.Visible = appSettings.ShowInstallButton; + + collapseDeviceGroup = Settings.GetRegValue("CollapseDeviceGroups", appSettings.CollapseDeviceGroups); + + bool showLicense = appSettings.ShowLicense; + + if (appSettings.AllowCommandArgs) + { + foreach (string arg in this.args) + { + if (arg.ToLower() == "-oldstyle") { deviceListViewMode = false; } + if (arg.ToLower() == "-install") { hookRouter(); forceExit = true; return; } + if (arg.ToLower() == "-uninstall") { unHookRouter(); forceExit = true; return; } + if (arg.ToLower() == "-noupdate") { allowUpdates = false; return; } + if (arg.ToLower() == "-debug") { debug = true; } + if (arg.ToLower() == "-tlsdump") { tlsdump = true; } + 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; } + 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; } + if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-pass:") { passwordTextBox.Text = arg.Substring(6); argflags |= 4; } + if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-search:") { searchTextBox.Text = arg.Substring(8); } + if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-update:") { update = arg.Substring(8); } + if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-delete:") { delete = arg.Substring(8); } + if (arg.Length > 11 && arg.Substring(0, 11).ToLower() == "mcrouter://") { authLoginUrl = new Uri(arg); } + if ((arg.Length > 1) && (arg[0] != '-') && (arg.ToLower().EndsWith(".mcrouter"))) { try { argflags |= loadMappingFile(File.ReadAllText(arg), 1); } catch (Exception) { } } + if (arg.ToLower() == "-localfiles") { FileViewer fileViewer = new FileViewer(meshcentral, null); fileViewer.Show(); } + } } + autoLogin = (argflags == 7); this.MinimizeBox = !notifyIcon.Visible; this.MinimumSize = new Size(this.Width, initialHeight); @@ -340,30 +354,32 @@ public MainForm(string[] args) } // Check MeshCentral .mcrouter hook - installButton.Visible = !isRouterHooked(); + installButton.Visible = appSettings.ShowInstallButton && !isRouterHooked(); // Right click action - deviceDoubleClickAction = int.Parse(Settings.GetRegValue("DevDoubleClickClickAction", "0")); + deviceDoubleClickAction = int.Parse(Settings.GetRegValue("DevDoubleClickClickAction", appSettings.DeviceDoubleClickAction)); setDoubleClickDeviceAction(); // Load customizations - bool showLicense = true; - FileInfo selfExe = new FileInfo(Assembly.GetExecutingAssembly().Location); - if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\topbanner.png"))) { try { pictureBox1.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\topbanner.png")); showLicense = false; } catch (Exception) { } } - if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png"))) { try { pictureBox2.Image = pictureBox6.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png")); showLicense = false; } catch (Exception) { } } - if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png"))) { try { pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox7.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png")); showLicense = false; } catch (Exception) { } } - licenseLinkLabel.Visible = showLicense; - connectionSettings.Visible = true; - try - { - if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt"))) + if (appSettings.AllowCustomizations) + { + FileInfo selfExe = new FileInfo(Assembly.GetExecutingAssembly().Location); + if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\topbanner.png"))) { try { pictureBox1.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\topbanner.png")); showLicense = false; } catch (Exception) { } } + if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png"))) { try { pictureBox2.Image = pictureBox6.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png")); showLicense = false; } catch (Exception) { } } + if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png"))) { try { pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox7.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png")); showLicense = false; } catch (Exception) { } } + licenseLinkLabel.Visible = showLicense; + connectionSettings.Visible = true; + try { - string[] lines = File.ReadAllLines(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt")); - if (lines[0] != "") { this.Text = lines[0]; } - if (lines[1] != "") { label1.Text = lines[1]; } + if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt"))) + { + string[] lines = File.ReadAllLines(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt")); + if (lines[0] != "") { this.Text = lines[0]; } + if (lines[1] != "") { label1.Text = lines[1]; } + } } + catch (Exception) { } } - catch (Exception) { } // Check if Windows SSH is present FileInfo nativeSshPath = new FileInfo(Path.Combine(Environment.SystemDirectory, "OpenSSH\\ssh.exe")); @@ -710,7 +726,7 @@ private void Meshcentral_onToolUpdate(string url, string hash, int size, string private void Meshcentral_onLoginTokenChanged() { if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.onLoginTokenChangedHandler(Meshcentral_onLoginTokenChanged)); return; } - openWebSiteButton.Visible = true; + openWebSiteButton.Visible = appSettings.ShowWebsiteButton; } private void Meshcentral_onNodesChanged(bool fullRefresh) @@ -812,6 +828,7 @@ private void updateDeviceList(bool forceGroupChanged) grp.Tag = node.meshid; node.listitem.Group = grp; bGroupChanged = true; + grp.HeaderAlignment = appSettings.GroupHeaderAlignment; } bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((node.conn & 1) != 0)) || (node.mtype == 3);