From 822b62ff459fa055c2824a1cdc742b483511f47c Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Sat, 30 Dec 2023 12:15:07 +0100 Subject: [PATCH] docs(Vfs): add documenation --- ZenKit/Vfs.cs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/ZenKit/Vfs.cs b/ZenKit/Vfs.cs index b98c729..f8a60c0 100644 --- a/ZenKit/Vfs.cs +++ b/ZenKit/Vfs.cs @@ -1,13 +1,29 @@ using System; using System.Collections.Generic; +using System.IO; namespace ZenKit { public enum VfsOverwriteBehavior { + /// + /// Overwrite no conflicting nodes. + /// None = 0, + + /// + /// Overwrite all conflicting nodes. + /// All = 1, + + /// + /// Overwrite newer conflicting nodes. + /// Newer = 2, + + /// + /// Overwrite older conflicting nodes. + /// Older = 3 } @@ -112,6 +128,10 @@ public bool Remove(string name) } } + /// + /// An implementation of the ZenGin's virtual file system. + /// + /// public class Vfs { public Vfs() @@ -120,14 +140,18 @@ public Vfs() if (Handle == UIntPtr.Zero) throw new Exception("Failed to create Vfs"); } - public UIntPtr Handle { get; } + internal UIntPtr Handle { get; } + /// + /// The root node of the virtual file system structure. + /// + /// Thrown if accessing the native object fails. public VfsNode Root { get { var node = Native.ZkVfs_getRoot(Handle); - if (node == UIntPtr.Zero) throw new Exception("Failed to get root Vfs node"); + if (node == UIntPtr.Zero) throw new IOException("Failed to get root Vfs node"); return new VfsNode(node); } } @@ -137,42 +161,90 @@ public VfsNode Root Native.ZkVfs_del(Handle); } - public void Mkdir(string path) + /// + /// Create all missing directories in the given path. + /// + /// Create all missing directories in the given path. + /// The newly created directory or null if creating the directory fails.. + public VfsNode? Mkdir(string path) { - Native.ZkVfs_mkdir(Handle, path); + var p = Native.ZkVfs_mkdir(Handle, path); + return p == UIntPtr.Zero ? null : new VfsNode(p); } + /// + /// Delete the file or directory at the given path + /// + /// The path of the node to delete. + /// true if removal was successful and false if not (ie. the file could not be found). public bool Remove(string path) { return Native.ZkVfs_remove(Handle, path); } + /// + /// Mount the given file system node into the given directory. When the given is a + /// directory, it is merged with any existing directory with the same name in the given + /// path. + /// + /// The file system node to mount. + /// The path of the parent node to mount into. + /// The behavior of the system when conflicting files are found. public void Mount(VfsNode node, string parent, VfsOverwriteBehavior overwrite) { Native.ZkVfs_mount(Handle, node.Handle, parent, overwrite); } + /// + /// Mount a file or directory from the host file system into the Vfs. + /// + /// If a path to a directory is provided, only its children are mounted, not the directory itself. + /// The path of the file or directory to mount. + /// The path of the parent node to mount into. + /// The behavior of the system when conflicting files are found. public void Mount(string path, string parent, VfsOverwriteBehavior overwrite) { Native.ZkVfs_mountHost(Handle, path, parent, overwrite); } + /// + /// Mount the disk file in the given buffer into the file system. The disk contents are mounted at the root node + /// of the file system and existing directories are merged together. + /// + /// A buffer containing the disk file contents. + /// The behavior of the system when conflicting files are found. public void MountDisk(Read buf, VfsOverwriteBehavior overwrite) { Native.ZkVfs_mountDisk(Handle, buf.Handle, overwrite); } + /// + /// Mount the disk file at the given host path into the file system. The disk contents are mounted at the root + /// node of the file system and existing directories are merged together. + /// + /// The path of the disk to mount. + /// The behavior of the system when conflicting files are found. public void MountDisk(string path, VfsOverwriteBehavior overwrite) { Native.ZkVfs_mountDiskHost(Handle, path, overwrite); } + /// + /// Resolve the given path in the Vfs to a file system node. + /// + /// The path to the node to resolve. + /// The node at the given path or null if the path could not be resolved. public VfsNode? Resolve(string path) { var result = Native.ZkVfs_resolvePath(Handle, path); return result == UIntPtr.Zero ? null : new VfsNode(result); } + /// + /// Find the first node with the given name in the Vfs. + /// + /// The name of the node to find. + /// The node with the given name or null if no node with the given name was found. public VfsNode? Find(string name) { var result = Native.ZkVfs_findNode(Handle, name);