From 5c44b1a4e438fc28729de9bdb632907638ede60c Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 16 Jun 2022 12:44:19 +0200 Subject: Updated PhysFS usage We now require at least PhysFS 2.1. Also no longer add the "current directory" to the search path and allow the "PKG_DATADIR" used to locate files shipping with the server to be overridden by the "serverPath" configuration variable. Closes #81 --- src/common/resourcemanager.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/common/resourcemanager.cpp b/src/common/resourcemanager.cpp index 82675c7b..bd6961d9 100644 --- a/src/common/resourcemanager.cpp +++ b/src/common/resourcemanager.cpp @@ -49,11 +49,12 @@ void ResourceManager::initialize() const std::string worldDataPath = Configuration::getValue("worldDataPath", "example"); + const std::string serverPath = + Configuration::getValue("serverPath", PKG_DATADIR); // world first to allow overriding of server's libraries - PHYSFS_addToSearchPath(worldDataPath.c_str(), 1); - PHYSFS_addToSearchPath(".", 1); - PHYSFS_addToSearchPath(PKG_DATADIR, 1); + PHYSFS_mount(worldDataPath.c_str(), nullptr, 1); + PHYSFS_mount(serverPath.c_str(), nullptr, 1); } /** @@ -95,7 +96,7 @@ char *ResourceManager::loadFile(const std::string &fileName, int &fileSize) if (file == nullptr) { LOG_WARN("Failed to load '" << fileName << "': " - << PHYSFS_getLastError()); + << PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return nullptr; } @@ -104,11 +105,11 @@ char *ResourceManager::loadFile(const std::string &fileName, int &fileSize) // Allocate memory and load the file char *buffer = (char *) malloc(fileSize + 1); - if (PHYSFS_read(file, buffer, 1, fileSize) != fileSize) + if (PHYSFS_readBytes(file, buffer, fileSize) != fileSize) { free(buffer); LOG_WARN("Failed to load '" << fileName << "': " - << PHYSFS_getLastError()); + << PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return nullptr; } -- cgit v1.2.3-70-g09d2