diff options
Diffstat (limited to 'src/fs/virtfs/virtfs.cpp')
-rw-r--r-- | src/fs/virtfs/virtfs.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfs.cpp b/src/fs/virtfs/virtfs.cpp index bab10197d..b36ee5ddd 100644 --- a/src/fs/virtfs/virtfs.cpp +++ b/src/fs/virtfs/virtfs.cpp @@ -561,4 +561,33 @@ namespace VirtFs { return file->funcs->eof(file); } + + char *loadFile(const std::string &restrict fileName, + int &restrict fileSize) + { + // Attempt to open the specified file using PhysicsFS + VirtFile *restrict const file = VirtFs::openRead(fileName); + + if (!file) + { + logger->log("Warning: Failed to load %s.", + fileName.c_str()); + return nullptr; + } + + logger->log("Loaded %s/%s", + VirtFs::getRealDir(fileName).c_str(), + fileName.c_str()); + + fileSize = CAST_S32(VirtFs::fileLength(file)); + // Allocate memory and load the file + char *restrict const buffer = new char[fileSize]; + if (fileSize > 0) + buffer[fileSize - 1] = 0; + VirtFs::read(file, buffer, 1, fileSize); + VirtFs::close(file); + + return buffer; + } + } // namespace VirtFs |