From bb87f2911b63eaf80e49d689bf52ecf2042ae098 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 28 May 2014 20:31:09 +0300 Subject: Move from resourcemanager functions related to files into other files. --- src/utils/physfstools.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/utils/physfstools.cpp') diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp index 58be77f0e..1ab1aaa25 100644 --- a/src/utils/physfstools.cpp +++ b/src/utils/physfstools.cpp @@ -20,6 +20,8 @@ #include "utils/physfstools.h" +#include "logger.h" + #include #include @@ -134,4 +136,28 @@ namespace PhysFs { return PHYSFS_mkdir(dirname); } + + void *loadFile(const std::string &fileName, int &fileSize) + { + // Attempt to open the specified file using PhysicsFS + PHYSFS_file *const file = PhysFs::openRead(fileName.c_str()); + + if (!file) + { + logger->log("Warning: Failed to load %s: %s", + fileName.c_str(), PHYSFS_getLastError()); + return nullptr; + } + + logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()), + fileName.c_str()); + + fileSize = static_cast(PHYSFS_fileLength(file)); + // Allocate memory and load the file + void *const buffer = calloc(fileSize, 1); + PHYSFS_read(file, buffer, 1, fileSize); + PHYSFS_close(file); + + return buffer; + } } // namespace PhysFs -- cgit v1.2.3-60-g2f50