Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tab text option witch command line #878

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions SuperPutty/Utils/CommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using SuperPutty.Data;
Expand Down Expand Up @@ -117,6 +117,9 @@ void Parse(string[] args)
case "-pw":
this.Password = queue.Dequeue();
break;
case "-t":
this.SessionName = queue.Dequeue();
break;
case "-load":
this.PuttySession = queue.Dequeue();
break;
Expand Down Expand Up @@ -207,28 +210,31 @@ public SessionDataStartInfo ToSessionStartInfo()
else if (this.Host != null || this.PuttySession != null)
{
// Host or puttySession provided
string sessionName;
if (this.Host != null)
{
// Decode URL type host spec, if provided (e.g. ssh://localhost:2020)
HostConnectionString connStr = new HostConnectionString(this.Host);
this.Host = connStr.Host;
this.Protocol = connStr.Protocol.GetValueOrDefault(this.Protocol.GetValueOrDefault(ConnectionProtocol.SSH));
this.Port = connStr.Port.GetValueOrDefault(this.Port.GetValueOrDefault(dlgEditSession.GetDefaultPort(this.Protocol.GetValueOrDefault())));
sessionName = this.Host;

if (this.SessionName == null)
{
this.SessionName = this.Host;
}
}
else
{
// no host provided so assume sss
sessionName = this.PuttySession;
this.SessionName = this.PuttySession;
}

ssi = new SessionDataStartInfo
{
Session = new SessionData
{
Host = this.Host,
SessionName = sessionName,
SessionName = this.SessionName,
SessionId = SuperPuTTY.MakeUniqueSessionId(SessionData.CombineSessionIds("CLI", this.Host)),
Port = this.Port.GetValueOrDefault(22),
Proto = this.Protocol.GetValueOrDefault(ConnectionProtocol.SSH),
Expand Down Expand Up @@ -262,6 +268,7 @@ public static string Usage()
sb.AppendLine(" SuperPutty.exe -load SETTINGS");
sb.AppendLine(" SuperPutty.exe -PROTO -P PORT -l USER -pw PASSWORD -load SETTINGS HOST");
sb.AppendLine(" SuperPutty.exe -l USER -pw PASSWORD -load SETTINGS PROTO://HOST:PORT");
sb.AppendLine(" SuperPutty.exe -l USER -pw PASSWORD -t TABTEXT PROTO://HOST:PORT");
sb.AppendLine();
sb.AppendLine("Options:");
sb.AppendLine();
Expand All @@ -271,6 +278,7 @@ public static string Usage()
sb.AppendLine(" PROTO\t\t - Protocol - (ssh|ssh2|telnet|serial|raw|scp|cygterm|rlogin|mintty|vnc)");
sb.AppendLine(" USER\t\t - User name");
sb.AppendLine(" PASSWORD\t - Login Password");
sb.AppendLine(" TABTEXT\t - Tab Text");
sb.AppendLine(" HOST\t\t - Hostname");
sb.AppendLine();
sb.AppendLine("Examples:");
Expand All @@ -295,6 +303,7 @@ public static string Usage()
public int? Port { get; private set; }
public string UserName { get; private set; }
public string Password { get; private set; }
public string SessionName { get; private set; }
public string PuttySession { get; private set; }

public string Host { get; private set; }
Expand Down
18 changes: 12 additions & 6 deletions SuperPutty/Utils/FormUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
Expand All @@ -17,17 +17,23 @@ public class FormUtils

public static void RestoreFormPositionAndState(Form form, Rectangle winPos, FormWindowState winState)
{
// check if the window state is Maximized
if (winState == FormWindowState.Maximized)
{
form.WindowState = winState;

Log.InfoFormat("Restoring form state. state={0}", winState);
}
// check if the saved bounds are nonzero and visible on any screen
if (!winPos.IsEmpty && IsVisibleOnAnyScreen(winPos))
else if(!winPos.IsEmpty && IsVisibleOnAnyScreen(winPos))
{
// first set the bounds
form.StartPosition = FormStartPosition.Manual;
form.DesktopBounds = winPos;

// afterwards set the window state to the saved value (which could be Maximized)
form.WindowState = winState;

Log.InfoFormat("Restoring form position and state. position={0}, state={1}", winPos, winState);
}
else if (!winPos.Size.IsEmpty)
Expand All @@ -53,14 +59,14 @@ public static bool IsVisibleOnAnyScreen(Rectangle rect)
return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(rect));
}

public static T SafeParseEnum<T>(string val, bool ignoreCase, T defaultVal)
public static T SafeParseEnum<T>(string val, bool ignoreCase, T defaultVal)
{
T enumVal = defaultVal;
try
{
enumVal = (T) Enum.Parse(typeof(T), val, ignoreCase);
enumVal = (T)Enum.Parse(typeof(T), val, ignoreCase);
}
catch(Exception ex)
catch (Exception ex)
{
Log.Error(string.Format("Could not parse ({0}) of type ({1})", val, typeof(T).Name), ex);
}
Expand Down