public void appButton_Click(object sender, EventArgs e) { bool shift = false; if (Control.ModifierKeys == Keys.Shift) { shift = true; } if (appId == 1) { System.Diagnostics.Process.Start("http://localhost:" + mapper.localport); } if (appId == 2) { System.Diagnostics.Process.Start("https://localhost:" + mapper.localport); } if (appId == 3) { System.Diagnostics.Process proc = null; string cmd = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\mstsc.exe"; string tfile = Path.Combine(Path.GetTempPath(), "MeshRdpFile.rdp"); string[] f = null; try { if (File.Exists(tfile)) { f = File.ReadAllLines(tfile); } } catch (Exception) { } if (f != null) { List <string> f2 = new List <string>(); foreach (string fx in f) { if (!fx.StartsWith("full address")) { f2.Add(fx); } } f2.Add(string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); File.WriteAllLines(tfile, f2.ToArray()); } else { File.WriteAllText(tfile, string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); } string args = "/edit:\"" + tfile + "\""; // Launch the process try { proc = System.Diagnostics.Process.Start(cmd, args); } catch (System.ComponentModel.Win32Exception) { } // Setup auto-exit if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } } if (appId == 4) { string appTag = null; string appPath = null; string puttyPath = loadFromRegistry("PuttyPath"); string openSshPath = loadFromRegistry("OpenSshPath"); if (File.Exists(puttyPath)) { appTag = "PuttyPath"; appPath = puttyPath; } if (File.Exists(openSshPath)) { appTag = "OpenSshPath"; appPath = openSshPath; } if ((shift == false) && (appPath != null)) { // Launch the process System.Diagnostics.Process proc = null; string args = null; if (appTag == "OpenSshPath") { SshUsernameForm f2 = new SshUsernameForm(); if (f2.ShowDialog(this) != DialogResult.OK) { return; } args = "127.0.0.1 -l " + f2.Username + " -p " + mapper.localport; } if (appTag == "PuttyPath") { args = "-ssh 127.0.0.1 -P " + mapper.localport; } try { proc = System.Diagnostics.Process.Start(appPath, args); } catch (System.ComponentModel.Win32Exception) { } // Setup auto-exit if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } } else { using (AppLaunchForm f = new AppLaunchForm()) { System.Diagnostics.Process proc = null; AppLaunchForm.AppInfo[] apps = new AppLaunchForm.AppInfo[2]; apps[0] = new AppLaunchForm.AppInfo(Properties.Resources.OpenSSHAppName, "https://www.openssh.com/", (parent.nativeSshPath != null) ? parent.nativeSshPath.FullName : "", "OpenSshPath"); apps[1] = new AppLaunchForm.AppInfo(Properties.Resources.PuttyAppName, "http://www.chiark.greenend.org.uk/~sgtatham/putty/", puttyPath, "PuttyPath"); f.SetApps(apps); if (f.ShowDialog(this) == DialogResult.OK) { appTag = f.GetAppTag(); appPath = f.GetAppPath(); saveToRegistry(appTag, f.GetAppPath()); string args = null; if (appTag == "OpenSshPath") { SshUsernameForm f2 = new SshUsernameForm(); if (f2.ShowDialog(this) != DialogResult.OK) { return; } args = "127.0.0.1 -l " + f2.Username + " -p " + mapper.localport; saveToRegistry("PuttyPath", ""); } if (appTag == "PuttyPath") { args = "-ssh 127.0.0.1 -P " + mapper.localport; saveToRegistry("OpenSshPath", ""); } if (args == null) { return; } // Launch the process try { proc = System.Diagnostics.Process.Start(appPath, args); } catch (Win32Exception) { } // Setup auto-exit if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } } } } } if (appId == 5) { string winScpPath = loadFromRegistry("WinSCPPath"); if ((shift == false) && (File.Exists(winScpPath))) { // Launch the process System.Diagnostics.Process proc = null; string args = "scp://127.0.0.1:" + mapper.localport; try { proc = System.Diagnostics.Process.Start(winScpPath, args); } catch (System.ComponentModel.Win32Exception) { } // Setup auto-exit if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } } else { using (AppLaunchForm f = new AppLaunchForm()) { System.Diagnostics.Process proc = null; f.SetAppName(Properties.Resources.WinscpAppName); f.SetAppLink("http://winscp.net/"); f.SetAppPath(winScpPath); if (f.ShowDialog(this) == DialogResult.OK) { saveToRegistry("WinSCPPath", f.GetAppPath()); string args = "scp://127.0.0.1:" + mapper.localport; // Launch the process try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); } catch (System.ComponentModel.Win32Exception) { } // Setup auto-exit if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } } } } } }
private void appButton_Click(object sender, EventArgs e) { if (appId == 1) { System.Diagnostics.Process.Start("http://localhost:" + mapper.localport); } if (appId == 2) { System.Diagnostics.Process.Start("https://localhost:" + mapper.localport); } if (appId == 3) { System.Diagnostics.Process proc = null; string cmd = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\mstsc.exe"; string tfile = Path.Combine(Path.GetTempPath(), "MeshRdpFile.rdp"); string[] f = null; try { if (File.Exists(tfile)) { f = File.ReadAllLines(tfile); } } catch (Exception) { } if (f != null) { List <string> f2 = new List <string>(); foreach (string fx in f) { if (!fx.StartsWith("full address")) { f2.Add(fx); } } f2.Add(string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); File.WriteAllLines(tfile, f2.ToArray()); } else { File.WriteAllText(tfile, string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); } string args = "/edit:\"" + tfile + "\""; // Launch the process try { proc = System.Diagnostics.Process.Start(cmd, args); } catch (System.ComponentModel.Win32Exception) { } } if (appId == 4) { using (AppLaunchForm f = new AppLaunchForm()) { System.Diagnostics.Process proc = null; f.SetAppName("PuTTY SSH client"); f.SetAppLink("http://www.chiark.greenend.org.uk/~sgtatham/putty/"); f.SetAppPath(loadFromRegistry("PuttyPath")); if (f.ShowDialog(this) == DialogResult.OK) { saveToRegistry("PuttyPath", f.GetAppPath()); string args = "-ssh 127.0.0.1 -P " + mapper.localport; // Launch the process try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); } catch (System.ComponentModel.Win32Exception) { } } } } if (appId == 5) { using (AppLaunchForm f = new AppLaunchForm()) { System.Diagnostics.Process proc = null; f.SetAppName("WinSCP client"); f.SetAppLink("http://winscp.net/"); f.SetAppPath(loadFromRegistry("WinSCPPath")); if (f.ShowDialog(this) == DialogResult.OK) { saveToRegistry("WinSCPPath", f.GetAppPath()); string args = "scp://127.0.0.1:" + mapper.localport; // Launch the process try { proc = System.Diagnostics.Process.Start(f.GetAppPath(), args); } catch (System.ComponentModel.Win32Exception) { } } } } }