From 2c6201683854d3f56c93f3f2ca1f826b1b2f450e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 22 Aug 2010 02:05:31 +0000 Subject: SWORD25: Added GetXmlFile helper function The XML files included with the game don't include an XML header line, which is required by the ScummVM XML parser. This helper function encapsulates the GetFile method to return a buffer that includes the required line at the start. svn-id: r53276 --- engines/sword25/package/packagemanager.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'engines/sword25/package/packagemanager.h') diff --git a/engines/sword25/package/packagemanager.h b/engines/sword25/package/packagemanager.h index 04f863bef8..c441fff122 100644 --- a/engines/sword25/package/packagemanager.h +++ b/engines/sword25/package/packagemanager.h @@ -101,6 +101,28 @@ public: * @remark The client must not forget to release the data of the file using BE_DELETE_A. */ virtual byte *GetFile(const Common::String &FileName, unsigned int *pFileSize = NULL) = 0; + /** + * Downloads an XML file and prefixes it with an XML Version key, since the XML files don't contain it, + * and it is required for ScummVM to correctly parse the XML. + * @param FileName The filename of the file to load + * @param pFileSize Pointer to the variable that will contain the size of the loaded file. The deafult is NULL. + * @return Specifies a pointer to the loaded data of the file + * @remark The client must not forget to release the data of the file using BE_DELETE_A. + */ + char *GetXmlFile(const Common::String &FileName, unsigned int *pFileSize = NULL) { + const char *versionStr = ""; + unsigned int fileSize; + char *data = (char *)GetFile(FileName, &fileSize); + char *result = (char *)malloc(fileSize + strlen(versionStr) + 1); + strcpy(result, versionStr); + Common::copy(data, data + fileSize, result + strlen(versionStr)); + result[fileSize + strlen(versionStr)] = '\0'; + + free(data); + if (pFileSize) *pFileSize = fileSize + strlen(versionStr); + return result; + } + /** * Returns the path to the current directory. * @return Returns a string containing the path to the current directory. -- cgit v1.2.3