-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModHearthManager.cs
More file actions
749 lines (634 loc) · 27.6 KB
/
ModHearthManager.cs
File metadata and controls
749 lines (634 loc) · 27.6 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
using ModHearth.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ModHearth
{
/// <summary>
/// Config class, to store folder information.
/// </summary>
[Serializable]
public class ModHearthConfig
{
// Path to DF.exe
public string DFEXEPath { get; set; }
public string DFFolderPath => Path.GetDirectoryName(DFEXEPath);
public string ModsPath => Path.Combine(DFFolderPath, "Mods");
// Should this be in lightmode?
public int theme { get; set; }
}
[Serializable]
public struct ModProblem
{
public string problemThrowerID;
public string problemID;
public enum ProblemType
{
MissingBefore,
MissingAfter,
ConflictPresent
};
public ProblemType problemType;
public ModProblem(string problemThrowerID, string problemID, ProblemType problemType)
{
this.problemThrowerID = problemThrowerID;
this.problemID = problemID;
this.problemType = problemType;
}
public override string ToString()
{
switch(problemType)
{
case ProblemType.MissingBefore:
return $"Mod '{problemThrowerID}' requires mod '{problemID}' to be loaded before it.";
case ProblemType.MissingAfter:
return $"Mod '{problemThrowerID}' requires mod '{problemID}' to be loaded after it.";
case ProblemType.ConflictPresent:
return $"Mod '{problemThrowerID}' is incompatible with mod '{problemID}'.";
}
return "";
}
}
public class ModHearthManager
{
// Maps strings to ModReferences. The keys match DFHMods.ToString() perfectly. Given a value V, V.ToDFHMod.ToString() returns it's key.
private Dictionary<string, ModReference> modrefMap;
// Get a ModReference given a string key.
public ModReference GetModRef(string key) => modrefMap[key];
// Get a DFHMod given a string key.
public DFHMod GetDFHackMod(string key) => modrefMap[key].ToDFHMod();
// Get a ModReference given a DFHMod key.
public ModReference GetRefFromDFHMod(DFHMod dfmod) => modrefMap[dfmod.ToString()];
// The sorted list of enabled DFHmods. This list is modified by the form, and when saved it overwrites the list of a ModPack.
public List<DFHMod> enabledMods;
// The unsorted list of disabled DFHmods
public HashSet<DFHMod> disabledMods;
// The unsorted list of all available DFHmods
public HashSet<DFHMod> modPool;
// Get the currently selected modpack
public DFHModpack SelectedModlist => modpacks[selectedModlistIndex];
// List of all modpacks. After a modpack in this list is modified the list is saved to file.
public List<DFHModpack> modpacks;
// The index of the currently selected modpack.
public int selectedModlistIndex;
// The file config for this class.
private ModHearthConfig config;
// Paths.
private static readonly string configPath = "config.json";
private static readonly string stylePath = "style.json";
// Mod problem tracker.
public List<ModProblem> modproblems;
public ModHearthManager()
{
Console.WriteLine("Crafting Hearth");
// Get and load config file, fix if needed.
AttemptLoadConfig();
FixConfig();
// Find all mods and add to the lists.
FindAllModsDFHackLua();
// Find DFHModpacks, and fix them if needed.
FindModpacks();
// Write some info on found things.
Console.WriteLine();
Console.WriteLine($"Found {modrefMap.Count} mods and {modpacks.Count} modlists");
Console.WriteLine();
}
// Run the game.
public void RunDwarfFortress()
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\nStarting " + config.DFEXEPath);
Console.ForegroundColor = ConsoleColor.White;
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = config.DFEXEPath;
processInfo.ErrorDialog = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
processInfo.WorkingDirectory = Path.GetDirectoryName(config.DFEXEPath);
Process.Start(processInfo);
}
//??
public ModHearthConfig GetConfig()
{
return config;
}
private void FindAllModsDFHackLua()
{
// If game not running, prompt user to run it and force restart.
if (!DwarfFortressRunning())
{
// Only restart if user hits OK.
Console.WriteLine("DF not running");
DialogResult result = MessageBox.Show("Please launch dwarf fortress and navigate to the world creation screen. Application will restart when done.", "DF not running", MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
Process.Start(Application.ExecutablePath);
// More forceful shutdown.
MainForm.instance.selfClosing = true;
Application.Exit();
Environment.Exit(0);
// Needed?
return;
}
// Initialize relevant variables.
modrefMap = new Dictionary<string, ModReference>();
modPool = new HashSet<DFHMod>();
// Get all mod folders.
Console.WriteLine("Finding all mods... ");
HashSet<Dictionary<string, string>> modData = GetModMemoryData();
foreach (Dictionary<string, string> modDataEntry in modData)
{
// Directory correction.
modDataEntry["src_dir"] = Path.Combine(config.DFFolderPath, modDataEntry["src_dir"]);
// Mod setup and registry.
ModReference modRef = new ModReference(modDataEntry);
string key = modRef.DFHackCompatibleString();
Console.WriteLine($" Mod registered: {modRef.name}.");
modrefMap.Add(key, modRef);
modPool.Add(modRef.ToDFHMod());
}
}
// Output a dictionary, that given a modID gets the true version.
private HashSet<Dictionary<string, string>> GetModMemoryData()
{
HashSet<Dictionary<string, string>> modData = new HashSet<Dictionary<string, string>>();
// Load raw memory data string, and parse it with regex
string RawModData = LoadModMemoryData();
if (RawModData.StartsWith('0'))
{
// Only restart if user hits OK.
DialogResult result = MessageBox.Show("Please navigate to the world creation screen. Application will restart when done.", "DF works creation screen not open.", MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
Process.Start(Application.ExecutablePath);
// More forceful shutdown.
MainForm.instance.selfClosing = true;
Application.Exit();
Environment.Exit(0);
// Needed?
return null;
}
// Split into mods, then loop through and extract headers.
string[] singleModDataPairs = RawModData.Split("___");
Console.WriteLine("Mods found: " + singleModDataPairs.Length);
foreach (string simpleModDataPair in singleModDataPairs)
{
// Split into headers and non headers. Deserialize headers into dict.
string[] pairArr = simpleModDataPair.Split("===");
string[] nonHeaders = pairArr[0].Split('|');
Dictionary<string, string> headers = JsonSerializer.Deserialize<Dictionary<string, string>>(pairArr[1]);
modData.Add(headers);
Console.WriteLine(" Mod Found: " + headers["name"]);
// To see which headers there are to choose from.
//foreach (string k in headers.Keys)
//Console.WriteLine($"header found. k: {k}, v: {headers[k]}");
}
return modData;
}
// Use dfhack-run.exe and lua to get raw mod data.
private string LoadModMemoryData()
{
// Get path to lua script.
string luaPath = Path.Combine(Environment.CurrentDirectory, "GetModMemoryData.lua");
// Set up dfhack process.
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = Path.Combine(config.DFFolderPath, "dfhack-run.exe"),
WorkingDirectory = config.DFFolderPath,
Arguments = $"lua -f \"{luaPath}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
// Start dfhack process.
Process process = new Process
{
StartInfo = processStartInfo
};
process.Start();
// Get output string.
string output = process.StandardOutput.ReadToEnd();
// Wait for the process to exit.
process.WaitForExit();
//Console.WriteLine("output:\n" + output);
return output;
}
// Check if DF is running.
public bool DwarfFortressRunning()
{
foreach(Process process in Process.GetProcesses())
if (process.ProcessName.Equals("Dwarf Fortress"))
return true;
return false;
}
// Alter the current modpack with enabledMods and save modpack list to dfhack file.
public void SaveCurrentModpack()
{
SelectedModlist.modlist = new List<DFHMod>(enabledMods);
SaveAllModpacks();
}
// Save the DFHModpack list to file.
public void SaveAllModpacks()
{
Console.WriteLine("Modlists saved.");
// Get the path, serialize with right options, and write to file.
string dfHackModlistPath = Path.Combine(config.DFFolderPath, @"dfhack-config\mod-manager.json");
JsonSerializerOptions options = new JsonSerializerOptions
{
WriteIndented = true // Enable pretty formatting
};
string modlistJson = JsonSerializer.Serialize(modpacks, options);
File.WriteAllText(dfHackModlistPath, modlistJson);
}
public void SetSelectedModpack(int index)
{
// Regenerate enabled and disabled lists to match newly selected modpack.
selectedModlistIndex = index;
SetActiveMods(SelectedModlist.modlist);
// Find problems with newly selected modpack.
FindModlistProblems();
}
// Changes currently enabled and disabled mods based on the given list.
// The only time this is called (other than SetSelectedModpack) is when overwriting a modpack due to importing.
public void SetActiveMods(List<DFHMod> mods)
{
enabledMods = new List<DFHMod>();
disabledMods = new HashSet<DFHMod>(modPool);
for (int i = 0; i < mods.Count; i++)
{
enabledMods.Add(mods[i]);
disabledMods.Remove(mods[i]);
}
}
// Move a mod from one place to another. Has four cases, depending on source and destination.
public void MoveMod(ModReference mod, int newIndex, bool sourceLeft, bool destinationLeft)
{
// Convert mod to DFHMod.
DFHMod dfm = mod.ToDFHMod();
Console.WriteLine($"Mod '{dfm.id}' moved from " + (sourceLeft ? "dis" : "en") + "abled to " + (destinationLeft ? "dis" : "en") + "abled.");
if (sourceLeft && destinationLeft)
{
// Do nothing since the order of disabled mods doesn't matter.
return;
}
else if (!sourceLeft && !destinationLeft)
{
// Get the old index of the mod
int oldIndex = enabledMods.IndexOf(dfm);
// If the mod is removed from the old index, and it would shift the whole list down, account for that.
if (oldIndex < newIndex)
newIndex--;
if (oldIndex < 0)
{
Console.WriteLine("Clicking too fast, attempted to disable same mod twice.");
return;
}
// Remove from old index and insert at the new index (or add if at end of list).
enabledMods.RemoveAt(oldIndex);
if (newIndex == enabledMods.Count)
enabledMods.Add(dfm);
else
enabledMods.Insert(newIndex, dfm);
}
else if (!sourceLeft && destinationLeft)
{
// Remove the mod from enabled list, and toss into disabled list (order doesn't matter).
enabledMods.Remove(dfm);
disabledMods.Add(dfm);
}
else if (sourceLeft && !destinationLeft)
{
// Insert/add from disabled to enabled.
disabledMods.Remove(dfm);
if (newIndex == enabledMods.Count)
enabledMods.Add(dfm);
else
enabledMods.Insert(newIndex, dfm);
}
// Refind mod problems since mod order changed.
FindModlistProblems();
}
// Go through modlist and scan for problems.
// Tuple representing problem has problem mod, int problemType (missing before, missing after, conflict present), and string modID.
public void FindModlistProblems()
{
// Set up list of problems to return.
modproblems = new List<ModProblem>();
// Set up a hashset of scanned mods and unscanned mods, for determining load order.
HashSet<string> scannedModIDs = new HashSet<string>();
HashSet<string> unscannedModIDs = new HashSet<string>();
// Add all enabled mod IDs to unscanned.
foreach (DFHMod dfm in enabledMods)
{
unscannedModIDs.Add(dfm.id.ToLower());
}
// Loop through enabled mods, doing a mock load.
for (int i = 0; i < enabledMods.Count; i++)
{
DFHMod currentDFM = enabledMods[i];
ModReference currentMod = GetRefFromDFHMod(currentDFM);
// Check for problems.
if (currentMod.problematic)
{
foreach (string beforeID in currentMod.require_before_me)
if (!scannedModIDs.Contains(beforeID.ToLower()))
{
modproblems.Add(new ModProblem(currentDFM.id, beforeID, ModProblem.ProblemType.MissingBefore));
//Console.WriteLine("Problem found: missing before mod with ID: " + beforeID + " mod needing is: " + currentDFM.id);
}
foreach (string afterID in currentMod.require_after_me)
if (!unscannedModIDs.Contains(afterID.ToLower()))
{
modproblems.Add(new ModProblem(currentDFM.id, afterID, ModProblem.ProblemType.MissingAfter));
//Console.WriteLine("Problem found: missing after mod with ID: " + afterID + " mod needing is: " + currentDFM.id);
}
foreach (string conflictID in currentMod.conflicts_with)
if (scannedModIDs.Contains(conflictID.ToLower()) || unscannedModIDs.Contains(conflictID.ToLower()) )
{
modproblems.Add(new ModProblem(currentDFM.id, conflictID, ModProblem.ProblemType.ConflictPresent));
//Console.WriteLine("Problem found: conflict present mod with ID: " + conflictID + " mod needing is: " + currentDFM.id);
}
}
// Move to scanned.
scannedModIDs.Add(currentDFM.id.ToLower());
unscannedModIDs.Remove(currentDFM.id.ToLower());
}
}
#region initialization file stuff
// Find modpacks from dfhack mod-manager config file.
private void FindModpacks()
{
// Get paths and read file. #TODO: handling the file not existing.
string dfHackModpackPath = Path.Combine(config.DFFolderPath, @"dfhack-config\mod-manager.json");
string dfHackModpackJson = File.ReadAllText(dfHackModpackPath);
modpacks = new List<DFHModpack>(JsonSerializer.Deserialize<List<DFHModpack>>(dfHackModpackJson));
Console.WriteLine();
Console.WriteLine("Found modlists: ");
// Handle mods missing.
bool modMissing = false;
string missingMessage = $"Some mods missing. \nModlists will be modified to not require lost mods. \nMissing mods: ";
HashSet<DFHMod> notFound = new HashSet<DFHMod>();
// If a default modpack exists.
bool defaultFound = false;
// Go through modpacks, and go through their modlists, looking for mods that we don't have.
for (int i = 0; i < modpacks.Count; i++)
{
DFHModpack modlist = modpacks[i];
HashSet<DFHMod> thisListMissingMods = new HashSet<DFHMod>();
foreach(DFHMod mod in modlist.modlist)
{
if(!modPool.Contains(mod))
{
modMissing = true;
notFound.Add(mod);
thisListMissingMods.Add(mod);
missingMessage += $"\n{mod}";
}
}
// Remove the missing mods from the modlist.
foreach(DFHMod m in thisListMissingMods)
{
modlist.modlist.Remove(m);
}
// Write out some info on the modpack
Console.WriteLine(" Name: " + modlist.name);
Console.WriteLine(" Default: " + modlist.@default);
Console.WriteLine(" Mods count: " + modlist.modlist.Count);
Console.WriteLine();
// If this is the default modpack, set index to that.
if (modlist.@default)
{
SetSelectedModpack(i);
defaultFound = true;
}
// Set modpacks[i] back to this modpack. #FIXME: why is this necessary? Isn't modpack a reference type?
modpacks[i] = modlist;
}
// Set default as backup.
if (!defaultFound)
{
SetSelectedModpack(0);
modpacks[0].@default = true;
SaveAllModpacks();
}
// Create default modpack if none present.
if(modpacks.Count == 0)
{
DFHModpack newPack = new DFHModpack(true, new List<DFHMod>(), "Default");
// FIXME: generate vanilla modpack in a better way than this
newPack.modlist = GenerateVanillaModlist();
}
// Pop up a message notifying the user that the missing mods have been removed.
if(modMissing)
{
MessageBox.Show(missingMessage, "Missing Mods", MessageBoxButtons.OK);
}
}
// Generated a vanilla modlist using manually generated mod ID list.
public List<DFHMod> GenerateVanillaModlist()
{
// Manually made vanilla modlist.
List<string> vanillaModIDList = new List<string>()
{
"vanilla_text",
"vanilla_languages",
"vanilla_descriptors",
"vanilla_materials",
"vanilla_environment",
"vanilla_plants",
"vanilla_items",
"vanilla_buildings",
"vanilla_bodies",
"vanilla_creatures",
"vanilla_entities",
"vanilla_reactions",
"vanilla_interactions",
"vanilla_descriptors_graphics",
"vanilla_plants_graphics",
"vanilla_items_graphics",
"vanilla_buildings_graphics",
"vanilla_creatures_graphics",
"vanilla_world_map",
"vanilla_interface",
"vanilla_music",
};
// Get all mods that are probably vanilla.
Dictionary<string, DFHMod> vanillaPool = new Dictionary<string, DFHMod>();
foreach (DFHMod dfm in modPool)
{
if (dfm.id.ToLower().Contains("vanilla"))
{
vanillaPool.Add(dfm.id, dfm);
Console.WriteLine("added mod with id " + dfm.id);
}
}
// Load vanilla mods into pack.
List<DFHMod> vanillaList = new List<DFHMod>();
for (int i = 0; i < vanillaModIDList.Count; i++)
{
Console.WriteLine("looking for mod with id " + vanillaModIDList[i]);
vanillaList.Add(vanillaPool[vanillaModIDList[i]]);
}
return vanillaList;
}
// Get the theme from config.
public int GetTheme()
{
return config.theme;
}
// Save the theme to config file.
public void SetTheme(int theme)
{
config.theme = theme;
SaveConfigFile();
}
// Fix the config file if it's broken or missing.
public void FixConfig()
{
// If it's missing create it.
if (config == null)
config = new ModHearthConfig();
// If it's missing the path to dwarf fortress executable, get the path.
if (String.IsNullOrEmpty(config.DFEXEPath))
{
Console.WriteLine("Config file missing DF path.");
string newPath = "";
while (string.IsNullOrEmpty(newPath))
{
newPath = GetDFPath();
}
config.DFEXEPath = newPath;
}
// Save the fixed config file.
SaveConfigFile();
}
// Destroy the config file, to be remade.
public void DestroyConfig()
{
if (File.Exists(configPath))
{
File.Delete(configPath);
}
}
// Get the path to the dwarf fortress executable from the user.
private string GetDFPath()
{
LocationMessageBox.Show("Please find the path to your Dwarf Fortress.exe.", "DF.exe location", MessageBoxButtons.OK);
OpenFileDialog dfFileDialog = new OpenFileDialog();
dfFileDialog.Filter = "Executable files (*.exe)|Dwarf Fortress.exe";
DialogResult result = dfFileDialog.ShowDialog();
if (result == DialogResult.OK)
{
string selectedFilePath = dfFileDialog.FileName;
Console.WriteLine("DF path set to: " + selectedFilePath);
return selectedFilePath;
}
return "";
}
// Attmempt loading config. If broken or failed, run FixConfig.
public void AttemptLoadConfig()
{
Console.WriteLine("Attempting config file load.");
try
{
if (File.Exists(configPath))
{
Console.WriteLine("Config file found.");
string jsonContent = File.ReadAllText(configPath);
// Deserialize the JSON content into an object
config = JsonSerializer.Deserialize<ModHearthConfig>(jsonContent);
if (config == null)
{
Console.WriteLine("Config file borked.");
FixConfig();
}
}
else
{
Console.WriteLine("Config file missing.");
FixConfig();
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
config = null;
FixConfig();
}
}
// Save the config to file.
public void SaveConfigFile()
{
Console.WriteLine("Config saved.");
JsonSerializerOptions options = new JsonSerializerOptions
{
WriteIndented = true // Enable pretty formatting
};
string jsonContent = JsonSerializer.Serialize(config);
File.WriteAllText(configPath, jsonContent);
}
// Try to load style file.
public Style LoadStyle()
{
Style style = new Style();
try
{
if (File.Exists(stylePath))
{
Console.WriteLine("Style file found.");
string jsonContent = File.ReadAllText(stylePath);
// Deserialize the JSON content into an object
Style foundStyle = JsonSerializer.Deserialize<Style>(jsonContent);
// If broken, save working one, otherwise, use found one.
if (foundStyle == null)
{
Console.WriteLine("Style file borked. Style regenerated.");
style = Style.lightModeStyle();
SaveStyle(style);
}
else
{
style = foundStyle;
}
}
else
{
Console.WriteLine("Style file missing. New style reated.");
style = Style.lightModeStyle();
SaveStyle(style);
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
// Set global instance and return.
Style.instance = style;
return style;
}
// Save the style to file.
private void SaveStyle(Style style)
{
Console.WriteLine("Style saved.");
JsonSerializerOptions options = new JsonSerializerOptions
{
WriteIndented = true // Enable pretty formatting
};
string jsonContent = JsonSerializer.Serialize(style, options);
File.WriteAllText(stylePath, jsonContent);
}
#endregion
}
}