Minor changes.

This commit is contained in:
Ottermandias 2025-01-25 13:54:19 +01:00
parent a3ddce0ef5
commit 30a957356a
6 changed files with 33 additions and 29 deletions

View file

@ -143,11 +143,11 @@ internal unsafe struct Record
Crc64 = 0,
};
public static Record CreateResourceComplete(CiByteString path, ResourceHandle* handle, Utf8GamePath originalPath)
public static Record CreateResourceComplete(CiByteString path, ResourceHandle* handle, Utf8GamePath originalPath, ReadOnlySpan<byte> additionalData)
=> new()
{
Time = DateTime.UtcNow,
Path = path.IsOwned ? path : path.Clone(),
Path = CombinedPath(path, additionalData),
OriginalPath = originalPath.Path.IsOwned ? originalPath.Path : originalPath.Path.Clone(),
Collection = null,
Handle = handle,
@ -162,4 +162,17 @@ internal unsafe struct Record
LoadState = handle->LoadState,
Crc64 = 0,
};
private static CiByteString CombinedPath(CiByteString path, ReadOnlySpan<byte> additionalData)
{
if (additionalData.Length is 0)
return path.IsOwned ? path : path.Clone();
fixed (byte* ptr = additionalData)
{
// If a path has additional data and is split, it is always in the form of |{additionalData}|{path},
// so we can just read from the start of additional data - 1 and sum their length +2 for the pipes.
return new CiByteString(new ReadOnlySpan<byte>(ptr - 1, additionalData.Length + 2 + path.Length)).Clone();
}
}
}

View file

@ -257,7 +257,7 @@ public sealed class ResourceWatcher : IDisposable, ITab, IUiService
_newRecords.Enqueue(record);
}
private unsafe void OnResourceComplete(ResourceHandle* resource, CiByteString path, Utf8GamePath original, ReadOnlySpan<byte> _, bool isAsync)
private unsafe void OnResourceComplete(ResourceHandle* resource, CiByteString path, Utf8GamePath original, ReadOnlySpan<byte> additionalData, bool isAsync)
{
if (!isAsync)
return;
@ -269,7 +269,7 @@ public sealed class ResourceWatcher : IDisposable, ITab, IUiService
if (!_ephemeral.EnableResourceWatcher)
return;
var record = Record.CreateResourceComplete(path, resource, original);
var record = Record.CreateResourceComplete(path, resource, original, additionalData);
if (!_ephemeral.OnlyAddMatchingResources || _table.WouldBeVisible(record))
_newRecords.Enqueue(record);
}