diff options
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. |