/
GeneralConfig.cs
303 lines (265 loc) · 11.8 KB
/
GeneralConfig.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
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using Ookii.Dialogs;
using RocksmithToolkitLib;
using RocksmithToolkitLib.Extensions;
using RocksmithToolkitLib.XmlRepository;
namespace RocksmithToolkitGUI.Config
{
public partial class GeneralConfig : UserControl
{
private const string MESSAGEBOX_CAPTION = "General Config";
private bool loading = false;
public string GetConfigVersion() // also used by AutoUpdater and AssemblyCaller
{
// increment the Version here to force RocksmithToolkitUpdater to do a fresh install of RocksmithToolkitLib.*.xml
return (string)"3";
}
// only gets called one time
public GeneralConfig()
{
InitializeComponent();
// fix readonly textbox/cuebox background colors
general_rs1path.BackColor = SystemColors.Window;
general_rs2014path.BackColor = SystemColors.Window;
general_wwisepath.BackColor = SystemColors.Window;
creator_defaulttone.BackColor = SystemColors.Window;
creator_defaultproject.BackColor = SystemColors.Window;
general_defaultauthor.Validating += ValidateSortName;
loading = true;
try
{
PopulateAppIdCombo(general_defaultappid_RS2012, GameVersion.RS2012);
PopulateAppIdCombo(general_defaultappid_RS2014, GameVersion.RS2014);
PopulateEnumCombo(general_defaultgameversion, typeof(GameVersion));
PopulateEnumCombo(general_defaultplatform, typeof(GamePlatform));
PopulateEnumCombo(converter_source, typeof(GamePlatform));
PopulateEnumCombo(converter_target, typeof(GamePlatform));
PopulateRampUp();
PopulateConfigDDC();
// CRITICAL - force static Wwise path and settings for Mac Mono/Wine packages on first run
if ((Environment.OSVersion.Platform == PlatformID.MacOSX || GeneralExtension.IsWine()) && ConfigRepository.Instance().GetBoolean("general_firstrun"))
{
ConfigRepository.Instance()["general_autoupdate"] = "false";
ConfigRepository.Instance()["general_replacerepo"] = "true";
ConfigRepository.Instance()["general_defaultauthor"] = "CST_Mac";
ConfigRepository.Instance()["general_wwisepath"] = "C:\\Program Files (x86)\\Audiokinetic\\Wwise\\Authoring"; // interestingly the full path is not needed here
ConfigRepository.Instance()["general_replacerepo"] = "false";
ConfigRepository.Instance()["general_defaultplatform"] = "Mac";
// TODO: identify these Mac paths if static (they are not static)
ConfigRepository.Instance()["general_rs2014path"] = "";
ConfigRepository.Instance()["general_rs1path"] = "";
}
LoadAndSetupConfiguration(this.Controls);
}
catch { /*For mono compatibility*/ }
loading = false;
}
private void ValidateSortName(object sender, CancelEventArgs e)
{
var tb = sender as TextBox;
if (tb != null)
tb.Text = tb.Text.Trim().GetValidSortableName();
}
private void LoadAndSetupConfiguration(ControlCollection controls)
{
foreach (var control in controls)
{
if (control is TextBox || control is CueTextBox)
{
var tb = (TextBox)control;
tb.Text = (string)ConfigRepository.Instance()[tb.Name];
}
else if (control is ComboBox)
{
var cb = (ComboBox)control;
var value = ConfigRepository.Instance()[cb.Name];
if (!String.IsNullOrEmpty(cb.ValueMember))
cb.SelectedValue = value;
else
cb.SelectedItem = value;
}
else if (control is CheckBox)
{
var ch = (CheckBox)control;
ch.Checked = ConfigRepository.Instance().GetBoolean(ch.Name);
}
else if (control is NumericUpDown)
{
var nud = (NumericUpDown)control;
nud.Value = ConfigRepository.Instance().GetDecimal(nud.Name);
}
else if (control is GroupBox)
LoadAndSetupConfiguration(((GroupBox)control).Controls);
}
// hide First Run
if (ConfigRepository.Instance()["general_firstrun"] == "false")
lblFirstRun.Visible = false;
}
private void PopulateAppIdCombo(ComboBox combo, GameVersion gameVersion)
{
var appIdList = SongAppIdRepository.Instance().Select(gameVersion).ToArray();
combo.DataSource = appIdList;
combo.DisplayMember = "DisplayName";
combo.ValueMember = "AppId";
}
private void PopulateEnumCombo(ComboBox combo, Type typeEnum)
{
var enumList = Enum.GetNames(typeEnum).ToList<string>();
enumList.Remove("None");
combo.DataSource = enumList;
}
private void PopulateRampUp()
{
if (Directory.Exists(@".\ddc\"))
{
ddc_rampup.Items.Clear();
foreach (var xml in Directory.EnumerateFiles(@".\ddc\", "*.xml", SearchOption.AllDirectories))
{
var name = Path.GetFileNameWithoutExtension(xml);
if (name.StartsWith("user_"))
name = name.Remove(0, 5);
ddc_rampup.Items.Add(name);
ddc_rampup.SelectedItem = ConfigRepository.Instance()[ddc_rampup.Name];
}
}
}
private void PopulateConfigDDC()
{
var ddcpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "ddc");
if (Directory.Exists(ddcpath))
{
ddc_config.Items.Clear();
foreach (var xml in Directory.EnumerateFiles(ddcpath, "*.cfg", SearchOption.AllDirectories))
{
var name = Path.GetFileNameWithoutExtension(xml);
if (name.StartsWith("user_", StringComparison.Ordinal))
name = name.Remove(0, 5);
ddc_config.Items.Add(name);
ddc_config.SelectedItem = ConfigRepository.Instance()[ddc_config.Name];
}
}
}
private void ConfigurationChanged(object sender, EventArgs e)
{
if (loading)
return;
Control control = (Control)sender;
var key = control.Name;
var value = control.Text;
if (control is ComboBox)
{
var combo = ((ComboBox)control);
if (!String.IsNullOrEmpty(combo.ValueMember))
value = combo.SelectedValue.ToString();
else
value = combo.SelectedItem.ToString();
}
else if (control is CheckBox)
{
value = ((CheckBox)control).Checked.ToString().ToLower();
}
else if (control is NumericUpDown)
{
value = ((NumericUpDown)control).Value.ToString(CultureInfo.InvariantCulture);
}
if (ConfigRepository.Instance().ValueChanged(key, value) && !String.IsNullOrEmpty(value))
ConfigRepository.Instance()[key] = value;
}
private void btnCloseConfig_Click(object sender, EventArgs e)
{
ConfigRepository.Instance()["generalconfigversion"] = GetConfigVersion();
ConfigRepository.Instance()["general_firstrun"] = "false";
((MainForm)ParentForm).ReloadControls();
}
private void btnRs1Path_Click(object sender, EventArgs e)
{
using (var fbd = new VistaFolderBrowserDialog())
{
fbd.SelectedPath = general_rs1path.Text;
fbd.Description = "Select Rocksmith 2012 executable root installation folder.";
if (fbd.ShowDialog() != DialogResult.OK)
return;
var rs1Path = fbd.SelectedPath;
general_rs1path.Text = rs1Path;
ConfigRepository.Instance()["general_rs1path"] = rs1Path;
}
}
private void btnRs2014Path_Click(object sender, EventArgs e)
{
using (var fbd = new VistaFolderBrowserDialog())
{
fbd.SelectedPath = general_rs2014path.Text;
fbd.Description = "Select Rocksmith 2014 executable root installation folder.";
if (fbd.ShowDialog() != DialogResult.OK)
return;
var rs2014Path = fbd.SelectedPath;
general_rs2014path.Text = rs2014Path;
ConfigRepository.Instance()["general_rs2014path"] = rs2014Path;
}
}
private void btnWwisePath_Click(object sender, EventArgs e)
{
using (var fbd = new VistaFolderBrowserDialog())
{
fbd.SelectedPath = general_wwisepath.Text;
fbd.Description = "Select Wwise CLI (*.exe) installation folder," + Environment.NewLine +
"or press 'X' to close and clear the Wwise Path.";
if (fbd.ShowDialog() != DialogResult.OK)
{
fbd.SelectedPath = ""; // allow user to clear the path
// return; // leaves the path as-is
}
var wwisePath = fbd.SelectedPath;
general_wwisepath.Text = wwisePath;
ConfigRepository.Instance()["general_wwisepath"] = wwisePath;
}
}
private void btnProjectDir_Click(object sender, EventArgs e)
{
using (var fbd = new VistaFolderBrowserDialog())
{
fbd.SelectedPath = creator_defaultproject.Text;
fbd.Description = "Select Default Project Folder for the CDLC Creator";
if (fbd.ShowDialog() != DialogResult.OK)
return;
var projectDir = fbd.SelectedPath;
creator_defaultproject.Text = projectDir;
ConfigRepository.Instance()["creator_defaultproject"] = projectDir;
}
}
private void btnTonePath_Click(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.InitialDirectory = creator_defaulttone.Text;
ofd.Title = "Select Default Tone for the CDLC Creator";
ofd.Filter = CurrentOFDFilter;
if (ofd.ShowDialog() != DialogResult.OK)
return;
var tonePath = ofd.FileName;
creator_defaulttone.Text = tonePath;
ConfigRepository.Instance()["creator_defaulttone"] = tonePath;
}
}
private string CurrentOFDFilter
{
get
{
switch (general_defaultgameversion.SelectedItem.ToString())
{
case "RS2014":
return "Rocksmith 2014 Tone Template(*.tone2014.xml)|*.tone2014.xml|All XML Files (*.xml)|*.xml";
default:
return "Rocksmith Tone Template (*.tone.xml)|*.tone.xml|All XML Files (*.xml)|*.xml";
}
}
}
}
}