@@ -97,9 +97,16 @@ public int CreateNewDat(XivDataFile dataFile)
97
97
public int GetLargestDatNumber ( XivDataFile dataFile )
98
98
{
99
99
100
+ string [ ] allFiles = null ;
100
101
_lock . Wait ( ) ;
101
- var allFiles = Directory . GetFiles ( _gameDirectory . FullName ) ;
102
- _lock . Release ( ) ;
102
+ try
103
+ {
104
+ allFiles = Directory . GetFiles ( _gameDirectory . FullName ) ;
105
+ }
106
+ finally
107
+ {
108
+ _lock . Release ( ) ;
109
+ }
103
110
104
111
var dataFiles = from file in allFiles where file . Contains ( dataFile . GetDataFileName ( ) ) && file . Contains ( ".dat" ) select file ;
105
112
@@ -146,29 +153,35 @@ public async Task<List<string>> GetModdedDatList(XivDataFile dataFile)
146
153
await Task . Run ( async ( ) =>
147
154
{
148
155
await _lock . WaitAsync ( ) ;
149
- for ( var i = 1 ; i < 20 ; i ++ )
156
+ try
150
157
{
151
- var datFilePath = $ "{ _gameDirectory } /{ dataFile . GetDataFileName ( ) } .win32.dat{ i } ";
152
-
153
- if ( File . Exists ( datFilePath ) )
158
+ for ( var i = 1 ; i < 20 ; i ++ )
154
159
{
155
- // Due to an issue where 060000 dat1 gets deleted, we are skipping it here
156
- if ( datFilePath . Contains ( "060000.win32.dat1" ) )
157
- {
158
- continue ;
159
- }
160
- using ( var binaryReader = new BinaryReader ( File . OpenRead ( datFilePath ) ) )
161
- {
162
- binaryReader . BaseStream . Seek ( 24 , SeekOrigin . Begin ) ;
160
+ var datFilePath = $ "{ _gameDirectory } /{ dataFile . GetDataFileName ( ) } .win32.dat{ i } ";
163
161
164
- if ( binaryReader . ReadByte ( ) == 0 )
162
+ if ( File . Exists ( datFilePath ) )
163
+ {
164
+ // Due to an issue where 060000 dat1 gets deleted, we are skipping it here
165
+ if ( datFilePath . Contains ( "060000.win32.dat1" ) )
165
166
{
166
- datList . Add ( datFilePath ) ;
167
+ continue ;
168
+ }
169
+ using ( var binaryReader = new BinaryReader ( File . OpenRead ( datFilePath ) ) )
170
+ {
171
+ binaryReader . BaseStream . Seek ( 24 , SeekOrigin . Begin ) ;
172
+
173
+ if ( binaryReader . ReadByte ( ) == 0 )
174
+ {
175
+ datList . Add ( datFilePath ) ;
176
+ }
167
177
}
168
178
}
169
179
}
170
180
}
171
- _lock . Release ( ) ;
181
+ finally
182
+ {
183
+ _lock . Release ( ) ;
184
+ }
172
185
} ) ;
173
186
return datList ;
174
187
}
@@ -1317,22 +1330,27 @@ public async Task<int> WriteToDat(List<byte> importData, Mod modEntry, string in
1317
1330
1318
1331
1319
1332
await _lock . WaitAsync ( ) ;
1320
- // If there is an existing modlist entry, use that data to get the modDatPath
1321
- if ( modEntry != null )
1333
+ try
1322
1334
{
1323
- datNum = ( ( modEntry . data . modOffset / 8 ) & 0x0F ) / 2 ;
1324
- modDatPath = Path . Combine ( _gameDirectory . FullName , $ "{ modEntry . datFile } { DatExtension } { datNum } ") ;
1325
-
1326
- if ( ! File . Exists ( modDatPath ) )
1335
+ // If there is an existing modlist entry, use that data to get the modDatPath
1336
+ if ( modEntry != null )
1327
1337
{
1328
- _lock . Release ( ) ;
1329
- throw new Exception ( $ "A mod entry is pointing to { Path . GetFileName ( modDatPath ) } , but the file does not exist.\n \n " +
1330
- $ "It is recommended to do a Start Over.") ;
1338
+ datNum = ( ( modEntry . data . modOffset / 8 ) & 0x0F ) / 2 ;
1339
+ modDatPath = Path . Combine ( _gameDirectory . FullName , $ "{ modEntry . datFile } { DatExtension } { datNum } ") ;
1340
+
1341
+ if ( ! File . Exists ( modDatPath ) )
1342
+ {
1343
+ throw new Exception ( $ "A mod entry is pointing to { Path . GetFileName ( modDatPath ) } , but the file does not exist.\n \n " +
1344
+ $ "It is recommended to do a Start Over.") ;
1345
+ }
1331
1346
}
1332
- }
1333
1347
1334
- var fileLength = new FileInfo ( modDatPath ) . Length ;
1335
- _lock . Release ( ) ;
1348
+ var fileLength = new FileInfo ( modDatPath ) . Length ;
1349
+ }
1350
+ finally
1351
+ {
1352
+ _lock . Release ( ) ;
1353
+ }
1336
1354
1337
1355
// Checks to make sure the offsets in the mod list are not 0
1338
1356
// If they are 0, something went wrong in the import proccess (Technically shouldn't happen)
@@ -1606,7 +1624,7 @@ where entry.fullPath.Equals(modEntry.fullPath)
1606
1624
}
1607
1625
1608
1626
// Queue our dependency information updates.
1609
- XivCache . QueueDependencyUpdate ( internalFilePath ) ;
1627
+ await XivCache . QueueDependencyUpdate ( internalFilePath ) ;
1610
1628
1611
1629
return offset ;
1612
1630
}
0 commit comments