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

Commit

Permalink
feat(PxVfs): partially implement phoenix::vfs_node API
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Oct 28, 2023
1 parent 221cce3 commit 3eb00a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/phoenix/cffi/Vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ typedef enum {

PXC_API PxVfs* pxVfsNew();
PXC_API void pxVfsMountDisk(PxVfs* vfs, char const* path, PxVfsOverwriteBehavior overwriteFlag);
PXC_API void pxVfsMountDiskData(PxVfs* vfs, PxBuffer* path, PxVfsOverwriteBehavior overwriteFlag);
PXC_API void pxVfsDestroy(PxVfs* vfs);

PXC_API PxVfsNode const* pxVfsGetRootNode(PxVfs const* node);
PXC_API char const* pxVfsNodeGetName(PxVfsNode const* node);
PXC_API size_t pxVfsNodeGetChildCount(PxVfsNode const* node);
PXC_API PxVfsNode const* pxVfsNodeGetChild(PxVfsNode const* node, size_t i);
PXC_API PxBool pxVfsNodeIsFile(PxVfsNode const* node);

PXC_API PxVfsNode const* pxVfsGetNodeByName(PxVfs const* vfs, char const* name);
PXC_API PxBuffer* pxVfsNodeOpenBuffer(PxVfsNode const* node);
30 changes: 30 additions & 0 deletions src/Vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ void pxVfsMountDisk(PxVfs* vfs, char const* path, PxVfsOverwriteBehavior overwri
}
}

void pxVfsMountDiskData(PxVfs* vfs, PxBuffer* path, PxVfsOverwriteBehavior overwriteFlag) {
try {
vfs->mount_disk(*path, static_cast<px::VfsOverwriteBehavior>(overwriteFlag));
} catch (std::exception const& e) {
px::logging::log(px::logging::level::error, "encountered exception while parsing PxVfs: ", e.what());
}
}

void pxVfsDestroy(PxVfs* vfs) {
delete vfs;
}
Expand All @@ -28,3 +36,25 @@ PxVfsNode const* pxVfsGetNodeByName(PxVfs const* vfs, char const* name) {
PxBuffer* pxVfsNodeOpenBuffer(PxVfsNode const* node) {
return new phoenix::buffer {node->open()};
}

PxVfsNode const* pxVfsGetRootNode(const PxVfs* node) {
return &node->root();
}

char const* pxVfsNodeGetName(const PxVfsNode* node) {
return node->name().c_str();
}

size_t pxVfsNodeGetChildCount(const PxVfsNode* node) {
if (node->type() == phoenix::VfsNodeType::FILE) return 0;
return node->children().size();
}

PxVfsNode const* pxVfsNodeGetChild(const PxVfsNode* node, size_t i) {
if (node->type() == phoenix::VfsNodeType::FILE) return nullptr;
return &node->children()[i];
}

PxBool pxVfsNodeIsFile(const PxVfsNode* node) {
return node->type() == phoenix::VfsNodeType::FILE;
}

0 comments on commit 3eb00a4

Please sign in to comment.