예제 #1
0
        public static void Initialize(string[] args)
        {
            Log.InfoFormat(
                "Initializing.  Version={0}, UserSettings={1}, SettingsFolder={2}",
                Version, Settings.SettingsFilePath, Settings.SettingsFolder);

            Images = LoadImageList("default");

            if (!SuperPuTTY.IsFirstRun)
            {
                // parse command line args
                CommandLine = new CommandLineOptions(args);

                // display help if --help specified
                if (CommandLine.Help)
                {
                    if (DialogResult.Cancel == MessageBox.Show(CommandLineOptions.Usage(), "SuperPutty CLI Help", MessageBoxButtons.OKCancel))
                    {
                        Environment.Exit(0);
                    }
                }

                // load data
                LoadLayouts();
                LoadSessions();

                // determine starting layout, if any.  CLI has priority
                if (CommandLine.IsValid)
                {
                    if (CommandLine.Layout != null)
                    {
                        StartingLayout = FindLayout(CommandLine.Layout);
                        if (StartingLayout != null)
                        {
                            Log.InfoFormat("Starting with layout from command line, {0}", CommandLine.Layout);
                        }
                    }
                    else
                    {
                        // ad-hoc session specified
                        SessionDataStartInfo sessionStartInfo = CommandLine.ToSessionStartInfo();
                        if (sessionStartInfo != null)
                        {
                            StartingSession = sessionStartInfo;
                            Log.InfoFormat("Starting adhoc Session from command line, {0}", StartingSession.Session.SessionId);
                        }
                    }
                }

                // if nothing specified, then try the default layout
                if (StartingLayout == null && StartingSession == null)
                {
                    StartingLayout = FindLayout(Settings.DefaultLayoutName);
                    if (StartingLayout != null)
                    {
                        Log.InfoFormat("Starting with default layout, {0}", Settings.DefaultLayoutName);
                    }
                }
            }

            // Register IpcChanncel for single instance support
            SingleInstanceHelper.RegisterRemotingService();
            WindowEvents = new GlobalWindowEvents();

            Log.Info("Initialized");
        }
예제 #2
0
        public SessionDataStartInfo ToSessionStartInfo()
        {
            SessionDataStartInfo ssi = null;

            if (SessionId != null)
            {
                // first try to resolve by sessionId
                SessionData session = SuperPuTTY.GetSessionById(SessionId);
                if (session == null)
                {
                    Log.WarnFormat("Session from command line not found, id={0}", SessionId);
                }
                else
                {
                    ssi = new SessionDataStartInfo
                    {
                        Session = session,
                        UseScp  = UseScp
                    };
                }
            }
            else if (Host != null || PuttySession != null)
            {
                // Host or puttySession provided
                string sessionName;
                if (Host != null)
                {
                    // Decode URL type host spec, if provided (e.g. ssh://localhost:2020)
                    HostConnectionString connStr = new HostConnectionString(Host);
                    Host        = connStr.Host;
                    Protocol    = connStr.Protocol.GetValueOrDefault(Protocol.GetValueOrDefault(ConnectionProtocol.SSH));
                    Port        = connStr.Port.GetValueOrDefault(Port.GetValueOrDefault(EditSessionDialog.GetDefaultPort(Protocol.GetValueOrDefault())));
                    sessionName = Host;
                }
                else
                {
                    // no host provided so assume sss
                    sessionName = PuttySession;
                }

                ssi = new SessionDataStartInfo
                {
                    Session = new SessionData
                    {
                        Host         = Host,
                        SessionName  = sessionName,
                        SessionId    = SuperPuTTY.MakeUniqueSessionId(SessionData.CombineSessionIds("CLI", Host)),
                        Port         = Port.GetValueOrDefault(22),
                        Proto        = Protocol.GetValueOrDefault(ConnectionProtocol.SSH),
                        Username     = UserName,
                        Password     = Password,
                        PuttySession = PuttySession
                    },
                    UseScp = UseScp
                };
            }

            if (ssi == null)
            {
                Log.WarnFormat("Could not determine session or host to connect.  SessionId or Host or PuttySession must be provided");
            }

            return(ssi);
        }