11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34
45namespace ZenKit
56{
67 public enum VfsOverwriteBehavior
78 {
9+ /// <summary>
10+ /// Overwrite no conflicting nodes.
11+ /// </summary>
812 None = 0 ,
13+
14+ /// <summary>
15+ /// Overwrite all conflicting nodes.
16+ /// </summary>
917 All = 1 ,
18+
19+ /// <summary>
20+ /// Overwrite newer conflicting nodes.
21+ /// </summary>
1022 Newer = 2 ,
23+
24+ /// <summary>
25+ /// Overwrite older conflicting nodes.
26+ /// </summary>
1127 Older = 3
1228 }
1329
@@ -112,6 +128,10 @@ public bool Remove(string name)
112128 }
113129 }
114130
131+ /// <summary>
132+ /// An implementation of the ZenGin's virtual file system.
133+ /// </summary>
134+ /// <seealso href="https://zk.gothickit.dev/library/api/virtual-file-system/" />
115135 public class Vfs
116136 {
117137 public Vfs ( )
@@ -120,14 +140,18 @@ public Vfs()
120140 if ( Handle == UIntPtr . Zero ) throw new Exception ( "Failed to create Vfs" ) ;
121141 }
122142
123- public UIntPtr Handle { get ; }
143+ internal UIntPtr Handle { get ; }
124144
145+ /// <summary>
146+ /// The root node of the virtual file system structure.
147+ /// </summary>
148+ /// <exception cref="IOException">Thrown if accessing the native object fails.</exception>
125149 public VfsNode Root
126150 {
127151 get
128152 {
129153 var node = Native . ZkVfs_getRoot ( Handle ) ;
130- if ( node == UIntPtr . Zero ) throw new Exception ( "Failed to get root Vfs node" ) ;
154+ if ( node == UIntPtr . Zero ) throw new IOException ( "Failed to get root Vfs node" ) ;
131155 return new VfsNode ( node ) ;
132156 }
133157 }
@@ -137,42 +161,90 @@ public VfsNode Root
137161 Native . ZkVfs_del ( Handle ) ;
138162 }
139163
140- public void Mkdir ( string path )
164+ /// <summary>
165+ /// Create all missing directories in the given path.
166+ /// </summary>
167+ /// <param name="path">Create all missing directories in the given path.</param>
168+ /// <returns>The newly created directory or <c>null</c> if creating the directory fails..</returns>
169+ public VfsNode ? Mkdir ( string path )
141170 {
142- Native . ZkVfs_mkdir ( Handle , path ) ;
171+ var p = Native . ZkVfs_mkdir ( Handle , path ) ;
172+ return p == UIntPtr . Zero ? null : new VfsNode ( p ) ;
143173 }
144174
175+ /// <summary>
176+ /// Delete the file or directory at the given path
177+ /// </summary>
178+ /// <param name="path">The path of the node to delete.</param>
179+ /// <returns><c>true</c> if removal was successful and <c>false</c> if not (ie. the file could not be found).</returns>
145180 public bool Remove ( string path )
146181 {
147182 return Native . ZkVfs_remove ( Handle , path ) ;
148183 }
149184
185+ /// <summary>
186+ /// <b>Mount the given file system node into the given directory.</b> When the given <paramref name="node" /> is a
187+ /// directory, it is merged with any existing directory with the same name in the given <paramref name="parent" />
188+ /// path.
189+ /// </summary>
190+ /// <param name="node">The file system node to mount.</param>
191+ /// <param name="parent">The path of the parent node to mount into.</param>
192+ /// <param name="overwrite">The behavior of the system when conflicting files are found.</param>
150193 public void Mount ( VfsNode node , string parent , VfsOverwriteBehavior overwrite )
151194 {
152195 Native . ZkVfs_mount ( Handle , node . Handle , parent , overwrite ) ;
153196 }
154197
198+ /// <summary>
199+ /// Mount a file or directory from the host file system into the Vfs.
200+ /// </summary>
201+ /// <remarks>If a path to a directory is provided, only its children are mounted, not the directory itself.</remarks>
202+ /// <param name="path">The path of the file or directory to mount.</param>
203+ /// <param name="parent">The path of the parent node to mount into.</param>
204+ /// <param name="overwrite">The behavior of the system when conflicting files are found.</param>
155205 public void Mount ( string path , string parent , VfsOverwriteBehavior overwrite )
156206 {
157207 Native . ZkVfs_mountHost ( Handle , path , parent , overwrite ) ;
158208 }
159209
210+ /// <summary>
211+ /// <b>Mount the disk file in the given buffer into the file system.</b> The disk contents are mounted at the root node
212+ /// of the file system and existing directories are merged together.
213+ /// </summary>
214+ /// <param name="buf">A buffer containing the disk file contents.</param>
215+ /// <param name="overwrite">The behavior of the system when conflicting files are found.</param>
160216 public void MountDisk ( Read buf , VfsOverwriteBehavior overwrite )
161217 {
162218 Native . ZkVfs_mountDisk ( Handle , buf . Handle , overwrite ) ;
163219 }
164220
221+ /// <summary>
222+ /// <b>Mount the disk file at the given host path into the file system.</b> The disk contents are mounted at the root
223+ /// node of the file system and existing directories are merged together.
224+ /// </summary>
225+ /// <param name="path">The path of the disk to mount.</param>
226+ /// <param name="overwrite">The behavior of the system when conflicting files are found.</param>
165227 public void MountDisk ( string path , VfsOverwriteBehavior overwrite )
166228 {
167229 Native . ZkVfs_mountDiskHost ( Handle , path , overwrite ) ;
168230 }
169231
232+ /// <summary>
233+ /// Resolve the given path in the Vfs to a file system node.
234+ /// </summary>
235+ /// <param name="path">The path to the node to resolve.</param>
236+ /// <returns>The node at the given path or <c>null</c> if the path could not be resolved.</returns>
170237 public VfsNode ? Resolve ( string path )
171238 {
172239 var result = Native . ZkVfs_resolvePath ( Handle , path ) ;
173240 return result == UIntPtr . Zero ? null : new VfsNode ( result ) ;
174241 }
175242
243+ /// <summary>
244+ /// Find the first node with the given name in the Vfs.
245+ /// </summary>
246+ /// <param name="name">The name of the node to find.</param>
247+ /// <returns>The node with the given name or <c>null</c> if no node with the given name was found.</returns>
176248 public VfsNode ? Find ( string name )
177249 {
178250 var result = Native . ZkVfs_findNode ( Handle , name ) ;
0 commit comments