Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion UnityFileSystem.Tests/UnityFileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public static void WithCopy(string source, string fileName, Action<string> test)
}
finally
{
Directory.Delete(dir, true);
// Best-effort cleanup: a delete failure (e.g. a handle not yet released on Windows)
// must not mask a test failure thrown from the block above.
try { Directory.Delete(dir, true); }
catch { /* ignore */ }
Comment on lines +30 to +33
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions UnityFileSystem/DllWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ public static class DllWrapper
public static extern ReturnCode GetArchiveNodeCount(UnityArchiveHandle handle, out int count);

// Strings returned from native (here and in the other StringBuilder-based calls) come back as
// UTF-8 bytes but are marshalled as the system ANSI code page, so only ASCII round-trips correctly.
// These are internal archive/serialized-file names, which Unity keeps ASCII, so it's not an issue in
// practice. Input paths, by contrast, are marshalled as UTF-8 (LPUTF8Str) to support non-ASCII paths.
// UTF-8 bytes but are marshalled as the system ANSI code page. On Windows that's a lossy code page,
// so only ASCII round-trips correctly (on macOS/Linux it happens to be UTF-8). These are internal
// archive/serialized-file names, which Unity keeps ASCII, so it's not an issue in practice. Input
// paths, by contrast, are marshalled as UTF-8 (LPUTF8Str) to support non-ASCII paths on all platforms.
Comment on lines 198 to +202
[DllImport("UnityFileSystemApi",
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "UFS_GetArchiveNode")]
Expand All @@ -215,14 +216,19 @@ private static extern ReturnCode CreateArchiveNative(IntPtr[] sourceFiles, IntPt
public static ReturnCode CreateArchive(string[] sourceFiles, string[] aliases, bool[] isSerializedFile, int count,
string archiveFile, CompressionType compression, out int crc)
{
var sourcePtrs = new IntPtr[sourceFiles.Length];
var aliasPtrs = new IntPtr[aliases.Length];
if (count < 0 || count > sourceFiles.Length || count > aliases.Length || count > isSerializedFile.Length)
throw new ArgumentOutOfRangeException(nameof(count));

// Marshal only the first `count` entries, since that's all the native call consumes.
var sourcePtrs = new IntPtr[count];
var aliasPtrs = new IntPtr[count];
try
{
for (int i = 0; i < sourceFiles.Length; ++i)
for (int i = 0; i < count; ++i)
{
sourcePtrs[i] = Marshal.StringToCoTaskMemUTF8(sourceFiles[i]);
for (int i = 0; i < aliases.Length; ++i)
aliasPtrs[i] = Marshal.StringToCoTaskMemUTF8(aliases[i]);
}

return CreateArchiveNative(sourcePtrs, aliasPtrs, isSerializedFile, count, archiveFile, compression, out crc);
}
Expand Down
Loading