Repository navigation
Expand file tree
/
Copy pathmodExport.cs
More file actions
1005 lines (892 loc) · 40.9 KB
/
Copy pathmodExport.cs
File metadata and controls
1005 lines (892 loc) · 40.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.IO.Compression;
using System.Security.Cryptography;
namespace SPTMiniLauncher
{
public partial class modExport : Form
{
string mainFolder;
public string currentDir = Environment.CurrentDirectory;
string[] serverMods = { };
string[] clientMods = { };
private int mainWidth = 0;
private int mainHeight = 0;
//public Color listBackcolor = Color.FromArgb(255, 35, 35, 35);
public Color listBackcolor = Color.FromArgb(255, 28, 28, 28);
// public Color listSelectedcolor = Color.FromArgb(255, 50, 50, 50);
public Color listSelectedcolor = Color.FromArgb(255, 38, 38, 38);
public Color listHovercolor = Color.FromArgb(255, 33, 33, 33);
public static string GetRelativePath(string fromPath, string toPath)
{
if (string.IsNullOrEmpty(fromPath) || string.IsNullOrEmpty(toPath))
{
throw new ArgumentNullException("Paths cannot be null or empty.");
}
Uri fromUri = new Uri(fromPath);
Uri toUri = new Uri(toPath);
if (fromUri.Scheme != toUri.Scheme)
{
return toPath;
}
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
if (toUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase))
{
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
return relativePath;
}
public modExport(int mWidth, int mHeight)
{
InitializeComponent();
mainWidth = mWidth;
mainHeight = mHeight;
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case 0x84: //WM_NCHITTEST
var result = (HitTest)m.Result.ToInt32();
if (result == HitTest.Left || result == HitTest.Right)
m.Result = new IntPtr((int)HitTest.Caption);
if (result == HitTest.TopLeft || result == HitTest.TopRight)
m.Result = new IntPtr((int)HitTest.Top);
if (result == HitTest.BottomLeft || result == HitTest.BottomRight)
m.Result = new IntPtr((int)HitTest.Bottom);
break;
}
}
enum HitTest
{
Caption = 2,
Transparent = -1,
Nowhere = 0,
Client = 1,
Left = 10,
Right = 11,
Top = 12,
TopLeft = 13,
TopRight = 14,
Bottom = 15,
BottomLeft = 16,
BottomRight = 17,
Border = 18
}
private void modExport_Load(object sender, EventArgs e)
{
// mainFolder = Path.Combine(currentDir, "Exported mods");
this.Size = new System.Drawing.Size(mainWidth, mainHeight);
mainFolder = currentDir;
loadClientMods();
loadServerMods();
generateClientMods();
generateServerMods();
}
public static void arrInsert(ref string[] array, string item)
{
Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = item;
}
private async Task exportModsAsync()
{
int clientMods = int.Parse(bCounterClientMods.Text);
int serverMods = int.Parse(bCounterServerMods.Text);
string result = "";
IEnumerable<Label> selectedClientMods = panelClientMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
IEnumerable<Label> selectedServerMods = panelServerMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
if (selectedClientMods.Any() && clientMods > 0)
{
result = await ExportClientModsAsync();
}
if (selectedServerMods.Any() && serverMods > 0)
{
result += await ExportServerModsAsync();
}
await zipMods();
result += $"Mods exported successfully. Would you like to open the transferred archive?";
statusExportingMods.Visible = false;
if (System.Windows.Forms.MessageBox.Show(result, "Export result", MessageBoxButtons.OK) == DialogResult.Yes)
{
try
{
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = currentDir;
newApp.FileName = Path.GetFileName(newApp.WorkingDirectory);
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
System.Windows.Forms.MessageBox.Show($"Oops! It seems like we received an error. If you're uncertain what it\'s about, please message the developer with a screenshot:\n\n{err.ToString()}", this.Text, MessageBoxButtons.OK);
}
}
}
public static void AddFolderContentsToZip(ZipArchive archive, string folderPath, string entryPath)
{
string[] files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories);
foreach (string file in files)
{
string relativePath = GetRelativePath(folderPath, file);
string entryName = Path.Combine(entryPath, relativePath);
archive.CreateEntryFromFile(file, entryName);
}
}
private async Task zipMods()
{
try
{
string homeBepinFolder = Path.Combine(mainFolder, "BepInEx");
string homePluginsFolder = Path.Combine(homeBepinFolder, "plugins");
string homeUserFolder = Path.Combine(mainFolder, "SPT_Runtime", "user");
string homeModsFolder = Path.Combine(homeUserFolder, "mods");
string zipPath = Path.Combine(currentDir, "Exported mods.zip");
bool fileExists = File.Exists(zipPath);
if (!fileExists)
{
ZipFile.CreateFromDirectory(homeBepinFolder, zipPath, CompressionLevel.NoCompression, true);
}
using (FileStream zipFileStream = new FileStream(zipPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (ZipArchive archive = new ZipArchive(zipFileStream, ZipArchiveMode.Update))
{
AddFolderContentsToZip(archive, homeUserFolder, "");
}
}
/*
bool homeBepinFolderExists = Directory.Exists(homeBepinFolder);
if (homeBepinFolderExists)
{
Directory.Delete(homeBepinFolder, true);
}
bool homeUserFolderExists = Directory.Exists(homeUserFolder);
if (homeUserFolderExists)
Directory.Delete(homeUserFolder, true);
*/
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
System.Windows.Forms.MessageBox.Show($"Oops! It seems like we received an error. If you're uncertain what it\'s about, please message the developer with a screenshot:\n\n{err.ToString()}", this.Text, MessageBoxButtons.OK);
}
}
private async Task<string> ExportClientModsAsync()
{
try
{
// Prepare client mods
string homeBepinFolder = Path.Combine(mainFolder, "BepInEx");
string homePluginsFolder = Path.Combine(homeBepinFolder, "plugins");
bool homeBepinFolderExists = Directory.Exists(homeBepinFolder);
if (homeBepinFolderExists)
{
Directory.Delete(homeBepinFolder, true);
}
Directory.CreateDirectory(Path.Combine(mainFolder, "BepInEx"));
Directory.CreateDirectory(Path.Combine(homeBepinFolder, "plugins"));
// Enumerate and fetch
IEnumerable<Label> clientMods = panelClientMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
// Check folders
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
List<string> movedItems = new List<string>();
// Enumerate and copy
foreach (Label lbl in clientMods)
{
string fileName = lbl.Text.Replace("[*] ", "");
string fullPath = Path.Combine(pluginsFolder, fileName);
string homeFullPath = Path.Combine(homePluginsFolder, fileName);
bool fileExists = File.Exists(fullPath);
if (fileExists)
{
File.Copy(fullPath, homeFullPath);
File.SetAttributes(homeFullPath, FileAttributes.Normal);
movedItems.Add(Path.GetFileName(homeFullPath));
}
else
{
bool folderExists = Directory.Exists(fullPath);
if (folderExists)
{
CopyDirectory(fullPath, homeFullPath);
movedItems.Add(Path.GetFileName(homeFullPath));
}
}
}
return $"Client mods export successful. Moved items:\n\n{string.Join("\n", movedItems)}\n\n";
}
}
}
catch (Exception ex)
{
return $"Error during export: {ex.Message}";
}
return "Export failed";
}
private async Task<string> ExportServerModsAsync()
{
try
{
// Prepare server mods
string homeUserFolder = Path.Combine(mainFolder, "SPT_Runtime", "user");
string homeModsFolder = Path.Combine(homeUserFolder, "mods");
bool homeUserFolderExists = Directory.Exists(homeUserFolder);
if (homeUserFolderExists)
{
Directory.Delete(homeUserFolder, true);
}
Directory.CreateDirectory(Path.Combine(mainFolder, "SPT_Runtime", "user"));
Directory.CreateDirectory(Path.Combine(homeUserFolder, "mods"));
// Enumerate and fetch
IEnumerable<Label> serverMods = panelServerMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
// Check folders
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
List<string> movedItems = new List<string>();
// Enumerate and copy
foreach (Label lbl in serverMods)
{
string fileName = lbl.Text.Replace("[*] ", "");
string fullPath = Path.Combine(modsFolder, fileName);
string homeFullPath = Path.Combine(homeModsFolder, fileName);
bool folderExists = Directory.Exists(fullPath);
if (folderExists)
{
CopyDirectory(fullPath, homeFullPath);
movedItems.Add(Path.GetFileName(homeFullPath));
}
}
return $"Server export successful. Moved items:\n{string.Join("\n", movedItems)}\n\n";
}
}
}
catch (Exception ex)
{
return $"Error during export: {ex.Message}";
}
return "Export failed";
}
private void exportClientMods()
{
// Prepare client mods
string homeBepinFolder = Path.Combine(mainFolder, "BepInEx");
string homePluginsFolder = Path.Combine(homeBepinFolder, "plugins");
bool homeBepinFolderExists = Directory.Exists(homeBepinFolder);
if (homeBepinFolderExists)
{
Directory.Delete(homeBepinFolder, true);
}
Directory.CreateDirectory(Path.Combine(mainFolder, "BepInEx"));
Directory.CreateDirectory(Path.Combine(homeBepinFolder, "plugins"));
// Enumerate and fetch
IEnumerable<Label> clientMods = panelClientMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
// Check folders
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
// Enumerate and copy
foreach (Label lbl in clientMods)
{
string fileName = lbl.Text.Replace("[*] ", "");
string fullPath = Path.Combine(pluginsFolder, fileName);
string homeFullPath = Path.Combine(homePluginsFolder, fileName);
bool fileExists = File.Exists(fullPath);
if (fileExists)
{
fullPath = $"{fullPath}.dll";
File.Copy(fullPath, homeFullPath);
File.SetAttributes(homeFullPath, FileAttributes.Normal);
}
else
{
bool folderExists = Directory.Exists(fullPath);
if (folderExists)
{
CopyDirectory(fullPath, homeFullPath);
}
}
}
}
}
}
private void exportServerMods()
{
// Prepare server mods
string homeUserFolder = Path.Combine(mainFolder, "SPT_Runtime", "user");
string homeModsFolder = Path.Combine(homeUserFolder, "mods");
bool homeUserFolderExists = Directory.Exists(homeUserFolder);
if (homeUserFolderExists)
Directory.Delete(homeUserFolder, true);
Directory.CreateDirectory(Path.Combine(mainFolder, "SPT_Runtime", "user"));
Directory.CreateDirectory(Path.Combine(homeUserFolder, "mods"));
// Enumerate and fetch
IEnumerable<Label> serverMods = panelServerMods.Controls
.OfType<Label>()
.Where(lbl => lbl.ForeColor == Color.DodgerBlue);
// Check folders
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
// Enumerate and copy
foreach (Label lbl in serverMods)
{
string fileName = lbl.Text.Replace("[*] ", "");
string fullPath = Path.Combine(modsFolder, fileName);
string homeFullPath = Path.Combine(homeModsFolder, fileName);
bool folderExists = Directory.Exists(fullPath);
if (folderExists)
{
CopyDirectory(fullPath, homeFullPath);
}
}
}
}
}
static void CopyDirectory(string source, string destination)
{
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination);
}
foreach (string file in Directory.GetFiles(source))
{
string destFile = Path.Combine(destination, Path.GetFileName(file));
File.Copy(file, destFile, true); // Set to true to overwrite files if they already exist
File.SetAttributes(destFile, FileAttributes.Normal);
}
foreach (string subDirectory in Directory.GetDirectories(source))
{
string destDirectory = Path.Combine(destination, Path.GetFileName(subDirectory));
CopyDirectory(subDirectory, destDirectory);
}
}
private void selectAllMods(bool isClient)
{
if (isClient)
{
foreach (Control ctrl in panelClientMods.Controls)
{
if (ctrl is Label lbl)
{
lbl.Text = $"[*] {lbl.Text}";
lbl.ForeColor = Color.DodgerBlue;
}
}
}
else
{
foreach (Control ctrl in panelServerMods.Controls)
{
if (ctrl is Label lbl)
{
lbl.Text = $"[*] {lbl.Text}";
lbl.ForeColor = Color.DodgerBlue;
}
}
}
}
private void unselectAllMods(bool isClient)
{
if (isClient)
{
foreach (Control ctrl in panelClientMods.Controls)
{
if (ctrl is Label lbl)
{
lbl.Text = lbl.Text.Replace("[*] ", "");
lbl.ForeColor = Color.LightGray;
}
}
}
else
{
foreach (Control ctrl in panelServerMods.Controls)
{
if (ctrl is Label lbl)
{
lbl.Text = lbl.Text.Replace("[*] ", "");
lbl.ForeColor = Color.LightGray;
}
}
}
}
int countLabelsWithColor(Panel panel, Color targetColor)
{
int count = 0;
foreach (Control control in panel.Controls)
{
if (control is Label label)
{
if (label.ForeColor == targetColor)
{
count++;
}
}
}
return count;
}
private void refreshClientCounter()
{
int counter = countLabelsWithColor(panelClientMods, Color.DodgerBlue);
bCounterClientMods.Text = panelClientMods.Controls.Count.ToString();
}
private void refreshServerCounter()
{
int counter = countLabelsWithColor(panelServerMods, Color.DodgerBlue);
bCounterServerMods.Text = panelServerMods.Controls.Count.ToString();
}
private void loadClientMods()
{
List<string> folderMods = new List<string>();
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
panelClientMods.Controls.Clear();
string[] modsFolders = Directory.GetDirectories(pluginsFolder);
foreach (string mod in modsFolders)
{
string modName = Path.GetFileName(mod);
if (modName != "spt")
{
arrInsert(ref clientMods, $"📂 {Path.GetFileName(mod)}");
}
}
bool c = false;
string[] modsFiles = Directory.GetFiles(pluginsFolder);
foreach (string mod in modsFiles)
{
foreach (string folderMod in modsFolders)
{
if (mod.Contains(folderMod))
{
c = true;
break;
}
}
if (!c)
{
arrInsert(ref clientMods, $"📄 {Path.GetFileName(mod)}"); ;
}
}
}
}
}
private void loadServerMods()
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
panelServerMods.Controls.Clear();
string[] mods = Directory.GetDirectories(modsFolder);
foreach (string mod in mods)
{
arrInsert(ref serverMods, $"📂 {Path.GetFileName(mod)}");
}
}
}
}
private void generateClientMods()
{
for (int i = 0; i < clientMods.Length; i++)
{
Label lbl = new Label();
lbl.AutoSize = false;
lbl.Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Size = new System.Drawing.Size(panelClientMods.Size.Width, 30);
lbl.Location = new System.Drawing.Point(0, 0 + (i * 30));
lbl.Cursor = Cursors.Hand;
lbl.Text = clientMods[i];
lbl.BackColor = listBackcolor;
lbl.ForeColor = Color.LightGray;
lbl.Font = new System.Drawing.Font("Bahnschrift Light", 10, System.Drawing.FontStyle.Regular);
lbl.Margin = new Padding(1, 1, 1, 1);
lbl.AutoEllipsis = true;
lbl.MouseEnter += new EventHandler(mods_MouseEnter);
lbl.MouseLeave += new EventHandler(mods_MouseLeave);
lbl.MouseDown += new MouseEventHandler(mods_MouseDown);
lbl.MouseDoubleClick += new MouseEventHandler(mods_MouseDoubleClick);
panelClientMods.Controls.Add(lbl);
}
bCounterClientMods.Text = clientMods.Length.ToString();
}
private void generateServerMods()
{
for (int i = 0; i < serverMods.Length; i++)
{
Label lbl = new Label();
lbl.AutoSize = false;
lbl.Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Size = new System.Drawing.Size(panelServerMods.Size.Width, 30);
lbl.Location = new System.Drawing.Point(0, 0 + (i * 30));
lbl.Cursor = Cursors.Hand;
lbl.Text = serverMods[i];
lbl.BackColor = listBackcolor;
lbl.ForeColor = Color.LightGray;
lbl.Font = new System.Drawing.Font("Bahnschrift Light", 10, System.Drawing.FontStyle.Regular);
lbl.Margin = new Padding(1, 1, 1, 1);
lbl.AutoEllipsis = true;
lbl.MouseEnter += new EventHandler(mods_MouseEnter);
lbl.MouseLeave += new EventHandler(mods_MouseLeave);
lbl.MouseDown += new MouseEventHandler(mods_MouseDown);
lbl.MouseDoubleClick += new MouseEventHandler(mods_MouseDoubleClick);
panelServerMods.Controls.Add(lbl);
}
bCounterServerMods.Text = serverMods.Length.ToString();
}
private void mods_MouseEnter(object sender, EventArgs e)
{
System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
if (label.Text != "")
{
if (label.BackColor != listSelectedcolor)
{
label.BackColor = listHovercolor;
}
}
}
private void mods_MouseLeave(object sender, EventArgs e)
{
System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
if (label.Text != "")
{
if (label.BackColor != listSelectedcolor)
{
label.BackColor = listBackcolor;
}
}
}
private void mods_MouseDown(object sender, MouseEventArgs e)
{
System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
if (label.Text != "")
{
if ((Control.MouseButtons & MouseButtons.Right) != 0)
{
string parentName = label.Parent.Name.ToLower();
if (parentName == "panelclientmods")
{
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
if (!label.Text.EndsWith(".dll"))
{
string modName = Path.GetFileName(label.Text.Substring(3));
if (System.Windows.Forms.MessageBox.Show("", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
}
}
else
{
}
}
}
}
else if (parentName == "panelservermods")
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
if (!chkPackageToggle.Checked)
{
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = modsFolder;
newApp.FileName = Path.GetFileName(label.Text.Substring(3));
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
else
{
string modPath = Path.Combine(modsFolder, Path.GetFileName(label.Text.Substring(3)));
string packageJson = Path.Combine(modPath, "package.json");
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = modPath;
newApp.FileName = Path.GetFileName(packageJson);
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
}
}
}
}
else
{
if (!chkOpenToggle.Checked)
{
string parentName = label.Parent.Name.ToLower();
if (parentName == "panelclientmods")
{
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
string relativePath = label.Text.Substring(3);
string fullPath = Path.Combine(pluginsFolder, relativePath);
if (!label.Text.EndsWith(".dll"))
{
if (Directory.Exists(fullPath))
{
Process.Start(new ProcessStartInfo
{
FileName = fullPath,
UseShellExecute = true
});
}
}
else
{
if (File.Exists(fullPath))
{
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"/select,\"{fullPath}\"",
UseShellExecute = true
});
}
}
}
}
}
else if (parentName == "panelservermods")
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
if (!chkPackageToggle.Checked)
{
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = modsFolder;
newApp.FileName = Path.GetFileName(label.Text.Substring(3));
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
else
{
string modPath = Path.Combine(modsFolder, Path.GetFileName(label.Text.Substring(3)));
string packageJson = Path.Combine(modPath, "package.json");
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = modPath;
newApp.FileName = Path.GetFileName(packageJson);
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
}
}
}
}
}
/*
if (label.ForeColor == Color.DodgerBlue)
{
label.Text = label.Text.Replace("[*] ", "");
label.ForeColor = Color.LightGray;
}
else
{
label.Text = $"[*] {label.Text}";
label.ForeColor = Color.DodgerBlue;
}
Panel pnl = (Panel)label.Parent;
if (pnl.Name.ToLower() == "panelclientmods")
refreshClientCounter();
else
refreshServerCounter();
*/
}
}
private void mods_MouseDoubleClick(object sender, MouseEventArgs e)
{
System.Windows.Forms.Label label = (System.Windows.Forms.Label)sender;
if (label.Text != "")
{
string parentName = label.Parent.Name.ToLower();
if (parentName == "panelclientmods")
{
string bepinFolder = Path.Combine(Properties.Settings.Default.server_path, "BepInEx");
bool bepinFolderExists = Directory.Exists(bepinFolder);
if (bepinFolderExists)
{
string pluginsFolder = Path.Combine(bepinFolder, "plugins");
bool pluginsFolderExists = Directory.Exists(pluginsFolder);
if (pluginsFolderExists)
{
string relativePath = label.Text.Substring(3);
string fullPath = Path.Combine(pluginsFolder, relativePath);
if (!label.Text.EndsWith(".dll"))
{
if (Directory.Exists(fullPath))
{
Process.Start(new ProcessStartInfo
{
FileName = fullPath,
UseShellExecute = true
});
}
}
else
{
if (File.Exists(fullPath))
{
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"/select,\"{fullPath}\"",
UseShellExecute = true
});
}
}
}
}
}
else if (parentName == "panelservermods")
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "SPT_Runtime", "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string modsFolder = Path.Combine(userFolder, "mods");
bool modsFolderExists = Directory.Exists(modsFolder);
if (modsFolderExists)
{
ProcessStartInfo newApp = new ProcessStartInfo();
newApp.WorkingDirectory = modsFolder;
newApp.FileName = Path.GetFileName(label.Text.Substring(3));
newApp.UseShellExecute = true;
newApp.Verb = "open";
Process.Start(newApp);
}
}
}
}
}
private void bSelectAllClientMods_Click(object sender, EventArgs e)
{
selectAllMods(true);
refreshClientCounter();
}
private void bUnselectAllClientMods_Click(object sender, EventArgs e)
{
unselectAllMods(true);
refreshClientCounter();
}
private void bSelectAllServerMods_Click(object sender, EventArgs e)
{
selectAllMods(false);
refreshServerCounter();
}
private void bUnselectAllServerMods_Click(object sender, EventArgs e)
{
unselectAllMods(false);
refreshServerCounter();
}
private async void bExportSelectedMods_Click(object sender, EventArgs e)
{
int clientMods = int.Parse(bCounterClientMods.Text);
int serverMods = int.Parse(bCounterServerMods.Text);
string homeBepinFolder = Path.Combine(mainFolder, "BepInEx");
string homeUserFolder = Path.Combine(mainFolder, "SPT_Runtime", "user");
string content = $"Do you wish to export {clientMods} client mods and {serverMods} server mods? This may take a minute.";
if (System.Windows.Forms.MessageBox.Show(content, this.Text, (MessageBoxButtons)MessageBoxButton.YesNo) == DialogResult.Yes)
{
statusExportingMods.Visible = true;
await exportModsAsync();
bool homeBepinFolderExists = Directory.Exists(homeBepinFolder);
bool homeUserFolderExists = Directory.Exists(homeUserFolder);
if (homeBepinFolderExists && homeUserFolderExists)
{
try
{
Directory.Delete(homeBepinFolder, true);
Directory.Delete(homeUserFolder, true);
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
System.Windows.Forms.MessageBox.Show($"Oops! It seems like we received an error. If you're uncertain what it\'s about, please message the developer with a screenshot:\n\n{err.ToString()}", this.Text, MessageBoxButtons.OK);
}