@@ -60,12 +60,18 @@ public void UpdateIndexDatCount(XivDataFile dataFile, int datNum)
60
60
foreach ( var indexPath in indexPaths )
61
61
{
62
62
_semaphoreSlim . Wait ( ) ;
63
- using ( var bw = new BinaryWriter ( File . OpenWrite ( indexPath ) ) )
63
+ try
64
64
{
65
- bw . BaseStream . Seek ( 1104 , SeekOrigin . Begin ) ;
66
- bw . Write ( datCount ) ;
65
+ using ( var bw = new BinaryWriter ( File . OpenWrite ( indexPath ) ) )
66
+ {
67
+ bw . BaseStream . Seek ( 1104 , SeekOrigin . Begin ) ;
68
+ bw . Write ( datCount ) ;
69
+ }
70
+ }
71
+ finally
72
+ {
73
+ _semaphoreSlim . Release ( ) ;
67
74
}
68
- _semaphoreSlim . Release ( ) ;
69
75
}
70
76
}
71
77
@@ -261,33 +267,39 @@ public async Task<int> GetDataOffsetIndex2(string fullPath)
261
267
262
268
263
269
await _semaphoreSlim . WaitAsync ( ) ;
264
-
265
- // Dump the index into memory, since we're going to have to inject data.
266
- byte [ ] originalIndex = File . ReadAllBytes ( index2Path ) ;
267
-
268
- // Get all the segment header data
269
- for ( int i = 0 ; i < SegmentHeaders . Length ; i ++ )
270
+ try
270
271
{
271
- SegmentOffsets [ i ] = BitConverter . ToInt32 ( originalIndex , SegmentHeaders [ i ] + 4 ) ;
272
- SegmentSizes [ i ] = BitConverter . ToInt32 ( originalIndex , SegmentHeaders [ i ] + 8 ) ;
273
- }
274
272
275
- int fileCount = SegmentSizes [ 0 ] / 8 ;
273
+ // Dump the index into memory, since we're going to have to inject data.
274
+ byte [ ] originalIndex = File . ReadAllBytes ( index2Path ) ;
276
275
277
- for ( int i = 0 ; i < fileCount ; i ++ )
278
- {
279
- int position = SegmentOffsets [ 0 ] + ( i * 8 ) ;
280
- uint iFullPathHash = BitConverter . ToUInt32 ( originalIndex , position ) ;
281
- uint iOffset = BitConverter . ToUInt32 ( originalIndex , position + 4 ) ;
276
+ // Get all the segment header data
277
+ for ( int i = 0 ; i < SegmentHeaders . Length ; i ++ )
278
+ {
279
+ SegmentOffsets [ i ] = BitConverter . ToInt32 ( originalIndex , SegmentHeaders [ i ] + 4 ) ;
280
+ SegmentSizes [ i ] = BitConverter . ToInt32 ( originalIndex , SegmentHeaders [ i ] + 8 ) ;
281
+ }
282
+
283
+ int fileCount = SegmentSizes [ 0 ] / 8 ;
282
284
283
- // Index 2 is just in hash order, so find the spot where we fit in.
284
- if ( iFullPathHash == uFullPathHash )
285
+ for ( int i = 0 ; i < fileCount ; i ++ )
285
286
{
286
- int signedOffset = BitConverter . ToInt32 ( originalIndex , position + 4 ) ;
287
- return signedOffset * 8 ;
287
+ int position = SegmentOffsets [ 0 ] + ( i * 8 ) ;
288
+ uint iFullPathHash = BitConverter . ToUInt32 ( originalIndex , position ) ;
289
+ uint iOffset = BitConverter . ToUInt32 ( originalIndex , position + 4 ) ;
290
+
291
+ // Index 2 is just in hash order, so find the spot where we fit in.
292
+ if ( iFullPathHash == uFullPathHash )
293
+ {
294
+ int signedOffset = BitConverter . ToInt32 ( originalIndex , position + 4 ) ;
295
+ return signedOffset * 8 ;
296
+ }
288
297
}
289
298
}
290
- _semaphoreSlim . Release ( ) ;
299
+ finally
300
+ {
301
+ _semaphoreSlim . Release ( ) ;
302
+ }
291
303
return 0 ;
292
304
}
293
305
@@ -711,31 +723,36 @@ public async Task<List<int>> GetAllHashedFilesInFolder(int hashedFolder, XivData
711
723
var indexPath = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { IndexExtension } ") ;
712
724
713
725
await _semaphoreSlim . WaitAsync ( ) ;
714
- await Task . Run ( ( ) =>
726
+ try
715
727
{
716
- using ( var br = new BinaryReader ( File . OpenRead ( indexPath ) ) )
728
+ await Task . Run ( ( ) =>
717
729
{
718
- br . BaseStream . Seek ( fileCountOffset , SeekOrigin . Begin ) ;
719
- var totalFiles = br . ReadInt32 ( ) ;
720
-
721
- br . BaseStream . Seek ( dataStartOffset , SeekOrigin . Begin ) ;
722
- for ( var i = 0 ; i < totalFiles ; br . ReadBytes ( 4 ) , i += 16 )
730
+ using ( var br = new BinaryReader ( File . OpenRead ( indexPath ) ) )
723
731
{
724
- var hashedFile = br . ReadInt32 ( ) ;
725
-
726
- var folderPathHash = br . ReadInt32 ( ) ;
732
+ br . BaseStream . Seek ( fileCountOffset , SeekOrigin . Begin ) ;
733
+ var totalFiles = br . ReadInt32 ( ) ;
727
734
728
- if ( folderPathHash == hashedFolder )
735
+ br . BaseStream . Seek ( dataStartOffset , SeekOrigin . Begin ) ;
736
+ for ( var i = 0 ; i < totalFiles ; br . ReadBytes ( 4 ) , i += 16 )
729
737
{
730
- fileHashesList . Add ( hashedFile ) ;
731
- }
738
+ var hashedFile = br . ReadInt32 ( ) ;
732
739
733
- br . ReadBytes ( 4 ) ;
734
- }
735
- }
736
- } ) ;
740
+ var folderPathHash = br . ReadInt32 ( ) ;
737
741
738
- _semaphoreSlim . Release ( ) ;
742
+ if ( folderPathHash == hashedFolder )
743
+ {
744
+ fileHashesList . Add ( hashedFile ) ;
745
+ }
746
+
747
+ br . ReadBytes ( 4 ) ;
748
+ }
749
+ }
750
+ } ) ;
751
+ }
752
+ finally
753
+ {
754
+ _semaphoreSlim . Release ( ) ;
755
+ }
739
756
return fileHashesList ;
740
757
}
741
758
@@ -756,32 +773,38 @@ public async Task<Dictionary<int, int>> GetAllHashedFilesAndOffsetsInFolder(int
756
773
var indexPath = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { IndexExtension } ") ;
757
774
758
775
await _semaphoreSlim . WaitAsync ( ) ;
759
- await Task . Run ( ( ) =>
776
+ try
760
777
{
761
- using ( var br = new BinaryReader ( File . OpenRead ( indexPath ) ) )
778
+ await Task . Run ( ( ) =>
762
779
{
763
- br . BaseStream . Seek ( fileCountOffset , SeekOrigin . Begin ) ;
764
- var totalFiles = br . ReadInt32 ( ) ;
765
-
766
- br . BaseStream . Seek ( dataStartOffset , SeekOrigin . Begin ) ;
767
- for ( var i = 0 ; i < totalFiles ; br . ReadBytes ( 4 ) , i += 16 )
780
+ using ( var br = new BinaryReader ( File . OpenRead ( indexPath ) ) )
768
781
{
769
- var hashedFile = br . ReadInt32 ( ) ;
770
-
771
- var folderPathHash = br . ReadInt32 ( ) ;
782
+ br . BaseStream . Seek ( fileCountOffset , SeekOrigin . Begin ) ;
783
+ var totalFiles = br . ReadInt32 ( ) ;
772
784
773
- if ( folderPathHash == hashedFolder )
774
- {
775
- fileHashesDict . Add ( hashedFile , br . ReadInt32 ( ) * 8 ) ;
776
- }
777
- else
785
+ br . BaseStream . Seek ( dataStartOffset , SeekOrigin . Begin ) ;
786
+ for ( var i = 0 ; i < totalFiles ; br . ReadBytes ( 4 ) , i += 16 )
778
787
{
779
- br . ReadBytes ( 4 ) ;
788
+ var hashedFile = br . ReadInt32 ( ) ;
789
+
790
+ var folderPathHash = br . ReadInt32 ( ) ;
791
+
792
+ if ( folderPathHash == hashedFolder )
793
+ {
794
+ fileHashesDict . Add ( hashedFile , br . ReadInt32 ( ) * 8 ) ;
795
+ }
796
+ else
797
+ {
798
+ br . ReadBytes ( 4 ) ;
799
+ }
780
800
}
781
801
}
782
- }
783
- } ) ;
784
- _semaphoreSlim . Release ( ) ;
802
+ } ) ;
803
+ }
804
+ finally
805
+ {
806
+ _semaphoreSlim . Release ( ) ;
807
+ }
785
808
786
809
return fileHashesDict ;
787
810
}
0 commit comments