Skip to content

Commit 2216f67

Browse files
committed
Added command input to dev console and minor changes to dev console colours
- Added command input on DevForm - Changed colour of '[INFO]' text in the console - Changed dev version tag - Removed some unused imports
1 parent 04e8a6e commit 2216f67

File tree

7 files changed

+263
-102
lines changed

7 files changed

+263
-102
lines changed

FileAES/CustomControls/TextBoxWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private void AppendWithColour(string text)
5454
_output.AppendText(Environment.NewLine);
5555

5656
CheckKeyword("[DEBUG]", Color.Violet);
57+
CheckKeyword("[INFO]", Color.LightBlue);
5758
CheckKeyword("[WARN]", Color.Yellow);
5859
CheckKeyword("[ERROR]", Color.Red);
5960

FileAES/DevForm.Designer.cs

Lines changed: 60 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FileAES/DevForm.cs

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
using FAES_GUI.CustomControls;
1+
using FAES;
2+
using FAES_GUI.CustomControls;
23
using System;
34
using System.Drawing;
45
using System.IO;
6+
using System.Text.RegularExpressions;
57
using System.Windows.Forms;
68

79
namespace FAES_GUI
810
{
911
public partial class DevForm : Form
1012
{
13+
private string _overrideLogPath = "";
14+
1115
public DevForm()
1216
{
1317
InitializeComponent();
@@ -106,13 +110,138 @@ private void ClearConsole_Click(object sender, EventArgs e)
106110
private void ExportLog_Click(object sender, EventArgs e)
107111
{
108112
string logPath = "FileAES-" + DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString() + ".log";
109-
File.WriteAllText(logPath, consoleTextBox.Text);
110-
consoleTextBox.SelectionColor = Color.LightBlue;
111-
consoleTextBox.AppendText("Log Exported! (" + logPath + ")" + Environment.NewLine);
112113

113-
consoleTextBox.SelectionStart = consoleTextBox.TextLength;
114-
consoleTextBox.SelectionLength = 0;
115-
consoleTextBox.ScrollToCaret();
114+
if (!string.IsNullOrWhiteSpace(_overrideLogPath))
115+
{
116+
if (_overrideLogPath.Contains("{default}") || _overrideLogPath.Contains("{d}"))
117+
logPath = _overrideLogPath.Replace("{default}", logPath).Replace("{d}", logPath);
118+
else
119+
logPath = _overrideLogPath;
120+
121+
string dir = Directory.GetParent(logPath).FullName;
122+
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
123+
}
124+
125+
try
126+
{
127+
File.WriteAllText(logPath, consoleTextBox.Text);
128+
AppendWithColour(consoleTextBox, String.Format("[INFO] Log Exported! ({0})", logPath));
129+
}
130+
catch
131+
{
132+
AppendWithColour(consoleTextBox, String.Format("[WARN] Log file could not be written to '{0}'!", logPath));
133+
}
134+
}
135+
136+
private void ConsoleInputTextBox_KeyDown(object sender, KeyEventArgs e)
137+
{
138+
if (e.KeyCode == Keys.Enter)
139+
{
140+
sendInputButton.PerformClick();
141+
e.SuppressKeyPress = true;
142+
e.Handled = true;
143+
}
144+
}
145+
146+
private void SendInputButton_Click(object sender, EventArgs e)
147+
{
148+
CommandInput(consoleInputTextBox);
149+
}
150+
151+
private void CommandInput(RichTextBox textbox)
152+
{
153+
string[] input = textbox.Text.ToLower().Split(' ');
154+
155+
uint csBufferTmp = 0;
156+
if (input[0] == "cryptostreambuffer" || input[0] == "csbuffer" || input[0] == "buffer")
157+
{
158+
if (input.Length > 1 && !string.IsNullOrEmpty(input[1]) && uint.TryParse(input[1], out csBufferTmp))
159+
{
160+
AppendWithColour(consoleTextBox, String.Format("[INFO] CryptoStream Buffer set to {0} bytes", csBufferTmp));
161+
FileAES_Utilities.SetCryptoStreamBuffer(csBufferTmp);
162+
}
163+
else AppendWithColour(consoleTextBox, String.Format("[WARN] Too few arguments provided for the '{0}' command!", textbox.Text));
164+
}
165+
else if (input[0] == "getcryptostreambuffer" || input[0] == "getcsbuffer" || input[0] == "getbuffer")
166+
{
167+
AppendWithColour(consoleTextBox, String.Format("[INFO] CryptoStream Buffer is {0} bytes", FileAES_Utilities.GetCryptoStreamBuffer()));
168+
}
169+
else if (input[0] == "getfaestempfolder" || input[0] == "gettemp" || input[0] == "gettempfolder")
170+
{
171+
AppendWithColour(consoleTextBox, String.Format("[INFO] FAES Temp Folder is: {0}", FileAES_Utilities.GetFaesTempFolder()));
172+
}
173+
else if (input[0] == "getfaesversion" || input[0] == "getfaesver" || input[0] == "faesver")
174+
{
175+
AppendWithColour(consoleTextBox, String.Format("[INFO] FAES Version: {0}", FileAES_Utilities.GetVersion()));
176+
}
177+
else if (input[0] == "getfaesuiversion" || input[0] == "getfaesuiver" || input[0] == "ver")
178+
{
179+
AppendWithColour(consoleTextBox, String.Format("[INFO] FAES_GUI Version: {0}", Program.GetVersion()));
180+
}
181+
else if (input[0] == "exportlog" || input[0] == "export" || input[0] == "log")
182+
{
183+
ExportLog_Click(null, null);
184+
}
185+
else if (input[0] == "setlogpath" || input[0] == "logpath")
186+
{
187+
if (input.Length > 1 && !string.IsNullOrEmpty(input[1]))
188+
{
189+
_overrideLogPath = input[1].Replace("\"", string.Empty).Replace("\'", string.Empty);
190+
AppendWithColour(consoleTextBox, String.Format("[INFO] Log path changed to: {0}", _overrideLogPath));
191+
}
192+
else AppendWithColour(consoleTextBox, String.Format("[WARN] Too few arguments provided for the '{0}' command!", textbox.Text));
193+
}
194+
else if (input[0] == "resetlogpath")
195+
{
196+
_overrideLogPath = "";
197+
AppendWithColour(consoleTextBox, String.Format("[INFO] Log path reset!"));
198+
}
199+
else if (input[0] == "clear" || input[0] == "cls")
200+
{
201+
clearConsole.PerformClick();
202+
}
203+
else AppendWithColour(consoleTextBox, String.Format("[WARN] Unknown command: {0}", textbox.Text));
204+
205+
textbox.Clear();
206+
}
207+
208+
private void ConsoleInputTextBox_TextChanged(object sender, EventArgs e)
209+
{
210+
if (string.IsNullOrWhiteSpace(consoleInputTextBox.Text))
211+
sendInputButton.Enabled = false;
212+
else
213+
sendInputButton.Enabled = true;
214+
}
215+
216+
private void AppendWithColour(RichTextBox textbox, string text)
217+
{
218+
textbox.SelectionColor = Color.LightGray;
219+
textbox.AppendText(text.ToString());
220+
textbox.AppendText(Environment.NewLine);
221+
222+
CheckKeyword(textbox, "[DEBUG]", Color.Violet);
223+
CheckKeyword(textbox, "[INFO]", Color.LightBlue);
224+
CheckKeyword(textbox, "[WARN]", Color.Yellow);
225+
CheckKeyword(textbox, "[ERROR]", Color.Red);
226+
227+
textbox.SelectionStart = textbox.TextLength;
228+
textbox.SelectionLength = 0;
229+
textbox.ScrollToCaret();
230+
}
231+
232+
private void CheckKeyword(RichTextBox textbox, string find, Color color)
233+
{
234+
if (textbox.Text.Contains(find))
235+
{
236+
var matchString = Regex.Escape(find);
237+
foreach (Match match in Regex.Matches(textbox.Text, matchString))
238+
{
239+
textbox.Select(match.Index, find.Length);
240+
textbox.SelectionColor = color;
241+
textbox.Select(textbox.TextLength, 0);
242+
textbox.SelectionColor = Color.LightGray;
243+
};
244+
}
116245
}
117246
}
118247
}

0 commit comments

Comments
 (0)