@@ -50,6 +50,7 @@ public class TTMP
50
50
51
51
private readonly string _currentWizardTTMPVersion = "1.3w" ;
52
52
private readonly string _currentSimpleTTMPVersion = "1.3s" ;
53
+ private readonly string _currentBackupTTMPVersion = "1.0b" ;
53
54
private const string _minimumAssembly = "1.3.0.0" ;
54
55
55
56
private string _tempMPD , _tempMPL , _source ;
@@ -461,8 +462,9 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
461
462
/// <param name="progress">The progress of the import</param>
462
463
/// <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>
463
464
/// <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 )
466
468
{
467
469
if ( modsJson == null || modsJson . Count == 0 ) return ( 0 , 0 , "" , 0 ) ;
468
470
@@ -490,7 +492,7 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
490
492
// the *LAST* mod json entry for each file path.
491
493
// This keeps us from having to constantly re-query the mod list file, and filters out redundant imports.
492
494
var filePaths = new HashSet < string > ( ) ;
493
- var newList = new List < ModsJson > ( modsJson . Count ) ;
495
+ var filteredModsJson = new List < ModsJson > ( modsJson . Count ) ;
494
496
for ( int i = modsJson . Count - 1 ; i >= 0 ; i -- )
495
497
{
496
498
var mj = modsJson [ i ] ;
@@ -504,11 +506,10 @@ public static string GetVersion(DirectoryInfo modPackDirectory)
504
506
if ( ForbiddenModTypes . Contains ( Path . GetExtension ( mj . FullPath ) ) ) continue ;
505
507
506
508
filePaths . Add ( mj . FullPath ) ;
507
- newList . Add ( mj ) ;
509
+ filteredModsJson . Add ( mj ) ;
508
510
}
509
- modsJson = newList ;
510
511
511
- if ( modsJson . Count == 0 )
512
+ if ( filteredModsJson . Count == 0 )
512
513
{
513
514
return ( 0 , 0 , "" , 0 ) ;
514
515
}
@@ -577,7 +578,7 @@ await Task.Run(async () =>
577
578
progress . Report ( ( 0 , 0 , "Writing new mod data to DAT files..." ) ) ;
578
579
using ( var binaryReader = new BinaryReader ( new FileStream ( _tempMPD , FileMode . Open ) ) )
579
580
{
580
- foreach ( var modJson in modsJson )
581
+ foreach ( var modJson in filteredModsJson )
581
582
{
582
583
try
583
584
{
@@ -598,7 +599,7 @@ await Task.Run(async () =>
598
599
Mod mod = null ;
599
600
if ( modsByFile . ContainsKey ( modJson . FullPath ) )
600
601
{
601
- mod = modsByFile [ modJson . FullPath ] ;
602
+ mod = modsByFile [ modJson . FullPath ] ;
602
603
}
603
604
604
605
// Always write data to end of file during modpack imports in case we need
@@ -669,17 +670,23 @@ await Task.Run(async () =>
669
670
progress . Report ( ( count , totalFiles , "Updating Index file references..." ) ) ;
670
671
}
671
672
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 )
676
675
{
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
+ }
678
682
}
679
- var modPack = modList . ModPacks . First ( x => x . name == modsJson [ 0 ] . ModPackEntry . name ) ;
683
+
680
684
681
685
if ( GetRootConversionsFunction != null )
682
686
{
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 ) ;
683
690
684
691
Dictionary < XivDependencyRoot , ( XivDependencyRoot Root , int Variant ) > rootConversions = null ;
685
692
try
@@ -730,7 +737,7 @@ await Task.Run(async () =>
730
737
foreach ( var fileKv in convertedFiles )
731
738
{
732
739
// 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 ) ;
734
741
735
742
if ( fileKv . Key != fileKv . Value )
736
743
{
@@ -784,15 +791,15 @@ await Task.Run(async () =>
784
791
785
792
// Update the Mod List file.
786
793
787
-
788
794
foreach ( var file in filePaths )
789
795
{
790
796
if ( ErroneousFiles . Contains ( file ) ) continue ;
791
797
try
792
798
{
793
- var json = modsJson . FirstOrDefault ( x => x . FullPath == file ) ;
799
+ var json = filteredModsJson . FirstOrDefault ( x => x . FullPath == file ) ;
794
800
if ( json == null ) continue ;
795
801
802
+
796
803
var mod = modList . Mods . FirstOrDefault ( x => x . fullPath == file ) ;
797
804
var longOffset = ( ( long ) DatOffsets [ file ] ) * 8L ;
798
805
var originalOffset = OriginalOffsets [ file ] ;
@@ -827,13 +834,12 @@ await Task.Run(async () =>
827
834
mod . data . originalOffset = ( fileAdditionMod ? longOffset : longOriginal ) ;
828
835
mod . data . dataType = fileType ;
829
836
mod . enabled = true ;
830
- mod . modPack = modPack ;
837
+ mod . modPack = json . ModPackEntry ;
831
838
modList . Mods . Add ( mod ) ;
832
839
833
840
}
834
841
else
835
842
{
836
-
837
843
var fileAdditionMod = originalOffset == 0 || mod . IsCustomFile ( ) ;
838
844
if ( fileAdditionMod )
839
845
{
@@ -843,7 +849,7 @@ await Task.Run(async () =>
843
849
mod . data . modSize = size ;
844
850
mod . data . modOffset = longOffset ;
845
851
mod . enabled = true ;
846
- mod . modPack = modPack ;
852
+ mod . modPack = json . ModPackEntry ;
847
853
mod . data . dataType = fileType ;
848
854
mod . name = json . Name ;
849
855
mod . category = json . Category ;
@@ -938,7 +944,7 @@ await Task.Run(async () =>
938
944
count = 0 ;
939
945
progress . Report ( ( 0 , 0 , "Queuing Cache Updates..." ) ) ;
940
946
// 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 ( ) ;
942
948
try
943
949
{
944
950
XivCache . QueueDependencyUpdate ( files ) ;
0 commit comments