From dac1c9d9b9558053ab9fc96eac8772604b8eedf2 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 16 Apr 2009 20:55:59 +0200 Subject: Added support for playing music in zip files. --- src/resources/resourcemanager.cpp | 26 ++++++++++++++++++++++++++ src/resources/resourcemanager.h | 11 +++++++++++ 2 files changed, 37 insertions(+) (limited to 'src/resources') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 33d5e3e5..e24ebafb 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -419,6 +419,32 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize) return buffer; } +bool ResourceManager::moveFile(const std::string &src, const std::string &dst) +{ + PHYSFS_file *srcFile = PHYSFS_openRead(src.c_str()); + if (!srcFile) + { + logger->log("Read error: %s", PHYSFS_getLastError()); + return false; + } + PHYSFS_file *dstFile = PHYSFS_openWrite(dst.c_str()); + if (!dstFile) + { + logger->log("Write error: %s", PHYSFS_getLastError()); + PHYSFS_close(srcFile); + return false; + } + + int fileSize = PHYSFS_fileLength(srcFile); + void *buf = malloc(fileSize); + PHYSFS_read(srcFile, buf, 1, fileSize); + PHYSFS_write(dstFile, buf, 1, fileSize); + + PHYSFS_close(srcFile); + PHYSFS_close(dstFile); + return true; +} + std::vector ResourceManager::loadTextFile(const std::string &fileName) { int contentsLength; diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index ec60fa9a..19c0cb61 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -124,6 +124,17 @@ class ResourceManager */ Resource *load(const std::string &path, loader fun); + /** + * Copies a file from one place to another (useful for extracting + * raw files from a zip archive, for example) + * + * @param src Source file name + * @param dst Destination file name + * @return true on success, false on failure. An error message should be + * in the log file. + */ + bool moveFile(const std::string &src, const std::string &dst); + /** * Convenience wrapper around ResourceManager::get for loading * images. -- cgit v1.2.3-60-g2f50