LoadOrSaveConfig(
int:iOperation,
LPDOPUSPLUGINCONFIGDATA:lpCfgData
)
→ BOOL
Arguments
iOperation
[in] Operation to perform. Valid values are:
| OPUSCFG_LOAD | Load configuration data |
| OPUSCFG_SAVE | Save configuration data |
lpCfgData
[in,out] Configuration data to load or save
Return value
Returns
TRUE if the operation was successful, or
FALSE on failure.
Description
The LoadOrSaveConfig function lets you load or save simple configuration data in XML format without needing to perform the XML parsing yourself.
The OPUSPLUGINCONFIGDATA structure contains the name of the configuration file to load or save, and an array of DOPUSPLUGINCONFIGITEM structures which define the actual data. The fields in the OPUSPLUGINCONFIGDATA structure are:
UINT cbSize
Before calling this function you must initialize this field to the size of the structure.
LPCTSTR pszName
The name of the configuration file to load or save. This should be based on the name of your plugin - for example, the RAR plugin uses "unrar". The file extension will be added automatically and the configuration file will be saved in the Opus plugin configuration folder.
BOOL fStateData
Set this to
TRUE if the configuration data describes
state data, that is, data that the user has not specifically configured themselves. State data is saved in a different folder to normal configuration data and may not be backed up or exported to USB. See
GetConfigPath for more information.
int iNumCfgItems
Specifies the number of configuration data items to save.
LPDOPUSPLUGINCONFIGITEM pCfgItemArray
Points to an array of DOPUSPLUGINCONFIGITEM structures, each of which defines an item of configuration data to load or save. The array must be the size specified by the iNumCfgItems field.
The DOPUSPLUGINCONFIGITEM array defines the configuration data to load or save. Each member of the array specifies one item of data. Each item has a name, a type, as well as the actual data. The fields of this structure are:
| DPCITYPE_Bool | Boolean value (TRUE or FALSE) |
| DPCITYPE_Int | Signed 32-bit integer value |
| DPCITYPE_DWORD | Unsigned 32-bit integer value |
| DPCITYPE_LPSTR | ANSI string (null-terminated) |
| DPCITYPE_LPWSTR | Unicode string (null-terminated) |
| DPCITYPE_Binary | Arbitrary binary data |
| DPCITYPE_LOGFONT | LOGFONT structure |
| DPCITYPE_Child | Nested child structure (no data) |
LPVOID pData
This specifies the actual data for the configuration item. For a save operation, this must point to a buffer containing the data to save. For a load operation, this must point to a buffer where the loaded data will be stored.
DWORD dwDataSize
This specifies the size of the buffer pointed to by pData, in bytes.
Note that several of the data types have special rules which apply to them:
DPCITYPE_Bool
When saving: If pData is set to 0 (null), or 1, dwDataSize is ignored, and the value of pData is used as the Boolean state.
When loading: If dwDataSize is 0, the Boolean state is stored in the pData field of the structure. If dwDataSize is set to sizeof(BOOL), the Boolean state is stored in the address pointed to by lpData.
DPCITYPE_Int
When saving: If dwDataSize is 0, the value of pData is used as the value to save. If dwDataSize is set to sizeof(int), the value pointed to by pData is used as the value to save. If dwDataSize is set to a multiple of sizeof(int), the address pointed to by pData is interpreted as an array of integers, and is saved as such.
When loading: If dwDataSize is 0, a single integer is loaded and stored in the pData field of the structure. If dwDataSize is set to sizeof(int), a single integer is loaded and stored in the address pointed to by pData. If dwDataSize is set to a multiple of sizeof(int), an array of integers is loaded and stored in the memory pointed to by pData.
DPCITYPE_DWORD
The same rules apply as for DPCITYPE_Int.
DPCITYPE_LPSTR / DPCITYPE_LPWSTR
When saving: The string pointed to by pData must be null-terminated. dwDataSize is ignored.
When loading: The loaded string will be stored in the buffer pointed to by pData, and is guaranteed to be null-terminated. If the buffer size specified by dwDataSize is too small, the string will be truncated. Note that the buffer size is always given as bytes, even for Unicode strings.
DPCITYPE_Binary
When saving: pData must point to valid memory and dwDataSize must specify the amount of binary data to save, in bytes.
When loading: The binary data will be stored in the memory pointed to by pData and dwDataSize must specify the size of the buffer in bytes. On return, dwDataSize will contain the amount of data that was stored in the buffer.
DPCITYPE_LOGFONT
In both cases, pData must point to either a LOGFONTA or a LOGFONTW structure, and the size of the structure must be given in dwDataSize.
DPCITYPE_Child
This data type does not actually store any data (lpData and dwDataSize are ignored.) Instead, it creates a child node in the XML data file providing simple control over the structure of the XML configuration file. Child nodes can be nested - to return from a child node to the previous level of the tree another DPCITYPE_Child item should be provided with an empty name.
See the supplied RAR sample VFS plugin for an example of how to use the LoadOrSaveConfig function.