Skip to content

Commit a297d64

Browse files
committed
Modpack import now pre-calculates which files to import, rather than constantly re-checking the ModList file mid batch import.
1 parent 121c610 commit a297d64

File tree

1 file changed

+29
-15
lines changed
  • xivModdingFramework/Mods/FileTypes

1 file changed

+29
-15
lines changed

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.IO;
2222
using System.IO.Compression;
2323
using System.Linq;
24+
using System.Threading;
2425
using System.Threading.Tasks;
2526
using xivModdingFramework.Cache;
2627
using xivModdingFramework.General.Enums;
@@ -429,6 +430,28 @@ public string GetVersion(DirectoryInfo modPackDirectory)
429430
// (Could result in improper parent file calculations, as the parent files may not be actually imported yet)
430431
XivCache.CacheWorkerEnabled = false;
431432

433+
434+
// Loop through all the incoming mod entries, and only take
435+
// the *LAST* mod json entry for each file path.
436+
// This keeps us from having to constantly re-query the mod list file, and filters out redundant imports.
437+
var filePaths = new HashSet<string>();
438+
var newList = new List<ModsJson>(modsJson.Count);
439+
for(int i = modsJson.Count -1; i >= 0; i--)
440+
{
441+
var mj = modsJson[i];
442+
if(filePaths.Contains(mj.FullPath))
443+
{
444+
// Already have a mod using this path, discard this mod entry.
445+
continue;
446+
}
447+
448+
filePaths.Add(mj.FullPath);
449+
newList.Add(mj);
450+
}
451+
modsJson = newList;
452+
453+
var importCount = 0;
454+
432455
try
433456
{
434457
foreach (var modListMod in modList.Mods)
@@ -473,31 +496,22 @@ where entry.fullPath.Equals(modJson.FullPath)
473496

474497
var data = binaryReader.ReadBytes(modJson.ModSize);
475498

476-
await dat.WriteToDat(new List<byte>(data), existingEntry,
499+
await (dat.WriteToDat(new List<byte>(data), existingEntry,
477500
modJson.FullPath,
478501
modJson.Category.GetDisplayName(), modJson.Name,
479502
XivDataFiles.GetXivDataFile(modJson.DatFile), _source,
480-
GetDataType(modJson.FullPath), modJson.ModPackEntry);
503+
GetDataType(modJson.FullPath), modJson.ModPackEntry));
481504
}
482505
else
483506
{
484507
binaryReader.BaseStream.Seek(modJson.ModOffset, SeekOrigin.Begin);
485508

486509
var data = binaryReader.ReadBytes(modJson.ModSize);
487510

488-
await dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
511+
await (dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
489512
modJson.Category.GetDisplayName(), modJson.Name,
490513
XivDataFiles.GetXivDataFile(modJson.DatFile), _source,
491-
GetDataType(modJson.FullPath), modJson.ModPackEntry);
492-
493-
// Add this new entry into the mod list we're testing against
494-
// so we don't redundantly add files.
495-
var modListEntry = await modding.TryGetModEntry(modJson.FullPath);
496-
if (modListEntry != null)
497-
{
498-
modListFullPaths.Add(modJson.FullPath);
499-
modList.Mods.Add(modListEntry);
500-
}
514+
GetDataType(modJson.FullPath), modJson.ModPackEntry));
501515
}
502516
}
503517
catch (Exception ex)
@@ -511,10 +525,10 @@ await dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
511525
importErrors +=
512526
$"Name: {modJson.Name}\nPath: {modJson.FullPath}\nOffset: {modJson.ModOffset}\nError: {ex.Message}\n\n";
513527
}
528+
importCount++;
514529

515-
progress?.Report((modCount, modsJson.Count, string.Empty));
530+
progress?.Report((importCount, modsJson.Count, string.Empty));
516531

517-
modCount++;
518532
}
519533
}
520534
}

0 commit comments

Comments
 (0)