1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added drag & drop support for .mcrouter files.

This commit is contained in:
Ylian Saint-Hilaire
2020-07-03 16:56:52 -07:00
parent 6a3bbfc369
commit 0806a06608
3 changed files with 43 additions and 15 deletions

3
MainForm.Designer.cs generated
View File

@@ -562,11 +562,14 @@
// //
// mapPanel // mapPanel
// //
this.mapPanel.AllowDrop = true;
resources.ApplyResources(this.mapPanel, "mapPanel"); resources.ApplyResources(this.mapPanel, "mapPanel");
this.mapPanel.BackColor = System.Drawing.SystemColors.ControlLightLight; this.mapPanel.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.mapPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.mapPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.mapPanel.Controls.Add(this.noMapLabel); this.mapPanel.Controls.Add(this.noMapLabel);
this.mapPanel.Name = "mapPanel"; this.mapPanel.Name = "mapPanel";
this.mapPanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.mapPanel_DragDrop);
this.mapPanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.mapPanel_DragEnter);
// //
// noMapLabel // noMapLabel
// //

View File

@@ -182,7 +182,7 @@ namespace MeshCentralRouter
if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-pass:") { passwordTextBox.Text = arg.Substring(6); argflags |= 4; } 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() == "-search:") { searchTextBox.Text = arg.Substring(8); }
if (arg.Length > 11 && arg.Substring(0, 11).ToLower() == "mcrouter://") { authLoginUrl = new Uri(arg); } 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)); } catch (Exception) { } } if ((arg.Length > 1) && (arg[0] != '-') && (arg.ToLower().EndsWith(".mcrouter"))) { try { argflags |= loadMappingFile(File.ReadAllText(arg), 1); } catch (Exception) { } }
} }
autoLogin = (argflags == 7); autoLogin = (argflags == 7);
@@ -1132,27 +1132,30 @@ namespace MeshCentralRouter
{ {
if (openMapFileDialog.ShowDialog(this) == DialogResult.OK) if (openMapFileDialog.ShowDialog(this) == DialogResult.OK)
{ {
string text = null; try { loadMappingFile(File.ReadAllText(openMapFileDialog.FileName), 2); } catch (Exception) { }
try { text = File.ReadAllText(openMapFileDialog.FileName); } catch (Exception) { }
if (text != null) { loadMappingFile(text); }
} }
} }
private int loadMappingFile(string data) private int loadMappingFile(string data, int mode)
{ {
int argFlags = 3; int argFlags = 3;
Dictionary<string, object> jsonAction = new Dictionary<string, object>(); Dictionary<string, object> jsonAction = new Dictionary<string, object>();
jsonAction = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(data); jsonAction = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(data);
if ((jsonAction == null) || (jsonAction["hostname"].GetType() != typeof(string)) || (jsonAction["username"].GetType() != typeof(string)) || (jsonAction["certhash"].GetType() != typeof(string))) return 0; if ((jsonAction == null) || (jsonAction["hostname"].GetType() != typeof(string)) || (jsonAction["username"].GetType() != typeof(string)) || (jsonAction["certhash"].GetType() != typeof(string))) return 0;
serverNameComboBox.Text = jsonAction["hostname"].ToString(); if (mode == 1)
userNameTextBox.Text = jsonAction["username"].ToString(); {
if (jsonAction.ContainsKey("password")) { passwordTextBox.Text = jsonAction["password"].ToString(); argFlags |= 4; } serverNameComboBox.Text = jsonAction["hostname"].ToString();
acceptableCertHash = jsonAction["certhash"].ToString(); userNameTextBox.Text = jsonAction["username"].ToString();
if (jsonAction.ContainsKey("password")) { passwordTextBox.Text = jsonAction["password"].ToString(); argFlags |= 4; }
acceptableCertHash = jsonAction["certhash"].ToString();
}
if (jsonAction["mappings"] != null) if (jsonAction["mappings"] != null)
{ {
ArrayList mappings = (ArrayList)jsonAction["mappings"]; ArrayList mappings = (ArrayList)jsonAction["mappings"];
if (mappings.Count > 0) { mappingsToSetup = mappings; } if (mappings.Count > 0) {
mappingsToSetup = mappings;
if (mode == 2) { setupMappings(); }
}
} }
return argFlags; return argFlags;
} }
@@ -1187,7 +1190,13 @@ namespace MeshCentralRouter
noMapLabel.Visible = false; noMapLabel.Visible = false;
// Launch any executable // Launch any executable
if (x.ContainsKey("launch")) { try { System.Diagnostics.Process.Start((string)x["launch"]); } catch (Exception) { } } if (x.ContainsKey("launch")) {
try {
string lanuchString = (string)x["launch"];
lanuchString = lanuchString.Replace("{port}", x["localPort"].ToString());
System.Diagnostics.Process.Start(lanuchString);
} catch (Exception) { }
}
} }
mappingsToSetup = null; mappingsToSetup = null;
} }
@@ -1220,6 +1229,22 @@ namespace MeshCentralRouter
} }
} }
private void mapPanel_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop) == false) return;
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if ((s.Length != 1) || (s[0].ToLower().EndsWith(".mcrouter") == false)) return;
e.Effect = DragDropEffects.All;
}
private void mapPanel_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop) == false) return;
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if ((s.Length != 1) || (s[0].ToLower().EndsWith(".mcrouter") == false)) return;
try { loadMappingFile(File.ReadAllText(s[0]), 2); } catch (Exception) { }
}
/* /*
private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress); private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress);
private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0) private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0)

View File

@@ -1336,7 +1336,7 @@
<value>2, 88</value> <value>2, 88</value>
</data> </data>
<data name="noSearchResultsLabel.Size" type="System.Drawing.Size, System.Drawing"> <data name="noSearchResultsLabel.Size" type="System.Drawing.Size, System.Drawing">
<value>462, 52</value> <value>458, 52</value>
</data> </data>
<data name="noSearchResultsLabel.TabIndex" type="System.Int32, mscorlib"> <data name="noSearchResultsLabel.TabIndex" type="System.Int32, mscorlib">
<value>5</value> <value>5</value>
@@ -1375,7 +1375,7 @@
<value>2, 88</value> <value>2, 88</value>
</data> </data>
<data name="noDevicesLabel.Size" type="System.Drawing.Size, System.Drawing"> <data name="noDevicesLabel.Size" type="System.Drawing.Size, System.Drawing">
<value>462, 52</value> <value>458, 52</value>
</data> </data>
<data name="noDevicesLabel.TabIndex" type="System.Int32, mscorlib"> <data name="noDevicesLabel.TabIndex" type="System.Int32, mscorlib">
<value>4</value> <value>4</value>
@@ -1465,7 +1465,7 @@
<value>2, 79</value> <value>2, 79</value>
</data> </data>
<data name="noMapLabel.Size" type="System.Drawing.Size, System.Drawing"> <data name="noMapLabel.Size" type="System.Drawing.Size, System.Drawing">
<value>462, 52</value> <value>458, 52</value>
</data> </data>
<data name="noMapLabel.TabIndex" type="System.Int32, mscorlib"> <data name="noMapLabel.TabIndex" type="System.Int32, mscorlib">
<value>4</value> <value>4</value>