-
Notifications
You must be signed in to change notification settings - Fork 0
/
XscriptWinForm.cs
202 lines (179 loc) · 6.56 KB
/
XscriptWinForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace PT_Sguil
{
partial class XscriptWinForm : Form
{
private string originalRtf = string.Empty;
private string sessionState = string.Empty;
private bool wasAborted = false;
public XscriptWinForm()
{
InitializeComponent();
}
private void abortXscript()
{
this.wasAborted = true;
SguildConnection.SendToSguild("AbortXscript " + this.Text);
this.btnFrmXscriptWinAbort.Enabled = false;
}
private void btnFrmXscriptWinAbort_Click(object sender, EventArgs e)
{
this.abortXscript();
}
private void btnFrmXscriptWinClose_Click(object sender, EventArgs e)
{
this.closeXscript();
}
private void btnSearch_ButtonClick(object sender, EventArgs e)
{
this.SearchXscript(true);
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.closeXscript();
}
private void closeXscript()
{
if (this.btnFrmXscriptWinAbort.Enabled)
{
this.abortXscript();
}
base.Close();
}
private void frmXscriptWin_FormClosing(object sender, FormClosingEventArgs e)
{
MainForm.xscriptWindows.Remove(this.Text);
}
private void searchToolStripMenuItem_Click(object sender, EventArgs e)
{
this.SearchXscript(false);
}
private void SearchXscript(bool caseSensitve)
{
string text = this.tbSearch.Text;
int num = 0;
if (caseSensitve)
{
num = 4;
}
if (this.originalRtf == string.Empty)
{
this.originalRtf = this.rtbXscript.Rtf;
}
MessageBox.Show(this.originalRtf);
if (text.Length > 0)
{
int start = -1;
int num3 = 0;
this.rtbXscript.Rtf = this.originalRtf;
while ((start = this.rtbXscript.Find(text, num3, (RichTextBoxFinds) num)) > -1)
{
this.rtbXscript.Select(start, text.Length);
this.rtbXscript.SelectionBackColor = Color.Yellow;
num3 = start + text.Length;
}
this.rtbXscript.Select(0, 0);
}
else
{
this.rtbXscript.Rtf = this.originalRtf;
}
}
private void tbSearch_Enter(object sender, EventArgs e)
{
this.SearchXscript(true);
}
private void tbSearch_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
e.Handled = true;
this.SearchXscript(true);
}
}
private delegate void XscriptDebugMsgDelegate(string s);
public void XscriptDebugMsg(string s)
{
if (this.textBox1.InvokeRequired)
{
this.textBox1.Invoke(new XscriptDebugMsgDelegate(this.XscriptDebugMsg), new object[] { s });
}
else
{
s = s.Trim(new char[] { '{', '}' });
this.textBox1.AppendText(s + Environment.NewLine);
}
}
private delegate void XscriptMainMsgDelegate(string s);
public void XscriptMainMsg(string s)
{
if (this.rtbXscript.InvokeRequired)
{
this.rtbXscript.Invoke(new XscriptMainMsgDelegate(this.XscriptMainMsg), new object[] { s });
return;
}
if (this.wasAborted && (s != "DONE"))
{
return;
}
switch (s)
{
case "HDR":
case "SRC":
case "DST":
case "DEBUG":
case "ERROR":
this.sessionState = s;
goto Label_02BF;
case "DONE":
this.sessionState = string.Empty;
goto Label_02BF;
default:
s = s.Trim(new char[] { '{', '}' });
s = s.PadRight(this.rtbXscript.Width - 4, ' ');
s = s + "\n";
this.rtbXscript.Select(this.rtbXscript.TextLength, 0);
switch (this.sessionState)
{
case "HDR":
this.rtbXscript.SelectionBackColor = ColorTranslator.FromHtml("#00FFFF");
this.rtbXscript.SelectionColor = Color.Black;
break;
case "SRC":
this.rtbXscript.SelectionBackColor = Color.White;
this.rtbXscript.SelectionColor = Color.Blue;
s = "SRC: " + s;
break;
case "DST":
this.rtbXscript.SelectionBackColor = Color.White;
this.rtbXscript.SelectionColor = Color.Red;
s = "DST: " + s;
break;
case "DONE":
this.btnFrmXscriptWinAbort.Enabled = false;
break;
}
break;
}
this.rtbXscript.AppendText(s);
Label_02BF:
if (!this.wasAborted && (this.rtbXscript.TextLength >= ConfigurationSupport.XscriptAutoAbortByteCount))
{
int xscriptAutoAbortByteCount = ConfigurationSupport.XscriptAutoAbortByteCount;
if (xscriptAutoAbortByteCount > 0x3e8)
{
this.XscriptDebugMsg(string.Format("Auto-Abort called based on config setting of {0}K bytes.", xscriptAutoAbortByteCount / 0x3e8));
}
else
{
this.XscriptDebugMsg(string.Format("Auto-Abort called based on config setting of {0} bytes.", xscriptAutoAbortByteCount));
}
this.abortXscript();
}
}
}
}