@@ -16,28 +16,6 @@ namespace Universal_THCRAP_Launcher
16
16
{
17
17
public partial class Form1 : Form
18
18
{
19
- #region Global variables
20
- private const string ConfigFile = "utl_config.js" ;
21
- private readonly Image _custom = new Bitmap ( Resources . Custom ) ;
22
- private readonly Image _game = new Bitmap ( Resources . Game ) ;
23
-
24
- private readonly Image _gameAndCustom = new Bitmap ( Resources . GameAndCustom ) ;
25
- private readonly List < string > _gamesList = new List < string > ( ) ;
26
-
27
- private readonly Image _sortAscending = new Bitmap ( Resources . Sort_Ascending ) ;
28
- private readonly Image _sortDescending = new Bitmap ( Resources . Sort_Decending ) ;
29
-
30
- private readonly Image _star = new Bitmap ( Resources . Star ) ;
31
- private readonly Image _starHollow = new Bitmap ( Resources . Star_Hollow ) ;
32
-
33
- private List < string > _jsFiles = new List < string > ( ) ;
34
-
35
- private int [ ] _resizeConstants ;
36
-
37
- private Configuration Configuration1 { get ; set ; }
38
- private Favourites Favourites1 { get ; set ; } = new Favourites ( new List < string > ( ) , new List < string > ( ) ) ;
39
- #endregion
40
-
41
19
public Form1 ( )
42
20
{
43
21
InitializeComponent ( ) ;
@@ -63,7 +41,7 @@ private void Form1_Load(object sender, EventArgs e)
63
41
const string msgError2 =
64
42
"games.js couldn't be found.\n Make sure you run thcrap_configure.exe first!" ;
65
43
if ( ! File . Exists ( "games.js" ) ) ErrorAndExit ( msgError2 ) ;
66
-
44
+
67
45
DeleteOutdatedConfig ( ) ;
68
46
69
47
#region Load data from files
@@ -96,15 +74,16 @@ private void Form1_Load(object sender, EventArgs e)
96
74
file = File . ReadAllText ( ConfigFile ) ;
97
75
Configuration1 = JsonConvert . DeserializeObject < Configuration > ( file , settings ) ;
98
76
}
99
-
77
+
100
78
//Load favourites
101
79
if ( File . Exists ( "favourites.js" ) )
102
80
{
103
81
file = File . ReadAllText ( "favourites.js" ) ;
104
82
Favourites1 = JsonConvert . DeserializeObject < Favourites > ( file ) ;
105
83
}
84
+
106
85
#endregion
107
-
86
+
108
87
#region Fix patch stack list
109
88
110
89
for ( var i = 0 ; i < _jsFiles . Count ; i ++ )
@@ -141,14 +120,13 @@ private void Form1_Load(object sender, EventArgs e)
141
120
_gamesList . Add ( item . Key ) ;
142
121
listBox2 . Items . Add ( item . Key ) ;
143
122
}
144
-
123
+
145
124
SetDefaultSettings ( ) ;
146
-
125
+
147
126
//Change Form settings
148
127
SetDesktopLocation ( Configuration1 . Window . Location [ 0 ] , Configuration1 . Window . Location [ 1 ] ) ;
149
128
Size = new Size ( Configuration1 . Window . Size [ 0 ] , Configuration1 . Window . Size [ 1 ] ) ;
150
-
151
- //Display config
129
+
152
130
checkBox1 . Checked = Configuration1 . ExitAfterStartup ;
153
131
154
132
//Update Display favourites
@@ -184,11 +162,12 @@ private void SetDefaultSettings()
184
162
185
163
if ( Configuration1 . Window == null )
186
164
{
187
- var window = new Window { Size = new [ ] { Size . Width , Size . Height } , Location = new [ ] { Location . X , Location . Y } } ;
165
+ var window = new Window
166
+ { Size = new [ ] { Size . Width , Size . Height } , Location = new [ ] { Location . X , Location . Y } } ;
188
167
Configuration1 . Window = window ;
189
168
}
190
-
191
-
169
+
170
+
192
171
//Default sort
193
172
for ( var i = 0 ; i < 2 ; i ++ )
194
173
if ( Configuration1 . IsDescending [ i ] == "false" )
@@ -249,8 +228,6 @@ private void SetDefaultSettings()
249
228
//Default exe type button state
250
229
filterByType_button . BackgroundImage = _gameAndCustom ;
251
230
for ( var i = 0 ; i < Configuration1 . FilterExeType ; i ++ ) filterByType_button_Click ( null , new EventArgs ( ) ) ;
252
-
253
-
254
231
}
255
232
256
233
@@ -269,9 +246,9 @@ private void Form1_Shown(object sender, EventArgs e)
269
246
270
247
private void DeleteOutdatedConfig ( )
271
248
{
272
- if ( File . Exists ( "uthcrapl_confis.js" ) ) File . Delete ( "uthcrapl_confis.js" ) ;
249
+ if ( File . Exists ( "uthcrapl_confis.js" ) ) File . Delete ( "uthcrapl_confis.js" ) ;
273
250
}
274
-
251
+
275
252
private void Form1_Resize ( object sender , EventArgs e )
276
253
{
277
254
button1 . Size = new Size ( Size . Width - _resizeConstants [ 0 ] , button1 . Size . Height ) ;
@@ -290,7 +267,7 @@ private void Form1_Resize(object sender, EventArgs e)
290
267
filterByType_button . Location = new Point (
291
268
star_button2 . Location . X + _resizeConstants [ 6 ] , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
292
269
}
293
-
270
+
294
271
private static void AddStars ( ListBox listBox , IEnumerable < string > list )
295
272
{
296
273
foreach ( var variable in list )
@@ -337,7 +314,7 @@ private void ReadConfig()
337
314
if ( listBox2 . SelectedIndex == - 1 && listBox2 . Items . Count > 0 )
338
315
listBox2 . SelectedIndex = 0 ;
339
316
}
340
-
317
+
341
318
/// <summary>
342
319
/// Updates the configuration and favourites list
343
320
/// </summary>
@@ -422,7 +399,107 @@ private void button1_MouseHover(object sender, EventArgs e) =>
422
399
private void button1_MouseLeave ( object sender , EventArgs e ) =>
423
400
button1 . BackgroundImage = Resources . Shinmera_Banner_5_mini_size ;
424
401
402
+ private void SelectedIndexChanged ( object sender , EventArgs e )
403
+ {
404
+ if ( ModifierKeys != Keys . None ) return ;
405
+ var lb = ( ListBox ) sender ;
406
+ switch ( lb . Name )
407
+ {
408
+ case "listBox1" :
409
+ if ( lb . SelectedIndex != - 1 )
410
+ Configuration1 . LastConfig = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
411
+ break ;
412
+ case "listBox2" :
413
+ if ( lb . SelectedIndex != - 1 )
414
+ Configuration1 . LastGame = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
415
+ break ;
416
+ default :
417
+ Debug . WriteLine ( "Invalid ListBox!" ) ;
418
+ break ;
419
+ }
420
+ }
421
+
422
+ private void checkBox1_CheckedChanged ( object sender , EventArgs e ) =>
423
+ Configuration1 . ExitAfterStartup = checkBox1 . Checked ;
424
+
425
+ private void Form1_KeyUp ( object sender , KeyEventArgs e )
426
+ {
427
+ if ( ModifierKeys != Keys . None )
428
+ {
429
+ listBox1 . SelectedItem = Configuration1 . LastConfig ;
430
+ listBox2 . SelectedItem = Configuration1 . LastGame ;
431
+ }
432
+
433
+ switch ( e . KeyCode )
434
+ {
435
+ case Keys . F2 when sender . GetType ( ) . FullName != "System.Windows.Forms.ListBox" :
436
+ case Keys . Enter when sender . GetType ( ) . FullName != "System.Windows.Forms.ListBox" :
437
+ return ;
438
+ case Keys . Enter :
439
+ UpdateConfigFile ( ) ;
440
+ StartThcrap ( ) ;
441
+ break ;
442
+ case Keys . F2 :
443
+ var lb = ( ListBox ) sender ;
444
+ if ( ! lb . SelectedItem . ToString ( ) . Contains ( "★" ) )
445
+ {
446
+ if ( lb . Equals ( listBox1 ) )
447
+ Favourites1 . Patches . Add ( lb . Items [ lb . SelectedIndex ] . ToString ( ) ) ;
448
+
449
+ if ( lb . Equals ( listBox2 ) )
450
+ Favourites1 . Games . Add ( lb . Items [ lb . SelectedIndex ] . ToString ( ) ) ;
451
+ lb . Items [ lb . SelectedIndex ] += " ★" ;
452
+ }
453
+ else
454
+ {
455
+ lb . Items [ lb . SelectedIndex ] = lb . Items [ lb . SelectedIndex ] . ToString ( ) . Replace ( " ★" , "" ) ;
456
+ }
457
+
458
+ UpdateConfigFile ( ) ;
459
+ break ;
460
+ }
461
+ }
462
+
463
+ private static void RestartProgram ( )
464
+ {
465
+ Process . Start ( Assembly . GetEntryAssembly ( ) . Location ) ;
466
+ Application . Exit ( ) ;
467
+ }
468
+
469
+ private static void ShowKeyboardShortcuts ( )
470
+ {
471
+ MessageBox . Show ( Resources . KeyboardShortcuts ,
472
+ @"Keyboard Shortcuts" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
473
+ }
474
+
475
+ private void Form1_FormClosing ( object sender , FormClosingEventArgs e ) => UpdateConfigFile ( ) ;
476
+
477
+ #region Global variables
478
+
479
+ private const string ConfigFile = "utl_config.js" ;
480
+ private readonly Image _custom = new Bitmap ( Resources . Custom ) ;
481
+ private readonly Image _game = new Bitmap ( Resources . Game ) ;
482
+
483
+ private readonly Image _gameAndCustom = new Bitmap ( Resources . GameAndCustom ) ;
484
+ private readonly List < string > _gamesList = new List < string > ( ) ;
485
+
486
+ private readonly Image _sortAscending = new Bitmap ( Resources . Sort_Ascending ) ;
487
+ private readonly Image _sortDescending = new Bitmap ( Resources . Sort_Decending ) ;
488
+
489
+ private readonly Image _star = new Bitmap ( Resources . Star ) ;
490
+ private readonly Image _starHollow = new Bitmap ( Resources . Star_Hollow ) ;
491
+
492
+ private List < string > _jsFiles = new List < string > ( ) ;
493
+
494
+ private int [ ] _resizeConstants ;
495
+
496
+ private Configuration Configuration1 { get ; set ; }
497
+ private Favourites Favourites1 { get ; set ; } = new Favourites ( new List < string > ( ) , new List < string > ( ) ) ;
498
+
499
+ #endregion
500
+
425
501
#region Sorting/Filtering Button functions
502
+
426
503
private void sort_az_button1_Click ( object sender , EventArgs e )
427
504
{
428
505
var isDesc = Configuration1 . IsDescending ;
@@ -461,7 +538,7 @@ private void sort_az_button2_Click(object sender, EventArgs e)
461
538
462
539
Configuration1 . IsDescending = isDesc ;
463
540
ReadConfig ( ) ;
464
- }
541
+ }
465
542
466
543
private void star_button1_Click ( object sender , EventArgs e )
467
544
{
@@ -520,7 +597,7 @@ private void star_button2_Click(object sender, EventArgs e)
520
597
Configuration1 . OnlyFavourites = onlyFav ;
521
598
ReadConfig ( ) ;
522
599
}
523
-
600
+
524
601
private void filterByType_button_Click ( object sender , EventArgs e )
525
602
{
526
603
if ( filterByType_button . BackgroundImage . Equals ( _gameAndCustom ) )
@@ -556,85 +633,13 @@ private void filterByType_button_Click(object sender, EventArgs e)
556
633
if ( sender != null ) Configuration1 . FilterExeType = 0 ;
557
634
}
558
635
}
559
- #endregion
560
-
561
- private void SelectedIndexChanged ( object sender , EventArgs e )
562
- {
563
- if ( ModifierKeys != Keys . None ) return ;
564
- var lb = ( ListBox ) sender ;
565
- switch ( lb . Name )
566
- {
567
- case "listBox1" :
568
- if ( lb . SelectedIndex != - 1 )
569
- Configuration1 . LastConfig = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
570
- break ;
571
- case "listBox2" :
572
- if ( lb . SelectedIndex != - 1 )
573
- Configuration1 . LastGame = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
574
- break ;
575
- default :
576
- Debug . WriteLine ( "Invalid ListBox!" ) ;
577
- break ;
578
- }
579
- }
580
636
581
- private void checkBox1_CheckedChanged ( object sender , EventArgs e ) =>
582
- Configuration1 . ExitAfterStartup = checkBox1 . Checked ;
583
-
584
- private void Form1_KeyUp ( object sender , KeyEventArgs e )
585
- {
586
- if ( ModifierKeys != Keys . None )
587
- {
588
- listBox1 . SelectedItem = Configuration1 . LastConfig ;
589
- listBox2 . SelectedItem = Configuration1 . LastGame ;
590
- }
591
-
592
- switch ( e . KeyCode )
593
- {
594
- case Keys . F2 when sender . GetType ( ) . FullName != "System.Windows.Forms.ListBox" :
595
- case Keys . Enter when sender . GetType ( ) . FullName != "System.Windows.Forms.ListBox" :
596
- return ;
597
- case Keys . Enter :
598
- UpdateConfigFile ( ) ;
599
- StartThcrap ( ) ;
600
- break ;
601
- case Keys . F2 :
602
- var lb = ( ListBox ) sender ;
603
- if ( ! lb . SelectedItem . ToString ( ) . Contains ( "★" ) )
604
- {
605
- if ( lb . Equals ( listBox1 ) )
606
- Favourites1 . Patches . Add ( lb . Items [ lb . SelectedIndex ] . ToString ( ) ) ;
607
-
608
- if ( lb . Equals ( listBox2 ) )
609
- Favourites1 . Games . Add ( lb . Items [ lb . SelectedIndex ] . ToString ( ) ) ;
610
- lb . Items [ lb . SelectedIndex ] += " ★" ;
611
- }
612
- else
613
- {
614
- lb . Items [ lb . SelectedIndex ] = lb . Items [ lb . SelectedIndex ] . ToString ( ) . Replace ( " ★" , "" ) ;
615
- }
616
-
617
- UpdateConfigFile ( ) ;
618
- break ;
619
- }
620
-
621
- }
637
+ #endregion
622
638
623
- private static void RestartProgram ( )
624
- {
625
- Process . Start ( Assembly . GetEntryAssembly ( ) . Location ) ;
626
- Application . Exit ( ) ;
627
- }
628
-
629
- private static void ShowKeyboardShortcuts ( )
630
- {
631
- MessageBox . Show ( Resources . KeyboardShortcuts ,
632
- @"Keyboard Shortcuts" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
633
- }
634
-
635
639
#region Tool Strip functions
640
+
636
641
private void keyboardShortcutsToolStripMenuItem_Click ( object sender , EventArgs e ) => ShowKeyboardShortcuts ( ) ;
637
-
642
+
638
643
private void restartToolStripMenuItem_Click ( object sender , EventArgs e ) => RestartProgram ( ) ;
639
644
640
645
private void exitToolStripMenuItem_Click ( object sender , EventArgs e ) => Application . Exit ( ) ;
@@ -689,12 +694,10 @@ private void createShortcutToolStripMenuItem_Click(object sender, EventArgs e)
689
694
shortcut . Save ( ) ;
690
695
}
691
696
692
- private void openSelectedPatchConfigurationToolStripMenuItem_Click ( object sender , EventArgs e ) => Process . Start ( Directory . GetCurrentDirectory ( ) + @"/" + listBox1 . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ) ;
697
+ private void openSelectedPatchConfigurationToolStripMenuItem_Click ( object sender , EventArgs e ) =>
698
+ Process . Start ( Directory . GetCurrentDirectory ( ) + @"/" + listBox1 . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ) ;
693
699
694
700
#endregion
695
-
696
- private void Form1_FormClosing ( object sender , FormClosingEventArgs e ) => UpdateConfigFile ( ) ;
697
-
698
701
}
699
702
700
703
public class Configuration
0 commit comments