mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
Fixes to prev commit - restore ttvfs functionality when reading XML files, and minor other things
This commit is contained in:
parent
4bafcb3e18
commit
065def0674
9 changed files with 73 additions and 24 deletions
|
@ -1253,7 +1253,12 @@ std::string Continuity::getInternalFormName()
|
||||||
void Continuity::loadIntoSongBank(const std::string &file)
|
void Continuity::loadIntoSongBank(const std::string &file)
|
||||||
{
|
{
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
doc.LoadFile(file.c_str());
|
if(readXML(file, doc) != XML_SUCCESS)
|
||||||
|
{
|
||||||
|
errorLog("Failed to load song bank: Malformed XML");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
XMLElement *song = doc.FirstChildElement("Song");
|
XMLElement *song = doc.FirstChildElement("Song");
|
||||||
while (song)
|
while (song)
|
||||||
{
|
{
|
||||||
|
@ -2722,7 +2727,7 @@ void Continuity::loadFileData(int slot, XMLDocument &doc)
|
||||||
teh_file = dsq->continuity.getSaveFileName(slot, "xml");
|
teh_file = dsq->continuity.getSaveFileName(slot, "xml");
|
||||||
if (exists(teh_file))
|
if (exists(teh_file))
|
||||||
{
|
{
|
||||||
if (doc.LoadFile(teh_file.c_str()) != XML_SUCCESS)
|
if (readXML(teh_file, doc) != XML_SUCCESS)
|
||||||
errorLog("Failed to load save data: " + teh_file);
|
errorLog("Failed to load save data: " + teh_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ void Demo::save(const std::string &name)
|
||||||
|
|
||||||
std::string filename = "" + name + ".demo";
|
std::string filename = "" + name + ".demo";
|
||||||
|
|
||||||
|
/*
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
|
|
||||||
// UNFINISHED
|
// UNFINISHED
|
||||||
|
@ -91,6 +92,7 @@ void Demo::save(const std::string &name)
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.SaveFile(filename.c_str());
|
doc.SaveFile(filename.c_str());
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Demo::load(const std::string &name)
|
void Demo::load(const std::string &name)
|
||||||
|
@ -101,8 +103,8 @@ void Demo::load(const std::string &name)
|
||||||
// UNFINISHED
|
// UNFINISHED
|
||||||
std::string filename = "" + name + ".demo";
|
std::string filename = "" + name + ".demo";
|
||||||
|
|
||||||
XMLDocument doc;
|
//XMLDocument doc;
|
||||||
doc.LoadFile(filename.c_str());
|
//doc.LoadFile(filename.c_str());
|
||||||
|
|
||||||
//doc.FirstChildElement("");
|
//doc.FirstChildElement("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4197,12 +4197,15 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
//errorLog("Could not find [" + fn + "]");
|
//errorLog("Could not find [" + fn + "]");
|
||||||
//msg("Could not find map [" + fn + "]");
|
//msg("Could not find map [" + fn + "]");
|
||||||
std::string s = "Could not find map [" + fn + "]";
|
std::string s = "Could not find map [" + fn + "]";
|
||||||
debugLog(s);
|
|
||||||
dsq->screenMessage(s);
|
dsq->screenMessage(s);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
doc.LoadFile(fn.c_str());
|
if(readXML(fn, doc) != XML_SUCCESS)
|
||||||
|
{
|
||||||
|
dsq->screenMessage("Could not load scene [" + fn + "] - Malformed XML");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (saveFile)
|
if (saveFile)
|
||||||
{
|
{
|
||||||
delete saveFile;
|
delete saveFile;
|
||||||
|
|
|
@ -85,7 +85,8 @@ bool Mod::isEditorBlocked()
|
||||||
|
|
||||||
bool Mod::loadModXML(XMLDocument *d, std::string modName)
|
bool Mod::loadModXML(XMLDocument *d, std::string modName)
|
||||||
{
|
{
|
||||||
return d->LoadFile((baseModPath + modName + ".xml").c_str()) == XML_SUCCESS;
|
return readXML((baseModPath + modName + ".xml").c_str(), *d) == XML_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Mod::getBaseModPath() const
|
const std::string& Mod::getBaseModPath() const
|
||||||
|
|
|
@ -250,7 +250,7 @@ void ModDL::NotifyModlist(ModlistRequest *rq, NetEvent ev, size_t recvd, size_t
|
||||||
bool ModDL::ParseModXML(const std::string& fn, bool allowChaining)
|
bool ModDL::ParseModXML(const std::string& fn, bool allowChaining)
|
||||||
{
|
{
|
||||||
XMLDocument xml;
|
XMLDocument xml;
|
||||||
if(xml.LoadFile(fn.c_str()) != XML_SUCCESS)
|
if(readXML(fn, xml) != XML_SUCCESS)
|
||||||
{
|
{
|
||||||
debugLog("Failed to parse downloaded XML: " + fn);
|
debugLog("Failed to parse downloaded XML: " + fn);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -301,17 +301,24 @@ void UserSettings::loadDefaults(bool doApply)
|
||||||
|
|
||||||
void UserSettings::load(bool doApply, const std::string &overrideFile)
|
void UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
{
|
{
|
||||||
XMLDocument doc;
|
std::string filename;
|
||||||
|
|
||||||
#if defined(BBGE_BUILD_UNIX)
|
#if defined(BBGE_BUILD_UNIX)
|
||||||
doc.LoadFile((dsq->getPreferencesFolder() + "/" + userSettingsFilename).c_str());
|
filename = dsq->getPreferencesFolder() + "/" + userSettingsFilename;
|
||||||
#elif defined(BBGE_BUILD_WINDOWS)
|
#elif defined(BBGE_BUILD_WINDOWS)
|
||||||
if (!overrideFile.empty())
|
if (!overrideFile.empty())
|
||||||
doc.LoadFile(overrideFile.c_str());
|
filename = overrideFile;
|
||||||
else
|
else
|
||||||
doc.LoadFile(userSettingsFilename.c_str());
|
filename = userSettingsFilename;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
XMLDocument doc;
|
||||||
|
if(readXML(filename, doc) != XML_SUCCESS)
|
||||||
|
{
|
||||||
|
errorLog("UserSettings: Malformed XML, continuing with defaults");
|
||||||
|
doc.Clear(); // just in case
|
||||||
|
}
|
||||||
|
|
||||||
version.settingsVersion = 0;
|
version.settingsVersion = 0;
|
||||||
|
|
||||||
XMLElement *xml_version = doc.FirstChildElement("Version");
|
XMLElement *xml_version = doc.FirstChildElement("Version");
|
||||||
|
|
|
@ -538,6 +538,29 @@ char *readFile(const std::string& path, unsigned long *size_ret)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc)
|
||||||
|
{
|
||||||
|
unsigned long sz = 0;
|
||||||
|
char *buf = readFile(fn, &sz);
|
||||||
|
tinyxml2::XMLError err = doc.Parse(buf, sz);
|
||||||
|
delete [] buf;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
|
||||||
|
tinyxml2::XMLError err = readXML(fn, *doc);
|
||||||
|
if(perr)
|
||||||
|
*perr = err;
|
||||||
|
if(err != tinyxml2::XML_SUCCESS)
|
||||||
|
{
|
||||||
|
delete doc;
|
||||||
|
doc = NULL;
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void pForEachFile(std::string path, std::string type, void callback(const std::string &filename, int param), int param)
|
void pForEachFile(std::string path, std::string type, void callback(const std::string &filename, int param), int param)
|
||||||
{
|
{
|
||||||
|
|
|
@ -143,6 +143,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "ttvfs_stdio.h"
|
#include "ttvfs_stdio.h"
|
||||||
|
|
||||||
|
#include "tinyxml2.h"
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_LINUX
|
#ifdef BBGE_BUILD_LINUX
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
|
@ -204,6 +206,8 @@ bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
|
||||||
void errorLog(const std::string &s);
|
void errorLog(const std::string &s);
|
||||||
void debugLog(const std::string &s);
|
void debugLog(const std::string &s);
|
||||||
char *readFile(const std::string& path, unsigned long *size_ret = 0);
|
char *readFile(const std::string& path, unsigned long *size_ret = 0);
|
||||||
|
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0);
|
||||||
|
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc);
|
||||||
char *readCompressedFile(std::string path, unsigned long *size_ret = 0);
|
char *readCompressedFile(std::string path, unsigned long *size_ret = 0);
|
||||||
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
|
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
|
||||||
std::string stripEndlineForUnix(const std::string &in);
|
std::string stripEndlineForUnix(const std::string &in);
|
||||||
|
|
|
@ -36,20 +36,19 @@ static std::map<std::string, XMLDocument*> skelCache;
|
||||||
|
|
||||||
static XMLDocument *_retrieveSkeletalXML(const std::string& name)
|
static XMLDocument *_retrieveSkeletalXML(const std::string& name)
|
||||||
{
|
{
|
||||||
XMLDocument *doc = skelCache[name];
|
std::map<std::string, XMLDocument*>::iterator it = skelCache.find(name);
|
||||||
if (!doc) {
|
if(it != skelCache.end())
|
||||||
doc = new XMLDocument();
|
return it->second;
|
||||||
doc->LoadFile(name.c_str());
|
|
||||||
|
XMLDocument *doc = readXML(name);
|
||||||
|
if(doc)
|
||||||
skelCache[name] = doc;
|
skelCache[name] = doc;
|
||||||
}
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletalSprite::clearCache()
|
void SkeletalSprite::clearCache()
|
||||||
{
|
{
|
||||||
for (std::map<std::string, XMLDocument*>::iterator i = skelCache.begin(); i != skelCache.end(); i++)
|
|
||||||
delete i->second;
|
|
||||||
|
|
||||||
skelCache.clear();
|
skelCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1316,16 +1315,21 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
|
||||||
if (!exists(file))
|
if (!exists(file))
|
||||||
{
|
{
|
||||||
filenameLoaded = "";
|
filenameLoaded = "";
|
||||||
errorLog("Could not load skeletal[" + file + "]");
|
errorLog("Could not load skeletal[" + file + "] - File not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = core->adjustFilenameCase(file);
|
file = core->adjustFilenameCase(file);
|
||||||
|
|
||||||
loaded = true;
|
|
||||||
|
|
||||||
XMLDocument *xml = _retrieveSkeletalXML(file);
|
XMLDocument *xml = _retrieveSkeletalXML(file);
|
||||||
xml->LoadFile(file.c_str());
|
if(!xml)
|
||||||
|
{
|
||||||
|
filenameLoaded = "";
|
||||||
|
errorLog("Could not load skeletal[" + file + "] - Malformed XML.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
|
||||||
XMLElement *bones = xml->FirstChildElement("Bones");
|
XMLElement *bones = xml->FirstChildElement("Bones");
|
||||||
if (bones)
|
if (bones)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue