~~Title: Batch Operations~~
Directory Opus 9 supports //batch-mode// operations for VFS plugins. If you implement the batch interface via the [[.exported_functions_reference:vfs_batchoperation|VFS_BatchOperation]] function, Opus will call this function for any copy or delete operation involving your plugin, rather than using the //filesystem-style// functions described above.
BOOL VFS_BatchOperation( HANDLE hVFSData, LPVFSFUNCDATA lpFuncData,
LPTSTR lpszPath, LPVFSBATCHDATA lpBatchData )
The **hVFSData** parameter is your namespace instance handle, and **lpFuncData** is not currently used. **lpszPath** specifies the current path in your namespace, and **lpBatchData** points to a **VFSBATCHDATA** structure that defines the operation parameters.
The fields of the **VFSBATCHDATA** structure are as follows:
* **UINT cbSize** \\ This field specifies the size of the **VFSBATCHDATA** structure.
* **HWND hwndParent** \\ This specifies the handle of the parent window, and can be used if you need to display any error dialogs or other windows while processing the batch operation.
* **HANDLE hAbortEvent** \\ This may be a handle to a Windows **event** object which is used to indicate that a batch operation should be aborted. If you wish to allow the user to abort your plugin (which is highly recommended), you should make sure that you check the event for //signaled// status at regular intervals. For example,
if ( hAbortEvent && WaitForSingleObject( hAbortEvent, 0 ) == WAIT_OBJECT_0 )
{
// aborted
}
* **UINT uiOperation** \\ Specifies the batch operation type. Currently defined operations are:
* **VFSBATCHOP_ADD** \\ An **add** operation is analogous to a copy **to** your namespace - for example, adding files to an archive.
* **VFSBATCHOP_EXTRACT** \\ An **extract** operation is analogous to a copy **from** your namespace - eg, extracting files from an archive.
* **VFSBATCHOP_DELETE** \\ This is a **delete** operation - for example, removing files from an archive.
* **int iNumFiles** \\ Specifies the number of selected files and folders (note: does not include the contents of any sub-folders)
* **LPTSTR pszFiles** \\ Points to a double-null terminated list of file paths. For **VFSBATCHOP_EXTRACT** and **VFSBATCHOP_DELETE**, these will be files in your plugin's namespace. For **VFSBATCHOP_ADD**, these will be real files in the filesystem.
* **%%int* piResults%%** \\ This points to an array of **int** values which lets you provide a result code for each of the files specified via **pszFiles**. You should set each integer value to 0 if the file or folder was processed successfully, or an appropriate error code on failure. The size of the **piResults** array is specified by the **iNumFiles** value.
* **LPTSTR pszDestPath** \\ This specifies the destination path for a **VFSBATCHOP_EXTRACT** operation.
* **DWORD dwFlags** \\ Flags that indicate how the batch operation should be performed. Currently defined flags are:
|BATCHF_COPY_PRESERVE_ATTR|preserve file attributes on add/extract|
|BATCHF_COPY_PRESERVE_DATE|preserve file timestamps on add/extract|
|BATCHF_COPY_PRESERVE_COMMENTS|preserve file comments on add/extract|
|BATCHF_COPY_PRESERVE_SECURITY|preserve file security information|
|BATCHF_COPY_ASK_REPLACE|ask before overwriting existing files|
|BATCHF_COPY_ASK_REPLACE_RO|ask before overwriting read-only files|
|BATCHF_COPY_RENAME|ask user for new filenames (copy as)|
|BATCHF_COPY_DELETE_ORIGINAL|operation is a 'move' - delete original files|
|BATCHF_DELETE_ASK|ask before beginning delete|
|BATCHF_DELETE_ASK_FILES|ask for each file before deleting|
|BATCHF_DELETE_ASK_FOLDERS|ask for each folder before deleting|
|BATCHF_DELETE_UNPROTECT|automatically unprotect files to delete|
|BATCHF_DELETE_ALL|delete all without prompting for each|
|BATCHF_DELETE_QUIET|don't prompt to begin deleting|
|BATCHF_DELETE_FORCE|force deletion|
|BATCHF_DELETE_SECURE|secure delete if possible|
|BATCHF_FILTER|a filter is in force|
|BATCHF_FILTER_FOLDERS|a filter is in force for folders|
|BATCHF_PROGRESS_SUBFOLDERS|progress bar knows about sub-folder contents|
Most of these flags correspond to the options in the Opus Preferences (Copying/Deleting) and may not be relevant to your plugin. The 'ask' flags should be respected if possible - you can display confirmation dialogs using the Plugin Support API, which also contains functions to make respecting the 'filter' flags easy as well.
* **LPVOID lpFuncData** \\ This provides a parameter that is used in several calls to the Plugin Support API for updating progress bars, filtering files, etc.
When Opus calls your [[.exported_functions_reference:vfs_batchoperation|VFS_BatchOperation]] function, you should examine the **VFSBATCHDATA** structure to determine if this is an operation you can process in batch mode. If it isn't (for example, you may support batch extraction but not deletion), you should return **VFSBATCHRES_DODEFAULT**. This indicates to Opus that batch mode is not available and Opus will then proceed to handle the operation in the usual way (via calls to [[.exported_functions_reference:vfs_createfile|VFS_CreateFile]], [[.exported_functions_reference:vfs_readfile|VFS_ReadFile]], etc.)
If, however, you can process the requested operation, you should then proceed to do so. Basically this is a matter of performing the requested actions, and returning result codes for each file. However, it is also the responsibility of the plugin to emulate Opus as much as possible while processing a batch operation. This may include displaying confirmation dialogs or dialogs asking for new filenames, displaying error messages, applying filters to files and folders and updating the progress bar. It is not required that you perform all these steps, however the user will enjoy a more seamless experience if you do.
The Plugin Support API (documented separately) provides several functions which can make these steps much easier for you. The functions specifically involved with batch mode operations that you may wish to use are:
|**ShowRequestDlg**|generic message dialog helper function|
|**ShowFunctionNewNameDlg**|displays a dialog allowing the user to specify a new filename|
|**GetWildNewName**|get a new filename from user-entered wildcard pattern|
|**ShowFunctionErrorDlg**|display an error message|
|**ShowFunctionReplaceDlg**|display 'replace existing file?' confirmation dialog|
|**ShowFunctionInitialDeleteDlg**|display initial confirmation dialog when deleting files|
|**ShowFunctionDeleteDlg**|display confirmation dialog when deleting a file or folder|
|**FilterFunctionFile**|apply filters to files or folders|
|**AddFunctionFileChange**|notify Opus of a file change in your plugin's namespace|
|**UpdateFunctionProgressBar**|update the progress bar for a batch mode operation|
|**GetFunctionWindow**|retrieve window handle for a batch mode operation|
For example, if the **BATCHF_FILTER** flag was set in the **VFSBATCHDATA** structure, you would call the **FilterFunctionFile** function to see if a file was to be filtered out.
See the Plugin Support API documentation for full information about these helper functions.
Your [[.exported_functions_reference:vfs_batchoperation|VFS_BatchOperation]] function should return a value indicating the result of the batch operation. See the reference section for a full description of the return codes.