-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
1105 lines (937 loc) · 33.4 KB
/
Form1.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 static Crackdown_Installer.InstallerManager;
using ZNix.SuperBLT;
namespace Crackdown_Installer
{
public partial class Form_InstallerWindow : Form
{
const int TOOLTIP_HOVER_DURATION = 10000; //10000ms -> 10s
int currentPage;
int? nextPageOverride = null;
int timesClickedTitle;
List<Panel> panels;
List<System.Windows.Forms.Label> labels;
CheckedListBoxDisabledItems checkedListBox_missingDependencyItems;
CheckedListBoxDisabledItems checkedListBox_installedDependencyItems;
List<ModDependencyEntry> allModsToInstall = new();
List<ModDependencyEntry> selectedModsToInstall = new();
private bool isQueryDependenciesInProgress = false;
private bool hasDoneCollectDependencies = false;
// placeholders; should use the localization resource framework provided by microsoft
const string TOOLTIP_DEPENDENCY_NEEDS_UPDATE = "Older version detected; an update is available.";
//const string TOOLTIP_DEPENDENCY_ALREADY_INSTALLED = "These are mods that you already have installed.";
const string TOOLTIP_DEPENDENCY_NEEDS_INSTALL = "This dependency has not yet been installed.";
const string DEPENDENCY_ALREADY_INSTALLED = "This mod has been installed and is up to date.";
const string INSTALL_STATUS_PENDING = "Pending";
const string INSTALL_STATUS_DONE = "Done";
const string INSTALL_STATUS_SUCCESS = "Installed";
const string INSTALL_STATUS_FAILED = "Failed ($reason$)";
const string INSTALL_STATUS_INPROGRESS = "In progress";
const string STAGE_DESC_ALL_ALREADY_INSTALLED = "You already have all Crackdown packages installed and up-to-date!";
const string END_DOWNLOAD_ERRORS_TITLE = "Installation Failed";
const string END_DOWNLOAD_ERRORS_DESC = "One or more errors were detected. You can try the installer process again, or install the dependencies manually.";
/*
readonly string[] DUCKSOUNDS = {
@"quack1.wav",
@"quack2.wav"
};
*/
int localMaxDependencyNameLength = 0;
const int MIN_NUM_SPACERS = 12;
// constructor method
public Form_InstallerWindow()
{
InitializeComponent();
// set initial value for pd2 install path
string detectedDirectory = InstallerWrapper.GetPd2InstallPath();
richTextBox_pd2InstallPath.Text = detectedDirectory;
folderBrowserDialog1.InitialDirectory = detectedDirectory;
currentPage = 0;
button_prevStage.Enabled = false;
timesClickedTitle = 0;
panels = new List<Panel>();
panels.Add(panel_stageLanding);
panels.Add(panel_stagePreDownload);
panels.Add(panel_stageDownload);
panels.Add(panel_stageEnd);
Point basePanelLocation = new Point(0, 0);
panel_stageLanding.Location = basePanelLocation;
panel_stagePreDownload.Location = basePanelLocation;
panel_stageDownload.Location = basePanelLocation;
panel_stageEnd.Location = basePanelLocation;
labels = new();
labels.Add(label_navigation_stage1);
labels.Add(label_navigation_stage2);
labels.Add(label_navigation_stage3);
labels.Add(label_navigation_stage4);
//register visibility change (aka on stage change) event callbacks
//panel_stage2.VisibleChanged += new EventHandler(this.panel_stage2_OnVisibleChanged);
panel_stagePreDownload.VisibleChanged += new EventHandler(this.panel_stage2_OnVisibleChanged);
panel_stageDownload.VisibleChanged += new EventHandler(this.panel_stage3_OnVisibleChanged);
panel_stageEnd.VisibleChanged += new EventHandler(this.panel_stage4_OnVisibleChanged);
//inherit selected properties from dummy checkboxes
//since the visual editor obviously can't handle custom extended control classes
checkedListBox_missingDependencyItems = new()
{
CheckOnClick = checkedListBox_dummyMissingMods.CheckOnClick,
Cursor = checkedListBox_dummyMissingMods.Cursor,
Size = checkedListBox_dummyMissingMods.Size,
MinimumSize = checkedListBox_dummyMissingMods.MinimumSize,
MaximumSize = checkedListBox_dummyMissingMods.MaximumSize,
Location = checkedListBox_dummyMissingMods.Location,
Font = checkedListBox_dummyMissingMods.Font,
HorizontalScrollbar = checkedListBox_dummyMissingMods.HorizontalScrollbar,
HorizontalExtent = checkedListBox_dummyMissingMods.HorizontalExtent,
ScrollAlwaysVisible = checkedListBox_dummyMissingMods.ScrollAlwaysVisible
};
panel_stagePreDownload.Controls.Add(checkedListBox_missingDependencyItems);
// disable "next stage" button when there are no items selected
void OnItemCheckChanged(object? sender, ItemCheckEventArgs e)
{
CheckedListBoxDisabledItems? send = sender as CheckedListBoxDisabledItems;
// evaluate true number of checked items
// since this event is run before the checked items count is updated
int count = send?.CheckedItems.Count ?? 0;
if (send?.IsDisabledItem(e.Index) ?? true)
{
if (e.NewValue == CheckState.Unchecked)
{
count--;
}
else if (e.NewValue == CheckState.Checked)
{
count++;
}
}
button_nextStage.Enabled = count > 0;
}
checkedListBox_missingDependencyItems.ItemCheck += new ItemCheckEventHandler(OnItemCheckChanged);
checkedListBox_installedDependencyItems = new()
{
CheckOnClick = checkedListBox_dummyInstalledMods.CheckOnClick,
Cursor = checkedListBox_dummyInstalledMods.Cursor,
Size = checkedListBox_dummyInstalledMods.Size,
MinimumSize = checkedListBox_dummyInstalledMods.MinimumSize,
MaximumSize = checkedListBox_dummyInstalledMods.MaximumSize,
Location = checkedListBox_dummyInstalledMods.Location,
Font = checkedListBox_dummyInstalledMods.Font,
HorizontalScrollbar = checkedListBox_dummyInstalledMods.HorizontalScrollbar,
HorizontalExtent = checkedListBox_dummyInstalledMods.HorizontalExtent,
ScrollAlwaysVisible = checkedListBox_dummyInstalledMods.ScrollAlwaysVisible
};
panel_stagePreDownload.Controls.Add(checkedListBox_installedDependencyItems);
}
/// <summary>
///
/// </summary>
private void CheckExistingMods(List<ModDependencyEntry> dependencyEntries)
{
// remove any existing dependency options
allModsToInstall.Clear();
checkedListBox_missingDependencyItems.Items.Clear();
checkedListBox_installedDependencyItems.Items.Clear();
// get list of detected mods that are installed
InstallerWrapper.CollectExistingMods();
if (dependencyEntries.Count == 0)
{
//todo dialog box error
//error fetching dependencies, please quit and try again later
//or download manually
}
foreach (ModDependencyEntry entry in dependencyEntries)
{
bool dependencyIsOptional = entry.IsOptional();
string dependencyName = entry.GetName();
string dependencyType = entry.GetDefinitionType();
string dependencyFileName = entry.GetFileName();
string dependencyDesc = entry.GetDescription();
string dependencyVersionType = entry.GetModVersionType();
string dependencyVersionId = entry.GetModVersionId();
string? dependencyHash = entry.GetHash();
bool dependencyExistingNeedsUpdate = false;
bool isDependencyInstalled = false;
bool ignoreThisDependency = false;
string? currentVersion = string.Empty;
string? currentHash = null;
if (!string.IsNullOrEmpty(dependencyName) && !string.IsNullOrEmpty(dependencyType))
{
// most dependencies will be mods, which are typically folders
Pd2ModFolder? modFolder = null;
Pd2ModData? definitionFile = null;
// find out if this dependency is already installed or not;
// dependencyType indicates which definition file we use to identify a dependency as being installed or not
// (searching for an exact name inside a given definition file)
LogMessage($"Looking for installed {dependencyType} mod {dependencyName}");
if (dependencyType == "json")
{
// use json definition
modFolder = InstallerWrapper.GetBltMod(dependencyName);
isDependencyInstalled = modFolder != null;
}
else if (dependencyType == "xml")
{
// use xml definition
modFolder = InstallerWrapper.GetBeardlibMod(dependencyName);
isDependencyInstalled = modFolder != null;
}
else if (dependencyType == "file")
{
// detect the presence of the file itself;
// since users can generally rename mod folders without impacting the mod's functionality
// (unless the mod is poorly written and does not account for this, eg. by hard-coding the folder name)
// then this should really only be used for mods that are individual files,
// which we can then also hash to compare version names
string pd2InstallationPath = InstallerWrapper.GetPd2InstallPath();
string modPath = Path.Combine(pd2InstallationPath, dependencyFileName);
// find "loose" mod data
// (each one is added manually on a casewise basis, eg. the sblt dll)
Pd2ModData? miscModData = InstallerWrapper.GetMiscMod(dependencyFileName);
if (miscModData != null)
{
isDependencyInstalled = true;
if (miscModData.GetName() == dependencyName)
{
isDependencyInstalled = true;
currentVersion = miscModData.GetVersion();
}
else
{
ignoreThisDependency = true;
// previously only used to ignore
// dll installation for either WSOCK32 or IPHLPAPI since only one was required
// (not used)
}
}
else
{
isDependencyInstalled = false;
}
}
else
{
throw new Exception($"Unknown dependency type: {dependencyType}");
}
// check manifest version against installed version
if (dependencyVersionType == "hash")
{
// determine whether to hash directory or file
string pd2InstallationPath = InstallerWrapper.GetPd2InstallPath();
string modPath = Path.Combine(pd2InstallationPath, dependencyFileName);
bool isDirectory = true;
if (modFolder != null)
{
//if it has a mod folder, hash the mod folder
isDirectory = true;
isDependencyInstalled = System.IO.Directory.Exists(modPath);
}
else
{
// determine if the dependency is supposed to be a folder or a file based on the name
isDirectory = InstallerWrapper.IsDirectory(dependencyFileName);
if (isDirectory)
{
isDependencyInstalled = System.IO.Directory.Exists(modPath);
}
else
{
isDependencyInstalled = System.IO.File.Exists(modPath);
}
}
if (isDependencyInstalled)
{
if (isDirectory)
{
currentHash = Hasher.HashDirectory(modPath);
}
else
{
currentHash = Hasher.HashFile(modPath);
}
}
dependencyExistingNeedsUpdate = dependencyHash != currentHash;
LogMessage($"Version check (hash): current {dependencyHash}, server {currentHash} ?");
}
else
{
// is standard mod folder; check version in definition file
if (dependencyVersionType == "xml")
{
// use beardlib (xml) definition file
if (modFolder != null)
{
definitionFile = modFolder.xmlModDefinition;
}
}
else if (dependencyVersionType == "json")
{
// use sblt (json) definition file
if (modFolder != null)
{
definitionFile = modFolder.jsonModDefinition;
}
}
if (definitionFile != null)
{
// compare version (or hash) here
currentVersion = definitionFile.GetVersion();
dependencyExistingNeedsUpdate = currentVersion != dependencyVersionId;
LogMessage($"Version check: current {currentVersion}, server {dependencyVersionId}");
}
}
}
LogMessage($"Is installed: {isDependencyInstalled}");
if (!ignoreThisDependency)
{
if (isDependencyInstalled)
{
// add to already-installed list
int itemIndex = checkedListBox_installedDependencyItems.Items.Add(dependencyName, true);
if (itemIndex > -1)
{
AddMouseoverDescription(checkedListBox_installedDependencyItems, itemIndex, dependencyDesc, label_modDependenciesItemMouseoverDescription);
checkedListBox_installedDependencyItems.CheckAndDisable(itemIndex);
}
// if version mismatch, also add to missing list as an optional update
if (dependencyExistingNeedsUpdate)
{
int itemIndex2 = checkedListBox_missingDependencyItems.Items.Add(dependencyName, true);
if (itemIndex2 > -1)
{
// give tooltip "installed but needs update";
//add dependency to "to-install" list
AddMouseoverToolTip(checkedListBox_missingDependencyItems, itemIndex2, TOOLTIP_DEPENDENCY_NEEDS_UPDATE);
AddMouseoverToolTip(checkedListBox_installedDependencyItems, itemIndex, TOOLTIP_DEPENDENCY_NEEDS_UPDATE);
allModsToInstall.Add(entry);
}
}
else
{
// give tooltip "already installed", does not need update
AddMouseoverToolTip(checkedListBox_installedDependencyItems, itemIndex, DEPENDENCY_ALREADY_INSTALLED);
}
}
else
{
// is not installed; add to "to-install" list
int itemIndex = checkedListBox_missingDependencyItems.Items.Add(dependencyName, true);
allModsToInstall.Add(entry);
if (itemIndex != -1)
{
AddMouseoverDescription(checkedListBox_missingDependencyItems, itemIndex, dependencyDesc, label_modDependenciesItemMouseoverDescription);
AddMouseoverToolTip(checkedListBox_missingDependencyItems, itemIndex, TOOLTIP_DEPENDENCY_NEEDS_INSTALL);
if (!dependencyIsOptional)
{
checkedListBox_missingDependencyItems.CheckAndDisable(itemIndex);
}
}
}
}
}
/*
if (checkedListBox_missingDependencyItems.Items.Count == 0)
{
// tell user that no downloads are required,
// and that they may quit and play at any time
label_stage3Desc_2.Text = STAGE_DESC_ALL_ALREADY_INSTALLED;
LogMessage($"Done all 1, current page {currentPage}");
if (currentPage == 2)
{
button_nextStage.Enabled = true;
// go to finish
nextPageOverride = 3;
}
}
*/
}
private void CallbackOnQuitButtonPressed()
{
//pre-quit callback
InstallerWrapper.OnApplicationClose();
//quit application
Application.Exit();
}
private void CallbackDetectPd2InstallDirectory() { }
private void CallbackPopulateDependencyInstallList()
{
selectedModsToInstall.Clear();
foreach (string s in checkedListBox_missingDependencyItems.Items)
{
int i = checkedListBox_missingDependencyItems.Items.IndexOf(s);
ModDependencyEntry entry = allModsToInstall[i];
if (entry != null)
{
bool shouldAddItem;
if (checkedListBox_missingDependencyItems.IsDisabledItem(i))
{
// custom disable-able checkedlistbox does not play nice sometimes
// clicking a disabled object doesn't update the draw but appears to toggle the item state regardless
// for the moment assume that any disabled items will be mandatory and must be checked
LogMessage($"Checkbox Mandatory: {i} {entry.GetName()}");
shouldAddItem = true;
}
else
{
if (checkedListBox_missingDependencyItems.CheckedIndices.Contains(i))
{
LogMessage($"Checkbox Checked: {i} {entry.GetName()}");
shouldAddItem = true;
}
else
{
LogMessage($"Checkbox Unchecked: {i} {entry.GetName()}");
shouldAddItem = false;
}
}
if (shouldAddItem)
{
selectedModsToInstall.Add(entry);
string entryName = entry.GetName();
localMaxDependencyNameLength = Math.Max(entryName.Length, localMaxDependencyNameLength);
}
}
}
/*
foreach (int i in checkedListBox_missingDependencyItems.CheckedIndices)
{
ModDependencyEntry entry = allModsToInstall[i];
if (entry != null)
{
selectedModsToInstall.Add(entry);
string entryName = entry.GetName();
localMaxDependencyNameLength = Math.Max(entryName.Length, localMaxDependencyNameLength);
}
}
*/
listBox_downloadList.Items.Clear();
int selectedDownloadCount = 0;
foreach (ModDependencyEntry entry in selectedModsToInstall)
{
selectedDownloadCount++;
int i = listBox_downloadList.Items.Add(GetDownloadSpacerString(entry.GetName(), INSTALL_STATUS_PENDING));
}
//only enable download button if there is at least one item to download
button_startDownload.Enabled = selectedDownloadCount > 0;
}
private string GetDownloadSpacerString(string dependencyName, string statusName)
{
int nameLen = dependencyName.Length;
int numSpacers = (localMaxDependencyNameLength - nameLen) + MIN_NUM_SPACERS;
string spacerString = new String('.', numSpacers);
return dependencyName + spacerString + statusName;
}
void SetDownloadProgressBar(double? percent, long current, long? total)
{
string convertBytes(int i)
{
if (i > 1000000)
{
return String.Format($"{i / 1000000}MB");
}
else if (i > 1000)
{
return String.Format($"{i / 1000}KB");
}
else
{
return String.Format($"{i}B");
}
}
System.Diagnostics.Debug.WriteLine($"Download Progress percent {percent} current {current} total {total}");
if (percent != null)
{
//progressBar_downloadIndividual.Value = (int) percent;
}
else
{
//progressBar_downloadIndividual.Value = 0;
}
string totalStr;
if (total != null)
{
totalStr = convertBytes((int)total);
}
else
{ totalStr = "-"; }
string currentStr = convertBytes((int)current);
label_downloadStatusTitle.Text = $"{currentStr} / {totalStr}";
}
void SetDownloadProgressBar(System.Windows.Forms.ProgressBar p, int current, int total)
{
p.Value = current / total * 100;
}
void SetDownloadProgressBar(System.Windows.Forms.ProgressBar p, int progress) { p.Value = progress; }
/// <summary>
/// Adds an event handler to set the given label to the given text when hovering over the given element in the given CheckedListBox.
/// </summary>
/// <param name="o"></param>
/// <param name="checkboxIndex"></param>
/// <param name="descriptionText"></param>
/// <param name="descLabel"></param>
void AddMouseoverDescription(CheckedListBox o, int checkboxIndex, string descriptionText, System.Windows.Forms.Label descLabel)
{
void OnMouseMove(object? sender, EventArgs e)
{
Point pos = o.PointToClient(MousePosition);
int index = o.IndexFromPoint(pos);
if (index == checkboxIndex)
{
pos = this.PointToClient(MousePosition);
if (!descLabel.Visible)
{
descLabel.Show();
}
descLabel.Text = descriptionText;
}
}
void OnMouseLeave(object? sender, EventArgs e)
{
descLabel.Hide();
}
//o.MouseHover+= new EventHandler(OnMouseHover);
o.MouseMove += new MouseEventHandler(OnMouseMove);
o.MouseLeave += new EventHandler(OnMouseLeave);
}
/// <summary>
/// Adds an event handler to show the given tooltip text when hovering over the given element in the given CheckedListBox.
/// </summary>
/// <param name="o"></param>
/// <param name="checkboxIndex"></param>
/// <param name="tooltipText"></param>
void AddMouseoverToolTip(CheckedListBox o, int checkboxIndex, string tooltipText)
{
void OnMouseMove(object? sender, EventArgs e)
{
Point pos = o.PointToClient(MousePosition);
int index = o.IndexFromPoint(pos);
//TODO optimize by passing a linked list/array of descriptions for the whole CheckedListBox
if (index == checkboxIndex)
{
pos = this.PointToClient(MousePosition);
toolTip1.Show(tooltipText, this, pos.X, pos.Y, TOOLTIP_HOVER_DURATION);
/*
LogMessage.WriteLine("Mousing over index " + index);
//string? s = null;
string? s = descriptions[index + 1];
if (s != null) {
toolTip1.Show(s, this, pos.X, pos.Y, 5000);
}
*/
}
}
void OnMouseLeave(object? sender, EventArgs e)
{
//hide tooltip
Point pos = o.PointToClient(MousePosition);
toolTip1.Hide(this);
}
o.MouseMove += new MouseEventHandler(OnMouseMove);
o.MouseLeave += new EventHandler(OnMouseLeave);
}
/// <summary>
/// Adds an event handler to show the given tooltip text when hovering over the given Control object.
/// </summary>
/// <param name="o"></param>
/// <param name="tooltipText"></param>
void AddMouseoverToolTip(Control o, string tooltipText)
{
void OnMouseHover(object? sender, EventArgs e)
{
Point pos = o.PointToClient(MousePosition);
toolTip1.Show(tooltipText, this, pos.X, pos.Y, TOOLTIP_HOVER_DURATION);
}
void OnMouseLeave(object? sender, EventArgs e)
{
Point pos = o.PointToClient(MousePosition);
toolTip1.Hide(this);
}
o.MouseHover += new EventHandler(OnMouseHover);
o.MouseLeave += new EventHandler(OnMouseLeave);
}
private void CallbackOnGetDependencies(List<ModDependencyEntry> modDependencyEntries)
{
if (!hasDoneCollectDependencies)
{
CheckExistingMods(modDependencyEntries);
//LogMessage("Callback complete");
//foreach (ModDependencyEntry entry in modDependencyEntries)
//{
// LogMessage("DEBUG:", entry.GetName());
//}
hasDoneCollectDependencies = true;
if (currentPage == 1)
{
button_nextStage.Enabled = true;
}
if (checkedListBox_missingDependencyItems.Items.Count == 0)
{
// tell user that no downloads are required,
// and that they may quit and play at any time
label_stagePreDownload_Desc_2.Text = STAGE_DESC_ALL_ALREADY_INSTALLED;
LogMessage("All dependencies were already installed");
// go to finish
nextPageOverride = 3;
}
}
}
/// <summary>
/// Event handler for showing the "select packages" page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_stage2_OnVisibleChanged(object? sender, EventArgs e)
{
if (panel_stagePreDownload.Visible)
{
if (hasDoneCollectDependencies)
{
button_nextStage.Enabled = true;
}
else
{
button_nextStage.Enabled = false;
// get list of dependency mods used in crackdown
// and then populate missing mods list
Action<List<ModDependencyEntry>> clbk = CallbackOnGetDependencies;
InstallerWrapper.GetModDependencyListAsync(true, clbk);
}
}
}
/// <summary>
/// Event handler for showing the "download packages" page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_stage3_OnVisibleChanged(object? sender, EventArgs e)
{
if (panel_stageDownload.Visible)
{
CallbackPopulateDependencyInstallList();
button_nextStage.Enabled = false;
}
}
/// <summary>
/// Event handler for showing the "installation complete" page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel_stage4_OnVisibleChanged(object? sender, EventArgs e)
{
if (panel_stageEnd.Visible)
{
button_nextStage.Visible = false;
button_nextStage.Enabled = false;
button_prevStage.Visible = false;
button_prevStage.Enabled = false;
button_quit.Visible = false;
button_quit.Enabled = false;
}
}
private void CallbackOnDownloadDependenciesComplete(List<DependencyDownloadResult> downloadResults)
{
LogMessage($"All downloads complete. Num results: {downloadResults?.Count ?? -1}");
//listBox_downloadFailedList.Visible = true;
if (downloadResults?.Count > 0)
{
bool failedAny = false;
listBox_downloadFailedList.Items.Clear();
foreach (DependencyDownloadResult downloadResult in downloadResults)
{
ModDependencyEntry entry = downloadResult.entry;
string name = entry.GetName();
string message = downloadResult.message;
string result = GetDownloadSpacerString(name, message);
int messageLen = message.Length;
listBox_downloadFailedList.Items.Add(result);
if (!downloadResult.success)
{
failedAny = true;
}
}
if (failedAny)
{
label_downloadStatusDesc.Text = INSTALL_STATUS_DONE;
label_stageEnd_Title.Text = END_DOWNLOAD_ERRORS_TITLE;
label_endDesc.Text = END_DOWNLOAD_ERRORS_DESC;
}
}
button_nextStage.Enabled = true;
}
private async Task<List<DependencyDownloadResult>> DownloadSelectedDependencies()
{
List<DependencyDownloadResult> downloadResults = new();
// iterate through selected downloads list in order and download each item
int i = 0;
int numDependenciesQueued = selectedModsToInstall.Count;
foreach (ModDependencyEntry dependencyEntry in selectedModsToInstall)
{
string entryName = dependencyEntry.GetName();
LogMessage("Downloading", entryName);
// set current download desc
label_downloadStatusDesc.Text = $"[{i + 1}/{numDependenciesQueued}] Downloading \"{entryName}\"...";
//reset download progress bar
progressBar_downloadIndividual.Value = 0;
Action<double?, long, long?> callbackSetDownloadProgress = SetDownloadProgressBar;
// update status to "in progress"
listBox_downloadList.Items.RemoveAt(i);
listBox_downloadList.Items.Insert(i, GetDownloadSpacerString(entryName, INSTALL_STATUS_INPROGRESS));
string? errorMsg = await InstallerWrapper.DownloadDependency(dependencyEntry, callbackSetDownloadProgress);
if (!string.IsNullOrEmpty(errorMsg))
{
LogMessage("Download fail");
// update status to "failed" (with reason)
listBox_downloadList.Items.RemoveAt(i);
listBox_downloadList.Items.Insert(i, GetDownloadSpacerString(entryName, INSTALL_STATUS_FAILED.Replace("$reason$", errorMsg)));
downloadResults.Add(new DependencyDownloadResult(false, dependencyEntry, INSTALL_STATUS_FAILED.Replace("$reason$", errorMsg)));
}
else
{
// update status to "done"
listBox_downloadList.Items.RemoveAt(i);
listBox_downloadList.Items.Insert(i, GetDownloadSpacerString(entryName, INSTALL_STATUS_DONE));
downloadResults.Add(new DependencyDownloadResult(true, dependencyEntry, INSTALL_STATUS_SUCCESS));
LogMessage("Download success");
}
i++;
}
label_downloadStatusDesc.Text = "All downloads complete.";
return downloadResults;
}
private void MoveToNextStage()
{
if (nextPageOverride != null)
{
MoveToStage((int)nextPageOverride);
nextPageOverride = null;
return;
}
if (currentPage < panels.Count - 1)
{
MoveToStage(currentPage + 1);
}
}
private void MoveToStage(int nextStage)
{
int prevStage = currentPage;
bool isWithinStageBounds(int i)
{
return (i <= panels.Count - 1 && i >= 0);
}
if (isWithinStageBounds(prevStage) && isWithinStageBounds(nextStage))
{
button_nextStage.Enabled = nextStage < panels.Count - 1;
button_prevStage.Enabled = (nextStage > 0);
Panel prevPanel = panels[prevStage];
prevPanel.Hide();
System.Windows.Forms.Label prevLabel = labels[prevStage];
prevLabel.ForeColor = SystemColors.ControlDark;
Panel nextPanel = panels[nextStage];
nextPanel.Show();
System.Windows.Forms.Label nextLabel = labels[nextStage];
nextLabel.ForeColor = Control.DefaultForeColor;
LogMessage($"paging from {currentPage} to {nextStage}");
currentPage = nextStage;
}
else
{
LogMessage($"Couldn't navigate to next page- one or more indices was out of bounds! previous {prevStage}, next {nextStage}");
}
}
private void MoveToPrevStage()
{
nextPageOverride = null;
if (currentPage > 0)
{
MoveToStage(currentPage - 1);
}
}
private void Form1_Load(object sender, EventArgs e) { }
//quit button (in navigation)
private void button1_Click(object sender, EventArgs e)
{
CallbackOnQuitButtonPressed();
}
//start download button
private async void button_start_Click(object sender, EventArgs e)
{
button_prevStage.Enabled = false;
button_startDownload.Enabled = false;
List<DependencyDownloadResult> downloadResults = await DownloadSelectedDependencies();
//button_prevStage.Enabled = true; //don't enable backtracking
//button_startDownload.Enabled = true; //should only be enabled on re-evaluate missing mods
CallbackOnDownloadDependenciesComplete(downloadResults);
}
private void button_browsePath_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
}
private void button_nextStage_Click(object sender, EventArgs e)
{
MoveToNextStage();
}
private void button_prevStage_Click(object sender, EventArgs e)
{
MoveToPrevStage();
}
private void button_detectExistingMods_Click(object sender, EventArgs e)
{
if (!isQueryDependenciesInProgress)
{
// CheckExistingMods();
}
}
private void button_browseInstallPath_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox_pd2InstallPath.Text = folderBrowserDialog1.SelectedPath + @"\";
}
}
private void button_resetInstallPath_Click(object sender, EventArgs e)
{
folderBrowserDialog1.SelectedPath = folderBrowserDialog1.InitialDirectory;
richTextBox_pd2InstallPath.Text = folderBrowserDialog1.InitialDirectory;
}
private void button_RegistryPathFix_Click(object sender, EventArgs e)
{
// test code to determine if long paths are enabled
//object? registryValue = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem", "LongPathsEnabled", "");
//LogMessage("Found thingy " + registryValue);
}
private void button_finalQuit_Click(object sender, EventArgs e)
{
CallbackOnQuitButtonPressed();
}
private void button_finishAndLaunch_Click(object sender, EventArgs e)
{
string? steamDir = InstallerWrapper.GetSteamDirectory();
if (steamDir != null)
{
try
{
InstallerWrapper.LaunchPD2();
}
catch (Exception er)
{
LogMessage($"Could not launch PAYDAY 2: {er}");
}
}
CallbackOnQuitButtonPressed();
}
private void button_openTempFolder_Click(object sender, EventArgs e)
{
InstallerWrapper.OpenTempDirectory();
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e) { }
private void richTextBox1_TextChanged(object sender, EventArgs e) { }
private void linkLabelDiscord_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
InstallerWrapper.BrowserOpenDiscord();
}
private void linkLabelHomepage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
InstallerWrapper.BrowserOpenHomepage();
}
private void linkLabelWiki_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
InstallerWrapper.BrowserOpenWiki();
}
private void linkLabelTroubleshooting_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
InstallerWrapper.BrowserOpenInstructions();
}
private void panel4_Paint(object sender, PaintEventArgs e) { }
private void panel_stage5_Paint(object sender, PaintEventArgs e) { }
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e) { }
private void labelStage3Title_Click(object sender, EventArgs e) { }
private void label_stage1Title_Click(object sender, EventArgs e)
{
if (++timesClickedTitle > 4)
{
LogMessage("Stop clicking him, he's already dead!");
}