|
1 |
| -using FAES_GUI.CustomControls; |
| 1 | +using FAES; |
| 2 | +using FAES_GUI.CustomControls; |
2 | 3 | using System;
|
3 | 4 | using System.Drawing;
|
4 | 5 | using System.IO;
|
| 6 | +using System.Text.RegularExpressions; |
5 | 7 | using System.Windows.Forms;
|
6 | 8 |
|
7 | 9 | namespace FAES_GUI
|
8 | 10 | {
|
9 | 11 | public partial class DevForm : Form
|
10 | 12 | {
|
| 13 | + private string _overrideLogPath = ""; |
| 14 | + |
11 | 15 | public DevForm()
|
12 | 16 | {
|
13 | 17 | InitializeComponent();
|
@@ -106,13 +110,138 @@ private void ClearConsole_Click(object sender, EventArgs e)
|
106 | 110 | private void ExportLog_Click(object sender, EventArgs e)
|
107 | 111 | {
|
108 | 112 | 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); |
112 | 113 |
|
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 | + } |
116 | 245 | }
|
117 | 246 | }
|
118 | 247 | }
|
0 commit comments