@@ -16,6 +16,7 @@ namespace Universal_THCRAP_Launcher
16
16
{
17
17
public partial class Form1 : Form
18
18
{
19
+ #region Global variables
19
20
private const string ConfigFile = "utl_config.js" ;
20
21
private readonly Image _custom = new Bitmap ( Resources . Custom ) ;
21
22
private readonly Image _game = new Bitmap ( Resources . Game ) ;
@@ -32,16 +33,16 @@ public partial class Form1 : Form
32
33
private List < string > _jsFiles = new List < string > ( ) ;
33
34
34
35
private int [ ] _resizeConstants ;
35
-
36
+
37
+ private Configuration Configuration1 { get ; set ; }
38
+ private Favourites Favourites1 { get ; set ; } = new Favourites ( new List < string > ( ) , new List < string > ( ) ) ;
39
+ #endregion
40
+
36
41
public Form1 ( )
37
42
{
38
43
InitializeComponent ( ) ;
39
44
}
40
45
41
- private Configuration Configuration1 { get ; set ; }
42
-
43
- private Favourites Favourites1 { get ; set ; } = new Favourites ( new List < string > ( ) , new List < string > ( ) ) ;
44
-
45
46
private static void ErrorAndExit ( string errorMessage )
46
47
{
47
48
MessageBox . Show ( errorMessage , @"Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
@@ -231,7 +232,47 @@ private void Form1_Load(object sender, EventArgs e)
231
232
232
233
Debug . WriteLine ( "Form1 Loaded" ) ;
233
234
}
235
+
236
+ private void Form1_Shown ( object sender , EventArgs e )
237
+ {
238
+ ReadConfig ( ) ;
239
+ //Set default selection index
240
+ if ( listBox1 . SelectedIndex == - 1 && listBox1 . Items . Count > 0 )
241
+ listBox1 . SelectedIndex = 0 ;
242
+
243
+ if ( listBox2 . SelectedIndex == - 1 && listBox2 . Items . Count > 0 )
244
+ listBox2 . SelectedIndex = 0 ;
234
245
246
+ UpdateConfigFile ( ) ;
247
+ }
248
+
249
+ private void Form1_Resize ( object sender , EventArgs e )
250
+ {
251
+ button1 . Size = new Size ( Size . Width - _resizeConstants [ 0 ] , button1 . Size . Height ) ;
252
+ splitContainer1 . Size = new Size ( Size . Width - _resizeConstants [ 1 ] , Size . Height - _resizeConstants [ 2 ] ) ;
253
+ listBox1 . Size = new Size ( splitContainer1 . Panel1 . Width - 1 , splitContainer1 . Panel1 . Height - 1 ) ;
254
+ listBox2 . Size = new Size ( splitContainer1 . Panel2 . Width - 1 , splitContainer1 . Panel2 . Height - 1 ) ;
255
+ checkBox1 . Location = new Point ( checkBox1 . Location . X , Size . Height - _resizeConstants [ 3 ] ) ;
256
+ sort_az_button1 . Location =
257
+ new Point ( sort_az_button1 . Location . X , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
258
+ sort_az_button2 . Location = new Point ( listBox1 . Size . Width + _resizeConstants [ 5 ] ,
259
+ splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
260
+ star_button1 . Location =
261
+ new Point ( star_button1 . Location . X , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
262
+ star_button2 . Location = new Point ( sort_az_button2 . Location . X + _resizeConstants [ 6 ] ,
263
+ splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
264
+ filterByType_button . Location = new Point (
265
+ star_button2 . Location . X + _resizeConstants [ 6 ] , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
266
+ }
267
+
268
+ private static void AddStars ( ListBox listBox , IEnumerable < string > list )
269
+ {
270
+ foreach ( var variable in list )
271
+ {
272
+ var index = listBox . FindStringExact ( variable ) ;
273
+ if ( index != - 1 ) listBox . Items [ index ] += " ★" ;
274
+ }
275
+ }
235
276
236
277
private static void SortListBoxItems ( ref ListBox lb )
237
278
{
@@ -247,6 +288,30 @@ private static void SortListBoxItemsDesc(ref ListBox lb)
247
288
lb . Items . AddRange ( items . OrderByDescending ( i => i ) . ToArray ( ) ) ;
248
289
}
249
290
291
+ /// <summary>
292
+ /// Selects the items based on the configuration
293
+ /// </summary>
294
+ private void ReadConfig ( )
295
+ {
296
+ checkBox1 . Checked = Configuration1 . ExitAfterStartup ;
297
+
298
+ var s = Configuration1 . LastConfig ;
299
+ if ( Favourites1 . Patches . Contains ( s ) )
300
+ s += " ★" ;
301
+ listBox1 . SelectedIndex = listBox1 . FindStringExact ( s ) ;
302
+ s = Configuration1 . LastGame ;
303
+
304
+ if ( Favourites1 . Games . Contains ( s ) )
305
+ s += " ★" ;
306
+
307
+ listBox2 . SelectedIndex = listBox2 . FindStringExact ( s ) ;
308
+
309
+ if ( listBox1 . SelectedIndex == - 1 && listBox1 . Items . Count > 0 )
310
+ listBox1 . SelectedIndex = 0 ;
311
+ if ( listBox2 . SelectedIndex == - 1 && listBox2 . Items . Count > 0 )
312
+ listBox2 . SelectedIndex = 0 ;
313
+ }
314
+
250
315
/// <summary>
251
316
/// Updates the configuration and favourites list
252
317
/// </summary>
@@ -283,30 +348,6 @@ private void UpdateConfig()
283
348
}
284
349
}
285
350
286
- /// <summary>
287
- /// Selects the items based on the configuration
288
- /// </summary>
289
- private void ReadConfig ( )
290
- {
291
- checkBox1 . Checked = Configuration1 . ExitAfterStartup ;
292
-
293
- var s = Configuration1 . LastConfig ;
294
- if ( Favourites1 . Patches . Contains ( s ) )
295
- s += " ★" ;
296
- listBox1 . SelectedIndex = listBox1 . FindStringExact ( s ) ;
297
- s = Configuration1 . LastGame ;
298
-
299
- if ( Favourites1 . Games . Contains ( s ) )
300
- s += " ★" ;
301
-
302
- listBox2 . SelectedIndex = listBox2 . FindStringExact ( s ) ;
303
-
304
- if ( listBox1 . SelectedIndex == - 1 && listBox1 . Items . Count > 0 )
305
- listBox1 . SelectedIndex = 0 ;
306
- if ( listBox2 . SelectedIndex == - 1 && listBox2 . Items . Count > 0 )
307
- listBox2 . SelectedIndex = 0 ;
308
- }
309
-
310
351
/// <summary>
311
352
/// Writes the configuration and favourites to file
312
353
/// </summary>
@@ -350,33 +391,13 @@ private void StartThcrap()
350
391
351
392
private void button1_Click ( object sender , EventArgs e ) => StartThcrap ( ) ;
352
393
353
- private void Form1_FormClosing ( object sender , FormClosingEventArgs e ) => UpdateConfigFile ( ) ;
354
-
355
394
private void button1_MouseHover ( object sender , EventArgs e ) =>
356
395
button1 . BackgroundImage = Resources . Shinmera_Banner_5_mini_size_hover ;
357
396
358
397
private void button1_MouseLeave ( object sender , EventArgs e ) =>
359
398
button1 . BackgroundImage = Resources . Shinmera_Banner_5_mini_size ;
360
399
361
- private void Form1_Resize ( object sender , EventArgs e )
362
- {
363
- button1 . Size = new Size ( Size . Width - _resizeConstants [ 0 ] , button1 . Size . Height ) ;
364
- splitContainer1 . Size = new Size ( Size . Width - _resizeConstants [ 1 ] , Size . Height - _resizeConstants [ 2 ] ) ;
365
- listBox1 . Size = new Size ( splitContainer1 . Panel1 . Width - 1 , splitContainer1 . Panel1 . Height - 1 ) ;
366
- listBox2 . Size = new Size ( splitContainer1 . Panel2 . Width - 1 , splitContainer1 . Panel2 . Height - 1 ) ;
367
- checkBox1 . Location = new Point ( checkBox1 . Location . X , Size . Height - _resizeConstants [ 3 ] ) ;
368
- sort_az_button1 . Location =
369
- new Point ( sort_az_button1 . Location . X , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
370
- sort_az_button2 . Location = new Point ( listBox1 . Size . Width + _resizeConstants [ 5 ] ,
371
- splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
372
- star_button1 . Location =
373
- new Point ( star_button1 . Location . X , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
374
- star_button2 . Location = new Point ( sort_az_button2 . Location . X + _resizeConstants [ 6 ] ,
375
- splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
376
- filterByType_button . Location = new Point (
377
- star_button2 . Location . X + _resizeConstants [ 6 ] , splitContainer1 . Location . Y - _resizeConstants [ 4 ] ) ;
378
- }
379
-
400
+ #region Sorting/Filtering Button functions
380
401
private void sort_az_button1_Click ( object sender , EventArgs e )
381
402
{
382
403
var isDesc = Configuration1 . IsDescending ;
@@ -415,16 +436,7 @@ private void sort_az_button2_Click(object sender, EventArgs e)
415
436
416
437
Configuration1 . IsDescending = isDesc ;
417
438
ReadConfig ( ) ;
418
- }
419
-
420
- private static void AddStars ( ListBox listBox , IEnumerable < string > list )
421
- {
422
- foreach ( var variable in list )
423
- {
424
- var index = listBox . FindStringExact ( variable ) ;
425
- if ( index != - 1 ) listBox . Items [ index ] += " ★" ;
426
- }
427
- }
439
+ }
428
440
429
441
private void star_button1_Click ( object sender , EventArgs e )
430
442
{
@@ -483,42 +495,7 @@ private void star_button2_Click(object sender, EventArgs e)
483
495
Configuration1 . OnlyFavourites = onlyFav ;
484
496
ReadConfig ( ) ;
485
497
}
486
-
487
- private void Form1_Shown ( object sender , EventArgs e )
488
- {
489
- ReadConfig ( ) ;
490
- //Set default selection index
491
- if ( listBox1 . SelectedIndex == - 1 && listBox1 . Items . Count > 0 )
492
- listBox1 . SelectedIndex = 0 ;
493
-
494
- if ( listBox2 . SelectedIndex == - 1 && listBox2 . Items . Count > 0 )
495
- listBox2 . SelectedIndex = 0 ;
496
-
497
- UpdateConfigFile ( ) ;
498
- }
499
-
500
- private void SelectedIndexChanged ( object sender , EventArgs e )
501
- {
502
- var lb = ( ListBox ) sender ;
503
- switch ( lb . Name )
504
- {
505
- case "listBox1" :
506
- if ( lb . SelectedIndex != - 1 )
507
- Configuration1 . LastConfig = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
508
- break ;
509
- case "listBox2" :
510
- if ( lb . SelectedIndex != - 1 )
511
- Configuration1 . LastGame = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
512
- break ;
513
- default :
514
- Debug . WriteLine ( "Invalid ListBox!" ) ;
515
- break ;
516
- }
517
- }
518
-
519
- private void checkBox1_CheckedChanged ( object sender , EventArgs e ) =>
520
- Configuration1 . ExitAfterStartup = checkBox1 . Checked ;
521
-
498
+
522
499
private void filterByType_button_Click ( object sender , EventArgs e )
523
500
{
524
501
if ( filterByType_button . BackgroundImage . Equals ( _gameAndCustom ) )
@@ -554,9 +531,39 @@ private void filterByType_button_Click(object sender, EventArgs e)
554
531
if ( sender != null ) Configuration1 . FilterExeType = 0 ;
555
532
}
556
533
}
534
+ #endregion
535
+
536
+ private void SelectedIndexChanged ( object sender , EventArgs e )
537
+ {
538
+ if ( ModifierKeys != Keys . None ) return ;
539
+ var lb = ( ListBox ) sender ;
540
+ switch ( lb . Name )
541
+ {
542
+ case "listBox1" :
543
+ if ( lb . SelectedIndex != - 1 )
544
+ Configuration1 . LastConfig = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
545
+ break ;
546
+ case "listBox2" :
547
+ if ( lb . SelectedIndex != - 1 )
548
+ Configuration1 . LastGame = lb . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ;
549
+ break ;
550
+ default :
551
+ Debug . WriteLine ( "Invalid ListBox!" ) ;
552
+ break ;
553
+ }
554
+ }
555
+
556
+ private void checkBox1_CheckedChanged ( object sender , EventArgs e ) =>
557
+ Configuration1 . ExitAfterStartup = checkBox1 . Checked ;
557
558
558
559
private void Form1_KeyUp ( object sender , KeyEventArgs e )
559
560
{
561
+ if ( ModifierKeys != Keys . None )
562
+ {
563
+ listBox1 . SelectedItem = Configuration1 . LastConfig ;
564
+ listBox2 . SelectedItem = Configuration1 . LastGame ;
565
+ }
566
+
560
567
switch ( e . KeyCode )
561
568
{
562
569
case Keys . F2 when sender . GetType ( ) . FullName != "System.Windows.Forms.ListBox" :
@@ -585,22 +592,24 @@ private void Form1_KeyUp(object sender, KeyEventArgs e)
585
592
UpdateConfigFile ( ) ;
586
593
break ;
587
594
}
595
+
588
596
}
589
597
590
598
private static void RestartProgram ( )
591
599
{
592
600
Process . Start ( Assembly . GetEntryAssembly ( ) . Location ) ;
593
601
Application . Exit ( ) ;
594
602
}
595
-
596
- private void keyboardShortcutsToolStripMenuItem_Click ( object sender , EventArgs e ) => ShowKeyboardShortcuts ( ) ;
597
-
598
- private void ShowKeyboardShortcuts ( )
603
+
604
+ private static void ShowKeyboardShortcuts ( )
599
605
{
600
606
MessageBox . Show ( Resources . KeyboardShortcuts ,
601
607
@"Keyboard Shortcuts" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
602
608
}
603
-
609
+
610
+ #region Tool Strip functions
611
+ private void keyboardShortcutsToolStripMenuItem_Click ( object sender , EventArgs e ) => ShowKeyboardShortcuts ( ) ;
612
+
604
613
private void restartToolStripMenuItem_Click ( object sender , EventArgs e ) => RestartProgram ( ) ;
605
614
606
615
private void exitToolStripMenuItem_Click ( object sender , EventArgs e ) => Application . Exit ( ) ;
@@ -655,10 +664,12 @@ private void createShortcutToolStripMenuItem_Click(object sender, EventArgs e)
655
664
shortcut . Save ( ) ;
656
665
}
657
666
658
- private void openSelectedPatchConfigurationToolStripMenuItem_Click ( object sender , EventArgs e )
659
- {
667
+ private void openSelectedPatchConfigurationToolStripMenuItem_Click ( object sender , EventArgs e ) => Process . Start ( Directory . GetCurrentDirectory ( ) + @"/" + listBox1 . SelectedItem . ToString ( ) . Replace ( " ★" , "" ) ) ;
660
668
661
- }
669
+ #endregion
670
+
671
+ private void Form1_FormClosing ( object sender , FormClosingEventArgs e ) => UpdateConfigFile ( ) ;
672
+
662
673
}
663
674
664
675
public class Configuration
0 commit comments