Skip to content

Commit 39be781

Browse files
committed
Replaced all instances of ModList file serialize/deserialize with GetModList/SaveModList
1 parent 0cd0d03 commit 39be781

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public string GetVersion(DirectoryInfo modPackDirectory)
421421
var dat = new Dat(gameDirectory);
422422
var modding = new Modding(gameDirectory);
423423
var modListFullPaths = new List<string>();
424-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(modListDirectory.FullName));
424+
var modList = modding.GetModList();
425425
var modCount = 1;
426426
var importErrors = "";
427427

@@ -530,7 +530,7 @@ await dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
530530

531531
if (modsJson[0].ModPackEntry != null)
532532
{
533-
modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(modListDirectory.FullName));
533+
modList = modding.GetModList();
534534

535535
// TODO - Probably need to look at keying this off more than just the name.
536536
var modPackExists = modList.ModPacks.Any(modpack => modpack.name == modsJson[0].ModPackEntry.name);
@@ -540,7 +540,7 @@ await dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
540540
modList.ModPacks.Add(modsJson[0].ModPackEntry);
541541
}
542542

543-
File.WriteAllText(modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
543+
modding.SaveModList(modList);
544544
}
545545
} finally
546546
{

xivModdingFramework/Mods/Modding.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ public ModList GetModList()
5656
{
5757
return JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
5858
}
59+
60+
public void SaveModList(ModList ml)
61+
{
62+
SaveModList(modList);
63+
}
64+
5965
public async Task DeleteAllFilesAddedByTexTools()
6066
{
61-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
67+
var modList = GetModList();
6268
var modsToRemove = modList.Mods.Where(it => it.source == "FilesAddedByTexTools");
6369
foreach(var mod in modsToRemove)
6470
{
@@ -85,7 +91,7 @@ public void CreateModlist()
8591
Mods = new List<Mod>()
8692
};
8793

88-
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
94+
SaveModList(modList);
8995
}
9096

9197
/// <summary>
@@ -99,7 +105,7 @@ public Task<Mod> TryGetModEntry(string internalFilePath)
99105
{
100106
internalFilePath = internalFilePath.Replace("\\", "/");
101107

102-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
108+
var modList = GetModList();
103109

104110
if (modList == null) return null;
105111

@@ -218,15 +224,15 @@ public async Task ToggleModStatus(string internalFilePath, bool enable)
218224

219225
var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
220226

221-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(modListDirectory.FullName));
227+
var modList = GetModList();
222228

223229
var entryEnableUpdate = (from entry in modList.Mods
224230
where entry.fullPath.Equals(modEntry.fullPath)
225231
select entry).FirstOrDefault();
226232

227233
entryEnableUpdate.enabled = enable;
228234

229-
File.WriteAllText(modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
235+
SaveModList(modList);
230236
}
231237

232238
/// <summary>
@@ -238,7 +244,7 @@ public async Task ToggleModPackStatus(string modPackName, bool enable)
238244
{
239245
var index = new Index(_gameDirectory);
240246

241-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
247+
var modList = GetModList();
242248
var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
243249
List<Mod> mods = null;
244250

@@ -279,7 +285,7 @@ public async Task ToggleModPackStatus(string modPackName, bool enable)
279285
}
280286
}
281287

282-
File.WriteAllText(modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
288+
SaveModList(modList);
283289
}
284290

285291
/// <summary>
@@ -290,9 +296,9 @@ public async Task ToggleAllMods(bool enable, IProgress<(int current, int total,
290296
{
291297
var index = new Index(_gameDirectory);
292298

293-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
299+
var modList = GetModList();
294300

295-
if(modList == null || modList.modCount == 0) return;
301+
if (modList == null || modList.modCount == 0) return;
296302

297303
var modNum = 0;
298304
foreach (var modEntry in modList.Mods)
@@ -359,7 +365,7 @@ public async Task DisableOldModList(DirectoryInfo oldModListDirectory)
359365
/// <param name="modItemPath">The mod item path of the mod to delete</param>
360366
public async Task DeleteMod(string modItemPath)
361367
{
362-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
368+
var modList = GetModList();
363369

364370
var modToRemove = (from mod in modList.Mods
365371
where mod.fullPath.Equals(modItemPath)
@@ -396,7 +402,7 @@ where mod.fullPath.Equals(modItemPath)
396402
modList.modCount -= 1;
397403

398404

399-
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
405+
SaveModList(modList);
400406
}
401407

402408
/// <summary>
@@ -405,7 +411,7 @@ where mod.fullPath.Equals(modItemPath)
405411
/// <param name="modPackName">The name of the Mod Pack to be deleted</param>
406412
public async Task DeleteModPack(string modPackName)
407413
{
408-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(ModListDirectory.FullName));
414+
var modList = GetModList();
409415

410416
var modPackItem = (from modPack in modList.ModPacks
411417
where modPack.name.Equals(modPackName)
@@ -454,7 +460,7 @@ where modPack.name.Equals(modPackName)
454460
modList.modCount -= modRemoveCount;
455461
modList.modPackCount -= 1;
456462

457-
File.WriteAllText(ModListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
463+
SaveModList(modList);
458464
}
459465
}
460466
}

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,8 @@ public async Task<int> WriteToDat(List<byte> importData, Mod modEntry, string in
13511351

13521352
dataOverwritten = true;
13531353

1354-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(_modListDirectory.FullName));
1354+
var modding = new Modding(_gameDirectory);
1355+
var modList = modding.GetModList();
13551356

13561357
var entryEnableUpdate = (from entry in modList.Mods
13571358
where entry.fullPath.Equals(modEntry.fullPath)
@@ -1364,7 +1365,7 @@ where entry.fullPath.Equals(modEntry.fullPath)
13641365
entryEnableUpdate.modPack = modPack;
13651366
}
13661367

1367-
File.WriteAllText(_modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
1368+
modding.SaveModList(modList);
13681369
}
13691370
}
13701371
else
@@ -1374,7 +1375,8 @@ where entry.fullPath.Equals(modEntry.fullPath)
13741375
* write the compressed data in the existing space.
13751376
*/
13761377

1377-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(_modListDirectory.FullName));
1378+
var modding = new Modding(_gameDirectory);
1379+
var modList = modding.GetModList();
13781380

13791381
if (modList != null && modList.emptyCount > 0)
13801382
{
@@ -1452,7 +1454,7 @@ where entry.fullPath.Equals(modEntry.fullPath)
14521454
modList.emptyCount -= 1;
14531455
modList.modCount += 1;
14541456

1455-
File.WriteAllText(_modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
1457+
modding.SaveModList(modList);
14561458

14571459
offset = mod.data.modOffset;
14581460

@@ -1528,7 +1530,8 @@ where entry.fullPath.Equals(modEntry.fullPath)
15281530
{
15291531
if (offset != 0)
15301532
{
1531-
var modList = JsonConvert.DeserializeObject<ModList>(File.ReadAllText(_modListDirectory.FullName));
1533+
var modding = new Modding(_gameDirectory);
1534+
var modList = modding.GetModList();
15321535
if (NewFilesNeedToBeAdded)
15331536
{
15341537
var success = true;
@@ -1589,7 +1592,7 @@ where entry.fullPath.Equals(modEntry.fullPath)
15891592

15901593
modList.modCount += 1;
15911594

1592-
File.WriteAllText(_modListDirectory.FullName, JsonConvert.SerializeObject(modList, Formatting.Indented));
1595+
modding.SaveModList(modList);
15931596
}
15941597
}
15951598

0 commit comments

Comments
 (0)