-
Notifications
You must be signed in to change notification settings - Fork 165
/
MainForm.cs
3201 lines (2742 loc) · 121 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
namespace Nexus.Client
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nexus.Client.BackgroundTasks;
using Nexus.Client.BackgroundTasks.UI;
using Nexus.Client.Commands;
using Nexus.Client.DownloadMonitoring.UI;
using Nexus.Client.UI.Controls;
using Nexus.Client.Games;
using Nexus.Client.Games.Settings;
using Nexus.Client.Games.Tools;
using Nexus.Client.ModActivationMonitoring.UI;
using Nexus.Client.ModManagement;
using Nexus.Client.ModManagement.UI;
using Nexus.Client.ModRepositories;
using Nexus.Client.Mods;
using Nexus.Client.PluginManagement.UI;
using Nexus.Client.Settings.UI;
using Nexus.Client.SSO;
using Nexus.Client.TipsManagement;
using Nexus.Client.UI;
using Nexus.Client.Util;
using Nexus.Client.Util.Collections;
using Nexus.UI.Controls;
using WeifenLuo.WinFormsUI.Docking;
/// <summary>
/// The main form of the mod manager.
/// </summary>
public partial class MainForm : ManagedFontForm
{
private MainFormVM _viewModel;
private FormWindowState _lastWindowState = FormWindowState.Normal;
private readonly ModManagerControl _modManagerControl;
private readonly PluginManagerControl _pluginManagerControl;
private readonly DownloadMonitorControl _downloadMonitorControl;
private readonly ModActivationMonitorControl _modActivationMonitorControl;
private double _defaultActivityManagerAutoHidePortion;
private double _defaultActivationMonitorAutoHidePortion;
public string OptionalPremiumMessage = string.Empty;
FormWindowState LastWindowState = FormWindowState.Minimized;
private bool _showLastBalloon;
private BalloonManager _balloonManager;
#region Properties
/// <summary>
/// Gets or sets the view model that provides the data and operations for this view.
/// </summary>
/// <value>The view model that provides the data and operations for this view.</value>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
protected MainFormVM ViewModel
{
get => _viewModel;
set
{
_viewModel = value;
_viewModel.ProfileManager.ModProfiles.CollectionChanged += ModProfiles_CollectionChanged;
_viewModel.ProfileSwitching += ViewModel_ProfileSwitching;
_viewModel.AbortedProfileSwitch += ViewModel_AbortedProfileSwitch;
_viewModel.ProfileDownloading += ViewModel_ProfileDownloading;
_viewModel.ProfileSharing += ViewModel_ProfileSharing;
_viewModel.MigratingMods += ViewModel_MigratingMods;
_viewModel.ModManager.VirtualModActivator.ModActivationChanged += VirtualModActivator_ModActivationChanged;
_viewModel.CheckingOnlineProfileIntegrity += ViewModel_CheckingOnlineProfileIntegrity;
_viewModel.ProfileManager.CheckOnlineProfileIntegrityStarted += ViewModel_CheckingOnlineProfileIntegrity;
_viewModel.ApplyingImportedLoadOrder += ViewModel_ApplyingImportedLoadOrder;
_viewModel.CreatingBackup += ViewModel_CreatingBackup;
_viewModel.RestoringBackup += ViewModel_RestoringBackup;
_viewModel.PurgingLooseFiles += ViewModel_PurgingLooseFiles;
_viewModel.ConfigFilesFixing += ViewModel_ConfigFilesFixing;
_viewModel.ModManagerVM.ProfileSwitchSettingUp += ModManagerVM_ProfileSwitchSettingUp;
_modManagerControl.ViewModel = _viewModel.ModManagerVM;
if (ViewModel.UsesPlugins)
{
_pluginManagerControl.ViewModel = _viewModel.PluginManagerVM;
_viewModel.PluginManager.ActivePlugins.CollectionChanged += ActivePlugins_CollectionChanged;
_pluginManagerControl.ViewModel.PluginMoved += pmcPluginManager_PluginMoved;
_pluginManagerControl.ViewModel.ApplyingImportedLoadOrder += ViewModel_ApplyingImportedLoadOrder;
}
_modActivationMonitorControl.ViewModel = _viewModel.ModActivationMonitorVM;
_downloadMonitorControl.ViewModel = _viewModel.DownloadMonitorVM;
_downloadMonitorControl.ViewModel.ActiveTasks.CollectionChanged += ActiveTasks_CollectionChanged;
_downloadMonitorControl.ViewModel.Tasks.CollectionChanged += Tasks_CollectionChanged;
_downloadMonitorControl.ViewModel.PropertyChanged += ActiveTasks_PropertyChanged;
ViewModel.ModRepository.UserStatusUpdate += ModRepository_UserStatusUpdate;
ApplyTheme(_viewModel.ModeTheme);
Text = _viewModel.Title;
_viewModel.ConfirmUpdaterAction = ConfirmUpdaterAction;
foreach (HelpInformation.HelpLink hlpLink in _viewModel.HelpInfo.HelpLinks)
{
ToolStripMenuItem tmiHelp = new ToolStripMenuItem
{
Tag = hlpLink,
Text = hlpLink.Name,
ToolTipText = hlpLink.Url,
ImageScaling = ToolStripItemImageScaling.None
};
tmiHelp.Click += tmiHelp_Click;
spbHelp.DropDownItems.Add(tmiHelp);
}
_balloonManager = new BalloonManager(ViewModel.UsesPlugins);
_balloonManager.ShowNextClick += BalloonManagerShowNextClick;
_balloonManager.ShowPreviousClick += BalloonManagerShowPreviousClick;
_balloonManager.CloseClick += BalloonManagerCloseClick;
tsbSkyrimDownloads.Visible = _viewModel.ModManagerVM.IsSkyrimSEGameMode;
if (_viewModel.ModManagerVM.IsSkyrimSEGameMode)
{
tsbSkyrimDownloads.Text = _viewModel.ModManagerVM.SkyrimSEDownloadFeedback;
_modManagerControl.ViewModel.SwitchingSkyrimDownloadMode += ViewModel_SwitchingSkyrimDownloadMode;
}
BindCommands();
}
}
private void ViewModel_SwitchingSkyrimDownloadMode(object sender, EventArgs e)
{
tsbSkyrimDownloads.Text = _viewModel.ModManagerVM.SkyrimSEDownloadFeedback;
}
private void ModManagerVM_ProfileSwitchSettingUp(object sender, EventArgs<IBackgroundTask> e)
{
if (InvokeRequired)
{
Invoke((Action<object, EventArgs<IBackgroundTask>>)ModManagerVM_ProfileSwitchSettingUp, sender, e);
return;
}
_modManagerControl.ToggleDisabledSummary(true);
ProgressDialog.ShowDialog(this, e.Argument);
_modManagerControl.ToggleDisabledSummary(false);
ViewModel.ExecuteProfileSwitch(this);
}
#endregion
#region Constructors
/// <summary>
/// A simple constructor that initializes the view with its dependencies.
/// </summary>
/// <param name="viewModel">The view model that provides the data and operations for this view.</param>
public MainForm(MainFormVM viewModel)
{
_defaultActivityManagerAutoHidePortion = 0;
InitializeComponent();
FormClosing += CheckDownloadsOnClosing;
ResizeEnd += MainForm_ResizeEnd;
ResizeBegin += MainForm_ResizeBegin;
Resize += MainForm_Resize;
Shown += MainForm_Shown;
_pluginManagerControl = new PluginManagerControl();
_modManagerControl = new ModManagerControl();
_downloadMonitorControl = new DownloadMonitorControl();
_modActivationMonitorControl = new ModActivationMonitorControl();
dockPanel1.ActiveContentChanged += dockPanel1_ActiveContentChanged;
_modManagerControl.SetTextBoxFocus += MmgModManagerControlSetTextBoxFocus;
_modManagerControl.ResetSearchBox += MmgModManagerControlResetSearchBox;
_modManagerControl.UpdateModsCount += MmgModManagerControlUpdateModsCount;
_modManagerControl.UninstallModFromProfiles += ModManagerControlUninstallModFromProfiles;
_modManagerControl.UninstalledAllMods += MmgModManagerControlUninstalledAllMods;
_downloadMonitorControl.SetTextBoxFocus += DmcDownloadMonitorControlSetTextBoxFocus;
_pluginManagerControl.UpdatePluginsCount += PmcPluginManagerControlUpdatePluginsCount;
_modActivationMonitorControl = new ModActivationMonitorControl();
_modActivationMonitorControl.UpdateBottomBarFeedback += MacModActivationMonitorControlUpdateBottomBarFeedback;
viewModel.ModManager.LoginTask.PropertyChanged += LoginTask_PropertyChanged;
toolStripButtonRateLimit.Click += ToolStripButtonRateLimitOnClick;
viewModel.ModRepository.RateLimitExceeded += (sender, args) => Invoke((Action<RateLimitExceededArgs>)OnRateLimitExceeded, args);
if (viewModel.GameMode.SupportedToolsLauncher != null)
{
viewModel.GameMode.SupportedToolsLauncher.ChangedToolPath += SupportedTools_ChangedToolPath;
}
ViewModel = viewModel;
try
{
InitializeDocuments();
}
catch
{
ResetUI();
}
viewModel.EnvironmentInfo.Settings.WindowPositions.GetWindowPosition("MainForm", this);
_lastWindowState = WindowState;
}
private void OnRateLimitExceeded(RateLimitExceededArgs args)
{
MessageBox.Show(this, $"You've reached your daily and hourly limit. Try again in {Math.Floor((args.RateLimit.HourlyReset - DateTimeOffset.UtcNow).TotalMinutes)} minutes.", "API Rate Limit exceeded", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
private void ToolStripButtonRateLimitOnClick(object sender, EventArgs e)
{
if (ViewModel.UserStatus != null)
{
var rateLimit = ViewModel.ModRepository.RateLimit;
var dailyReset = rateLimit.DailyReset - DateTimeOffset.UtcNow;
var info =
$"Daily: {rateLimit.DailyRemaining}/{rateLimit.DailyLimit} requests left (resets in {dailyReset.Hours}h {dailyReset.Minutes} m)\n" +
$"Hourly: {rateLimit.HourlyRemaining}/{rateLimit.HourlyLimit} requests left (resets in {Math.Floor((rateLimit.HourlyReset - DateTimeOffset.UtcNow).TotalMinutes)} m)";
MessageBox.Show(this, info, "API Rate Limit status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(this, "You need to be logged in to view rate limits.", "API Rate Limit status", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
#endregion
#region Startup Checks
/// <summary>
/// Checks whether we need to migrate from the old install method to the new one.
/// </summary>
private void ModMigrationCheck()
{
if (ViewModel.ProfileManager?.CurrentProfile != null)
{
ViewModel.ModManager.VirtualModActivator.Initialize();
if (!ViewModel.ModManager.VirtualModActivator.Initialized)
{
ViewModel.ModManager.VirtualModActivator.Setup();
}
return;
}
if (ViewModel.RequiresModMigration())
{
var strMigrationWarning = "This new version of NMM includes a major update to the way we store and install your mods which allows us to accommodate" + Environment.NewLine +
"mod profiling (different profiles for different playthroughs of your game)." + Environment.NewLine +
"In order for it to work NMM needs to REINSTALL or UNINSTALL all your currently installed mods." + Environment.NewLine + Environment.NewLine +
"Choose option 'YES' if you would like NMM to attempt to try and REINSTALL all your currently installed mods using the new method. " + Environment.NewLine +
"The migration procedure is a lengthy process and it could require several minutes or even hours depending on your PC speed and quantity and size " + Environment.NewLine +
"of your currently installed mods." + Environment.NewLine + "You may be required to interact with some scripted installers during the reinstall process." + Environment.NewLine +
"NMM will also backup the current Bashed/Perkus/DualSheat patches if presents, but you should rerun the various patchers should your game crash at startup." + Environment.NewLine + Environment.NewLine +
"Choose option 'NO' if you want NMM to UNINSTALL all your mods and leave you to activate the ones you use again. " + Environment.NewLine +
"(this doesn't delete your mods, it simply deactivates them)" + Environment.NewLine + Environment.NewLine +
"Choose the 'CANCEL' option if you would like to cancel this setup and not proceed with this new version." + Environment.NewLine +
"and you will need to reinstall the previous version of NMM you were using to be able to use NMM again." + Environment.NewLine;
var drResult = ExtendedMessageBox.Show(this, strMigrationWarning, "New version setup", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (drResult == DialogResult.Cancel)
{
Environment.Exit(0);
}
else
{
ViewModel.MigrateMods(_modManagerControl, drResult == DialogResult.Yes);
}
}
}
/// <summary>
/// Checks whether to show a game specific disclaimer.
/// </summary>
private void ShowGameSpecificDisclaimer()
{
string warning = ViewModel.RequiresStartupWarning();
if (!string.IsNullOrEmpty(warning))
{
ExtendedMessageBox.Show(this, warning, "New game version disclaimer", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (ViewModel.GameMode.ModeId.Equals("Cyberpunk2077", StringComparison.InvariantCultureIgnoreCase))
_modManagerControl.DeactivateAllMods(true, true);
}
}
private void ConfigFilesCheck()
{
var lstConfigFiles = new List<string>();
var strVirtualConfigFile = ViewModel.VirtualModActivator.RequiresFixing();
if (!string.IsNullOrEmpty(strVirtualConfigFile))
{
lstConfigFiles.Add(strVirtualConfigFile);
}
var strCurrentProfile = ViewModel.VirtualModActivator.RequiresFixing(ViewModel.ProfileManager.GetProfileModListPath(ViewModel.ProfileManager.CurrentProfile));
if (!string.IsNullOrEmpty(strCurrentProfile))
{
lstConfigFiles.Add(strCurrentProfile);
}
if (lstConfigFiles.Count > 0)
{
ViewModel.FixConfigFiles(lstConfigFiles, null);
}
}
#endregion
/// <summary>
/// Initializes the main UI components.
/// </summary>
/// <remarks>
/// If the metrics of the various UI components have been saved, they are loaded. Otherwise,
/// the default layout is applied.
/// </remarks>
protected void InitializeDocuments()
{
if (ViewModel.EnvironmentInfo.Settings.DockPanelLayouts.ContainsKey("mainForm") && !string.IsNullOrEmpty(ViewModel.EnvironmentInfo.Settings.DockPanelLayouts["mainForm"]))
{
dockPanel1.LoadFromXmlString(ViewModel.EnvironmentInfo.Settings.DockPanelLayouts["mainForm"], LoadDockedContent);
try
{
if (_defaultActivityManagerAutoHidePortion == 0)
{
_defaultActivityManagerAutoHidePortion = _downloadMonitorControl.AutoHidePortion;
}
}
catch { }
if (!ViewModel.UsesPlugins)
{
_pluginManagerControl.Hide();
}
}
else
{
if (ViewModel.UsesPlugins)
{
_pluginManagerControl.DockState = DockState.Unknown;
}
_modManagerControl.DockState = DockState.Unknown;
_downloadMonitorControl.DockState = DockState.Unknown;
_downloadMonitorControl.ShowHint = DockState.DockBottomAutoHide;
_downloadMonitorControl.Show(dockPanel1, DockState.DockBottomAutoHide);
if (_defaultActivityManagerAutoHidePortion == 0)
{
_defaultActivityManagerAutoHidePortion = _downloadMonitorControl.Height;
}
try
{
_downloadMonitorControl.AutoHidePortion = _defaultActivityManagerAutoHidePortion;
}
catch { }
_modActivationMonitorControl.DockState = DockState.Unknown;
_modActivationMonitorControl.ShowHint = DockState.DockBottom;
_modActivationMonitorControl.Show(dockPanel1, DockState.DockBottom);
if (_defaultActivationMonitorAutoHidePortion == 0)
{
_defaultActivationMonitorAutoHidePortion = _modActivationMonitorControl.Height;
}
try
{
_modActivationMonitorControl.AutoHidePortion = _defaultActivationMonitorAutoHidePortion;
}
catch { }
if (ViewModel.UsesPlugins)
{
_pluginManagerControl.Show(dockPanel1);
}
_modManagerControl.Show(dockPanel1);
}
var strTab = dockPanel1.ActiveDocument.DockHandler.TabText;
if (ViewModel.PluginManagerVM != null)
{
_pluginManagerControl.Show(dockPanel1);
}
if (ViewModel.UsesPlugins && strTab == "Plugins")
{
_pluginManagerControl.Show(dockPanel1);
}
else
{
_modManagerControl.Show(dockPanel1);
}
if (_downloadMonitorControl == null || _downloadMonitorControl.VisibleState == DockState.Unknown || _downloadMonitorControl.VisibleState == DockState.Hidden)
{
_downloadMonitorControl.Show(dockPanel1, DockState.DockBottom);
if (_defaultActivityManagerAutoHidePortion == 0)
{
_defaultActivityManagerAutoHidePortion = _downloadMonitorControl.Height;
}
try
{
_downloadMonitorControl.AutoHidePortion = _defaultActivityManagerAutoHidePortion;
}
catch { }
}
if (_modActivationMonitorControl == null || _modActivationMonitorControl.VisibleState == DockState.Unknown || _modActivationMonitorControl.VisibleState == DockState.Hidden)
{
_modActivationMonitorControl.Show(dockPanel1, DockState.DockBottom);
if (_defaultActivationMonitorAutoHidePortion == 0)
{
_defaultActivationMonitorAutoHidePortion = _modActivationMonitorControl.Height;
}
try
{
_modActivationMonitorControl.AutoHidePortion = _defaultActivationMonitorAutoHidePortion;
}
catch { }
}
_modActivationMonitorControl.DockTo(_downloadMonitorControl.Pane, DockStyle.Right, 1);
if (ViewModel.UsesPlugins)
{
toolStripLabelPluginsCounter.Text = " Total plugins: " + ViewModel.PluginManagerVM.ManagedPlugins.Count + " | Active plugins: ";
var myFontFamily = new FontFamily(toolStripLabelActivePluginsCounter.Font.Name);
int limitedPluginsCount = ViewModel.PluginManagerVM.ActivePlugins.Count(x => !x.IgnoreIndexing);
if (limitedPluginsCount > ViewModel.PluginManagerVM.MaxAllowedActivePluginsCount)
{
var icoIcon = new Icon(SystemIcons.Warning, 16, 16);
toolStripLabelActivePluginsCounter.Image = icoIcon.ToBitmap();
toolStripLabelActivePluginsCounter.ForeColor = Color.Red;
if (myFontFamily.IsStyleAvailable(FontStyle.Bold))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Bold);
}
else if (myFontFamily.IsStyleAvailable(FontStyle.Regular))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Regular);
}
toolStripLabelActivePluginsCounter.Text = limitedPluginsCount.ToString() + " (" + ViewModel.PluginManagerVM.ActivePlugins.Count.ToString() + ")";
toolStripLabelActivePluginsCounter.ToolTipText = $"There may be too many active plugins. {ViewModel.CurrentGameModeName} might not start!";
}
else
{
toolStripLabelActivePluginsCounter.Image = null;
toolStripLabelActivePluginsCounter.ForeColor = Color.Black;
if (myFontFamily.IsStyleAvailable(FontStyle.Regular))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Regular);
}
else if (myFontFamily.IsStyleAvailable(FontStyle.Bold))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Bold);
}
toolStripLabelActivePluginsCounter.Text = limitedPluginsCount.ToString() + " (" + ViewModel.PluginManagerVM.ActivePlugins.Count.ToString() + ")";
}
}
else
{
toolStripSeparatorPluginSeparator.Visible = false;
toolStripLabelPluginsCounter.Visible = false;
}
UpdateModsFeedback();
UserStatusFeedback();
}
/// <summary>
/// Shows the tips.
/// </summary>
/// <param name="p_strVersion">The version of the DropDownMenu clicked</param>
public void ShowTips(string p_strVersion)
{
if (!string.IsNullOrEmpty(p_strVersion))
{
_balloonManager.SetTipList(p_strVersion);
}
var strTipSection = string.IsNullOrEmpty(_balloonManager.TipSection) ? "toolStrip1" : _balloonManager.TipSection;
var strTipObject = string.IsNullOrEmpty(_balloonManager.TipObject) ? "tsbTips" : _balloonManager.TipObject;
_balloonManager.ShowNextTip(FindControlCoords(strTipSection, strTipObject));
}
/// <summary>
/// The BalloonManager ShowNextClick event.
/// </summary>
private void BalloonManagerShowNextClick(object sender, EventArgs e)
{
if (_viewModel.EnvironmentInfo.Settings.CheckForTipsOnStartup)
{
_viewModel.EnvironmentInfo.Settings.CheckForTipsOnStartup = false;
_viewModel.EnvironmentInfo.Settings.Save();
}
ShowTips(_balloonManager.CurrentTip == null
? _viewModel.EnvironmentInfo.ApplicationVersion.ToString()
: string.Empty);
}
/// <summary>
/// The BalloonManager ShowPreviousClick event.
/// </summary>
private void BalloonManagerShowPreviousClick(object sender, EventArgs e)
{
ShowTips(string.Empty);
}
/// <summary>
/// The BalloonManager CloseClick event.
/// </summary>
private void BalloonManagerCloseClick(object sender, EventArgs e)
{
if (_viewModel.EnvironmentInfo.Settings.CheckForTipsOnStartup)
{
_viewModel.EnvironmentInfo.Settings.CheckForTipsOnStartup = false;
_viewModel.EnvironmentInfo.Settings.Save();
}
}
/// <summary>
/// Sets the UI elements providing feedback on the user online status.
/// </summary>
protected void UserStatusFeedback()
{
toolStripLabelLoginMessage.Visible = true;
if (ViewModel.OfflineMode)
{
if (toolStripProgressBarDownloadSpeed != null)
{
toolStripProgressBarDownloadSpeed.Visible = false;
}
toolStripLabelLoginMessage.Text = "You are not logged in.";
toolStripLabelLoginMessage.Font = new Font(base.Font, FontStyle.Bold);
toolStripButtonGoPremium.Visible = false;
toolStripButtonOnlineStatus.Image = new Bitmap(Properties.Resources.loggedout_flat, 32, 30);
toolStripLabelDownloads.Visible = false;
}
else
{
toolStripButtonOnlineStatus.Image = new Bitmap(Properties.Resources.loggedin_flat, 32, 30);
// We no longer give a damn about a user's Nexus status
//if (ViewModel.UserStatus.IsPremium)
//{
toolStripButtonGoPremium.Visible = false;
OptionalPremiumMessage = string.Empty;
toolStripButtonGoPremium.Enabled = false;
if (toolStripProgressBarDownloadSpeed != null)
{
toolStripProgressBarDownloadSpeed.Maximum = 100;
toolStripProgressBarDownloadSpeed.Value = 0;
toolStripProgressBarDownloadSpeed.ColorFillMode = ProgressLabel.FillType.Ascending;
toolStripProgressBarDownloadSpeed.ShowOptionalProgress = true;
}
toolStripLabelDownloads.Tag = "Download Progress:";
//}
//else
//{
// toolStripButtonGoPremium.Visible = true;
// toolStripButtonGoPremium.Enabled = true;
// OptionalPremiumMessage = " Not a Premium Member.";
// if (toolStripProgressBarDownloadSpeed != null)
// {
// // Disabled for the time being since there's currently no way to check whether an user is browsing the Nexus with an active adblocker
// toolStripProgressBarDownloadSpeed.Maximum = (ViewModel.UserStatus.IsSupporter) ? 2048 : 2048;
// toolStripProgressBarDownloadSpeed.Value = 0;
// toolStripProgressBarDownloadSpeed.ColorFillMode = ProgressLabel.FillType.Descending;
// toolStripProgressBarDownloadSpeed.ShowOptionalProgress = false;
// }
// toolStripLabelDownloads.Tag = "Download Speed:";
//}
if (toolStripProgressBarDownloadSpeed != null && _downloadMonitorControl.ViewModel.ActiveTasks.Count > 0)
{
toolStripProgressBarDownloadSpeed.Visible = true;
}
toolStripLabelDownloads.Text = $"{toolStripLabelDownloads.Tag} ({_downloadMonitorControl.ViewModel.ActiveTasks.Count} {(_downloadMonitorControl.ViewModel.ActiveTasks.Count == 1 ? "File" : "Files")}) ";
}
}
/// <summary>
/// Resets the UI layout to the default.
/// </summary>
protected void ResetUI()
{
ViewModel.EnvironmentInfo.Settings.DockPanelLayouts.Remove("mainForm");
InitializeDocuments();
try
{
_modManagerControl.ResetColumns();
}
catch { }
}
/// <summary>
/// Automatically sorts the plugin list.
/// </summary>
protected void SortPlugins()
{
if (ViewModel.SupportsPluginAutoSorting && ViewModel.PluginSorterInitialized)
{
ViewModel.SortPlugins();
}
else
{
MessageBox.Show("Nexus Mod Manager was unable to properly initialize the Automatic Sorting functionality." +
Environment.NewLine + Environment.NewLine + "This game is not supported or something is wrong with your loadorder.txt or plugins.txt files," +
Environment.NewLine + "or one or more plugins are corrupt/broken.",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
/// <summary>
/// Disable all active mods.
/// </summary>
protected void DisableAllMods()
{
_modManagerControl.DisableAllMods(false);
}
/// <summary>
/// Uninstall all active mods.
/// </summary>
protected void UninstallAllMods()
{
UninstallAllMods(false, false);
}
/// <summary>
/// Purge Loose Files.
/// </summary>
protected void PurgeLooseFiles()
{
if (ViewModel.UsesPlugins)
{
var drPurgeLooseFiles = ExtendedMessageBox.Show(this, "USE THIS FUNCTION AT YOUR OWN RISK: Would you like to clean your game folder from unmanaged files (not installed by NMM and not official game files)? Legit files may be lost if the mod manager doesn't recognize them as official game files.", "Purge Unmanaged Files", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (drPurgeLooseFiles == DialogResult.Yes)
{
ViewModel.PurgeLooseFiles();
}
}
}
/// <summary>
/// Adds the backup profile to the profile list.
/// </summary>
protected void RestoreBackupProfile()
{
if (ViewModel.ProfileManager.RestoreBackupProfile(ViewModel.GameMode.ModeId, out var error) == false)
{
MessageBox.Show("Nexus Mod Manager was unable to restore your backup profile." +
Environment.NewLine + Environment.NewLine + error,
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show(String.Format("{0} has been successfully added to your profile list.", error),
"Restored", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
protected void CreateBackup()
{
ViewModel.CreateBackup(this);
}
protected void RestoreBackup()
{
ViewModel.RestoreBackup(_modManagerControl);
}
/// <summary>
/// Uninstall all active mods.
/// </summary>
protected void UninstallAllMods(bool forceUninstall, bool silent)
{
_modManagerControl.DeactivateAllMods(forceUninstall, silent);
}
/// <summary>
/// This will show the Virtual folders settings.
/// </summary>
protected void ChangeVirtualFolders()
{
var vmlSetup = new VirtualDirectoriesSetupVM(ViewModel.EnvironmentInfo, ViewModel.GameMode, ViewModel.ModManager.VirtualModActivator);
var frmSetup = new VirtualDirectoriesSetupForm(vmlSetup);
if (frmSetup.ShowDialog(this) == DialogResult.OK)
{
if (ViewModel.ProfileManager.CurrentProfile == null)
{
byte[] bteLoadOrder = null;
if (ViewModel.GameMode.UsesPlugins)
{
bteLoadOrder = ViewModel.PluginManagerVM.ExportLoadOrder();
}
var bteModList = ViewModel.ModManager.InstallationLog.GetXmlModList();
var bteIniList = ViewModel.ModManager.InstallationLog.GetXmlIniList();
var intModCount = ViewModel.ModManager.ActiveMods.Count;
AddNewProfile(bteModList, bteIniList, bteLoadOrder, intModCount, true);
UninstallAllMods(true, true);
ViewModel.ModManager.VirtualModActivator.Reset();
AddNewProfile(bteModList, bteIniList, bteLoadOrder, intModCount, false);
ViewModel.SwitchProfile(this, ViewModel.ProfileManager.CurrentProfile, true, false);
}
else
{
var impCurrentProfile = ViewModel.ProfileManager.CurrentProfile;
ViewModel.ProfileManager.SetCurrentProfile(null);
UninstallAllMods(true, true);
ViewModel.ModManager.VirtualModActivator.Reset();
ViewModel.SwitchProfile(this, impCurrentProfile, true, false);
}
}
}
private void LoginTask_PropertyChanged(object sender, EventArgs e)
{
var authenticationFormTask = (AuthenticationFormTask)sender;
if (authenticationFormTask.OverallMessage != null && authenticationFormTask.OverallMessage.Contains("Logged in"))
{
toolStripLabelLoginMessage.Text = $"{authenticationFormTask.OverallMessage}{OptionalPremiumMessage}";
toolStripButtonOnlineStatus.ToolTipText = "Logout";
}
else
{
toolStripLabelLoginMessage.Text = authenticationFormTask.OverallMessage;
toolStripButtonOnlineStatus.ToolTipText = "Login";
}
}
/// <summary>
/// Opens the selected game folder.
/// </summary>
protected void OpenGameFolder()
{
if (FileUtil.IsValidPath(ViewModel.GamePath))
{
Process.Start(ViewModel.GamePath);
}
}
/// <summary>
/// Checks if there are any active downloads before closing the mod manager.
/// </summary>
/// <remarks>
/// If there's an active download, the program will ask the user if he really wants to close it.
/// </remarks>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">An <see cref="FormClosingEventArgs"/> describing the event arguments.</param>
private void CheckDownloadsOnClosing(object sender, FormClosingEventArgs e)
{
if (ViewModel.DownloadMonitorVM.ActiveTasks.Count > 0)
{
var drFormClose = MessageBox.Show($"There is an ongoing download, are you sure you want to close {Application.ProductName}?", "Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (drFormClose != DialogResult.Yes)
{
e.Cancel = true;
}
}
if (ViewModel.IsInstalling)
{
var drFormClose = MessageBox.Show($"There is an ongoing mod install/uninstall, are you sure you want to close {Application.ProductName}?", "Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (drFormClose != DialogResult.Yes)
{
e.Cancel = true;
}
}
}
/// <summary>
/// The Main Form resizeEnd event.
/// </summary>
private void MainForm_ResizeEnd(object sender, EventArgs e)
{
if (ViewModel.EnvironmentInfo.Settings.CheckForTipsOnStartup && _balloonManager.balloonHelp != null)
{
_balloonManager.balloonHelp.Close();
}
else
{
if (_showLastBalloon)
{
_showLastBalloon = false;
ShowTips(string.Empty);
}
}
}
/// <summary>
/// The Main Form resizeBegin event.
/// </summary>
private void MainForm_ResizeBegin(object sender, EventArgs e)
{
if (_balloonManager?.balloonHelp != null)
{
if (_balloonManager.balloonHelp.Visible)
{
if (_balloonManager.CurrentTip != null)
{
_balloonManager.SetPreviousTip(true);
}
_balloonManager.balloonHelp.Close();
_showLastBalloon = true;
}
else
{
_showLastBalloon = false;
}
}
}
/// <summary>
/// The Main Form resize event.
/// </summary>
private void MainForm_Resize(object sender, EventArgs e)
{
if (WindowState != LastWindowState)
{
LastWindowState = WindowState;
if (WindowState == FormWindowState.Maximized || WindowState == FormWindowState.Normal)
{
if (_balloonManager?.balloonHelp != null && _balloonManager.balloonHelp.Visible)
{
if (_balloonManager.CurrentTip != null)
{
_balloonManager.SetPreviousTip(true);
ShowTips(string.Empty);
}
else
{
_balloonManager.balloonHelp.Close();
}
}
}
}
}
private void MainForm_Shown(object sender, EventArgs e)
{
ModMigrationCheck();
ShowGameSpecificDisclaimer();
ConfigFilesCheck();
}
/// <summary>
/// This will check whether the SearchBox should be visible.
/// </summary>
private void dockPanel1_ActiveContentChanged(object sender, EventArgs e)
{
if (Visible && dockPanel1.ActiveDocument != null)
{
toolStripTextBoxFind.Visible = dockPanel1.ActiveDocument.DockHandler.TabText == "Mods";
toolStripTextBoxFind.Enabled = dockPanel1.ActiveDocument.DockHandler.TabText == "Mods";
}
}
/// <summary>
/// Updates the Mods Counter
/// </summary>
private void MmgModManagerControlUpdateModsCount(object sender, EventArgs e)
{
UpdateModsFeedback();
}
/// <summary>
/// Updates the Mods Counter
/// </summary>
private void UpdateModsFeedback()
{
tlbModsCounter.Text = " Total mods: " + ViewModel.ModManagerVM.ManagedMods.Count + " | Installed mods: " + ViewModel.ModManager.ActiveMods.Count + " | Active mods: " + ViewModel.ModManager.VirtualModActivator.ActiveModList.Count();
}
/// <summary>
/// Updates the Plugins Counter
/// </summary>
private void PmcPluginManagerControlUpdatePluginsCount(object sender, EventArgs e)
{
toolStripLabelPluginsCounter.Text = " Total plugins: " + ViewModel.PluginManagerVM.ManagedPlugins.Count + " | Active plugins: ";
var myFontFamily = new FontFamily(toolStripLabelActivePluginsCounter.Font.Name);
int limitedPluginsCount = ViewModel.PluginManagerVM.ActivePlugins.Count(x => !x.IgnoreIndexing);
if (limitedPluginsCount > ViewModel.PluginManagerVM.MaxAllowedActivePluginsCount)
{
var icoIcon = new Icon(SystemIcons.Warning, 16, 16);
toolStripLabelActivePluginsCounter.Image = icoIcon.ToBitmap();
toolStripLabelActivePluginsCounter.ForeColor = Color.Red;
if (myFontFamily.IsStyleAvailable(FontStyle.Bold))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Bold);
}
else if (myFontFamily.IsStyleAvailable(FontStyle.Regular))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Regular);
}
toolStripLabelActivePluginsCounter.Text = limitedPluginsCount.ToString() + " (" + ViewModel.PluginManagerVM.ActivePlugins.Count.ToString() + ")";
toolStripLabelActivePluginsCounter.ToolTipText = $"There may be too many active plugins. {ViewModel.CurrentGameModeName} might not start!"; ;
}
else
{
toolStripLabelActivePluginsCounter.Image = null;
if (myFontFamily.IsStyleAvailable(FontStyle.Regular))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Regular);
}
else if (myFontFamily.IsStyleAvailable(FontStyle.Bold))
{
toolStripLabelActivePluginsCounter.Font = new Font(toolStripLabelActivePluginsCounter.Font, FontStyle.Bold);
}
toolStripLabelActivePluginsCounter.ForeColor = Color.Black;
toolStripLabelActivePluginsCounter.Text = limitedPluginsCount.ToString() + " (" + ViewModel.PluginManagerVM.ActivePlugins.Count.ToString() + ")";
}
}
/// <summary>
/// Updates the Plugins Counter
/// </summary>
private void pmcPluginManager_PluginMoved(object sender, EventArgs e)
{
if (ViewModel.ProfileManager.CurrentProfile != null && !ViewModel.IsSwitching)
{
if (ViewModel.GameMode.UsesPlugins)
{
var bteLoadOrder = ViewModel.PluginManagerVM.ExportLoadOrder();
ViewModel.ProfileManager.UpdateProfile(ViewModel.ProfileManager.CurrentProfile, null, bteLoadOrder, null, out var error);
if (!string.IsNullOrEmpty(error))
{
error = error + Environment.NewLine + Environment.NewLine + "Unable to automatically save the profile file, please close the program blocking the reported file and manually click on Save Profile from the profiles context menu";
MessageBox.Show(error, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}