-
Notifications
You must be signed in to change notification settings - Fork 80
/
MainForm.cs
337 lines (286 loc) · 11.8 KB
/
MainForm.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Diagnostics;
using RocksmithToolkitLib;
using System.IO;
using System.Net;
using System.ComponentModel;
using System.Globalization;
using RocksmithToolkitLib.Extensions;
using RocksmithToolkitLib.XmlRepository;
using System.Threading;
//
// DEVNOTE: WHEN ISSUING NEW RELEASE VERION OF TOOLKIT ...
// Modify the RocksmithToolkitLib prebuild event which will update
// PatchAssemblyVersion.ps1 file '$AssemblyVersion' and '$AssemblyConfiguration' values
//
// MS VS2010 IDE has periodic glitch that adds values to dlcPackageCreator1 in MainForm.designer.cs
// This prevents the Platform or GameVersion from being set correctly by GeneralConfig.cs
//
namespace RocksmithToolkitGUI
{
public partial class MainForm : Form
{
internal BackgroundWorker bWorker;
private ToolkitVersionOnline onlineVersion;
public MainForm(string[] args)
{
// load order is important
InitializeComponent();
var ci = new CultureInfo("en-US");
var thread = Thread.CurrentThread;
Application.CurrentCulture = thread.CurrentCulture = thread.CurrentUICulture = ci;
//Application.CurrentInputLanguage = InputLanguage.FromCulture(ci); //may cause issues for non us cultures esp on wineMAC build got report of such issue.
// it is better to be hidden initially and then unhide when needed
if (GeneralExtensions.IsInDesignMode)
btnDevTestMethod.Visible = true;
// verify external apps in 'tools' and 'ddc' directory
ExternalApps.VerifyExternalApps();
InitMainForm();
}
private void InitMainForm()
{
this.Text = String.Format("Song Creator Toolkit for Rocksmith (v{0})", ToolkitVersion.RSTKGuiVersion);
btnUpdate.FlatStyle = FlatStyle.Flat;
btnUpdate.BackColor = SystemColors.Control;
btnUpdate.Text = "Updates are disabled";
btnUpdate.Enabled = false;
try
{
// always disable updates on Mac or according to general_autoupdate setting
if (Environment.OSVersion.Platform != PlatformID.MacOSX &&
ConfigRepository.Instance().GetBoolean("general_autoupdate"))
{
bWorker = new BackgroundWorker();
bWorker.DoWork += CheckForUpdate;
bWorker.RunWorkerCompleted += EnableUpdate;
bWorker.RunWorkerAsync();
}
// update current VersionInfo.txt file based on what's running
ToolkitVersion.UpdateVersionInfoFile();
}
catch {/* DO NOTHING */}
}
public sealed override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
private void MainForm_Load(object sender, EventArgs e)
{
// Show this tab only by 'Configuration' click
tabControl1.TabPages.Remove(GeneralConfigTab);
// position main form at top center of screen to avoid having to reposition on low res displays
if ((Screen.PrimaryScreen.WorkingArea.Height - this.Height) > 0)
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2);
else
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2, 0);
}
private void CheckForUpdate(object sender, DoWorkEventArgs e)
{
// CHECK FOR NEW AVAILABLE REVISION AND ENABLE UPDATE
try
{
onlineVersion = ToolkitVersionOnline.Load();
}
catch (WebException) { /* Do nothing on 404 */ }
catch (Exception)
{
throw;
}
}
private void EnableUpdate(object sender, RunWorkerCompletedEventArgs e)
{
if (onlineVersion == null)
{
MessageBox.Show("Check Internet Connection ... ToolkitVersionOnline: null");
return;
}
if (onlineVersion.UpdateAvailable)
{
btnUpdate.BackColor = Color.Orange;
btnUpdate.FlatStyle = FlatStyle.Standard;
btnUpdate.Text = "Click here to update";
}
else
{
btnUpdate.BackColor = Color.LightGreen;
btnUpdate.FlatStyle = FlatStyle.Popup;
btnUpdate.Text = "Updates are enabled";
}
btnUpdate.Enabled = true;
}
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
// hidden easter eggs ... commented out bad practice
//if (!e.Control || !e.Shift) return;
//switch (e.KeyCode)
//{
// case Keys.O: //<< Load Template
// dlcPackageCreator1.btnTemplateLoad_Click();
// break;
// case Keys.S: //<< Save Template
// dlcPackageCreator1.SaveTemplateFile();
// break;
// case Keys.I: //<< Import Package
// dlcPackageCreator1.btnPackageImport_Click();
// break;
// case Keys.G: //<< Generate Package
// dlcPackageCreator1.btnPackageGenerate_Click();
// break;
// case Keys.A: //<< Add Arrangement
// dlcPackageCreator1.btnArrangementAdd_Click();
// break;
// case Keys.T: //<< Add Tone
// dlcPackageCreator1.btnToneAdd_Click();
// break;
//}
}
private void restartToolStripMenuItem_Click(object sender, EventArgs e)
{
ReloadControls();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
using (var a = new AboutForm())
{
a.ShowDialog();
}
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowHelpForm(); //Just show initial help form here!
}
private void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Enabled = false;
using (var u = new UpdateForm())
{
u.Init(onlineVersion);
u.ShowDialog();
}
btnUpdate.Enabled = true;
}
private void configurationToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowConfigScreen();
}
private void ShowConfigScreen()
{
configurationToolStripMenuItem.Enabled = false;
// Save data
//GeneralConfigTab.cachedTabs = tabControl1.TabPages;
// Remove all tabs
tabControl1.TabPages.Clear();
// Add config tab
tabControl1.TabPages.Add(GeneralConfigTab);
}
public void ReloadControls()
{
this.Controls.Clear();
InitializeComponent();
tabControl1.TabPages.Remove(GeneralConfigTab);
InitMainForm();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
// autosave the dlc.xml template on closing
//if (dlcPackageCreator1.IsDirty && ConfigRepository.Instance().GetBoolean("creator_autosavetemplate"))
// dlcPackageCreator1.SaveTemplateFile(dlcPackageCreator1.UnpackedDir, false);
// leave temp folder contents for developer debugging
if (GeneralExtensions.IsInDesignMode)
return;
// cleanup temp folder garbage carefully
// confirm this is the 'Local Settings\Temp' directory
var di = new DirectoryInfo(Path.GetTempPath());
if (di.Parent != null)
return;
if (di.Parent.Name == "Local Settings" && di.Name == "Temp")
{
foreach (FileInfo file in di.GetFiles())
try
{
file.Delete();
}
catch {/*Don't worry just skip locked file*/}
foreach (DirectoryInfo dir in di.GetDirectories())
try
{
dir.Delete(true);
}
catch {/*Don't worry just skip locked directory*/}
}
}
private void MainForm_Shown(object sender, EventArgs e)
{
// don't bug the Developers when in design mode ;)
if (GeneralExtensions.IsInDesignMode)
return;
bool showRevNote = ConfigRepository.Instance().GetBoolean("general_showrevnote");
if (showRevNote)
{
if (this.Text.ToUpper().Contains("BETA"))
ShowHelpForm();
ConfigRepository.Instance()["general_showrevnote"] = "false";
}
this.Refresh();
// check for first run //Check if author set at least, then it's not a first run tho, but let it show msg anyways...
bool firstRun = ConfigRepository.Instance().GetBoolean("general_firstrun");
if (!firstRun)
return;
MessageBox.Show(new Form { TopMost = true },
" Welcome to the Song Creator Toolkit for Rocksmith." + Environment.NewLine +
" Commonly known as, 'the toolkit'." + Environment.NewLine + Environment.NewLine +
"It looks like this may be your first time running the toolkit. " + Environment.NewLine +
"Please fill in the Configuration menu with your selections.",
"Song Creator Toolkit for Rocksmith - FIRST RUN", MessageBoxButtons.OK, MessageBoxIcon.Information);
ShowConfigScreen();
BringToFront();
}
private void ShowHelpForm()
{
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream streamBetaInfo = assembly.GetManifestResourceStream("RocksmithToolkitGUI.BetaInfo.rtf")) //RocksmithToolkitGUI.Resources.
{
using (var helpViewer = new HelpForm())
{
helpViewer.Text = String.Format("{0}", "TOOLKIT BETA REVISION MESSAGE ...");
helpViewer.PopulateRichText(streamBetaInfo);
helpViewer.ShowDialog();
}
}
}
// area for developer testing
private void DevTestMethod()
{
var args = new string[]
{
"-u",
"-input=D:\\Temp\\PeppaPig_p.psarc",
"-x",
"-d",
"-f=Pc",
"-v=RS2014",
"-output=D:\\Temp",
"-c"
};
var cmdArgs = String.Join(" ", args);
var appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var cliPath = Path.Combine(appDir, "packer.exe");
if (File.Exists(cliPath))
GeneralExtensions.RunExternalExecutable(cliPath, arguments: cmdArgs);
else
MessageBox.Show("'Build, Rebuild Solution' while configuration is set to 'Debug w CLI'", "WRONG CONFIGURATION IS SELECTED ...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void btnDevTestMethod_Click(object sender, EventArgs e)
{
DevTestMethod();
}
}
}