public static Load ( JoeriBekker.PuttyTunnelManager.Session session, string data ) : |
||
session | JoeriBekker.PuttyTunnelManager.Session | |
data | string | |
return |
public static Session Load(string keyName) { string puttyKeyPath = PuttySettings.PUTTY_REGISTRY_KEYPATH_SESSIONS + @"\" + keyName; RegistryKey puttySessionKey = Registry.CurrentUser.OpenSubKey(puttyKeyPath); Session session = new Session( Uri.UnescapeDataString(keyName), puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_HOSTNAME, "").ToString(), Int32.Parse(puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_PORTNUMBER, "22").ToString()) ); session.Username = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_USERNAME, "").ToString(); session.Compression = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_COMPRESSION, 0).Equals(1); session.LocalPortsAcceptAll = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_LOCALPORTACCEPTALL, 0).Equals(1); string ptmKeyPath = PuttyTunnelManagerSettings.PTM_REGISTRY_KEYPATH_SESSIONS + @"\" + keyName; RegistryKey ptmSessionKey = Registry.CurrentUser.OpenSubKey(ptmKeyPath); // Load Tunnel Manager specific settings. if (ptmSessionKey != null) { session.UsePtmForTunnels = ptmSessionKey.GetValue(PTM_REGISTRY_KEY_SESSION_USEPTMFORTUNNELS, 0).Equals(1); session.AutoStart = ptmSessionKey.GetValue(PTM_REGISTRY_KEY_SESSION_AUTOSTART, 0).Equals(1); } string[] portForwardingList; if (session.UsePtmForTunnels && ptmSessionKey != null) { portForwardingList = ptmSessionKey.GetValue(PTM_REGISTRY_KEY_SESSION_PORTFORWARDINGS, "").ToString().Split(','); ptmSessionKey.Close(); } else { portForwardingList = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_PORTFORWARDINGS, "").ToString().Split(','); } puttySessionKey.Close(); foreach (string portForwarding in portForwardingList) { if (portForwarding.Length > 0) { Tunnel t = Tunnel.Load(session, portForwarding); session.Tunnels.Add(t); } } return(session); }
public virtual void MergeBackPuttyTunnels() { try { Registry.CurrentUser.DeleteSubKey(this.PuttyTunnelManagerKeyPath); } catch (Exception) { } RegistryKey puttySessionKey = Registry.CurrentUser.OpenSubKey(this.PuttyKeyPath); string[] portForwardingList = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_PORTFORWARDINGS, "").ToString().Split(','); puttySessionKey.Close(); List <Tunnel> additionalTunnels = new List <Tunnel>(); foreach (string portForwarding in portForwardingList.Where(pf => pf.Length > 0)) { Tunnel t1 = Tunnel.Load(this, portForwarding); additionalTunnels.AddRange(from t2 in this.tunnels where !t1.Equals(t2) select t1); } this.tunnels.AddRange(additionalTunnels); }