summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-19 08:22:56 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-19 08:22:56 +0000
commit65fac3220e870160e888da4bc8e826653a8a0720 (patch)
tree676615b7aefa814dace3cdf7d42699ed01b2af58
parenteab47c4f2674516d9499e837eff5b6b40f48213d (diff)
downloadMana-65fac3220e870160e888da4bc8e826653a8a0720.tar.gz
Mana-65fac3220e870160e888da4bc8e826653a8a0720.tar.bz2
Mana-65fac3220e870160e888da4bc8e826653a8a0720.tar.xz
Mana-65fac3220e870160e888da4bc8e826653a8a0720.zip
Updated PhysicsFS API usage
Unfortunately, since we're making a difference between config and data, and also want to know where to write screenshots, we can't get rid of PHYSFS_getUserDir entirely. We'd need a replacement to get rid of the deprecation warnings. Also removed copying of old config file at "/.tmw/config.xml".
-rw-r--r--src/client.cpp56
-rw-r--r--src/main.cpp2
-rw-r--r--src/resources/resourcemanager.cpp23
3 files changed, 24 insertions, 57 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 6bbba39b..705cfdc0 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1114,22 +1114,16 @@ void Client::initHomeDir()
if (mLocalDataDir.empty())
{
-#ifdef __APPLE__
- // Use Application Directory instead of .mana
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
- "/Library/Application Support/" +
- branding.getValue("appName", "Mana");
-#elif defined __HAIKU__
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
- "/config/data/Mana";
+#if defined __HAIKU__
+ mLocalDataDir = PHYSFS_getUserDir();
+ mLocalDataDir += "/config/data/Mana";
#elif defined _WIN32
mLocalDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
if (mLocalDataDir.empty())
- mLocalDataDir = std::string(PHYSFS_getUserDir());
+ mLocalDataDir = PHYSFS_getUserDir();
mLocalDataDir += "/Mana";
#else
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
- "/.local/share/mana";
+ mLocalDataDir = PHYSFS_getPrefDir("manasource.org", "mana");
#endif
}
@@ -1147,17 +1141,12 @@ void Client::initHomeDir()
#ifdef __APPLE__
mConfigDir = mLocalDataDir + "/" + app;
#elif defined __HAIKU__
- mConfigDir = std::string(PHYSFS_getUserDir()) +
- "/config/settings/Mana" +
- branding.getValue("appName", "manasource");
+ mConfigDir = PHYSFS_getPrefDir("manasource.org", "Mana");
+ mConfigDir += app;
#elif defined _WIN32
- mConfigDir = getSpecialFolderLocation(CSIDL_APPDATA);
- if (mConfigDir.empty())
- mConfigDir = mLocalDataDir;
- else
- mConfigDir += "/mana/" + app;
+ mConfigDir = PHYSFS_getPrefDir("Mana", app.c_str());
#else
- mConfigDir = std::string(PHYSFS_getUserDir()) + "/.config/mana/" + app;
+ mConfigDir = std::string(PHYSFS_getUserDir()) + ".config/mana/" + app;
#endif
}
@@ -1166,33 +1155,6 @@ void Client::initHomeDir()
logger->error(strprintf(_("%s doesn't exist and can't be created! "
"Exiting."), mConfigDir.c_str()));
}
-
- struct stat statbuf;
- std::string newConfigFile = mConfigDir + "/config.xml";
- if (stat(newConfigFile.c_str(), &statbuf))
- {
- std::string oldConfigFile = std::string(PHYSFS_getUserDir()) +
- "/.tmw/config.xml";
- if (mRootDir.empty() && !stat(oldConfigFile.c_str(), &statbuf)
- && S_ISREG(statbuf.st_mode))
- {
- std::ifstream oldConfig;
- std::ofstream newConfig;
- logger->log("Copying old TMW settings.");
-
- oldConfig.open(oldConfigFile.c_str(), std::ios::binary);
- newConfig.open(newConfigFile.c_str(), std::ios::binary);
-
- if (!oldConfig.is_open() || !newConfig.is_open())
- logger->log("Unable to copy old settings.");
- else
- {
- newConfig << oldConfig.rdbuf();
- newConfig.close();
- oldConfig.close();
- }
- }
- }
}
/**
diff --git a/src/main.cpp b/src/main.cpp
index eecb60e7..b3fd699c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
// Initialize PhysicsFS
if (!PHYSFS_init(argv[0])) {
std::cout << "Error while initializing PhysFS: "
- << PHYSFS_getLastError() << std::endl;
+ << PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) << std::endl;
return 1;
}
atexit((void(*)()) PHYSFS_deinit);
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 71d9ca1c..dd9aaebb 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -155,9 +155,9 @@ bool ResourceManager::setWriteDir(const std::string &path)
bool ResourceManager::addToSearchPath(const std::string &path, bool append)
{
logger->log("Adding to PhysicsFS: %s", path.c_str());
- if (!PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0))
+ if (!PHYSFS_mount(path.c_str(), nullptr, append ? 1 : 0))
{
- logger->log("Error: %s", PHYSFS_getLastError());
+ logger->log("Error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
return false;
}
return true;
@@ -201,7 +201,12 @@ bool ResourceManager::exists(const std::string &path)
bool ResourceManager::isDirectory(const std::string &path)
{
- return PHYSFS_isDirectory(path.c_str());
+ PHYSFS_Stat stat;
+ if (PHYSFS_stat(path.c_str(), &stat) != 0)
+ {
+ return stat.filetype == PHYSFS_FILETYPE_DIRECTORY;
+ }
+ return false;
}
std::string ResourceManager::getPath(const std::string &file)
@@ -442,7 +447,7 @@ void *ResourceManager::loadFile(const std::string &filename, int &filesize,
if (file == nullptr)
{
logger->log("Warning: Failed to load %s: %s",
- filename.c_str(), PHYSFS_getLastError());
+ filename.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
return nullptr;
}
@@ -455,7 +460,7 @@ void *ResourceManager::loadFile(const std::string &filename, int &filesize,
// Allocate memory and load the file
void *buffer = malloc(filesize);
- PHYSFS_read(file, buffer, 1, filesize);
+ PHYSFS_readBytes(file, buffer, filesize);
// Close the file and let the user deallocate the memory
PHYSFS_close(file);
@@ -492,21 +497,21 @@ bool ResourceManager::copyFile(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());
+ logger->log("Read error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
return false;
}
PHYSFS_file *dstFile = PHYSFS_openWrite(dst.c_str());
if (!dstFile)
{
- logger->log("Write error: %s", PHYSFS_getLastError());
+ logger->log("Write error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
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_readBytes(srcFile, buf, fileSize);
+ PHYSFS_writeBytes(dstFile, buf, fileSize);
PHYSFS_close(srcFile);
PHYSFS_close(dstFile);