summaryrefslogtreecommitdiff
path: root/src/resources/settingsmanager.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 22:22:12 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 22:25:09 +0100
commitd86a1df562e00a6e930683534b9d001f45a951ff (patch)
tree9a93089f89580e6023f5671d6a2256285b75c590 /src/resources/settingsmanager.cpp
parent5afe88df2538274859a162ffd63ed52118e80c19 (diff)
downloadmana-d86a1df562e00a6e930683534b9d001f45a951ff.tar.gz
mana-d86a1df562e00a6e930683534b9d001f45a951ff.tar.bz2
mana-d86a1df562e00a6e930683534b9d001f45a951ff.tar.xz
mana-d86a1df562e00a6e930683534b9d001f45a951ff.zip
Added fallback for XML data files and support absolute paths
For compatibility with TMW, which has not yet adopted a central "settings.xml" that includes all the other files. Also, a "name" attribute with an absolute path is now supported in addition to the relative "file" attribute, since that is what ManaPlus supported. This resolves most of issue #43.
Diffstat (limited to 'src/resources/settingsmanager.cpp')
-rw-r--r--src/resources/settingsmanager.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp
index a26fae9d..ad872385 100644
--- a/src/resources/settingsmanager.cpp
+++ b/src/resources/settingsmanager.cpp
@@ -43,7 +43,7 @@ namespace SettingsManager
static std::string mSettingsFile;
static std::set<std::string> mIncludedFiles;
- static void loadFile(const std::string &filename);
+ static bool loadFile(const std::string &filename);
void load()
{
@@ -60,7 +60,18 @@ namespace SettingsManager
Units::init();
// load stuff from settings
- loadFile("settings.xml");
+ if (!loadFile("settings.xml"))
+ {
+ // fall back to loading certain known files for TMW compatibility
+ loadFile("paths.xml");
+ loadFile("items.xml");
+ loadFile("monsters.xml");
+ loadFile("npcs.xml");
+ loadFile("emotes.xml");
+ loadFile("status-effects.xml");
+ loadFile("hair.xml");
+ loadFile("units.xml");
+ }
Attributes::checkStatus();
hairDB.checkStatus();
@@ -94,7 +105,7 @@ namespace SettingsManager
/**
* Loads a settings file.
*/
- static void loadFile(const std::string &filename)
+ static bool loadFile(const std::string &filename)
{
logger->log("Loading game settings from %s", filename.c_str());
@@ -108,10 +119,9 @@ namespace SettingsManager
if (!node /*|| !xmlStrEqual(node->name, BAD_CAST "settings") */)
{
logger->log("Settings Manager: %s is not a valid settings file!", filename.c_str());
- return;
+ return false;
}
-
// go through every node
for_each_xml_child_node(childNode, node)
{
@@ -121,27 +131,37 @@ namespace SettingsManager
if (xmlStrEqual(childNode->name, BAD_CAST "include"))
{
// include an other file
- const std::string includeFile = XML::getProperty(childNode, "file", std::string());
+ std::string includeFile = XML::getProperty(childNode, "file", std::string());
- // check if file property was given
if (!includeFile.empty())
{
// build absolute path path
const utils::splittedPath splittedPath = utils::splitFileNameAndPath(filename);
- const std::string realIncludeFile = utils::cleanPath(
- utils::joinPaths(splittedPath.path, includeFile));
+ includeFile = utils::cleanPath(utils::joinPaths(splittedPath.path, includeFile));
+ }
+ else
+ {
+ // try to get name property, which has an absolute value
+ includeFile = XML::getProperty(childNode, "name", std::string());
+ }
+ // check if file property was given
+ if (!includeFile.empty())
+ {
// check if we're not entering a loop
- if (mIncludedFiles.find(realIncludeFile) != mIncludedFiles.end())
+ if (mIncludedFiles.find(includeFile) != mIncludedFiles.end())
{
- logger->log("Circular include loop detecting while including %s from %s", includeFile.c_str(), filename.c_str());
+ logger->log("Warning: Circular include loop detecting while including %s from %s", includeFile.c_str(), filename.c_str());
}
else
{
- // include that file
- loadFile(realIncludeFile);
+ loadFile(includeFile);
}
}
+ else
+ {
+ logger->log("Warning: <include> element without 'file' or 'name' attribute in %s", filename.c_str());
+ }
}
else if (xmlStrEqual(childNode->name, BAD_CAST "option"))
{
@@ -207,6 +227,6 @@ namespace SettingsManager
}
mIncludedFiles.erase(filename);
+ return true;
}
-
}