-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForm1.cs
1599 lines (1406 loc) · 57.9 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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Media;
using System.Threading.Tasks;
using System.Windows.Forms;
using Application = System.Windows.Forms.Application;
namespace MW5_Mod_Manager
{
public partial class Form1 : Form
{
public Form1 MainForm;
public MainLogic logic = new MainLogic();
//public TCPFileShare fileShare;
bool filtered = false;
private List<ModItem> ListViewData = new List<ModItem>();
private List<ListViewItem> markedForRemoval;
public Form4 WaitForm;
private bool MovingItem = false;
internal bool JustPacking = true;
public bool LoadingAndFilling { get; private set; }
public Form1()
{
InitializeComponent();
this.MainForm = this;
this.logic.MainForm = this;
//this.fileShare = new TCPFileShare(logic, this);
this.markedForRemoval = new List<ListViewItem>();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
this.listBox4.MouseDoubleClick += new MouseEventHandler(listBox4_OnMouseClick);
this.BringToFront();
this.Focus();
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(form1_KeyDown);
this.KeyUp += new KeyEventHandler(form1_KeyUp);
backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker2.WorkerReportsProgress = true;
backgroundWorker2.WorkerSupportsCancellation = true;
//start the TCP listner for TCP mod sharing
//Disabled for now.
//this.fileShare.Listener.RunWorkerAsync();
}
//called upon loading the form
private void Form1_Load(object sender, EventArgs e)
{
this.logic = new MainLogic();
if (logic.TryLoadProgramData())
{
this.textBox1.Text = logic.BasePath[0];
LoadAndFill(false);
}
this.LoadPresets();
this.SetVersionAndVender();
SetupRotatingLabel();
}
private void SetupRotatingLabel()
{
this.rotatingLabel1.Text = ""; // which can be changed by NewText property
this.rotatingLabel1.AutoSize = false; // adjust according to your text
this.rotatingLabel1.NewText = "<- Low Priority/Loaded First --- High Priority/Loaded Last ->"; // whatever you want to display
this.rotatingLabel1.ForeColor = Color.Black; // color to display
this.rotatingLabel1.RotateAngle = -90; // angle to rotate
}
//handling key presses for hotkeys.
private async void form1_KeyUp(object sender, KeyEventArgs e)
{
//Console.WriteLine("KEY Released: " + e.KeyCode);
if (e.KeyCode == Keys.ShiftKey)
{
await Task.Delay(50);
this.button1.Text = "&UP";
this.button2.Text = "&DOWN";
}
}
private void form1_KeyDown(object sender, KeyEventArgs e)
{
//Console.WriteLine("KEY Pressed: " + e.KeyCode);
if (e.Shift)
{
this.button1.Text = "MOVE TO TOP";
this.button2.Text = "MOVE TO BOTTOM";
}
}
//When we hover over the manager with a file or folder
void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
//When we drop a file or folder on the manager
void Form1_DragDrop(object sender, DragEventArgs e)
{
//We only support single file drops!
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length != 1)
{
return;
}
string file = files[0];
Console.WriteLine(file);
//Lets see what we got here
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(file);
bool IsDirectory = attr.ToString() == "Directory";
if (!HandleDirectory())
{
HandleFile();
}
//Refresh button
button6_Click(null, null);
void HandleFile()
{
if (!file.Contains(".zip"))
{
string message = "Only .zip files are supported. " +
"Please extract first and drag the folder into the application.";
string caption = "Unsuported File Type";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
return;
}
//we have a zip!
using (ZipArchive archive = ZipFile.OpenRead(file))
{
bool modFound = false;
foreach (ZipArchiveEntry entry in archive.Entries)
{
//Console.WriteLine(entry.FullName);
if (entry.Name.Contains("mod.json"))
{
//we have found a mod!
//Console.WriteLine("MOD FOUND IN ZIP!: " + entry.FullName);
modFound = true;
break;
}
}
if (!modFound)
{
return;
}
//Extract mod to mods dir
ZipFile.ExtractToDirectory(file, logic.BasePath[0]);
button6_Click(null, null);
}
}
//Return succes
bool HandleDirectory()
{
if (!IsDirectory)
{
return false;
}
if (!ModInDirectory(file))
{
return false;
}
if (ModsFolderNotSet())
{
return false;
}
string modName;
string[] splitString = file.Split('\\');
modName = splitString[splitString.Length - 1];
Utils.DirectoryCopy(file, logic.BasePath[0] + "\\" + modName, true);
return true;
}
bool ModInDirectory(string _file)
{
bool foundMod = false;
foreach (string f in Directory.GetFiles(_file))
{
if (f.Contains("mod.json"))
{
foundMod = true;
break;
}
}
return foundMod;
}
bool ModsFolderNotSet()
{
return Utils.StringNullEmptyOrWhiteSpace(logic.BasePath[0]);
}
}
//Up button
//Get item info, remove item, insert above, set new item as selected.
private void button1_Click(object sender, EventArgs e)
{
ListView.ListViewItemCollection items = listView1.Items;
this.MovingItem = true;
int i = SelectedItemIndex();
if (i < 1)
{
this.MovingItem = false;
return;
}
ModItem item = ListViewData[i];
items.RemoveAt(i);
ListViewData.RemoveAt(i);
if (Control.ModifierKeys == Keys.Shift)
{
//Move to top
items.Insert(0, item);
ListViewData.Insert(0, item);
}
else
{
//move one up
items.Insert(i - 1, item);
ListViewData.Insert(i - 1, item);
}
item.Selected = true;
this.logic.GetOverridingData(this.ListViewData);
this.logic.CheckRequires(this.ListViewData);
listView1_SelectedIndexChanged(null, null);
this.MovingItem = false;
}
//Down button
//Get item info, remove item, insert below, set new item as selected.
private void button2_Click(object sender, EventArgs e)
{
ListView.ListViewItemCollection items = listView1.Items;
this.MovingItem = true;
int i = SelectedItemIndex();
if (i > ListViewData.Count - 2 || i < 0)
{
this.MovingItem = false;
return;
}
ModItem item = ListViewData[i];
items.RemoveAt(i);
ListViewData.RemoveAt(i);
if (Control.ModifierKeys == Keys.Shift)
{
//Move to bottom
items.Insert(ListViewData.Count, item);
ListViewData.Insert(ListViewData.Count, item);
}
else
{
//move one down
items.Insert(i + 1, item);
ListViewData.Insert(i + 1, item);
}
item.Selected = true;
//Move to below when refactor is complete
//UpdateListView();
this.logic.GetOverridingData(ListViewData);
this.logic.CheckRequires(ListViewData);
listView1_SelectedIndexChanged(null, null);
this.MovingItem = false;
}
//Apply button
private void button3_Click(object sender, EventArgs e)
{
#region mod removal
//Stuff for removing mods:
if (this.markedForRemoval.Count > 0)
{
List<string> modNames = new List<string>();
foreach (ListViewItem item in this.markedForRemoval)
{
modNames.Add(item.SubItems[1].Text);
}
string m = "The following mods will be permanently be removed:\n" + string.Join("\n---", modNames) + "\nARE YOU SURE?";
string c = "Are you sure?";
MessageBoxButtons b = MessageBoxButtons.YesNo;
DialogResult r = MessageBox.Show(m, c, b);
if (r == DialogResult.Yes)
{
foreach (ModItem item in markedForRemoval)
{
ListViewData.Remove(item);
listView1.Items.Remove(item);
logic.DeleteMod(logic.DirectoryToPathDict[item.SubItems[2].Text]);
this.logic.ModDetails.Remove(logic.DirectoryToPathDict[item.SubItems[2].Text]);
}
markedForRemoval.Clear();
}
else if (r == DialogResult.No)
{
foreach (ListViewItem item in markedForRemoval)
{
item.ForeColor = Color.Black;
}
return;
}
}
#endregion
#region mod dependencies/requirments
//Checking requirements:
Dictionary<string, List<string>> CheckResult = logic.CheckRequires(ListViewData);
//Super ugly as we are undoing stuff we just did here but i'm lazy.
foreach (ListViewItem item in this.listView1.Items)
{
item.SubItems[5].BackColor = Color.White;
}
if (CheckResult.Count > 0)
{
string wText = "";
foreach (string key in CheckResult.Keys)
{
wText += (key + "\n");
foreach (string value in CheckResult[key])
{
wText += ("--" + value + "\n");
}
}
string m2 = "Mods are missing or loaded after required dependencies: \n\n" + wText + "\nDo you want to apply anyway?";
string c2 = "Mods Missing Dependencies";
MessageBoxButtons b2 = MessageBoxButtons.YesNo;
DialogResult r2 = MessageBox.Show(m2, c2, b2);
if (r2 == DialogResult.No)
return;
}
#endregion
#region Activation and Load order
//Stuff for applying mods activation and load order:
//Reset filter:
this.filterBox.Text = "";
this.filterBox_TextChanged(null, null);
//Regenerate ModList dict
this.logic.ModList = new Dictionary<string, bool>();
//For each mod in the list view:
//Check if mod enabled
//Get its priority
//Put mod in the ModList with it status
//Adjust the ModDetails priority
int length = listView1.Items.Count;
for (int i = 0; i < length; i++)
{
string modName = listView1.Items[i].SubItems[2].Text;
string modDir = logic.DirectoryToPathDict[modName];
try
{
bool modEnabled = listView1.Items[i].Checked;
int priority = listView1.Items.Count - i;
this.logic.ModList[modDir] = modEnabled;
this.logic.ModDetails[modDir].defaultLoadOrder = priority;
Console.WriteLine(modDir + " : " + priority.ToString());
}
catch (Exception Ex)
{
string message = "ERROR Mismatch between list key and details key : " + modName
+ ". Details keys available: " + string.Join(",", this.logic.ModDetails.Keys.ToList()) + ". This mod will be skipped and the operation continued.";
string caption = "ERROR Key Mismatch";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
continue;
}
}
//Save the ModDetails to json file.
this.logic.SaveToFiles();
#endregion
}
//For clearing the entire applications data
private void ClearAll()
{
this.ListViewData.Clear();
this.listView1.Items.Clear();
logic.ClearAll();
}
//For processing internals and updating ui after setting a vendor
private void SetVersionAndVender()
{
if (this.logic.Version > 0f)
{
this.label1.Text = @"~RJ v." + this.logic.Version.ToString();
}
if (this.logic.Vendor != "")
{
if (this.logic.Vendor == "EPIC")
{
this.toolStripLabel1.Text = "Game Vendor : Epic Store";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = false;
this.button4.Enabled = true;
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
}
else if (this.logic.Vendor == "WINDOWS")
{
this.toolStripLabel1.Text = "Game Vendor : Windows Store";
this.selectToolStripMenuItem.Enabled = false;
//this.searcgToolStripMenuItem.Enabled = false;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = false;
this.epicStoreToolStripMenuItem.Enabled = true;
this.button4.Enabled = false;
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
}
else if (this.logic.Vendor == "STEAM")
{
this.toolStripLabel1.Text = "Game Vendor : Steam";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = false;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.MainForm.button5.Enabled = false;
this.button4.Enabled = true;
this.textBox3.Visible = true;
this.textBox1.Size = new Size(250, 20);
this.textBox3.Text = logic.BasePath[1];
}
else if (this.logic.Vendor == "GOG")
{
this.toolStripLabel1.Text = "Game Vendor : GOG";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
}
}
ScrollFolderTextBoxToRight();
}
//Load mod data and fill in the list box..
private void LoadAndFill(bool FromClipboard)
{
this.LoadingAndFilling = true;
KeyValuePair<string, bool> currentEntry = new KeyValuePair<string, bool>();
try
{
if (FromClipboard)
logic.LoadFromImportString();
else
logic.LoadFromFiles();
foreach (KeyValuePair<string, bool> entry in logic.ModList)
{
if (entry.Equals(new KeyValuePair<string, bool>(null, false)))
continue;
if (entry.Key == null)
continue;
currentEntry = entry;
AddEntryToListViewAndData(entry);
}
UpdateListView();
logic.SaveProgramData();
}
catch (Exception e)
{
if(currentEntry.Key == null)
{
currentEntry = new KeyValuePair<string, bool>("NULL", false);
}
Console.WriteLine(e.StackTrace);
string message = "While loading " + currentEntry.Key.ToString() + "something went wrong.\n" + e.StackTrace;
string caption = "Error Loading";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
this.LoadingAndFilling = false;
logic.CheckRequires(ListViewData);
logic.GetOverridingData(ListViewData);
}
private void AddEntryToListViewAndData(KeyValuePair<string, bool> entry)
{
string modName = entry.Key;
ModItem item1 = new ModItem
{
UseItemStyleForSubItems = false,
Checked = entry.Value
};
item1.SubItems.Add(logic.ModDetails[entry.Key].displayName);
item1.SubItems.Add(logic.PathToDirectoryDict[modName]);
item1.SubItems.Add(logic.ModDetails[entry.Key].author);
item1.SubItems.Add(logic.ModDetails[entry.Key].version);
item1.SubItems.Add(" ");
item1.EnsureVisible();
ListViewData.Add(item1);
}
//Fill list view from internal list of data.
private void UpdateListView()
{
listView1.Items.Clear();
listView1.Items.AddRange(ListViewData.ToArray());
}
//gets the index of the selected item in listview1.
private int SelectedItemIndex()
{
int index = -1;
var SelectedItems = listView1.SelectedItems;
if(SelectedItems.Count == 0)
{
return index;
}
index = listView1.SelectedItems[0].Index;
if (index < 0)
{
return -1;
}
return index;
}
//Select install directory button
private void SelectInstallDirectory()
{
ClearAll();
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !Utils.StringNullEmptyOrWhiteSpace(fbd.SelectedPath))
{
string path = fbd.SelectedPath;
logic.BasePath[0] = path + @"\MW5Mercs\Mods";
//We need to do something different for steam cause its special.
//Once a switch now an iff.
switch (this.logic.Vendor)
{
case "STEAM":
SetSteamWorkshopPath();
break;
//case "GAMEPASS":
// SetGamepassPath();
// break;
}
MainForm.textBox1.Text = logic.BasePath[0];
MainForm.textBox3.Text = logic.BasePath[1];
LoadAndFill(false);
ScrollFolderTextBoxToRight();
}
}
}
private void ScrollFolderTextBoxToRight()
{
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox1.Focus();
textBox3.SelectionStart = textBox1.Text.Length;
textBox3.ScrollToCaret();
textBox3.Focus();
}
private void SetSteamWorkshopPath()
{
//Split by folder depth
List<string> splitBasePath = this.logic.BasePath[0].Split('\\').ToList<string>();
//Find the steamapps folder
int steamAppsIndex = splitBasePath.IndexOf("steamapps");
//Remove all past the steamapps folder
splitBasePath.RemoveRange(steamAppsIndex + 1, splitBasePath.Count - steamAppsIndex - 1);
//Put string back together
this.logic.BasePath[1] = string.Join("\\", splitBasePath);
//Point to workshop folder.
this.logic.BasePath[1] += @"\workshop\content\784080";
}
//Refresh listedcheckbox
private void button6_Click(object sender, EventArgs e)
{
RefreshAll();
}
private void RefreshAll()
{
ClearAll();
if (logic.TryLoadProgramData())
{
LoadAndFill(false);
filterBox_TextChanged(null, null);
logic.GetOverridingData(ListViewData);
logic.CheckRequires(ListViewData);
}
}
//Image
private void button8_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"https://www.nexusmods.com/mechwarrior5mercenaries/mods/174?tab=description");
}
//Saves current load order to preset.
private void SavePreset(string name)
{
Dictionary<string, bool> NoPathModlist = new Dictionary<string, bool>();
foreach (KeyValuePair<string, bool> entry in logic.ModList)
{
string folderName = logic.PathToDirectoryDict[entry.Key];
NoPathModlist[folderName] = entry.Value;
}
this.logic.Presets[name] = JsonConvert.SerializeObject(NoPathModlist, Formatting.Indented);
this.logic.SavePresets();
}
//Sets up the load order from a preset.
private void LoadPreset(string name)
{
string JsonString = logic.Presets[name];
Dictionary<string, bool> temp;
try
{
temp = JsonConvert.DeserializeObject<Dictionary<string, bool>>(JsonString);
}
catch (Exception Ex)
{
string message = "There was an error in decoding the load order string.";
string caption = "Load Order Decoding Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
return;
}
this.listView1.Items.Clear();
this.ListViewData.Clear();
this.logic.ModDetails = new Dictionary<string, ModObject>();
this.logic.ModList.Clear();
this.logic.ModList = temp;
this.LoadAndFill(true);
this.filterBox_TextChanged(null, null);
}
//Load all presets from file and fill the listbox.
private void LoadPresets()
{
this.logic.LoadPresets();
foreach (string key in logic.Presets.Keys)
{
this.listBox4.Items.Add(key);
}
}
//Export load order
private void ExportLoadOrderToolStripMenuItem_Click(object sender, EventArgs e)
{
Dictionary<string, bool> FolderNameModList = new Dictionary<string, bool>();
//Get the folder names from the paths in modlist
foreach (string key in logic.ModList.Keys)
{
string folderName = logic.PathToDirectoryDict[key];
FolderNameModList[folderName] = logic.ModList[key];
}
string json = JsonConvert.SerializeObject(FolderNameModList, Formatting.Indented);
Form3 exportDialog = new Form3();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
exportDialog.textBox1.Text = json; //logic.Scramble(json);
exportDialog.ShowDialog(this);
exportDialog.Dispose();
}
//Import load order
private void ImportLoadOrderToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 testDialog = new Form2();
string txtResult = "";
// Show testDialog as a modal dialog and determine if DialogResult = OK.
testDialog.ShowDialog(this);
txtResult = testDialog.textBox1.Text;
testDialog.Dispose();
if (Utils.StringNullEmptyOrWhiteSpace(txtResult) ||
txtResult == "Paste load order clipboard here, any mods that you do not have but are in the pasted load order will be ignored.")
return;
Dictionary<string, bool> temp;
try
{
temp = JsonConvert.DeserializeObject<Dictionary<string, bool>>(txtResult);//logic.UnScramble(txtResult));
}
catch (Exception Ex)
{
string message = "There was an error in decoding the load order string.";
string caption = "Load Order Decoding Error";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
return;
}
//this.ClearAll();
this.listView1.Items.Clear();
this.ListViewData.Clear();
this.logic.ModDetails = new Dictionary<string, ModObject>();
this.logic.ModList = new Dictionary<string, bool>();
this.logic.ModList = temp;
this.LoadAndFill(true);
this.filterBox_TextChanged(null, null);
}
#region Vendor Selection Tool Strip buttons
//Tool strip for selecting steam as a vendor
private void steamToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
this.logic.Vendor = "STEAM";
this.toolStripLabel1.Text = "Game Vendor : Steam";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.MainForm.button5.Enabled = false;
this.textBox1.Text = logic.BasePath[0];
this.textBox3.Text = logic.BasePath[1];
this.textBox3.Visible = true;
this.textBox1.Size = new Size(250, 20);
logic.SaveProgramData();
}
//Tool strip for selecting gog as a vendor
private void gogToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
this.logic.Vendor = "GOG";
this.toolStripLabel1.Text = "Game Vendor : GOG";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = false;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = true;
this.textBox1.Text = logic.BasePath[0];
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
logic.SaveProgramData();
}
//Tool strip for selecting windows store as a vendor
private void windowsStoreToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
this.logic.Vendor = "WINDOWS";
this.toolStripLabel1.Text = "Game Vendor : Windows Store";
this.selectToolStripMenuItem.Enabled = false;
this.button4.Enabled = false;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = false;
this.epicStoreToolStripMenuItem.Enabled = true;
string AppDataRoaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
this.logic.BasePath[0] = GetBasePathFromAppDataRoaming(AppDataRoaming);
this.logic.CheckModsDir();
Console.WriteLine("BasePath from AppDataRoaming" + this.logic.BasePath[0]);
this.textBox1.Text = logic.BasePath[0];
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
logic.SaveProgramData();
RefreshAll();
}
private static string GetBasePathFromAppDataRoaming(string AppDataRoaming)
{
//Split by folder depth
List<string> splitBasePath = AppDataRoaming.Split('\\').ToList<string>();
//Find the steamapps folder
int AppDataIndex = splitBasePath.IndexOf("AppData");
//Remove all past the steamapps folder
splitBasePath.RemoveRange(AppDataIndex + 1, splitBasePath.Count - AppDataIndex - 1);
//Put string back together
return string.Join("\\", splitBasePath) + @"\Local\MW5Mercs\Saved\Mods";
}
//Tool strip for selecting epic store as a vendor
private void epicStoreToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAll();
this.logic.Vendor = "EPIC";
this.toolStripLabel1.Text = "Game Vendor : Epic Store";
this.selectToolStripMenuItem.Enabled = true;
//this.searcgToolStripMenuItem.Enabled = true;
this.button4.Enabled = true;
this.steamToolStripMenuItem.Enabled = true;
this.gogToolStripMenuItem.Enabled = true;
this.windowsStoreToolStripMenuItem.Enabled = true;
this.epicStoreToolStripMenuItem.Enabled = false;
this.textBox1.Text = logic.BasePath[0];
this.MainForm.button5.Enabled = true;
this.textBox3.Visible = false;
this.textBox1.Size = new Size(506, 20);
logic.SaveProgramData();
}
#endregion
//Launch game button
private void button4_Click(object sender, EventArgs e)
{
switch (logic.Vendor)
{
case "EPIC":
LaunchEpicGame();
break;
case "STEAM":
LaunchSteamGame();
break;
case "GOG":
LaunchGogGame();
break;
case "WINDOWS":
LaunchWindowsGame();
break;
case "GAMEPASS":
LaunchGamepassGame();
break;
}
}
#region Launch Game
private static void LaunchWindowsGame()
{
//Dunno how this works at all..
string message = "This feature is not available in this version.";
string caption = "Feature not available.";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
private static void LaunchGamepassGame()
{
//Dunno how this works at all..
string message = "This feature is not available in this version.";
string caption = "Feature not available.";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
private void LaunchGogGame()
{
string Gamepath = this.logic.BasePath[0];
Gamepath = Gamepath.Remove(Gamepath.Length - 13, 13);
Gamepath += "MechWarrior.exe";
try
{
Process.Start(Gamepath);
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}
private static void LaunchEpicGame()
{
try
{
Process.Start(@"com.epicgames.launcher://apps/Hoopoe?action=launch&silent=false");
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to make EPIC Games Launcher launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}
private static void LaunchSteamGame()
{
try
{
System.Diagnostics.Process.Start(@"steam://rungameid/784080");
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine(Ex.StackTrace);
string message = "There was an error while trying to make Steam launch Mechwarrior 5.";
string caption = "Error Launching";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(message, caption, buttons);
}
}
#endregion
//Tool strip for selecting a install folder
private void selectToolStripMenuItem_Click(object sender, EventArgs e)
{
SelectInstallDirectory();
}
//Open mods folder button
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (Utils.StringNullEmptyOrWhiteSpace(this.logic.BasePath[0]))
{
return;
}