-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgumentHelper.cs
306 lines (267 loc) · 11.4 KB
/
ArgumentHelper.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//Guild Wars MultiLaunch - Safe and efficient way to launch multiple GWs.
//The Guild Wars executable is never modified, keeping you inline with the tos.
//
//Copyright (C) 2010 IMKey@GuildWarsGuru
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace GWMultiLaunch
{
public partial class ArgumentsWizard : Form
{
private string mArguments;
private Dictionary<string, bool> mSwitches;
private Dictionary<string, string> mTooltips;
public string Arguments
{
get
{
return mArguments;
}
set
{
mArguments = value;
}
}
public ArgumentsWizard()
{
InitializeComponent();
linkLabel1.Links.Add(0, linkLabel1.Text.Length,
"http://wiki.guildwars.com/wiki/Command_line_arguments");
mSwitches = new Dictionary<string, bool>();
mSwitches.Add("-bmp", false);
mSwitches.Add("-character", true);
mSwitches.Add("-diag", false);
mSwitches.Add("-dsound", false);
mSwitches.Add("-dx8", false);
mSwitches.Add("-email", true);
mSwitches.Add("-fps", true);
mSwitches.Add("-image", false);
mSwitches.Add("-mce", false);
mSwitches.Add("-mute", false);
mSwitches.Add("-noshaders", false);
mSwitches.Add("-nosound", false);
mSwitches.Add("-noui", false);
mSwitches.Add("-password", true);
mSwitches.Add("-perf", false);
mSwitches.Add("-repair", false);
mSwitches.Add("-sndasio", false);
mSwitches.Add("-sndwinmm", false);
mSwitches.Add("-uninstall", false);
mSwitches.Add("-update", false);
mSwitches.Add("-windowed", false);
mTooltips = new Dictionary<string, string>();
mTooltips.Add("-bmp", "Save screenshots as .BMP files.");
mTooltips.Add("-character", "Specify character name for login.");
mTooltips.Add("-diag", "Create diagnostics file.");
mTooltips.Add("-dsound", "Force old DirectSound mixer.");
mTooltips.Add("-dx8", "Force DirectX 8 compatibility.");
mTooltips.Add("-email", "Specify email for login.");
mTooltips.Add("-fps", "Specify max frame rate.");
mTooltips.Add("-image", "Force download of all updates and missing files.");
mTooltips.Add("-mce", "Enable Windows Media Center compatibility.");
mTooltips.Add("-mute", "Disable audio output.");
mTooltips.Add("-noshaders", "Disable usage of shaders for graphics.");
mTooltips.Add("-nosound", "Disable audio system.");
mTooltips.Add("-noui", "Hide user interface.");
mTooltips.Add("-password", "Specify password for login.");
mTooltips.Add("-perf", "Show performance stats.");
mTooltips.Add("-repair", "Fix GW.dat file.");
mTooltips.Add("-sndasio", "Use ASIO driver in software mode.");
mTooltips.Add("-sndwinmm", "Use WM Audio driver in software mode.");
mTooltips.Add("-uninstall", "Uninstall Guild Wars.");
mTooltips.Add("-update", "Prompt for install disc to update GW.dat");
mTooltips.Add("-windowed", "Run game in windowed mode.");
}
private void ArgumentHelper_Load(object sender, EventArgs e)
{
FillArguments(mArguments);
FillDefaultArguments();
FillToolTips();
}
private void FillArguments(string arguments)
{
Regex rgx = new Regex(@"(?<match>[^""\s]+)|\""(?<match>[^""]*)""");
MatchCollection matches = rgx.Matches(arguments);
int iRow = -1;
string sSwitch = string.Empty;
bool enableOptionColumn = false;
foreach (Match m in matches)
{
if (m.Value[0] == '-')
{
object[] rowData = new object[] { true, m.Value };
iRow = gwSwitchesGridView.Rows.Add(rowData);
sSwitch = m.Value;
//disable options column?
if (mSwitches.TryGetValue(sSwitch, out enableOptionColumn))
{
if (enableOptionColumn == false)
{
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].ReadOnly = true;
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].Style.BackColor =
System.Drawing.SystemColors.ControlDark;
}
}
else
{
enableOptionColumn = true;
}
}
else if (enableOptionColumn && iRow >= 0)
{
if (gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].Value != null)
{
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].Value += " " + m.Value;
}
else
{
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].Value = m.Value;
}
}
}
}
private void FillDefaultArguments()
{
foreach (KeyValuePair<string, bool> i in mSwitches)
{
if (FindSwitch(i.Key) == false)
{
object[] rowData = new object[] { false, i.Key };
int iRow = gwSwitchesGridView.Rows.Add(rowData);
//disable 3rd column
if (i.Value == false)
{
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].ReadOnly = true;
gwSwitchesGridView.Rows[iRow].Cells["optionColumn"].Style.BackColor =
System.Drawing.SystemColors.ControlDark;
}
}
}
}
private void FillToolTips()
{
foreach (DataGridViewRow r in gwSwitchesGridView.Rows)
{
string gridVal = r.Cells["switchColumn"].Value.ToString().Trim();
string sTooltip = string.Empty;
//disable options column?
if (mTooltips.TryGetValue(gridVal, out sTooltip))
{
r.Cells["switchColumn"].ToolTipText = sTooltip;
if (r.Cells["optionColumn"].ReadOnly == false)
{
r.Cells["optionColumn"].ToolTipText = sTooltip;
}
}
}
}
private bool FindSwitch(string sValue)
{
bool foundSwitch = false;
foreach (DataGridViewRow r in gwSwitchesGridView.Rows)
{
string gridVal = r.Cells["switchColumn"].Value.ToString().Trim();
if (gridVal == sValue)
{
foundSwitch = true;
break;
}
}
return foundSwitch;
}
private string ListToArgString()
{
StringBuilder sb = new StringBuilder();
foreach (DataGridViewRow r in gwSwitchesGridView.Rows)
{
bool rEnabled = (bool)r.Cells["enableColumn"].Value;
if (rEnabled)
{
string rSwitch = r.Cells["switchColumn"].Value.ToString().Trim();
sb.Append(rSwitch);
sb.Append(' ');
string rOption = (string)r.Cells["optionColumn"].Value;
if (rOption != null && rOption != string.Empty)
{
if (rOption[0] != '"' && rOption.Contains(" "))
{
sb.Append('"');
}
sb.Append(rOption);
if (rOption[rOption.Length - 1] != '"' && rOption.Contains(" "))
{
sb.Append('"');
}
sb.Append(' ');
}
}
}
//we don't want last space
return sb.ToString(0, Math.Max(0, sb.Length - 1));
}
private void okButton_Click(object sender, EventArgs e)
{
mArguments = ListToArgString();
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
private void gwSwitchesGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 2)
{
string cellValue = (string)gwSwitchesGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (cellValue != null && cellValue != string.Empty)
{
gwSwitchesGridView.Rows[e.RowIndex].Cells["enableColumn"].Value = true;
}
else
{
gwSwitchesGridView.Rows[e.RowIndex].Cells["enableColumn"].Value = false;
}
}
}
private void gwSwitchesGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 1)
{
gwSwitchesGridView.Rows[e.RowIndex].Cells["enableColumn"].Value =
!(bool)gwSwitchesGridView.Rows[e.RowIndex].Cells["enableColumn"].Value;
}
}
private void gwSwitchesGridView_KeyDown(object sender, KeyEventArgs e)
{
if (gwSwitchesGridView.IsCurrentCellInEditMode == false &&
e.KeyCode == Keys.Delete)
{
foreach (DataGridViewCell c in gwSwitchesGridView.SelectedCells)
{
if (c.ColumnIndex == 2)
{
c.Value = string.Empty;
}
}
}
}
}
}