Skip to content

Commit 68f58ee

Browse files
committed
Don't explode the world if Penumbra eats our mod folder, and fix mod tags stuff.
1 parent 91efef0 commit 68f58ee

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

xivModdingFramework/Mods/FileTypes/PMP.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
114114
{
115115
if (Path.GetFileName(file).StartsWith("group_") && Path.GetFileName(file).ToLower().EndsWith(".json"))
116116
{
117-
groups.Add(JsonConvert.DeserializeObject<PMPGroupJson>(File.ReadAllText(file)));
117+
var group = JsonConvert.DeserializeObject<PMPGroupJson>(File.ReadAllText(file));
118+
if (group != null)
119+
{
120+
groups.Add(group);
121+
}
118122
}
119123
}
120124

@@ -137,9 +141,10 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
137141
foreach(var o in g.Options)
138142
{
139143
var op = o as PmpStandardOptionJson;
140-
if(op != null)
144+
if (op != null)
141145
{
142-
foreach(var kv in op.Files)
146+
ValidateOption(op);
147+
foreach (var kv in op.Files)
143148
{
144149
var zipPath = kv.Value;
145150
allPmpFiles.Add(zipPath);
@@ -151,6 +156,7 @@ await IOUtil.UnzipFiles(path, tempFolder, (file) =>
151156
var defOp = pmp.DefaultMod as PmpStandardOptionJson;
152157
if(defOp != null)
153158
{
159+
ValidateOption(defOp);
154160
foreach (var kv in defOp.Files)
155161
{
156162
var zipPath = kv.Value;
@@ -190,6 +196,26 @@ private static bool IsPmpJsonFile(string file)
190196
return false;
191197
}
192198

199+
/// <summary>
200+
/// Preforms basic cleanup-validation on options.
201+
/// </summary>
202+
/// <param name="op"></param>
203+
private static void ValidateOption(PmpStandardOptionJson op)
204+
{
205+
if (op.Files == null)
206+
{
207+
op.Files = new Dictionary<string, string>();
208+
}
209+
if(op.Manipulations == null)
210+
{
211+
op.Manipulations = new List<PMPManipulationWrapperJson>();
212+
}
213+
if(op.FileSwaps == null)
214+
{
215+
op.FileSwaps = new Dictionary<string, string>();
216+
}
217+
}
218+
193219
/// <summary>
194220
/// Imports a given PMP File, Penumbra Folder, or Penumbra Folder Root JSON into the game files.
195221
/// </summary>
@@ -712,6 +738,7 @@ public static async Task CreateSimplePmp(string destination, BaseModpackData mod
712738
pmp.Meta.FileVersion = 3;
713739
pmp.Meta.Version = modpackMeta.Version.ToString();
714740
pmp.Meta.Website = modpackMeta.Url;
741+
pmp.Meta.ModTags = pmp.Meta.ModTags ?? new List<string>();
715742

716743

717744
await WritePmp(pmp, workingPath, zip ? destination : null);
@@ -734,6 +761,11 @@ public static async Task WritePmp(PMPJson pmp, string workingDirectory, string z
734761
var metapath = Path.Combine(workingDirectory, "meta.json");
735762
var defaultModPath = Path.Combine(workingDirectory, "default_mod.json");
736763

764+
if(pmp.Meta.ModTags == null)
765+
{
766+
pmp.Meta.ModTags = new List<string>();
767+
}
768+
737769
var metaString = JsonConvert.SerializeObject(pmp.Meta, Formatting.Indented);
738770
File.WriteAllText(metapath, metaString);
739771

xivModdingFramework/Mods/WizardData.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ protected override bool CheckHasData()
9292

9393
public void SortManipulations()
9494
{
95+
if(Manipulations == null)
96+
{
97+
Manipulations = new List<PMPManipulationWrapperJson>();
98+
}
99+
95100
Manipulations.Sort((a, b) =>
96101
{
97102
if (a == null || b == null)

xivModdingFramework/SqPack/FileTypes/TransactionDataHandler.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -833,20 +833,6 @@ internal void UNSAFE_AddFileInfo(FileStorageInformation storageInfo, XivDataFile
833833

834834
var di = new DirectoryInfo(dir);
835835

836-
var i = 0;
837-
if (di.EnumerateDirectories().Count() > 10)
838-
{
839-
// Sus...
840-
throw new Exception("Target Penumbra Mod Directory seems invalid. Please select an individual Penumbra mod folder or create a blank folder.");
841-
}
842-
843-
var files = di.EnumerateFiles();
844-
if (!files.Any(x => x.Extension.ToLower() == ".json"))
845-
{
846-
// Sus...
847-
throw new Exception("Target Penumbra Mod Directory seems invalid. Please select an individual Penumbra mod folder or create a blank folder.");
848-
}
849-
850836
var dict = await GetFinalWriteList(tx);
851837

852838
var pathName = di.Name;

0 commit comments

Comments
 (0)