Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Vfs overwrite behaviour is now configurable. #28

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion PxCs.Tests/PxPhoenixTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected IntPtr LoadVfs(string relativeFilePath)
Assert.True(File.Exists(fullPath), "Path >" + fullPath + "< does not exist.");

var vfsPtr = PxVfs.pxVfsNew();
PxVfs.pxVfsMountDisk(vfsPtr, fullPath);
PxVfs.pxVfsMountDisk(vfsPtr, fullPath, PxVfs.PxVfsOverwriteBehavior.PxVfsOverwrite_Older);

return vfsPtr;
}
Expand Down
4 changes: 2 additions & 2 deletions PxCs.Tests/PxVfsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class PxVfsTest : PxPhoenixTest
public void Test_load_Vfs()
{
var vfsPtr = PxVfs.pxVfsNew();
PxVfs.pxVfsMountDisk(vfsPtr, GetAssetPath("Data/worlds.VDF"));
PxVfs.pxVfsMountDisk(vfsPtr, GetAssetPath("Data/textures.VDF"));
PxVfs.pxVfsMountDisk(vfsPtr, GetAssetPath("Data/worlds.VDF"), PxVfs.PxVfsOverwriteBehavior.PxVfsOverwrite_Older);
PxVfs.pxVfsMountDisk(vfsPtr, GetAssetPath("Data/textures.VDF"), PxVfs.PxVfsOverwriteBehavior.PxVfsOverwrite_Older);

// If we reach this far, mounting was successful. Test complete. Starting cleanup.

Expand Down
14 changes: 11 additions & 3 deletions PxCs/Interface/PxVfs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ public static class PxVfs
{
private const string DLLNAME = PxPhoenix.DLLNAME;

public enum PxVfsOverwriteBehavior
{
PxVfsOverwrite_None = 0, // Overwrite no conflicting nodes.
PxVfsOverwrite_All = 1, // Overwrite all conflicting nodes.
PxVfsOverwrite_Newer = 2, // Overwrite newer conflicting nodes. (i.e. use older versions)
PxVfsOverwrite_Older = 3 // Overwrite older conflicting nodes. (i.e. use newer versions)
}

[DllImport(DLLNAME)] public static extern IntPtr pxVfsNew();
[DllImport(DLLNAME)] public static extern void pxVfsMountDisk(IntPtr vfs, string path);
[DllImport(DLLNAME)] public static extern void pxVfsMountDisk(IntPtr vfs, string path, PxVfsOverwriteBehavior overwriteFlag);
[DllImport(DLLNAME)] public static extern void pxVfsDestroy(IntPtr vfs);

[DllImport(DLLNAME)] public static extern IntPtr pxVfsGetNodeByName(IntPtr vfs, string name);
Expand All @@ -19,13 +27,13 @@ public static class PxVfs
/// <summary>
/// Hint: This file isn't taking care of special flags like LoadAdditive or UseNewer (for patches and mods)
/// </summary>
public static IntPtr LoadVfs(string[] files)
public static IntPtr LoadVfs(string[] files, PxVfsOverwriteBehavior overwriteFlag)
{
var vfsPtr = pxVfsNew();

foreach (var file in files)
{
pxVfsMountDisk(vfsPtr, file);
pxVfsMountDisk(vfsPtr, file, overwriteFlag);
}

return vfsPtr;
Expand Down