-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreTracker.cs
521 lines (446 loc) · 14.9 KB
/
ScoreTracker.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
using System.Text;
using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Globalization;
public class ScoreTracker : Form
{
public static string version = "11/16/2019";
public static string license = @"Copyright (c) 2017-2019 Austin Allman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
private static TrackerCore tracker;
private static TrackerData data;
public static TrackerCore Tracker
{
get { return tracker; }
}
public static TrackerData Data
{
get { return tracker.Data; }
set { tracker.Data = value; }
}
private static int fileIndex = 0;
public static int FileIndex
{
get { return fileIndex; }
set
{
fileIndex = value;
if (fileIndex >= files.Count)
{
fileIndex = 0;
}
if (fileIndex < 0)
{
fileIndex = files.Count - 1;
}
}
}
public static FileReader config;
public static List<string> files;
public static FileReader individualLevels;
public static ColorFileReader colors;
public ScoreTracker()
{
}
public static int DateToNumber(string dt) {
string[] parts = dt.Split('/');
return Int32.Parse(parts[2]) * 10000 + Int32.Parse(parts[0]) * 100 + Int32.Parse(parts[1]);
}
public static void Main(string[] args)
{
Console.WriteLine("Running in: " + Directory.GetCurrentDirectory());
try
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
}
catch (Exception)
{
}
for (int i = 0; i < args.Length; i++)
{
/*if (args[i] == "-s")
{
// If -s is found in the arguments check if the port is specified
for (int j = 0; j < args.Length; j++)
{
if (args[j] == "-p" && j < args.Length - 1)
{
// If -p is found set port to the next argument
port = Convert.ToInt32(args[j+1]);
}
}
// Start server and return from Main() before client is started
StartServer(port);
return;
}*/
}
/*OpenFileDialog test = new OpenFileDialog();
test.Filter = ".ini|*.ini";
test.Title = "Test";
test.ShowDialog();*/
try
{
//Test();
ConvertFiles();
}
catch (Exception e)
{
Console.WriteLine("Conversion Error: " + e.Message + "\n" + e.StackTrace);
}
//try
{
config = new FileReader("config.ini", SortingStyle.Sort);
config.AddNewItem("version", "");
config.AddNewItem("file_index", "0");
config.AddNewItem("casual_mode", "0");
config.AddNewItem("layout", "1");
config.AddNewItem("include_route_pbs_in_individuals_file", "0");
config.AddNewItem("sums_horizontal_alignment", "0");
List<string> fonts = new List<string>();
foreach (FontFamily f in System.Drawing.FontFamily.Families)
{
fonts.Add(f.Name);
}
if (fonts.Contains("Segoe UI"))
{
config.AddNewItem("font", "Segoe UI");
}
else if (fonts.Contains("DejaVu Sans"))
{
config.AddNewItem("font", "DejaVu Sans");
}
else if (fonts.Contains("Arial"))
{
config.AddNewItem("font", "Arial");
}
else
{
config.AddNewItem("font", SystemFonts.MessageBoxFont.Name);
}
config.AddNewItem("font_size", "18");
config.AddNewItem("highlight_current", "0");
config.AddNewItem("start_highlighted", "1");
config.AddNewItem("horizontal_width", "1296");
config.AddNewItem("horizontal_height", "99");
config.AddNewItem("vertical_width", "316");
config.AddNewItem("vertical_height", "309");
config["version"] = version;
if (config.ContainsKey("debug") && config["debug"] == "1")
{
try
{
var handle = GetConsoleWindow ();
ShowWindow (handle, SW_SHOW);
}
catch (Exception)
{
}
}
if (config ["layout"] == "horizontal")
{
config ["layout"] = "0";
}
if (config ["layout"] == "vertical")
{
config ["layout"] = "1";
}
if (config ["layout"] != "0" && config ["layout"] != "1")
{
config ["layout"] = "0";
}
if (config ["sums_horizontal_alignment"] == "right")
{
config ["sums_horizontal_alignment"] = "0";
}
if (config ["sums_horizontal_alignment"] == "left")
{
config ["sums_horizontal_alignment"] = "1";
}
if (config ["sums_horizontal_alignment"] != "0" && config ["sums_horizontal_alignment"] != "1")
{
config ["sums_horizontal_alignment"] = "0";
}
config.Save();
colors = new ColorFileReader("color_theme.ini", SortingStyle.Validate);
colors.AddNewItem("text_color", "#FFFFFF");
colors.AddNewItem("text_color_total", "#FFFFFF");
colors.AddNewItem("text_color_highlighted", "#FFFFFF");
colors.AddNewItem("background_color", "#0F0F0F");
colors.AddNewItem("background_color_highlighted", "#3373F4");
colors.AddNewItem("text_color_ahead", "#00CC36");
colors.AddNewItem("text_color_behind", "#CC1200");
colors.AddNewItem("text_color_best", "#D8AF1F");
if (config.ContainsKey("text_color"))
{
string c = config["text_color"];
config.RemoveKey("text_color");
colors["text_color"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("text_color_total"))
{
string c = config["text_color_total"];
config.RemoveKey("text_color_total");
colors["text_color_total"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("text_color_highlighted"))
{
string c = config["text_color_highlighted"];
config.RemoveKey("text_color_highlighted");
colors["text_color_highlighted"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("background_color"))
{
string c = config["background_color"];
config.RemoveKey("background_color");
colors["background_color"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("background_color_highlighted"))
{
string c = config["background_color_highlighted"];
config.RemoveKey("background_color_highlighted");
colors["background_color_highlighted"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("text_color_ahead"))
{
string c = config["text_color_ahead"];
config.RemoveKey("text_color_ahead");
colors["text_color_ahead"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("text_color_behind"))
{
string c = config["text_color_behind"];
config.RemoveKey("text_color_behind");
colors["text_color_behind"] = ColorTranslator.FromHtml(c);
}
if (config.ContainsKey("text_color_best"))
{
string c = config["text_color_best"];
config.RemoveKey("text_color_best");
colors["text_color_best"] = ColorTranslator.FromHtml(c);
}
files = new List<string>();
if (config.ContainsSection("Files"))
{
foreach (string key in config.GetSection("Files").Keys)
{
if (!System.IO.File.Exists(config["Files", key]))
{
config.RemoveKey("Files", key);
continue;
}
try
{
FileReader tmp = new FileReader(config["Files", key]);
if (!tmp.ContainsSection("Best Run"))
{
config.RemoveKey("Files", key);
continue;
}
}
catch (Exception)
{
config.RemoveKey("Files", key);
continue;
}
files.Add(config["Files", key]);
config.RemoveKey("Files", key);
}
int fileIndex = 0;
foreach (string file in files)
{
config.AddNewItem("Files", "File_" + FormatNumber(fileIndex++), file);
}
}
else
{
config["Files", "File_0000"] = "pb_easy.ini";
config["Files", "File_0001"] = "pb_hard.ini";
files.Add("pb_easy.ini");
files.Add("pb_hard.ini");
}
colors.Save();
config.Save();
FileReader pbEasy = new FileReader("pb_easy.ini", SortingStyle.Validate);
if (!File.Exists("pb_easy.ini"))
{
pbEasy.AddNewItem("Best Run", "Corneria", "0");
pbEasy.AddNewItem("Best Run", "Meteo", "0");
pbEasy.AddNewItem("Best Run", "Katina", "0");
pbEasy.AddNewItem("Best Run", "Sector X", "0");
pbEasy.AddNewItem("Best Run", "Macbeth", "0");
pbEasy.AddNewItem("Best Run", "Area 6", "0");
pbEasy.AddNewItem("Best Run", "Venom 2", "0");
pbEasy.Save();
}
if (!pbEasy.ContainsKey("game"))
{
pbEasy["name"] = "Easy Route";
pbEasy["game"] = "Star Fox 64";
//pbEasy["IL Syncing"] = "on";
}
TrackerData.ValidateFile(pbEasy);
FileReader pbHard = new FileReader("pb_hard.ini", SortingStyle.Validate);
if (!File.Exists("pb_hard.ini"))
{
pbHard.AddNewItem("Best Run", "Corneria", "0");
pbHard.AddNewItem("Best Run", "Sector Y", "0");
pbHard.AddNewItem("Best Run", "Aquas", "0");
pbHard.AddNewItem("Best Run", "Zoness", "0");
pbHard.AddNewItem("Best Run", "Macbeth", "0");
pbHard.AddNewItem("Best Run", "Area 6", "0");
pbHard.AddNewItem("Best Run", "Venom 2", "0");
pbHard.Save();
}
if (!pbHard.ContainsKey("game"))
{
pbHard["name"] = "Hard Route";
pbHard["game"] = "Star Fox 64";
//pbHard["IL Syncing"] = "on";
}
TrackerData.ValidateFile(pbHard);
individualLevels = new FileReader(':', "pb_individuals.txt", SortingStyle.Unsort);
fileIndex = Int32.Parse(config["file_index"]);
if (fileIndex >= files.Count || fileIndex < 0)
{
fileIndex = 0;
config["file_index"] = "0";
config.Save();
}
data = new TrackerData(new FileReader(files[FileIndex], SortingStyle.Validate));
tracker = new TrackerCore(data);
}
/*
catch (Exception e)
{
Console.WriteLine("Startup Error: " + e.Message);
}
*/
try
{
Application.Run(new InputWindow());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
if (config.ContainsKey("debug") && config["debug"] == "1")
Console.Read();
}
public static string FormatNumber(int i)
{
if (i < 10) return "000" + i;
if (i < 100) return "00" + i;
if (i < 1000) return "0" + i;
return "" + i;
}
public static void ConvertFiles()
{
if (File.Exists("config.txt"))
{
FileReader convertConfig = new FileReader(':', "config.txt", SortingStyle.Sort);
convertConfig.KeySeparator = '=';
convertConfig.FileName = "config.ini";
convertConfig.Save();
FileReader convertEasy = new FileReader(':', "pb_easy.txt");
FileReader convertHard = new FileReader(':', "pb_hard.txt");
FileReader convertIL = new FileReader(':', "pb_individuals.txt");
FileReader easy = new FileReader("pb_easy.ini");
FileReader hard = new FileReader("pb_hard.ini");
easy.AddNewItem("name", "Easy Route");
foreach (SectionKeyValue<string> pair in convertEasy)
{
string k = (pair.Key != "Venom") ? pair.Key : "Venom 2";
easy.AddNewItem("Best Run", k, convertEasy[pair.Key]);
string tmp = "0";
if (convertIL.ContainsKey(pair.Key)) tmp = convertIL["General", pair.Key];
easy.AddNewItem("Top Scores", k, tmp);
}
if (easy.GetSection("Best Run").Keys.Count > 0) easy.Save();
easy.AddNewItem("name", "Hard Route");
foreach (SectionKeyValue<string> pair in convertHard)
{
string k = (pair.Key != "Venom") ? pair.Key : "Venom 2";
hard.AddNewItem("Best Run", k, convertHard[pair.Key]);
string tmp = "0";
if (convertIL.ContainsKey(pair.Key)) tmp = convertIL["General", pair.Key];
hard.AddNewItem("Top Scores", k, tmp);
}
if (hard.GetSection("Best Run").Keys.Count > 0) hard.Save();
if (convertIL.ContainsKey("Venom"))
{
convertIL["Venom 2"] = convertIL["Venom"];
convertIL.RemoveKey("Venom");
}
convertIL.Export();
File.Delete("config.txt");
File.Delete("pb_easy.txt");
File.Delete("pb_hard.txt");
MessageBox.Show("Your files have been converted to a new format."+
" Going forward \"pb_individuals.txt\" will no longer be used to track your individual level PBs.\r\n\r\n"+
"Instead level pbs are now saved in the same file as your run pb and are unique to that run with no crossover between routes.\r\n\r\n"+
"Your \"pb_individuals.txt\" will be left intact and if you wish to continue storing your ILs in this file you can do so by adding \"generate_legacy_il_file = 1\" to \"config.ini\" while the program is closed.\r\n\r\n"+
"Do note that enabling this option WILL NOT change where this program reads these scores from."+
" These scores will still be output to and read from the file that stores your best run.",
"Your tracker files have been converted!");
}
}
public static void Test()
{
FileReader unsort = new FileReader("unsort.ini", SortingStyle.Unsort);
unsort.AddNewItem("add 1", "value");
unsort.AddNewItem("Section", "add 2", "value");
unsort["set 1"] = "value";
unsort["Section", "set 2"] = "value";
unsort.Save();
FileReader sort = new FileReader("sort.ini", SortingStyle.Sort);
sort.AddNewItem("add 1", "value");
sort.AddNewItem("Section", "add 2", "value");
sort["set 1"] = "value";
sort["Section", "set 2"] = "value";
sort.Save();
FileReader validate = new FileReader("validate.ini", SortingStyle.Validate);
validate.AddNewItem("add 1", "value");
validate.AddNewItem("Section", "add 2", "value");
validate["set 1"] = "value";
validate["Section", "set 2"] = "value";
validate.Save();
}
}
public class NumericTextBox : TextBox
{
public delegate void OnChanged();
public OnChanged Changed
{
get;
set;
}
public NumericTextBox() : base()
{
TextChanged += delegate { if (Changed != null) Changed(); };
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
// Check if the pressed character was a backspace or numeric.
if (e.KeyChar != (char)8 && !char.IsNumber(e.KeyChar) && e.KeyChar != '\n')
{
e.Handled = true;
}
}
}