-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
4806 lines (4282 loc) · 200 KB
/
Copy pathForm1.cs
File metadata and controls
4806 lines (4282 loc) · 200 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 Microsoft.WindowsAPICodePack.Dialogs;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media.Animation;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using System.Net.NetworkInformation;
using System.Security.Policy;
using System.Security.Permissions;
using System.Runtime.InteropServices.ComTypes;
using System.Configuration;
using System.Windows.Media.Imaging;
namespace SPTMiniLauncher
{
public partial class Form1 : Form
{
// Start variables
// Pre-set path variables
// Palette
// Pre-set processes
public string currentDir = Environment.CurrentDirectory;
public bool isLoneServer = false;
public bool hasStopped = false;
public bool isServerOnly = false;
public string selectedServer;
public string settingsFile;
public string thirdPartyFile;
public string galleryFile;
public string optionsFile;
public string firstTime;
public string core;
public string selectedAID;
public string[] thirdPartyContent = { };
public string[] sptGallery = { };
public DateTime startTimeTarkov;
public DateTime startTimeServer;
public Color listBackcolor = Color.FromArgb(255, 35, 35, 35);
public Color listSelectedcolor = Color.FromArgb(255, 50, 50, 50);
public Color listHovercolor = Color.FromArgb(255, 45, 45, 45);
public Process server;
public Process launcher;
public outputWindow outputwindow;
private List<string> globalProcesses;
public Dictionary<string, ThirdPartyInfo> appDict { get; set; }
public Dictionary<string, Gallery> galleryDictionary { get; set; }
public static Form1 Instance { get; private set; }
// background working
BackgroundWorker CheckServerWorker;
public BackgroundWorker TarkovProcessDetector;
public BackgroundWorker TarkovEndDetector;
public BackgroundWorker globalProcessDetector;
public StringBuilder akiServerOutputter;
string[] serverOptions = { };
// Lists
string[] serverOptionsStreets = {
"Actions",
"Clear cache",
"Launch SPT",
"Stop SPT",
"Mods",
"View installed mods",
"Open server mods",
"Open client mods",
"Open profiles folder",
"Open modloader JSON",
"Miscellaneous",
"Open profile -",
"Open control panel",
"ThirdPartyApps"
};
public Form1()
{
InitializeComponent();
appDict = new Dictionary<string, ThirdPartyInfo>();
Instance = this;
}
private void Form1_Load(object sender, EventArgs e)
{
if (!isLauncherRunning())
{
boxPath.Text = "";
outputwindow = new outputWindow();
outputwindow.Visible = false;
outputwindow.Owner = this;
settingsFile = System.IO.Path.Combine(Environment.CurrentDirectory, "SPT Mini.json");
thirdPartyFile = System.IO.Path.Combine(Environment.CurrentDirectory, "Third Party Apps.json");
galleryFile = System.IO.Path.Combine(Environment.CurrentDirectory, "Gallery.json");
optionsFile = System.IO.Path.Combine(Environment.CurrentDirectory, "options.json");
messageBoard form = new messageBoard();
RichTextBox messageBox = (RichTextBox)form.Controls["messageBox"];
Label messageTitle = (Label)form.Controls["messageTitle"];
messageTitle.ForeColor = Color.LightGray;
if (File.Exists(optionsFile))
{
try
{
compileOptions();
}
catch (Exception ex)
{
if (MessageBox.Show("It looks like your 'options.json' has an invalid structure. Click Yes to let the Launcher restart and re-generate the file for you.",
this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
File.Delete(optionsFile);
createOptions();
compileOptions();
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err}");
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);
}
}
}
}
else
{
createOptions();
compileOptions();
}
if (File.Exists(thirdPartyFile))
{
appDict = new Dictionary<string, ThirdPartyInfo>();
string thirdPartyContent = System.IO.File.ReadAllText(thirdPartyFile);
JObject thirdParty = JObject.Parse(thirdPartyContent);
JArray appsArray = (JArray)thirdParty["ThirdPartyApps"];
foreach (JObject app in appsArray)
{
string name = (string)app["Name"];
string path = (string)app["Path"];
string type = (string)app["Type"];
appDict[name] = new ThirdPartyInfo(name, path, type);
}
}
else
{
var thirdpartyData = new JObject
{
["ThirdPartyApps"] = new JArray
{
new JObject
{
["Name"] = "Load Order Editor",
["Path"] = "mods\\Load Order Editor.exe",
["Type"] = "App"
},
new JObject
{
["Name"] = "SPT-AKI Profile Editor",
["Path"] = "C:\\Program Files\\SPT-AKI Profile Editor\\SPT-AKI Profile Editor.exe",
["Type"] = "App"
},
new JObject
{
["Name"] = "Server Value Modifier",
["Path"] = "mods\\ServerValueModifier\\GFVE.exe",
["Type"] = "App"
},
new JObject
{
["Name"] = "SPT Realism",
["Path"] = "mods\\SPT-Realism-Mod\\RealismModConfig.exe",
["Type"] = "App"
}
}
};
string json = thirdpartyData.ToString();
try
{
File.WriteAllText(thirdPartyFile, json);
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
try
{
string thirdPartyContent = System.IO.File.ReadAllText(thirdPartyFile);
JObject thirdParty = JObject.Parse(thirdPartyContent);
JArray appsArray = (JArray)thirdParty["ThirdPartyApps"];
foreach (JObject app in appsArray)
{
string name = (string)app["Name"];
string path = (string)app["Path"];
string type = (string)app["Type"];
appDict[name] = new ThirdPartyInfo(name, path, type);
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
if (File.Exists(settingsFile))
{
globalProcesses = new List<string> { "SPT.Server", "SPT.Launcher", "EscapeFromTarkov" };
string readSettings = File.ReadAllText(settingsFile);
JObject settingsObject = JObject.Parse(readSettings);
if (settingsObject.ContainsKey("mainWidth") && settingsObject.ContainsKey("mainHeight"))
{
this.Width = (int)settingsObject["mainWidth"];
this.Height = (int)settingsObject["mainHeight"];
}
else
{
saveDimensions();
}
if (!settingsObject.ContainsKey("showFirstTimeMessage"))
{
settingsObject["showFirstTimeMessage"] = true;
string updatedJSON = settingsObject.ToString();
File.WriteAllText(settingsFile, updatedJSON);
Application.Restart();
}
else
{
if (settingsObject["showFirstTimeMessage"].ToString().ToLower() == "true")
{
settingsObject.Property("showFirstTimeMessage").Value = "false";
messageTitle.Text = "First time setup";
messageBox.Text = Properties.Settings.Default.firstTimeMessage; /* File.ReadAllText(firstTime); */
form.Size = new Size(623, 730);
form.ShowDialog();
File.WriteAllText(settingsFile, settingsObject.ToString());
}
}
if (settingsObject.ContainsKey("Developer_Options"))
{
JObject devOptions = (JObject)settingsObject["Developer_Options"];
if (!devOptions.ContainsKey("Simple_Mode"))
{
settingsObject["Developer_Options"]["Simple_Mode"] = false;
string updatedJSON = settingsObject.ToString();
File.WriteAllText(settingsFile, updatedJSON);
}
}
else
{
settingsObject["Developer_Options"] = new JObject();
settingsObject["Developer_Options"]["Simple_Mode"] = false;
string updatedJSON = settingsObject.ToString();
File.WriteAllText(settingsFile, updatedJSON);
}
boxPathBox.Select();
}
else
{
messageTitle.Text = "Settings file was not detected!";
messageBox.Text = $"We could not detect the settings file. Please restart so that the launcher can generate it!";
form.Size = new Size(623, 200);
form.ShowDialog();
}
readGallery();
if (Properties.Settings.Default.currentProfileAID != null)
{
string convertedProfile = fetchProfileFromAID(Properties.Settings.Default.currentProfileAID);
if (convertedProfile != null &&
convertedProfile != Properties.Settings.Default.currentProfileAID)
{
if (convertedProfile.Length > 1)
{
if (convertedProfile != null)
{
bProfilePlaceholder.Text = $"Profile: {convertedProfile}";
}
}
}
}
}
else
{
MessageBox.Show("It appears that SPT Launcher is already running!\n\n\nWe\'ll close all of them and restart for you.", this.Text, MessageBoxButtons.OK);
string sptLauncherProcess = "SPT Launcher";
Process[] procs = Process.GetProcessesByName(sptLauncherProcess);
if (procs != null && procs.Length > 1)
{
foreach (Process launcher in procs)
{
if (!launcher.HasExited)
{
if (!launcher.CloseMainWindow())
{
launcher.Kill();
launcher.WaitForExit();
}
else
{
launcher.WaitForExit();
}
}
}
}
Application.Restart();
}
}
private void createOptions()
{
JObject thirdPartyData = new JObject(
new JProperty("Actions",
new JArray(
new JObject(new JProperty("Clear cache", true)),
new JObject(new JProperty("Launch SPT", true)),
new JObject(new JProperty("Stop SPT", true))
)
),
new JProperty("Mods",
new JArray(
new JObject(new JProperty("View installed mods", true)),
new JObject(new JProperty("Open server mods", true)),
new JObject(new JProperty("Open client mods", true)),
new JObject(new JProperty("Open profiles folder", true)),
new JObject(new JProperty("Open modloader", true))
)
),
new JProperty("Miscellaneous",
new JArray(
new JObject(new JProperty("Open a profile", true)),
new JObject(new JProperty("Open control panel", true))
)
),
new JProperty("DisableTPA",
new bool()
)
);
try
{
File.WriteAllText(optionsFile, thirdPartyData.ToString());
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
private void compileOptions()
{
Array.Clear(serverOptions, 0, serverOptions.Length);
serverOptions = new string[] { };
string readOptions = File.ReadAllText(optionsFile);
JObject readObject = JObject.Parse(readOptions);
JArray Actions = (JArray)readObject["Actions"];
bool allActionsDisabled = Actions.All(relevantItem =>
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
return false;
}
return true;
});
if (!allActionsDisabled)
arrInsert(ref serverOptions, "Actions");
foreach (var relevantItem in (JArray)Actions)
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
arrInsert(ref serverOptions, item.Key);
}
}
JArray Mods = (JArray)readObject["Mods"];
bool allModsDisabled = Mods.All(relevantItem =>
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
return false;
}
return true;
});
if (!allModsDisabled)
arrInsert(ref serverOptions, "Mods");
foreach (var relevantItem in (JArray)Mods)
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
arrInsert(ref serverOptions, item.Key);
}
}
JArray Miscellaneous = (JArray)readObject["Miscellaneous"];
bool allMiscellaneousDisabled = Miscellaneous.All(relevantItem =>
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
return false;
}
return true;
});
if (!allMiscellaneousDisabled)
arrInsert(ref serverOptions, "Miscellaneous");
foreach (var relevantItem in (JArray)Miscellaneous)
{
foreach (var item in ((JObject)relevantItem))
{
if ((bool)item.Value)
arrInsert(ref serverOptions, item.Key);
}
}
bool DisableTPA = (bool)readObject["DisableTPA"];
if (!DisableTPA)
arrInsert(ref serverOptions, "ThirdPartyApps");
}
public void readGallery()
{
clearUI(true);
try
{
// instantiate internal array for storing installs and the "add new" button
sptGallery = new string[] { };
arrInsert(ref sptGallery, "Add new SPT install");
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err}");
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);
}
Label lastItem = null;
foreach (Control ctrl in boxServers.Controls)
{
if (ctrl is Label lbl)
{
lastItem = lbl;
}
}
bool galleryFileExists = File.Exists(galleryFile);
if (galleryFileExists)
{
galleryDictionary = new Dictionary<string, Gallery>();
string sptGallery = System.IO.File.ReadAllText(galleryFile);
JObject galleryObj = JObject.Parse(sptGallery);
JArray galleryArray = (JArray)galleryObj["Gallery"];
foreach (JObject folder in galleryArray)
{
string name = (string)folder["Name"];
string path = (string)folder["Path"];
galleryDictionary[name] = new Gallery(name, path);
}
}
else
{
var galleryData = new JObject
{
["Gallery"] = new JArray { }
};
string json = galleryData.ToString();
try
{
File.WriteAllText(galleryFile, json);
galleryDictionary = new Dictionary<string, Gallery>();
string sptGallery = System.IO.File.ReadAllText(galleryFile);
JObject galleryObj = JObject.Parse(sptGallery);
JArray galleryArray = (JArray)galleryObj["Gallery"];
foreach (JObject folder in galleryArray)
{
string name = (string)folder["Name"];
string path = (string)folder["Path"];
galleryDictionary[name] = new Gallery(name, path);
}
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err}");
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);
}
}
if (galleryDictionary != null)
{
if (galleryDictionary.Count > 0)
{
foreach (var folder in galleryDictionary)
{
clearUI(true);
string name = folder.Key;
Gallery folderInfo = folder.Value;
string installName = folderInfo.Name;
string installPath = folderInfo.Path;
arrInsert(ref sptGallery, name);
}
}
}
for (int i = 0; i < sptGallery.Length; i++)
{
Label lbl = new Label();
lbl.AutoSize = false;
lbl.Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Size = new Size(boxServers.Size.Width, boxServerPlaceholder.Size.Height);
lbl.Location = new Point(boxServerPlaceholder.Location.X, boxServerPlaceholder.Location.Y + (i * 30));
lbl.Font = new Font("Bahnschrift Light", 9, FontStyle.Regular);
lbl.BackColor = listBackcolor;
lbl.ForeColor = Color.LightGray;
lbl.Margin = new Padding(1, 1, 1, 1);
lbl.Cursor = Cursors.Hand;
lbl.MouseEnter += new EventHandler(lbl_MouseEnter);
lbl.MouseLeave += new EventHandler(lbl_MouseLeave);
lbl.MouseDown += new MouseEventHandler(lbl_MouseDown);
lbl.MouseUp += new MouseEventHandler(lbl_MouseUp);
if (sptGallery[i].ToLower() == "add new spt install")
{
lbl.Name = $"gallery_addBtn";
}
else
{
lbl.Name = $"install_{sptGallery[i]}";
}
lbl.Text = sptGallery[i];
boxServers.Controls.Add(lbl);
selectCurrentInstall();
}
}
public void selectCurrentInstall()
{
string fullPath = Properties.Settings.Default.server_path;
string fullName = Properties.Settings.Default.lastUsedInstall;
if (fullPath != null && fullName != null)
{
foreach (Control ctrl in boxServers.Controls)
{
if (ctrl is Label lbl && lbl.Text == fullName)
{
useInstall(fullName);
boxPathBox.Select();
}
}
}
}
public string fetchProfileFromAID(string profileAID)
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string profilesFolder = Path.Combine(userFolder, "profiles");
bool profilesFolderExists = Directory.Exists(profilesFolder);
if (profilesFolderExists)
{
string fullAID = Path.Combine(profilesFolder, $"{profileAID}.json");
bool fullAIDExists = File.Exists(fullAID);
if (fullAIDExists)
{
string fileContent = File.ReadAllText(fullAID);
JObject parsedFile = JObject.Parse(fileContent);
JObject info = (JObject)parsedFile["info"];
string infoAID = (string)info["id"];
JObject characters = (JObject)parsedFile["characters"];
JObject pmc = (JObject)characters["pmc"];
JObject Info = (JObject)pmc["Info"];
string Nickname = (string)Info["Nickname"];
if (infoAID == profileAID)
{
return Nickname;
}
}
}
}
return null;
}
public JObject fetchFullProfileFromAID(string profileAID)
{
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "user");
bool userFolderExists = Directory.Exists(userFolder);
if (userFolderExists)
{
string profilesFolder = Path.Combine(userFolder, "profiles");
bool profilesFolderExists = Directory.Exists(profilesFolder);
if (profilesFolderExists)
{
string fullAID = Path.Combine(profilesFolder, $"{profileAID}.json");
bool fullAIDExists = File.Exists(fullAID);
if (fullAIDExists)
{
string fileContent = File.ReadAllText(fullAID);
JObject parsedFile = JObject.Parse(fileContent);
JObject info = (JObject)parsedFile["info"];
string infoAID = (string)info["id"];
JObject characters = (JObject)parsedFile["characters"];
JObject pmc = (JObject)characters["pmc"];
JObject Info = (JObject)pmc["Info"];
string Nickname = (string)Info["Nickname"];
if (infoAID == profileAID)
{
return Info;
}
}
}
}
return null;
}
public bool isLauncherRunning()
{
string sptLauncherProcess = "SPT Launcher";
Process[] sptLauncher = Process.GetProcessesByName(sptLauncherProcess);
if (sptLauncher != null && sptLauncher.Length > 1)
{
return true;
}
return false;
}
public void updateOrderJSON(string path)
{
// Personal reference: path means user/mods
//
// I guess I'll document this for whoever is interested lmao
// pls no judgerino, I am dumdum with c soft
//
// This function will do the following:
//
// 1. Check if order.json exists in the user/mods folder
// >> If it doesn't, create and structure it
//
// 2. If it exists, check the list of server mods against the order list
// >> If the order list is missing an existing mod, it adds said mod
//
// 3. Next, check if the order list contains any mods that don't exist anymore
// >> If it does, remove said non-existent mods from the order list
//
try
{
string orderFile = Path.Combine(path, "order.json");
if (!File.Exists(orderFile))
{
var jsonOrder = new { order = new List<string>() };
string json = JsonConvert.SerializeObject(jsonOrder, Formatting.Indented);
File.WriteAllText(orderFile, json);
}
string orderJSON = File.ReadAllText(orderFile);
JObject order = JObject.Parse(orderJSON);
string[] modsFolder = Directory.GetDirectories(path);
List<JToken> removeMods = new List<JToken>();
foreach (JToken mod in order["order"])
{
string modName = mod.Value<string>();
if (!Array.Exists(modsFolder, s => Path.GetFileName(s).Equals(modName)))
{
removeMods.Add(mod);
}
}
foreach (JToken mod in removeMods)
{
mod.Remove();
}
foreach (string mod in modsFolder)
{
string name = Path.GetFileName(mod);
bool exists = ((JArray)order["order"]).Any(t => t.Value<string>() == name);
if (!exists)
{
((JArray)order["order"]).Add(name);
}
}
File.WriteAllText(orderFile, order.ToString());
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err}");
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 void showError(string content)
{
MessageBox.Show(content, this.Text, MessageBoxButtons.OK);
}
public void clearUI(bool all)
{
if (all)
{
// server box
for (int i = boxServers.Controls.Count - 1; i >= 0; i--)
{
Label selected = boxServers.Controls[i] as Label;
if ((selected != null) && (selected.Name.ToLower() != "boxserverstitle"))
{
if (boxServers.Controls.Count > 0)
{
try
{
boxServers.Controls.RemoveAt(i);
selected.Dispose();
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
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);
}
}
}
}
// option box
for (int i = boxSelectedServer.Controls.Count - 1; i >= 0; i--)
{
Label selected = boxSelectedServer.Controls[i] as Label;
if ((selected != null) && (selected.Name.ToLower() != "boxselectedservertitle"))
{
if (boxSelectedServer.Controls.Count > 0)
{
try
{
boxSelectedServer.Controls.RemoveAt(i);
selected.Dispose();
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
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);
}
}
}
}
}
else
{
// option box
for (int i = boxSelectedServer.Controls.Count - 1; i >= 0; i--)
{
Label selected = boxSelectedServer.Controls[i] as Label;
if ((selected != null) && (selected.Name.ToLower() != "boxselectedservertitle"))
{
try
{
boxSelectedServer.Controls.RemoveAt(i);
selected.Dispose();
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err.ToString()}");
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 arrInsert(ref string[] array, string item)
{
Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = item;
}
public static void arrRemove(ref string[] array, string item)
{
int index = Array.IndexOf(array, item);
if (index != -1)
{
for (int i = index; i < array.Length - 1; i++)
{
array[i] = array[i + 1];
}
Array.Resize(ref array, array.Length - 1);
}
}
public void saveDimensions()
{
int curWidth = this.Size.Width;
int curHeight = this.Size.Height;
bool settingsFileExists = File.Exists(settingsFile);
if (settingsFileExists)
{
string readSettings = File.ReadAllText(settingsFile);
JObject settingsObject = JObject.Parse(readSettings);
if (!settingsObject.ContainsKey("mainWidth"))
settingsObject.Add("mainWidth", 695);
if (!settingsObject.ContainsKey("mainHeight"))
settingsObject.Add("mainHeight", 690);
settingsObject["mainWidth"] = curWidth;
settingsObject["mainHeight"] = curHeight;
string updatedJSON = settingsObject.ToString();
File.WriteAllText(settingsFile, updatedJSON);
}
}
public void checkThirdPartyApps(string path)
{
if (appDict.Count > 0)
{
string readOptions = File.ReadAllText(optionsFile);
JObject readObject = JObject.Parse(readOptions);
bool DisableTPA = (bool)readObject["DisableTPA"];
if (!DisableTPA)
{
try
{
thirdPartyContent = new string[] { };
}
catch (Exception err)
{
Debug.WriteLine($"ERROR: {err}");
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);
}
Array.Resize(ref thirdPartyContent, thirdPartyContent.Length + 1);
thirdPartyContent[thirdPartyContent.Length - 1] = "Add new tool";
string userFolder = Path.Combine(Properties.Settings.Default.server_path, "user");
string modsFolder = Path.Combine(userFolder, "mods");
foreach (var app in appDict)
{
string appName = app.Key;
ThirdPartyInfo appInfo = app.Value;
string _name = appInfo.Name;
string _path = appInfo.Path;
if (_path.ToLower().StartsWith("mods"))
{
string newPath = _path.ToLower().Replace("mods", modsFolder);
Array.Resize(ref thirdPartyContent, thirdPartyContent.Length + 1);
thirdPartyContent[thirdPartyContent.Length - 1] = _name;
}
else
{
Array.Resize(ref thirdPartyContent, thirdPartyContent.Length + 1);
thirdPartyContent[thirdPartyContent.Length - 1] = _name;
}
}
Label lastItem = null;
foreach (Control ctrl in boxSelectedServer.Controls)
{
if (ctrl is Label lbl)
{
lastItem = lbl;
}
}
for (int i = 0; i < thirdPartyContent.Length; i++)
{
Label lbl = new Label();
lbl.AutoSize = false;
lbl.Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
lbl.TextAlign = ContentAlignment.MiddleLeft;
lbl.Size = new Size(boxSelectedServer.Size.Width, boxSelectedServerPlaceholder.Size.Height);
lbl.Location = new Point(lastItem.Location.X, lastItem.Location.Y + 30 + (i * 30));
lbl.Cursor = Cursors.Hand;
lbl.Margin = new Padding(1, 1, 1, 1);
lbl.MouseEnter += new EventHandler(lbl2_MouseEnter);
lbl.MouseLeave += new EventHandler(lbl2_MouseLeave);
lbl.MouseDown += new MouseEventHandler(lbl2_MouseDown);
lbl.MouseUp += new MouseEventHandler(lbl2_MouseUp);
lbl.Name = $"thirdparty_{thirdPartyContent[i].ToLower()}";
if (thirdPartyContent[i].ToLower() == "add new tool")
{
lbl.Text = thirdPartyContent[i];
}
else
{
lbl.Text = $"Open {thirdPartyContent[i]}";
}
lbl.BackColor = listBackcolor;
lbl.ForeColor = Color.LightGray;
lbl.Font = new Font("Bahnschrift Light", 9, FontStyle.Regular);
boxSelectedServer.Controls.Add(lbl);
}
}
}
/*
string loepath = Path.Combine(path, "user\\mods\\Load Order Editor.exe");
if (File.Exists(loepath))
{
Properties.Settings.Default.loe_path = loepath;
Properties.Settings.Default.Save();
serverOptionsStreets[11] = "Open Load Order Editor (LOE)";
}
else
{
Properties.Settings.Default.loe_path = "";
Properties.Settings.Default.Save();
serverOptionsStreets[11] = "LOE not detected - click to download";
}
string progFiles = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
if (Directory.Exists(Path.Combine(progFiles, "SPT-AKI Profile Editor")) &&
File.Exists(Path.Combine(progFiles, "SPT-AKI Profile Editor\\SPT-AKI Profile Editor.exe")))
{
Properties.Settings.Default.profile_editor_path = Path.Combine(progFiles, "SPT-AKI Profile Editor");
Properties.Settings.Default.Save();
serverOptionsStreets[12] = "Open Profile Editor";