Skip to content

Commit 7f38b5d

Browse files
committed
ListBox
1 parent 6f554ea commit 7f38b5d

File tree

1 file changed

+27
-21
lines changed
  • xivModdingFramework/Mods/FileTypes

1 file changed

+27
-21
lines changed

xivModdingFramework/Mods/FileTypes/TTMP.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class TTMP
5050

5151
private readonly string _currentWizardTTMPVersion = "1.3w";
5252
private readonly string _currentSimpleTTMPVersion = "1.3s";
53+
private readonly string _currentBackupTTMPVersion = "1.0b";
5354
private const string _minimumAssembly = "1.3.0.0";
5455

5556
private string _tempMPD, _tempMPL, _source;
@@ -461,8 +462,9 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
461462
/// <param name="progress">The progress of the import</param>
462463
/// <param name="GetRootConversionsFunction">Function called part-way through import to resolve rood conversions, if any are desired. Function takes a List of files, the in-progress modified index and modlist files, and returns a dictionary of conversion data. If this function throws and OperationCancelledException, the import is cancelled.</param>
463464
/// <returns>The number of total mods imported</returns>
464-
public async Task<(int ImportCount, int ErrorCount, string Errors, float Duration)> ImportModPackAsync(DirectoryInfo modPackDirectory, List<ModsJson> modsJson,
465-
DirectoryInfo gameDirectory, DirectoryInfo modListDirectory, IProgress<(int current, int total, string message)> progress, Func<HashSet<string>, Dictionary<XivDataFile, IndexFile>, ModList, Task<Dictionary<XivDependencyRoot, (XivDependencyRoot Root, int Variant)>>> GetRootConversionsFunction = null )
465+
public async Task<(int ImportCount, int ErrorCount, string Errors, float Duration)> ImportModPackAsync(
466+
DirectoryInfo modPackDirectory, List<ModsJson> modsJson, DirectoryInfo gameDirectory, DirectoryInfo modListDirectory, IProgress<(int current, int total, string message)> progress,
467+
Func<HashSet<string>, Dictionary<XivDataFile, IndexFile>, ModList, Task<Dictionary<XivDependencyRoot, (XivDependencyRoot Root, int Variant)>>> GetRootConversionsFunction = null)
466468
{
467469
if (modsJson == null || modsJson.Count == 0) return (0, 0, "", 0);
468470

@@ -490,7 +492,7 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
490492
// the *LAST* mod json entry for each file path.
491493
// This keeps us from having to constantly re-query the mod list file, and filters out redundant imports.
492494
var filePaths = new HashSet<string>();
493-
var newList = new List<ModsJson>(modsJson.Count);
495+
var filteredModsJson = new List<ModsJson>(modsJson.Count);
494496
for(int i = modsJson.Count -1; i >= 0; i--)
495497
{
496498
var mj = modsJson[i];
@@ -504,11 +506,10 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
504506
if (ForbiddenModTypes.Contains(Path.GetExtension(mj.FullPath))) continue;
505507

506508
filePaths.Add(mj.FullPath);
507-
newList.Add(mj);
509+
filteredModsJson.Add(mj);
508510
}
509-
modsJson = newList;
510511

511-
if(modsJson.Count == 0)
512+
if(filteredModsJson.Count == 0)
512513
{
513514
return (0, 0, "", 0);
514515
}
@@ -577,7 +578,7 @@ await Task.Run(async () =>
577578
progress.Report((0, 0, "Writing new mod data to DAT files..."));
578579
using (var binaryReader = new BinaryReader(new FileStream(_tempMPD, FileMode.Open)))
579580
{
580-
foreach (var modJson in modsJson)
581+
foreach (var modJson in filteredModsJson)
581582
{
582583
try
583584
{
@@ -598,7 +599,7 @@ await Task.Run(async () =>
598599
Mod mod = null;
599600
if (modsByFile.ContainsKey(modJson.FullPath))
600601
{
601-
mod= modsByFile[modJson.FullPath];
602+
mod = modsByFile[modJson.FullPath];
602603
}
603604

604605
// Always write data to end of file during modpack imports in case we need
@@ -669,17 +670,23 @@ await Task.Run(async () =>
669670
progress.Report((count, totalFiles, "Updating Index file references..."));
670671
}
671672

672-
673-
var modPackExists = modList.ModPacks.Any(modpack => modpack.name == modsJson[0].ModPackEntry.name);
674-
675-
if (!modPackExists)
673+
// Add entries for new modpacks to the mod list
674+
foreach (var modsJson in filteredModsJson)
676675
{
677-
modList.ModPacks.Add(modsJson[0].ModPackEntry);
676+
var modPackExists = modList.ModPacks.Any(modpack => modpack.name == modsJson.ModPackEntry.name);
677+
678+
if (!modPackExists)
679+
{
680+
modList.ModPacks.Add(modsJson.ModPackEntry);
681+
}
678682
}
679-
var modPack = modList.ModPacks.First(x => x.name == modsJson[0].ModPackEntry.name);
683+
680684

681685
if (GetRootConversionsFunction != null)
682686
{
687+
// Get the modpack to list the conversions under, this is the just the modpack entry of the first modsJson since they're all the same unless it's a backup
688+
// However, this code isn't used for importing backup modpacks since they already had the choice to change the destination item after the initial import
689+
var modPack = modList.ModPacks.First(x => x.name == filteredModsJson[0].ModPackEntry.name);
683690

684691
Dictionary<XivDependencyRoot, (XivDependencyRoot Root, int Variant)> rootConversions = null;
685692
try
@@ -730,7 +737,7 @@ await Task.Run(async () =>
730737
foreach (var fileKv in convertedFiles)
731738
{
732739
// Remove the file from our json list, the conversion already handled everything we needed to do with it.
733-
var json = modsJson.RemoveAll(x => x.FullPath == fileKv.Key);
740+
var json = filteredModsJson.RemoveAll(x => x.FullPath == fileKv.Key);
734741

735742
if (fileKv.Key != fileKv.Value)
736743
{
@@ -784,15 +791,15 @@ await Task.Run(async () =>
784791

785792
// Update the Mod List file.
786793

787-
788794
foreach (var file in filePaths)
789795
{
790796
if (ErroneousFiles.Contains(file)) continue;
791797
try
792798
{
793-
var json = modsJson.FirstOrDefault(x => x.FullPath == file);
799+
var json = filteredModsJson.FirstOrDefault(x => x.FullPath == file);
794800
if (json == null) continue;
795801

802+
796803
var mod = modList.Mods.FirstOrDefault(x => x.fullPath == file);
797804
var longOffset = ((long)DatOffsets[file]) * 8L;
798805
var originalOffset = OriginalOffsets[file];
@@ -827,13 +834,12 @@ await Task.Run(async () =>
827834
mod.data.originalOffset = (fileAdditionMod ? longOffset : longOriginal);
828835
mod.data.dataType = fileType;
829836
mod.enabled = true;
830-
mod.modPack = modPack;
837+
mod.modPack = json.ModPackEntry;
831838
modList.Mods.Add(mod);
832839

833840
}
834841
else
835842
{
836-
837843
var fileAdditionMod = originalOffset == 0 || mod.IsCustomFile();
838844
if (fileAdditionMod)
839845
{
@@ -843,7 +849,7 @@ await Task.Run(async () =>
843849
mod.data.modSize = size;
844850
mod.data.modOffset = longOffset;
845851
mod.enabled = true;
846-
mod.modPack = modPack;
852+
mod.modPack = json.ModPackEntry;
847853
mod.data.dataType = fileType;
848854
mod.name = json.Name;
849855
mod.category = json.Category;
@@ -938,7 +944,7 @@ await Task.Run(async () =>
938944
count = 0;
939945
progress.Report((0, 0, "Queuing Cache Updates..."));
940946
// Metadata files expanded, last thing is to queue everthing up for the Cache.
941-
var files = modsJson.Select(x => x.FullPath).ToList();
947+
var files = filteredModsJson.Select(x => x.FullPath).ToList();
942948
try
943949
{
944950
XivCache.QueueDependencyUpdate(files);

0 commit comments

Comments
 (0)