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:
3
MainForm.Designer.cs
generated
3
MainForm.Designer.cs
generated
@@ -562,11 +562,14 @@
|
||||
//
|
||||
// mapPanel
|
||||
//
|
||||
this.mapPanel.AllowDrop = true;
|
||||
resources.ApplyResources(this.mapPanel, "mapPanel");
|
||||
this.mapPanel.BackColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.mapPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.mapPanel.Controls.Add(this.noMapLabel);
|
||||
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
|
||||
//
|
||||
|
||||
49
MainForm.cs
49
MainForm.cs
@@ -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 > 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 > 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);
|
||||
|
||||
@@ -1132,27 +1132,30 @@ namespace MeshCentralRouter
|
||||
{
|
||||
if (openMapFileDialog.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
string text = null;
|
||||
try { text = File.ReadAllText(openMapFileDialog.FileName); } catch (Exception) { }
|
||||
if (text != null) { loadMappingFile(text); }
|
||||
try { loadMappingFile(File.ReadAllText(openMapFileDialog.FileName), 2); } catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
private int loadMappingFile(string data)
|
||||
private int loadMappingFile(string data, int mode)
|
||||
{
|
||||
int argFlags = 3;
|
||||
Dictionary<string, object> jsonAction = new Dictionary<string, object>();
|
||||
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;
|
||||
serverNameComboBox.Text = jsonAction["hostname"].ToString();
|
||||
userNameTextBox.Text = jsonAction["username"].ToString();
|
||||
if (jsonAction.ContainsKey("password")) { passwordTextBox.Text = jsonAction["password"].ToString(); argFlags |= 4; }
|
||||
acceptableCertHash = jsonAction["certhash"].ToString();
|
||||
|
||||
if (mode == 1)
|
||||
{
|
||||
serverNameComboBox.Text = jsonAction["hostname"].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)
|
||||
{
|
||||
ArrayList mappings = (ArrayList)jsonAction["mappings"];
|
||||
if (mappings.Count > 0) { mappingsToSetup = mappings; }
|
||||
if (mappings.Count > 0) {
|
||||
mappingsToSetup = mappings;
|
||||
if (mode == 2) { setupMappings(); }
|
||||
}
|
||||
}
|
||||
return argFlags;
|
||||
}
|
||||
@@ -1187,7 +1190,13 @@ namespace MeshCentralRouter
|
||||
noMapLabel.Visible = false;
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -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 void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0)
|
||||
|
||||
@@ -1336,7 +1336,7 @@
|
||||
<value>2, 88</value>
|
||||
</data>
|
||||
<data name="noSearchResultsLabel.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>462, 52</value>
|
||||
<value>458, 52</value>
|
||||
</data>
|
||||
<data name="noSearchResultsLabel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
@@ -1375,7 +1375,7 @@
|
||||
<value>2, 88</value>
|
||||
</data>
|
||||
<data name="noDevicesLabel.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>462, 52</value>
|
||||
<value>458, 52</value>
|
||||
</data>
|
||||
<data name="noDevicesLabel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
@@ -1465,7 +1465,7 @@
|
||||
<value>2, 79</value>
|
||||
</data>
|
||||
<data name="noMapLabel.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>462, 52</value>
|
||||
<value>458, 52</value>
|
||||
</data>
|
||||
<data name="noMapLabel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
|
||||
Reference in New Issue
Block a user