-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
1172 lines (1046 loc) · 47.7 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
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace osu_helper
{
public class MainForm : Form
{
private TextBox /* osuFolderPathBox, */ searchSkinBox;
private Button changeOsuPathButton, /* searchOsuSkinsButton, */ deleteSkinButton, useSkinButton, randomSkinButton, openSkinFolderButton, showFilteredSkinsButton,
hideSelectedSkinFilterButton, deleteSkinSelectorButton, renameSkinButton;
private CheckBox showSkinNumbersBox, showSliderEndsBox, disableSkinChangesBox, disableCursorTrailBox, showComboBurstsBox, showHitLightingBox, hiddenSkinFiltersText, showHitCirclesBox,
makeInstafadeBox, expandingCursorBox;
private OpenFileDialog openFileDialog1;
private ToolTip toolTip;
private ComboBox skinFilterSelector;
private Font mainFont, searchBoxFont;
private ListBox osuSkinsListBox;
private readonly List<UserSkin> osuSkinsList = new();
public static HelperSkin HelperSkin { get; private set; }
public enum ValueName
{
disableCursorTrail,
osuPath,
selectedSkinFilter,
showHitCircleNumbers,
skinFilters,
showSliderEnds,
disableSkinChanges,
showComboBursts,
showHitLighting,
hiddenSkinFilter,
showHitCircles,
makeInstafade,
expandingCursor,
//skinFilterSelector,
writeCurrSkin,
selectedSkin,
searchSkinsText,
defaultValue,
};
readonly Dictionary<ValueName, string> loadedValues = new();
#region Setup
/// <summary>
/// Pops up box asking user to change the osu! path
/// </summary>
public static void ChangeOsuPath()
{
OsuHelper.ChangeOsuPath();
}
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public MainForm()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
SetupForm();
}
/// <summary>
/// Sets up the form for the user
/// </summary>
/// <param name="debugModeArgs">Should it be run in debug mode?</param>
/// <param name="spamLogsArgs">Should it log everything it does?</param>
public void SetupForm()
{
FormClosing += new FormClosingEventHandler(SaveEditedValues);
DebugLog("[STARTING UP]", false);
LoadValues();
mainFont = new Font("Segoe UI", 12);
searchBoxFont = new Font("Segoe UI", 10);
//TODO: Fix changing osu path so OsuHelper.osuPath can be private set
openFileDialog1 = new()
{
InitialDirectory = OsuHelper.OsuFolderPath,
Filter = "Directory|*.directory",
FileName = "",
Title = "Select osu! directory"
};
if (IsSavedValueEmpty(ValueName.osuPath)) //If the path is not set, try to get default directory. If it is not there throw an error
{
OsuHelper.OsuFolderPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE")!, "appdata", "Local", "osu!");
if (!File.Exists(OsuHelper.OsuExePath))
{
MessageBox.Show("Unable to find valid osu directory. Please select one.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ChangeOsuPath();
}
}
else
OsuHelper.OsuFolderPath = GetValue(ValueName.osuPath);
if (HelperSkin == null)
throw new Exception($"Error setting up {HelperSkin}");
MaximizeBox = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Name = "Skin Manager";
Text = "Skin Manager";
Size = new Size(800, 800);
Icon = new Icon(Path.Combine(".", "Images", "o_h_kDs_icon.ico"));
List<Control> topRow = new();
List<Control> searchRow = new();
List<Control> bottomRow = new();
SetupTopRowControls(ref topRow);
AddControls(topRow, 3);
SetupSearchRowControls(ref searchRow);
AddControls(searchRow, 33);
SetupBottomRowControls(ref bottomRow);
AddControls(bottomRow, 737);
SetupSkinChangeCheckBoxes();
SetupToolTips();
DirectoryInfo osuPathDI = new(OsuHelper.OsuSkinsFolderPath);
if (osuPathDI.Exists)
{
if (!Directory.Exists(HelperSkin.Path))
osuPathDI.CreateSubdirectory(OsuHelper.ManagerFolderName);
if (!Directory.Exists(OsuHelper.DeletedSkinsFolderPath))
osuPathDI.CreateSubdirectory("Deleted Skins");
FindOsuSkins(new object());
}
DebugLog("[STARTUP FINISHED. WAITING FOR INPUT]", false);
}
private void SetupToolTips()
{
toolTip = new ToolTip();
//toolTip.SetToolTip(searchOsuSkinsButton, "Searches osu! folder for skins");
toolTip.SetToolTip(changeOsuPathButton, "Set the path that houses the osu!.exe");
//toolTip.SetToolTip(writeCurrSkinBox, "Writes the name of the current skin to a text\nfile in the \"Skins\" folder. Helpful for streamers.");
toolTip.SetToolTip(randomSkinButton, "Selects random skin from visible skins");
toolTip.SetToolTip(openSkinFolderButton, "Opens selected skin folder");
toolTip.SetToolTip(useSkinButton, "Changes to selected skin. If multiple\nare selected, it chooses a random one.");
toolTip.SetToolTip(deleteSkinButton, "Moves selected skin to \"Deleted Skins\" folder");
toolTip.SetToolTip(showSkinNumbersBox, "Controls if numbers are shown on hitcircles");
toolTip.SetToolTip(showSliderEndsBox, "Controls if slider ends are visible\nChecked means that they are shown.");
toolTip.SetToolTip(skinFilterSelector, "Allows you to designate a prefix on the skin folders to categorize the skins");
toolTip.SetToolTip(disableSkinChangesBox, "Disables all changes to skin files and only copies them over");
toolTip.SetToolTip(disableCursorTrailBox, "Checked means no cursor trail is shown.\nWill not add trail to skin that does not have it.");
toolTip.SetToolTip(showFilteredSkinsButton, "Shows only the skins with the selected prefix.\nResets hidden folders.");
toolTip.SetToolTip(hideSelectedSkinFilterButton, "Hides skins with selected prefix.\nPress show button to reset them.");
toolTip.SetToolTip(deleteSkinSelectorButton, "Deletes skin prefix from list");
toolTip.SetToolTip(showComboBurstsBox, "If checked, combo bursts will be shown if the skin has them");
toolTip.SetToolTip(hiddenSkinFiltersText, "The skins with these prefixes are hidden from the list");
toolTip.SetToolTip(expandingCursorBox, "Checked means the cursor will expand on click");
toolTip.SetToolTip(searchSkinBox, "Filter the skins by what you put here");
toolTip.SetToolTip(renameSkinButton, "Renames selected skin.");
//toolTip.SetToolTip(makeInstafadeBox, "Makes hitcircles fade instantly\nMay not convert back from instafade correctly\nMake intermediate (grey) to disable editing");
}
private void AddControls(List<Control> controls, int offsetFromTop)
{
int leftOffset = 1;
foreach (Control obj in controls)
{
if (obj is not ComboBox && obj is not TextBox)
obj.Width = TextRenderer.MeasureText(obj.Text, mainFont).Width + 10;
obj.Top = offsetFromTop;
obj.Left = leftOffset;
leftOffset += obj.Width + 3;
Controls.Add(obj);
}
}
private void SetupTopRowControls(ref List<Control> controls)
{
/* writeCurrSkinBox = new CheckBox()
{
Height = 25,
Width = 100,
Left = 483,
Top = 3,
Text = "Write current skin to .txt file",
Name = ValueNames.writeCurrSkin.ToString(),
TextAlign = ContentAlignment.MiddleLeft,
};
if (!IsSavedValueEmpty(ValueNames.writeCurrSkin))
writeCurrSkinBox.CheckState = GetCheckState(ValueNames.writeCurrSkin);
else
writeCurrSkinBox.Checked = false;
writeCurrSkinBox.CheckedChanged += new EventHandler(OnClick);
Controls.Add(writeCurrSkinBox); */
changeOsuPathButton = new Button()
{
Left = 0,
Top = 3,
Width = 84,
Font = mainFont,
Text = "Change osu! Path",
Name = "changeOsuPathButton",
};
changeOsuPathButton.Click += new EventHandler(OnButtonClick);
changeOsuPathButton.Select();
disableSkinChangesBox = new CheckBox()
{
Height = 25,
Width = 200,
Left = 483,
Top = 3,
Text = "Disable skin changes",
Name = ValueName.disableSkinChanges.ToString(),
TextAlign = ContentAlignment.MiddleLeft,
};
if (!IsSavedValueEmpty(ValueName.disableSkinChanges))
disableSkinChangesBox.CheckState = GetCheckState(ValueName.disableSkinChanges);
else
disableSkinChangesBox.Checked = false;
disableSkinChangesBox.CheckedChanged += new EventHandler(OnCheckBoxClick);
osuSkinsListBox = new ListBox()
{
Width = 500,
Height = 676,
Top = 60,
Font = mainFont,
SelectionMode = SelectionMode.MultiExtended,
BorderStyle = BorderStyle.Fixed3D,
};
/*
osuFolderPathBox = new System.Windows.Forms.TextBox()
{
Text = OsuHelper.osuPath,
Left = 87,
Width = 300,
Font = mainFont,
Name = ValueName.osuPath.ToString(),
};
Controls.Add(osuFolderPathBox);
osuFolderPathBox.KeyPress += (sender, thisEvent) =>
{
if (thisEvent.KeyChar.Equals((char)13))
{
if (!File.Exists(Path.Combine(osuFolderPathBox.Text, "osu!.exe")))
{
MessageBox.Show("Not a valid osu! directory!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//OsuHelper.osuPath = osuFolderPathBox.Text;
//helperSkin = new Skin(Path.Combine(osuPath, "skins", managerFolderName));
OnCheckBoxClick(sender, thisEvent);
thisEvent.Handled = true;
}
}; */
controls.Add(changeOsuPathButton);
controls.Add(disableSkinChangesBox);
}
private void SetupSearchRowControls(ref List<Control> controls)
{
searchSkinBox = new TextBox()
{
Left = 218,
Width = 100,
Top = 32,
Font = searchBoxFont,
Name = ValueName.searchSkinsText.ToString(),
PlaceholderText = "Search for skin",
};
searchSkinBox.KeyUp += UserSearchSkins;
searchSkinBox.TextChanged += (sender, e) =>
{
int textWidth = TextRenderer.MeasureText(searchSkinBox.Text, searchBoxFont).Width;
if (textWidth > 95)
searchSkinBox.Width = textWidth + 5;
else if (textWidth < searchSkinBox.Width - 5)
searchSkinBox.Width = textWidth < 95 ? 100 : textWidth + 5;
};
if (!IsSavedValueEmpty(ValueName.searchSkinsText))
searchSkinBox.Text = GetValue(ValueName.searchSkinsText);
hiddenSkinFiltersText = new CheckBox()
{
Top = 33,
Font = mainFont,
Left = 136,
Text = "a",
Name = ValueName.hiddenSkinFilter.ToString(),
TextAlign = ContentAlignment.MiddleLeft,
};
deleteSkinSelectorButton = new Button()
{
Top = 33,
Font = mainFont,
Width = 61,
Left = 156,
Text = "Delete",
Name = "deleteSkinSelectorButton",
};
/* hiddenSkinFiltersText.TextChanged += new EventHandler((sender, ev) =>
{
int textWidth = TextRenderer.MeasureText(hiddenSkinFiltersText.Text, mainFont).Width;
if (textWidth == 0)
{
if (Controls.Contains(hiddenSkinFiltersText))
Controls.Remove(hiddenSkinFiltersText);
//deleteSkinSelectorButton.Left = 153;
//searchSkinBox.Left = 218;
}
else
{
if (!Controls.Contains(hiddenSkinFiltersText))
Controls.Add(hiddenSkinFiltersText);
//deleteSkinSelectorButton.Left = textWidth + 152;
hiddenSkinFiltersText.Width = textWidth + 30;
//searchSkinBox.Left = textWidth + 218;
}
}); */
if (!IsSavedValueEmpty(ValueName.hiddenSkinFilter))
hiddenSkinFiltersText.Text = hiddenSkinFiltersText.Text = GetValue(ValueName.hiddenSkinFilter)!.Replace(",", ", ");
else
hiddenSkinFiltersText.Text = "";
deleteSkinSelectorButton.Click += new EventHandler((sender, e) =>
{
if (skinFilterSelector.Items.Contains(skinFilterSelector.Text))
{
string[] origValue = GetValue(ValueName.skinFilters)!.Split(',');
string fixedValue = "";
foreach (string name in origValue)
{
if (skinFilterSelector.Text != name)
fixedValue += name + ",";
}
//ChangeRegValue(ValueNames.skinFilters, fixedValue.Remove(fixedValue.Length-1));
skinFilterSelector.Items.Remove(skinFilterSelector.Text);
}
else if (skinFilterSelector.Text == "All")
DebugLog("You can't delete the \"All\" prefix silly.", true);
skinFilterSelector.Text = "All";
//ChangeRegValue(ValueNames.selectedSkinFilter, "All");
});
skinFilterSelector = new ComboBox()
{
Top = 30,
Font = mainFont,
Height = 23,
Width = 43,
Name = ValueName.skinFilters.ToString(),
};
skinFilterSelector.KeyUp += (sender, thisEvent) =>
{
if (thisEvent.KeyCode.Equals(Keys.Enter))
{
AddToSkinFilters();
thisEvent.Handled = true;
}
};
if (!IsSavedValueEmpty(ValueName.skinFilters))
{
if (!skinFilterSelector.Items.Contains("All"))
skinFilterSelector.Items.Add("All");
string[] foldersArr = GetValue(ValueName.skinFilters)!.Split(',');
foreach (string name in foldersArr)
skinFilterSelector.Items.Add(name);
}
else
{
skinFilterSelector.Items.Add("All");
skinFilterSelector.Text = "All";
}
if (!IsSavedValueEmpty(ValueName.selectedSkinFilter))
skinFilterSelector.Text = GetValue(ValueName.selectedSkinFilter);
else
skinFilterSelector.Text = "All";
showFilteredSkinsButton = new Button()
{
Top = 33,
Font = mainFont,
//Height = 23,
Width = 53,
Left = 46,
Text = "Show",
Name = "showFilteredSkinsButton",
};
showFilteredSkinsButton.Click += new EventHandler(OnButtonClick);
hideSelectedSkinFilterButton = new Button()
{
Top = 33,
Font = mainFont,
Width = 48,
Left = 102,
Text = "Hide",
Name = "hideSelectedSkinFilterButton",
};
hideSelectedSkinFilterButton.Click += new EventHandler(OnButtonClick);
/* searchOsuSkinsButton = new System.Windows.Forms.Button()
{
Left = 390,
Top = 3,
Width = 90,
Font = mainFont,
Text = "Find Skins"
};
searchOsuSkinsButton.Click += new EventHandler(OnButtonClick);
Controls.Add(searchOsuSkinsButton); */
controls.Add(searchSkinBox);
controls.Add(showFilteredSkinsButton);
controls.Add(hideSelectedSkinFilterButton);
controls.Add(deleteSkinSelectorButton);
controls.Add(skinFilterSelector);
}
private void SetupBottomRowControls(ref List<Control> controls)
{
useSkinButton = new Button()
{
Left = 102,
Top = 737,
Width = 80,
Font = mainFont,
Text = "Use Skin",
Name = "useSkinButton",
};
useSkinButton.Click += new EventHandler(OnButtonClick);
randomSkinButton = new Button()
{
Left = 185,
Top = 737,
Width = 110,
Font = mainFont,
Text = "Random Skin",
Name = "randomSkinButton",
};
randomSkinButton.Click += new EventHandler(OnButtonClick);
deleteSkinButton = new Button()
{
Left = 3,
Top = 737,
Width = 96,
Font = mainFont,
Text = "Delete Skin",
Name = "deleteSkinButton",
};
deleteSkinButton.Click += new EventHandler(OnButtonClick);
openSkinFolderButton = new Button()
{
Left = 298,
Top = 737,
Width = 139,
Font = mainFont,
Text = "Open Skin Folder",
Name = "openSkinFolderButton",
};
openSkinFolderButton.Click += new EventHandler(OnButtonClick);
renameSkinButton = new Button()
{
Left = 440,
Top = 737,
Width = 107,
Font = mainFont,
Text = "Rename Skin",
Name = "renameSkinButton",
};
renameSkinButton.Click += new EventHandler(OnButtonClick);
controls.Add(useSkinButton);
controls.Add(randomSkinButton);
controls.Add(renameSkinButton);
controls.Add(openSkinFolderButton);
controls.Add(deleteSkinButton);
}
private void SetupSkinChangeCheckBoxes()
{
CheckBox workingCheckBox;
int indexInControls;
CheckState defaultCheckState = CheckState.Indeterminate;
for (int i = 0; i <= 6; i++)
{
if (i == 7) //skipping instafade for now
continue;
workingCheckBox = new CheckBox
{
Height = 25,
Width = 297,
Font = mainFont,
Left = 503,
Top = 60 + (i * 20),
TextAlign = ContentAlignment.MiddleLeft
};
workingCheckBox.CheckStateChanged += new EventHandler(OnCheckBoxClick);
workingCheckBox.ThreeState = true;
Controls.Add(workingCheckBox);
indexInControls = Controls.IndexOf(workingCheckBox);
switch (i)
{
case 0:
Controls[indexInControls].Name = ValueName.showComboBursts.ToString();
Controls[indexInControls].Text = "Combo Bursts";
showComboBurstsBox = (CheckBox)Controls[indexInControls];
break;
case 1:
Controls[indexInControls].Name = ValueName.showHitLighting.ToString();
Controls[indexInControls].Text = "Hit Lighting";
showHitLightingBox = (CheckBox)Controls[indexInControls];
break;
case 2:
Controls[indexInControls].Name = ValueName.showHitCircleNumbers.ToString();
Controls[indexInControls].Text = "Hitcircle Numbers";
showSkinNumbersBox = (CheckBox)Controls[indexInControls];
break;
case 3:
Controls[indexInControls].Name = ValueName.disableCursorTrail.ToString();
Controls[indexInControls].Text = "Cursor Trail";
disableCursorTrailBox = (CheckBox)Controls[indexInControls];
break;
case 4:
Controls[indexInControls].Name = ValueName.showSliderEnds.ToString();
Controls[indexInControls].Text = "Slider Ends";
showSliderEndsBox = (CheckBox)Controls[indexInControls];
break;
case 5:
Controls[indexInControls].Name = ValueName.showHitCircles.ToString();
Controls[indexInControls].Text = "Show Hitcircles";
defaultCheckState = CheckState.Checked;
showHitCirclesBox = (CheckBox)Controls[indexInControls];
break;
case 6:
Controls[indexInControls].Name = ValueName.expandingCursor.ToString();
Controls[indexInControls].Text = "Expanding Cursor";
expandingCursorBox = (CheckBox)Controls[indexInControls];
break;
case 7:
Controls[indexInControls].Name = ValueName.makeInstafade.ToString();
Controls[indexInControls].Text = "Make Instafade";
makeInstafadeBox = (CheckBox)Controls[indexInControls];
break;
default:
DebugLog("Error building CheckBoxes. i = " + i.ToString(), true);
return;
}
string regValue = GetValue(Controls[indexInControls].Name)!;
switch (regValue)
{
case "True":
((CheckBox)Controls[indexInControls]).Checked = true;
break;
case "False":
((CheckBox)Controls[indexInControls]).Checked = false;
break;
case "Indeterminate":
((CheckBox)Controls[indexInControls]).CheckState = CheckState.Indeterminate;
break;
case "Checked":
((CheckBox)Controls[indexInControls]).CheckState = CheckState.Checked;
break;
case "Unchecked":
((CheckBox)Controls[indexInControls]).CheckState = CheckState.Unchecked;
break;
default:
((CheckBox)Controls[indexInControls]).CheckState = defaultCheckState;
break;
}
DebugLog($"CheckBox Name is: {Controls[indexInControls].Name} | Text is: {Controls[indexInControls].Text} | Checked: {((CheckBox)Controls[indexInControls]).Checked}", false);
}
}
#endregion
#region Find/search skins
/// <summary>
/// Called when the user types in <paramref name="searchSkinBox"/>.
/// </summary>
private void UserSearchSkins(object? sender, EventArgs e)
{
FindOsuSkins(sender);
}
/// <summary>
/// Searches the skin directory and adds skins to <paramref name="osuSkinsList"/> and <paramref name="osuSkinsListBox"/>.
/// </summary>
private void FindOsuSkins(object? sender)
{
if (sender != searchSkinBox)
EnableAllControls(false);
if (sender == hideSelectedSkinFilterButton)
{
DebugLog($"{nameof(hideSelectedSkinFilterButton)} called {nameof(FindOsuSkins)}()", false);
//Adds selected prefix to hidden list
if (skinFilterSelector.Text != "All" && !hiddenSkinFiltersText.Text.Contains(skinFilterSelector.Text))
{
if (hiddenSkinFiltersText.Text == "")
hiddenSkinFiltersText.Text = skinFilterSelector.Text;
else
hiddenSkinFiltersText.Text += ", " + skinFilterSelector.Text;
}
AddToSkinFilters();
skinFilterSelector.Text = "All";
}
else if (sender == showFilteredSkinsButton)
{
DebugLog($"{nameof(showFilteredSkinsButton)} called {nameof(FindOsuSkins)}()", false);
hiddenSkinFiltersText.Text = "";
if (skinFilterSelector.Text == ",")
{
skinFilterSelector.Text = "All";
DebugLog("You cannot use \",\" as a prefix", true);
}
AddToSkinFilters();
/* if (!skinFilterSelector.Items.Contains(skinFilterSelector.Text))
skinFilterSelector.Items.Add(skinFilterSelector.Text); */
}
/* List<string> hiddenSkinFiltersList = new List<string>();
if (hiddenSkinFiltersText.Text.Contains(','))
hiddenSkinFiltersList = hiddenSkinFiltersText.Text.Replace(" ", "").Split(',').ToList();
else if (!String.IsNullOrWhiteSpace(hiddenSkinFiltersText.Text))
hiddenSkinFiltersList.Add(hiddenSkinFiltersText.Text); */
osuSkinsListBox.BeginUpdate();
osuSkinsListBox.ClearSelected();
osuSkinsListBox.Items.Clear();
osuSkinsList.Clear();
DirectoryInfo skinFolderDI = new(OsuHelper.OsuSkinsFolderPath);
DirectoryInfo[] osuSkins = skinFolderDI.GetDirectories();
foreach (DirectoryInfo workingSkin in osuSkins)
{
AddSkin(new UserSkin(workingSkin.FullName));
}
osuSkinsListBox.EndUpdate();
if (!Controls.Contains(osuSkinsListBox))
Controls.Add(osuSkinsListBox);
//if skin that was last selected is shown, select it
string lastSkinName = GetValue(ValueName.selectedSkin)!;
if (lastSkinName != null && osuSkinsListBox.Items.Contains(lastSkinName))
{
osuSkinsListBox.SetSelected(osuSkinsListBox.Items.IndexOf(lastSkinName), true);
DebugLog("Previous selected skin name: " + lastSkinName, false);
}
if (sender != searchSkinBox)
EnableAllControls(true);
}
#endregion
#region Selected Skin Handling
/// <summary>
/// Opens the skin folder of the selected skin.
/// </summary>
/// <remarks>
/// If no skin is selected, throws error.
/// </remarks>
private void OpenSelectedSkinFolder()
{
if (osuSkinsListBox.SelectedItem == null)
{
DebugLog("Select skin before trying to open its folder", true);
return;
}
DebugLog("Attempting open skin folder: " + Skin.GetSkinFolderPathFromName(osuSkinsListBox.SelectedItem.ToString()!), false);
if (OperatingSystem.IsWindows())
Process.Start("explorer.exe", Skin.GetSkinFolderPathFromName(osuSkinsListBox.SelectedItem.ToString()!));
}
/// <summary>
/// Deletes the selected skin.
/// </summary>
private void DeleteSelectedSkin()
{
//PopUp confirm = new PopUp();
if (!PopUp.Conformation("Are you sure you want to delete this skin?"))
return;
EnableAllControls(false);
if (osuSkinsListBox.SelectedItem == null)
{
DebugLog("Find skins first. Error occurred when trying to delete skin", true);
return;
}
string currentSkinPath = osuSkinsList[osuSkinsListBox.SelectedIndex].Path;
Directory.Move(currentSkinPath, Path.Combine(OsuHelper.DeletedSkinsFolderPath, osuSkinsListBox.SelectedItem.ToString()!));
DebugLog($"Moving {currentSkinPath} to {Path.Combine(OsuHelper.DeletedSkinsFolderPath, osuSkinsListBox.SelectedItem.ToString()!)}", false);
osuSkinsList.RemoveAt(osuSkinsListBox.SelectedIndex);
osuSkinsListBox.Items.RemoveAt(osuSkinsListBox.SelectedIndex);
EnableAllControls(true);
}
/// <summary>
/// Renames the selected skin
/// </summary>
private void RenameSelectedSkin()
{
if (osuSkinsListBox.SelectedItems.Count != 1)
return;
string renameTo = osuSkinsListBox.SelectedItem.ToString()!;
if (PopUp.InputBox("Rename", "Rename:", ref renameTo) == DialogResult.Cancel)
return;
while (renameTo.Contains(Path.DirectorySeparatorChar))
if (PopUp.InputBox("Cannot contain \"" + Path.DirectorySeparatorChar + "\"", "Rename:", ref renameTo) == DialogResult.Cancel)
return;
renameTo = osuSkinsList[osuSkinsListBox.SelectedIndex].Path.Replace(osuSkinsListBox.SelectedItem.ToString()!, renameTo);
if (osuSkinsList[osuSkinsListBox.SelectedIndex].Path != renameTo)
Directory.Move(osuSkinsList[osuSkinsListBox.SelectedIndex].Path, renameTo);
FindOsuSkins(new object());
osuSkinsListBox.ClearSelected();
osuSkinsListBox.SetSelected(osuSkinsList.IndexOf(new UserSkin(renameTo)), true);
}
#region Change to skin
/// <summary>
/// Changes to the selected skin
/// </summary>
private void ChangeToSelectedSkin()
{
DebugLog("[STARTING TO CHANGE SKIN]", false);
if (osuSkinsListBox.SelectedItem == null)
{
DebugLog("Please select skin before trying to change to it.", true);
return;
}
EnableAllControls(false);
HelperSkin.DeleteSkinElements();
UserSkin workingSkin;
if (osuSkinsListBox.SelectedItems.Count == 1) //false if multiple skins are selected
workingSkin = osuSkinsList[osuSkinsListBox.SelectedIndex];
else
{
Random r = new();
int randomSkinIndex = osuSkinsListBox.Items.IndexOf(osuSkinsListBox.SelectedItems[r.Next(0, osuSkinsListBox.SelectedItems.Count)]);
workingSkin = osuSkinsList[randomSkinIndex];
osuSkinsListBox.ClearSelected();
osuSkinsListBox.SetSelected(randomSkinIndex, true);
DebugLog($"Changing to random skin from selected | Selected: {osuSkinsListBox.SelectedItem}", false);
}
workingSkin.ChangeToSkin();
DebugLog("[FINISHED CHANGING TO SKIN]", false);
if (!disableSkinChangesBox!.Checked)
{
DebugLog("[STARTING EDITING SKIN]", false);
GetCurrentSkin()!.EditSkin(Controls);
/* GetCurrentSkin().ShowHitCircleNumbers(showSkinNumbersBox.CheckState);
GetCurrentSkin().ShowSliderEnds(showSliderEndsBox.CheckState);
GetCurrentSkin().ShowCursorTrail(disableCursorTrailBox.CheckState);
GetCurrentSkin().ShowComboBursts(showComboBurstsBox.CheckState);
GetCurrentSkin().ShowHitLighting(showHitLightingBox.CheckState);
GetCurrentSkin().ShowHitCircles(showHitCirclesBox.CheckState);
GetCurrentSkin().ChangeExpandingCursor(expandingCursorBox.CheckState); */
//MakeInstafade(makeInstafadeBox.CheckState);
DebugLog("[FINISHED EDITING SKIN]", false);
}
EnableAllControls(true);
}
/// <summary>
/// Selects a random skin of all the available skins.
/// </summary>
private void ChangeToRandomSkin()
{
EnableAllControls(false);
Random r = new();
osuSkinsListBox.ClearSelected();
osuSkinsListBox.SetSelected(r.Next(0, osuSkinsListBox.Items.Count), true);
DebugLog($"Changed to random skin. Picked \"{osuSkinsListBox.SelectedItem}\"", false);
ChangeToSelectedSkin();
}
#endregion
#endregion
#region On Click
/// <summary>
/// Handles button click events
/// </summary>
private void OnButtonClick(object? sender, EventArgs e)
{
if (sender == null)
return;
if (sender == randomSkinButton)
ChangeToRandomSkin();
else if (sender == useSkinButton)
ChangeToSelectedSkin();
else if (sender == deleteSkinButton)
DeleteSelectedSkin();
else if (sender == openSkinFolderButton)
OpenSelectedSkinFolder();
else if (sender == searchSkinBox || sender == hideSelectedSkinFilterButton || sender == showFilteredSkinsButton)
FindOsuSkins(sender);
else if (sender == changeOsuPathButton)
ChangeOsuPath();
else if (sender == searchSkinBox)
FindOsuSkins(sender);
else if (sender == renameSkinButton)
RenameSelectedSkin();
else
DebugLog($"Problem with {nameof(OnButtonClick)}. Sender: " + ((Control)sender).Name + " | EventArgs: " + e.ToString(), true);
}
/// <summary>
/// Handles click events of all of the checkboxes.
/// </summary>
private void OnCheckBoxClick(object? sender, EventArgs e)
{
if (sender == null || GetCurrentSkin() == null)
return;
if (osuSkinsListBox.SelectedIndex == -1)
return;
else if (sender == showSkinNumbersBox)
GetCurrentSkin()!.ShowHitCircleNumbers(showSkinNumbersBox.CheckState);
else if (sender == showSliderEndsBox)
GetCurrentSkin()!.ShowSliderEnds(showSliderEndsBox.CheckState);
else if (sender == disableCursorTrailBox)
GetCurrentSkin()!.ShowCursorTrail(disableCursorTrailBox.CheckState);
else if (sender == showComboBurstsBox)
GetCurrentSkin()!.ShowComboBursts(showComboBurstsBox.CheckState);
else if (sender == showHitLightingBox)
GetCurrentSkin()!.ShowHitLighting(showHitLightingBox.CheckState);
else if (sender == showHitCirclesBox)
GetCurrentSkin()!.ShowHitCircles(showHitCirclesBox.CheckState);
else if (sender == expandingCursorBox)
GetCurrentSkin()!.ChangeExpandingCursor(expandingCursorBox.CheckState);
else if (sender == disableSkinChangesBox) { }
/* else if (sender == makeInstafadeBox)
MakeInstafade(makeInstafadeBox.CheckState); */
else
{
DebugLog($"Error with {nameof(OnCheckBoxClick)} | {sender}", true);
return;
}
}
#endregion
#region Handle saved and loaded values
/// <param name="valName">The name you want the value of</param>
/// <returns>The value of the ValueName with the same name.</returns>
private string? GetValue(ValueName valName)
{
if (!IsSavedValueEmpty(valName))
return loadedValues[valName];
else
return null;
/* try
{
DebugLog($"Reg value of {valName.ToString()} is \"{Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\osuHelper", ((int)valName).ToString(), null).ToString()}\"", false);
return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\osuHelper", ((int)valName).ToString(), null).ToString();
}
catch
{
return null;
} */
}
/// <param name="valName">The name you want the value of</param>
/// <returns>The value of the ValueName with the same name.</returns>
private string? GetValue(string valName)
{
return GetValue(ParseValueName(valName));
}
/// <summary>
/// Parses <paramref name="name"/> to <paramref name="ValueName"/>.
/// </summary>
/// <remarks>
/// If <paramref name="name"/> is not a <paramref name="ValueName"/>, returns ValueName.defaultValue
/// </remarks>
/// <param name="name">The name to parse</param>
public static ValueName ParseValueName(string name)
{
if (Enum.TryParse(typeof(ValueName), name, true, out object? result))
if (result == null)
return ValueName.defaultValue;
else
return (ValueName)result;
else
return ValueName.defaultValue;
}
/// <summary>
/// Returns true if the saved value is non-existent or empty.
/// </summary>
/// <param name="valName">The name of the value you are checking.</param>
/// <returns>bool if the values is non-existent or empty.</returns>
private bool IsSavedValueEmpty(ValueName valName)
{
if (!loadedValues.ContainsKey(valName))
return true;
return string.IsNullOrWhiteSpace(loadedValues[valName]);
}
/// <param name="name">The name of the checkbox you want the state of.</param>
/// <returns>The CheckState of <paramref name="name"/>.</returns>
private CheckState GetCheckState(ValueName name)
{
if (!IsSavedValueEmpty(name))
return (CheckState)Enum.Parse(typeof(CheckState), GetValue(name)!, true);
else
return CheckState.Unchecked;
}
/// <summary>
/// Loads the values from "settings.txt" into <paramref name="loadedValues"/>.
/// </summary>
private void LoadValues()
{
const string path = "settings.text";
if (!File.Exists(path))
return;
DebugLog($"[Starting loading values from {path}]", false);
using StreamReader reader = new(path);
string curLine;
while ((curLine = reader.ReadLine()!) != null)
{
if (OsuHelper.SpamLogs)
DebugLog("Read | " + curLine, false);
string[] curLineArr = curLine.Split(',');
if (curLineArr[0].Equals(ValueName.skinFilters.ToString()))
{
curLineArr[1] = curLine.Replace(ValueName.skinFilters.ToString() + ",", "");
}
loadedValues.Add(ParseValueName(curLineArr[0]), curLineArr[1]);
}
DebugLog($"[Finished loading values from {path}]", false);
}
/// <summary>
/// Saves the values of checkboxes, filters, ect. to settings.txt
/// </summary>
private void SaveEditedValues(object? sender, EventArgs e)
{
const string path = "settings.txt";
//save the values of things
if (!File.Exists(path))
File.Create(path);
using StreamWriter writer = new(path);
foreach (Control currentObj in Controls)
{