@@ -776,6 +776,38 @@ public async Task<bool> DeleteFileDescriptor(string fullPath, XivDataFile dataFi
776
776
var oldChildren = await XivCache . GetChildFiles ( fullPath ) ;
777
777
778
778
await _semaphoreSlim . WaitAsync ( ) ;
779
+
780
+ // Test both index files for write access.
781
+ try
782
+ {
783
+ var indexPath = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { IndexExtension } ") ;
784
+ using ( var fs = new FileStream ( indexPath , FileMode . Open ) )
785
+ {
786
+ var canRead = fs . CanRead ;
787
+ var canWrite = fs . CanWrite ;
788
+ if ( ! canRead || ! canWrite )
789
+ {
790
+ throw new Exception ( ) ;
791
+ }
792
+ }
793
+ var index2Path = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { Index2Extension } ") ;
794
+ using ( var fs = new FileStream ( index2Path , FileMode . Open ) )
795
+ {
796
+ var canRead = fs . CanRead ;
797
+ var canWrite = fs . CanWrite ;
798
+ if ( ! canRead || ! canWrite )
799
+ {
800
+ throw new Exception ( ) ;
801
+ }
802
+ }
803
+ }
804
+ catch
805
+ {
806
+ _semaphoreSlim . Release ( ) ;
807
+ throw new Exception ( "Unable to update Index files. File(s) are currently in use." ) ;
808
+ }
809
+
810
+
779
811
fullPath = fullPath . Replace ( "\\ " , "/" ) ;
780
812
var pathHash = HashGenerator . GetHash ( fullPath . Substring ( 0 , fullPath . LastIndexOf ( "/" , StringComparison . Ordinal ) ) ) ;
781
813
var fileHash = HashGenerator . GetHash ( Path . GetFileName ( fullPath ) ) ;
@@ -1048,6 +1080,37 @@ public async Task<bool> DeleteFileDescriptor(string fullPath, XivDataFile dataFi
1048
1080
public async Task < bool > AddFileDescriptor ( string fullPath , int dataOffset , XivDataFile dataFile )
1049
1081
{
1050
1082
await _semaphoreSlim . WaitAsync ( ) ;
1083
+
1084
+ // Test both index files for write access.
1085
+ try
1086
+ {
1087
+ var indexPath = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { IndexExtension } ") ;
1088
+ using ( var fs = new FileStream ( indexPath , FileMode . Open ) )
1089
+ {
1090
+ var canRead = fs . CanRead ;
1091
+ var canWrite = fs . CanWrite ;
1092
+ if ( ! canRead || ! canWrite )
1093
+ {
1094
+ throw new Exception ( ) ;
1095
+ }
1096
+ }
1097
+ var index2Path = Path . Combine ( _gameDirectory . FullName , $ "{ dataFile . GetDataFileName ( ) } { Index2Extension } ") ;
1098
+ using ( var fs = new FileStream ( index2Path , FileMode . Open ) )
1099
+ {
1100
+ var canRead = fs . CanRead ;
1101
+ var canWrite = fs . CanWrite ;
1102
+ if ( ! canRead || ! canWrite )
1103
+ {
1104
+ throw new Exception ( ) ;
1105
+ }
1106
+ }
1107
+ }
1108
+ catch
1109
+ {
1110
+ _semaphoreSlim . Release ( ) ;
1111
+ throw new Exception ( "Unable to update Index files. File(s) are currently in use." ) ;
1112
+ }
1113
+
1051
1114
fullPath = fullPath . Replace ( "\\ " , "/" ) ;
1052
1115
var pathHash = HashGenerator . GetHash ( fullPath . Substring ( 0 , fullPath . LastIndexOf ( "/" , StringComparison . Ordinal ) ) ) ;
1053
1116
var fileHash = HashGenerator . GetHash ( Path . GetFileName ( fullPath ) ) ;
0 commit comments