Skip to content

Commit

Permalink
Initial Application Settings implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephMDavis committed Aug 18, 2022
1 parent 00fda33 commit ea7a2a4
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 42 deletions.
1 change: 1 addition & 0 deletions MeshCentralRouter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Settings.cs" />
<Compile Include="src\AddPortMapForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
72 changes: 72 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="MeshCentralRouter.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings />
<Settings>
<Setting Name="ShowInstallButton" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AllowCommandArgs" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CollapseDeviceGroups" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="DeviceDoubleClickAction" Type="System.String" Scope="Application">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="ShowLicense" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AllowCustomizations" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="GroupHeaderAlignment" Type="System.Windows.Forms.HorizontalAlignment" Scope="Application">
<Value Profile="(Default)">Center</Value>
</Setting>
<Setting Name="ShowWebsiteButton" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
28 changes: 28 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
@@ -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.
}
}
}
33 changes: 32 additions & 1 deletion app.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<section name="MeshServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="MeshStateMonitor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MeshCentralRouter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<MeshServer.Properties.Settings>
Expand Down Expand Up @@ -39,4 +42,32 @@
</setting>
</MeshStateMonitor.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup><applicationSettings>
<MeshCentralRouter.Properties.Settings>
<setting name="ShowInstallButton" serializeAs="String">
<value>False</value>
</setting>
<setting name="AllowCommandArgs" serializeAs="String">
<value>False</value>
</setting>
<setting name="CollapseDeviceGroups" serializeAs="String">
<value>False</value>
</setting>
<setting name="DeviceDoubleClickAction" serializeAs="String">
<value>2</value>
</setting>
<setting name="ShowLicense" serializeAs="String">
<value>False</value>
</setting>
<setting name="AllowCustomizations" serializeAs="String">
<value>False</value>
</setting>
<setting name="GroupHeaderAlignment" serializeAs="String">
<value>Center</value>
</setting>
<setting name="ShowWebsiteButton" serializeAs="String">
<value>False</value>
</setting>
</MeshCentralRouter.Properties.Settings>
</applicationSettings>
</configuration>
95 changes: 56 additions & 39 deletions src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ea7a2a4

Please sign in to comment.