fix #18, ReadLineSecure causes ArgumentOutOfRangeException in setup
This commit is contained in:
parent
1f4f7901a1
commit
79d477ac3a
1 changed files with 17 additions and 3 deletions
20
Utils.cs
20
Utils.cs
|
@ -12,9 +12,16 @@ namespace SteamGuard
|
|||
do
|
||||
{
|
||||
key = Console.ReadKey(true);
|
||||
if ((int)key.Key >= 65 && (int)key.Key <= 90)
|
||||
if (((int)key.Key) >= 65 && ((int)key.Key <= 90))
|
||||
{
|
||||
text.Insert(cursorIndex, key.KeyChar.ToString());
|
||||
if (cursorIndex == 0 || cursorIndex == text.Length - 1)
|
||||
{
|
||||
text += key.KeyChar.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
text.Insert(cursorIndex, key.KeyChar.ToString());
|
||||
}
|
||||
cursorIndex++;
|
||||
}
|
||||
else if (key.Key == ConsoleKey.Backspace && cursorIndex > 0)
|
||||
|
@ -35,10 +42,17 @@ namespace SteamGuard
|
|||
{
|
||||
cursorIndex = 0;
|
||||
}
|
||||
else if (cursorIndex > text.Length)
|
||||
else if (text.Length == 0 && cursorIndex > text.Length)
|
||||
{
|
||||
cursorIndex = 0;
|
||||
}
|
||||
else if (text.Length != 0 && cursorIndex >= text.Length)
|
||||
{
|
||||
cursorIndex = text.Length - 1;
|
||||
}
|
||||
|
||||
// For debugging:
|
||||
// Console.Title = string.Format("{0}/{1} - {2} ({3}) - {4}", cursorIndex, text.Length, key.Key.ToString(), (int)key.Key, text);
|
||||
} while (key.Key != ConsoleKey.Enter);
|
||||
return text;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue