Skip to content

Commit 451162b

Browse files
committed
- Bugfixes for deleting scaling mods without first disabling them.
- Retry for failure to write to DAT/Index due to file in use errors.
1 parent 7a41841 commit 451162b

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

xivModdingFramework/Mods/Modding.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ public async Task<bool> ToggleModUnsafe(bool enable, Mod mod, bool includeIntern
385385

386386
// And write that metadata to the actual constituent files.
387387
await ItemMetadata.ApplyMetadata(meta, cachedIndex, cachedModlist);
388+
} else if(ext == ".rgsp")
389+
{
390+
await CMP.ApplyRgspFile(mod.fullPath, cachedIndex, cachedModlist);
388391
}
389392
}
390393
}
@@ -396,6 +399,18 @@ public async Task<bool> ToggleModUnsafe(bool enable, Mod mod, bool includeIntern
396399
if (cachedIndex != null)
397400
{
398401
cachedIndex.SetDataOffset(mod.fullPath, 0);
402+
403+
// This is a metadata entry being deleted, we'll need to restore the metadata entries back to default.
404+
if (mod.fullPath.EndsWith(".meta"))
405+
{
406+
var root = await XivCache.GetFirstRoot(mod.fullPath);
407+
await ItemMetadata.RestoreDefaultMetadata(root, cachedIndex, cachedModlist);
408+
}
409+
410+
if (mod.fullPath.EndsWith(".rgsp"))
411+
{
412+
await CMP.RestoreDefaultScaling(mod.fullPath, cachedIndex, cachedModlist);
413+
}
399414
}
400415
else
401416
{

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,11 +1553,31 @@ public async Task<uint> WriteToDat(byte[] importData, XivDataFile dataFile, long
15531553
var datPath = Path.Combine(_gameDirectory.FullName, $"{dataFile.GetDataFileName()}{DatExtension}{datNum}");
15541554

15551555
// Copy the data into the file.
1556-
using (var bw = new BinaryWriter(File.OpenWrite(datPath)))
1556+
BinaryWriter bw = null;
1557+
1558+
try
15571559
{
1558-
if(targetOffset >= 2048) {
1560+
try
1561+
{
1562+
bw = new BinaryWriter(File.OpenWrite(datPath));
1563+
}
1564+
catch
1565+
{
1566+
if(bw != null)
1567+
{
1568+
bw.Dispose();
1569+
}
1570+
1571+
// Wait just a bit and try again.
1572+
await Task.Delay(100);
1573+
bw = new BinaryWriter(File.OpenWrite(datPath));
1574+
}
1575+
1576+
if (targetOffset >= 2048)
1577+
{
15591578
bw.BaseStream.Seek(seekPointer, SeekOrigin.Begin);
1560-
} else
1579+
}
1580+
else
15611581
{
15621582
bw.BaseStream.Seek(0, SeekOrigin.End);
15631583
}
@@ -1579,6 +1599,13 @@ public async Task<uint> WriteToDat(byte[] importData, XivDataFile dataFile, long
15791599
bw.Write((byte)0);
15801600
}
15811601
}
1602+
finally
1603+
{
1604+
if (bw != null)
1605+
{
1606+
bw.Dispose();
1607+
}
1608+
}
15821609

15831610
var intFormat = (uint)(filePointer / 8);
15841611
uint datIdentifier = (uint)(datNum * 2);

xivModdingFramework/SqPack/FileTypes/Index.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,33 @@ public async Task SaveIndexFile(IndexFile index, bool alreadySemaphoreLocked = f
794794
throw new Exception("Cannot write index files; files current in use.");
795795
}
796796

797-
using (var index1Stream = new BinaryWriter(File.OpenWrite(index1Path)))
797+
BinaryWriter index1Stream = null;
798+
BinaryWriter index2Stream = null;
799+
try
798800
{
799-
using (var index2Stream = new BinaryWriter(File.OpenWrite(index2Path)))
801+
try
802+
{
803+
index1Stream = new BinaryWriter(File.OpenWrite(index1Path));
804+
index2Stream = new BinaryWriter(File.OpenWrite(index2Path));
805+
}
806+
catch
800807
{
801-
index.Save(index1Stream, index2Stream);
808+
index1Stream?.Dispose();
809+
index2Stream?.Dispose();
810+
811+
// Set a minor delay and try again, in case the user has some sort of locking issue.
812+
await Task.Delay(200);
813+
814+
index1Stream = new BinaryWriter(File.OpenWrite(index1Path));
815+
index2Stream = new BinaryWriter(File.OpenWrite(index2Path));
802816
}
817+
818+
index.Save(index1Stream, index2Stream);
819+
}
820+
finally
821+
{
822+
index1Stream?.Dispose();
823+
index2Stream?.Dispose();
803824
}
804825

805826

0 commit comments

Comments
 (0)