diff options
author | Chuck Miller <shadowmil@gmail.com> | 2009-12-19 04:40:42 -0500 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-12-19 05:08:56 -0500 |
commit | cbc14c8a3c6614987d2331057e114d92336cbac0 (patch) | |
tree | a3693bd6ac6aca39a34a2d9a9f644873d63ecf32 /src/utils | |
parent | 117cc13e863b788bfc8adef9468dba54c4909b9b (diff) | |
download | mana-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.gz mana-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.bz2 mana-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.xz mana-cbc14c8a3c6614987d2331057e114d92336cbac0.zip |
Added support for resources.xml from update server... Also added option to download music optionally
I had to edit the XML wrapper a bit, basicilly its constructor can now take a optional
thrid arguement which will tell it to use a resman or open the file directly
Also I added fallback support for the old resouce2.txt so servers don't have to
upgrade if they do not want to
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/xml.cpp | 35 | ||||
-rw-r--r-- | src/utils/xml.h | 2 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 7a6f75de..4d85e87f 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -25,14 +25,43 @@ #include "resources/resourcemanager.h" +#include <iostream> +#include <fstream> + namespace XML { - Document::Document(const std::string &filename): + Document::Document(const std::string &filename, bool useResman): mDoc(0) { int size; - ResourceManager *resman = ResourceManager::getInstance(); - char *data = (char*) resman->loadFile(filename.c_str(), size); + char *data; + if (useResman) + { + ResourceManager *resman = ResourceManager::getInstance(); + data = (char*) resman->loadFile(filename.c_str(), size); + } + else + { + std::ifstream file; + file.open(filename.c_str(), std::ios::in); + + if (file.is_open()) + { + // Get length of file + file.seekg (0, std::ios::end); + size = file.tellg(); + file.seekg(0, std::ios::beg); + + data = new char[size]; + + file.read(data, size); + file.close(); + } + else + { + logger->log("Error loading XML file %s", filename.c_str()); + } + } if (data) { mDoc = xmlParseMemory(data, size); diff --git a/src/utils/xml.h b/src/utils/xml.h index e7075279..441d2125 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -42,7 +42,7 @@ namespace XML * Constructor that attempts to load the given file through the * resource manager. Logs errors. */ - Document(const std::string &filename); + Document(const std::string &filename, bool useResman = true); /** * Constructor that attempts to load an XML document from memory. |