diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2022-06-16 12:44:19 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2022-06-16 12:44:25 +0200 |
commit | 5c44b1a4e438fc28729de9bdb632907638ede60c (patch) | |
tree | 75e50711e908ff53d47f8dff2418655826311cc6 /src | |
parent | 42bef16cfac893d5f628e5218c82236e9e694248 (diff) | |
download | manaserv-5c44b1a4e438fc28729de9bdb632907638ede60c.tar.gz manaserv-5c44b1a4e438fc28729de9bdb632907638ede60c.tar.bz2 manaserv-5c44b1a4e438fc28729de9bdb632907638ede60c.tar.xz manaserv-5c44b1a4e438fc28729de9bdb632907638ede60c.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/common/resourcemanager.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
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; } |