1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-25 14:15:46 +00:00

Fixes to prev commit - restore ttvfs functionality when reading XML files, and minor other things

This commit is contained in:
fgenesis 2014-06-09 23:39:33 +02:00
parent 4bafcb3e18
commit 065def0674
9 changed files with 73 additions and 24 deletions

View file

@ -1253,7 +1253,12 @@ std::string Continuity::getInternalFormName()
void Continuity::loadIntoSongBank(const std::string &file)
{
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");
while (song)
{
@ -2722,7 +2727,7 @@ void Continuity::loadFileData(int slot, XMLDocument &doc)
teh_file = dsq->continuity.getSaveFileName(slot, "xml");
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);
}
}

View file

@ -77,6 +77,7 @@ void Demo::save(const std::string &name)
std::string filename = "" + name + ".demo";
/*
XMLDocument doc;
// UNFINISHED
@ -91,6 +92,7 @@ void Demo::save(const std::string &name)
}
doc.SaveFile(filename.c_str());
*/
}
void Demo::load(const std::string &name)
@ -101,8 +103,8 @@ void Demo::load(const std::string &name)
// UNFINISHED
std::string filename = "" + name + ".demo";
XMLDocument doc;
doc.LoadFile(filename.c_str());
//XMLDocument doc;
//doc.LoadFile(filename.c_str());
//doc.FirstChildElement("");
}

View file

@ -4197,12 +4197,15 @@ bool Game::loadSceneXML(std::string scene)
//errorLog("Could not find [" + fn + "]");
//msg("Could not find map [" + fn + "]");
std::string s = "Could not find map [" + fn + "]";
debugLog(s);
dsq->screenMessage(s);
return false;
}
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)
{
delete saveFile;

View file

@ -85,7 +85,8 @@ bool Mod::isEditorBlocked()
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

View file

@ -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)
{
XMLDocument xml;
if(xml.LoadFile(fn.c_str()) != XML_SUCCESS)
if(readXML(fn, xml) != XML_SUCCESS)
{
debugLog("Failed to parse downloaded XML: " + fn);
return false;

View file

@ -301,17 +301,24 @@ void UserSettings::loadDefaults(bool doApply)
void UserSettings::load(bool doApply, const std::string &overrideFile)
{
XMLDocument doc;
std::string filename;
#if defined(BBGE_BUILD_UNIX)
doc.LoadFile((dsq->getPreferencesFolder() + "/" + userSettingsFilename).c_str());
filename = dsq->getPreferencesFolder() + "/" + userSettingsFilename;
#elif defined(BBGE_BUILD_WINDOWS)
if (!overrideFile.empty())
doc.LoadFile(overrideFile.c_str());
filename = overrideFile;
else
doc.LoadFile(userSettingsFilename.c_str());
filename = userSettingsFilename;
#endif
XMLDocument doc;
if(readXML(filename, doc) != XML_SUCCESS)
{
errorLog("UserSettings: Malformed XML, continuing with defaults");
doc.Clear(); // just in case
}
version.settingsVersion = 0;
XMLElement *xml_version = doc.FirstChildElement("Version");

View file

@ -538,6 +538,29 @@ char *readFile(const std::string& path, unsigned long *size_ret)
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)
{

View file

@ -143,6 +143,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "math.h"
#include "ttvfs_stdio.h"
#include "tinyxml2.h"
#ifdef BBGE_BUILD_LINUX
# include <sys/types.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 debugLog(const std::string &s);
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);
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);

View file

@ -36,20 +36,19 @@ static std::map<std::string, XMLDocument*> skelCache;
static XMLDocument *_retrieveSkeletalXML(const std::string& name)
{
XMLDocument *doc = skelCache[name];
if (!doc) {
doc = new XMLDocument();
doc->LoadFile(name.c_str());
std::map<std::string, XMLDocument*>::iterator it = skelCache.find(name);
if(it != skelCache.end())
return it->second;
XMLDocument *doc = readXML(name);
if(doc)
skelCache[name] = doc;
}
return doc;
}
void SkeletalSprite::clearCache()
{
for (std::map<std::string, XMLDocument*>::iterator i = skelCache.begin(); i != skelCache.end(); i++)
delete i->second;
skelCache.clear();
}
@ -1316,16 +1315,21 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
if (!exists(file))
{
filenameLoaded = "";
errorLog("Could not load skeletal[" + file + "]");
errorLog("Could not load skeletal[" + file + "] - File not found.");
return;
}
file = core->adjustFilenameCase(file);
loaded = true;
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");
if (bones)