21
21
using System . IO ;
22
22
using System . IO . Compression ;
23
23
using System . Linq ;
24
+ using System . Threading ;
24
25
using System . Threading . Tasks ;
25
26
using xivModdingFramework . Cache ;
26
27
using xivModdingFramework . General . Enums ;
@@ -429,6 +430,28 @@ public string GetVersion(DirectoryInfo modPackDirectory)
429
430
// (Could result in improper parent file calculations, as the parent files may not be actually imported yet)
430
431
XivCache . CacheWorkerEnabled = false ;
431
432
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
+
432
455
try
433
456
{
434
457
foreach ( var modListMod in modList . Mods )
@@ -473,31 +496,22 @@ where entry.fullPath.Equals(modJson.FullPath)
473
496
474
497
var data = binaryReader . ReadBytes ( modJson . ModSize ) ;
475
498
476
- await dat . WriteToDat ( new List < byte > ( data ) , existingEntry ,
499
+ await ( dat . WriteToDat ( new List < byte > ( data ) , existingEntry ,
477
500
modJson . FullPath ,
478
501
modJson . Category . GetDisplayName ( ) , modJson . Name ,
479
502
XivDataFiles . GetXivDataFile ( modJson . DatFile ) , _source ,
480
- GetDataType ( modJson . FullPath ) , modJson . ModPackEntry ) ;
503
+ GetDataType ( modJson . FullPath ) , modJson . ModPackEntry ) ) ;
481
504
}
482
505
else
483
506
{
484
507
binaryReader . BaseStream . Seek ( modJson . ModOffset , SeekOrigin . Begin ) ;
485
508
486
509
var data = binaryReader . ReadBytes ( modJson . ModSize ) ;
487
510
488
- await dat . WriteToDat ( new List < byte > ( data ) , null , modJson . FullPath ,
511
+ await ( dat . WriteToDat ( new List < byte > ( data ) , null , modJson . FullPath ,
489
512
modJson . Category . GetDisplayName ( ) , modJson . Name ,
490
513
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 ) ) ;
501
515
}
502
516
}
503
517
catch ( Exception ex )
@@ -511,10 +525,10 @@ await dat.WriteToDat(new List<byte>(data), null, modJson.FullPath,
511
525
importErrors +=
512
526
$ "Name: { modJson . Name } \n Path: { modJson . FullPath } \n Offset: { modJson . ModOffset } \n Error: { ex . Message } \n \n ";
513
527
}
528
+ importCount ++ ;
514
529
515
- progress ? . Report ( ( modCount , modsJson . Count , string . Empty ) ) ;
530
+ progress ? . Report ( ( importCount , modsJson . Count , string . Empty ) ) ;
516
531
517
- modCount ++ ;
518
532
}
519
533
}
520
534
}
0 commit comments