Perhaps the most important function in the plugin API is the VFS_ReadDirectory function. This is called by Opus whenever the user browses to a new folder in your plugin's namespace.

BOOL VFS_ReadDirectory( HANDLE hVFSData, LPVFSFUNCDATA lpFuncData,
    LPVFSREADDIRDATA lpReadDirData )

The hVFSData parameter is your instance handle, returned from VFS_Create. This parameter is passed to almost all of the functions in the plugin. The lpFuncData parameter is a general purpose data pointer that currently is not used. Many functions accept this parameter and it may be used in future revisions of the API to provide additional information or callback parameters to your functions. For now you should ignore this parameter - it will usually be NULL.

The final parameter, lpReadDirData, is a pointer to a VFSREADDIRDATA structure. This structure provides information about the folder to be read, the type of event that has triggered the read, and provides a mechanism for you to pass back to Opus information about the folder contents.

The members of the VFSREADDIRDATA structure are as follows:

if ( hAbortEvent && WaitForSingleObject( hAbortEvent, 0 ) == WAIT_OBJECT_0 )
{
    // aborted
}
      lpFileData
          |
          v
+-------------------+
| VFSFILEDATAHEADER |---+
+-------------------+   |
|    VFSFILEDATA    |   |
|    VFSFILEDATA    |   | lpNext
|    VFSFILEDATA    |   |
+-------------------+   |
                        |
+-------------------+   |
| VFSFILEDATAHEADER |<--+
+-------------------+
|    VFSFILEDATA    |
|    VFSFILEDATA    |
+-------------------+

The lpFileData member of the structure must be set to point to the address of the first allocated VFSFILEDATAHEADER structure. The lpNext member of the VFSFILEDATAHEADER structure is used to chain on to subsequent allocation blocks. Set the lpNext member of the final allocation to 0.

Note that all memory must be allocated using the Windows HeapAlloc function and the memory heap passed in hMemHeap. Opus will free the memory you allocate using HeapFree and/or HeapDestroy when it no longer needs it.

The members of the VFSFILEDATAHEADER structure are:

Immediately following the VFSFILEDATAHEADER structure in memory must be one or more VFSFILEDATA structures, the number of which is given by the iNumItems member in the header structure.

The members of the VFSFILEDATA structure are:

Once you have allocated and returned the directory contents, Opus will display the folder in the Lister. By default, icons displayed for your files and folders are the default system ones (that is, the standard folder icon for your folders, and the appropriate icon for your files based on their filename extensions).

If you wish to provide custom icons for your files and folders you should implement the VFS_GetFileIcon function. This function will be called by Opus for every file and folder in your plugin's namespace (but only when the icon is actually required, and potentially on a background thread.)