diff options
author | Andrew <forkk@forkk.net> | 2013-12-09 12:04:05 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-12-09 12:04:05 -0600 |
commit | 7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c (patch) | |
tree | 52097b57dc7d18ec4e35ef3a8e554af2d91545e8 /mmc_updater/src/UpdateScript.cpp | |
parent | 9410dd042ea62224fa3e0eb3b525abbdf0c316ee (diff) | |
parent | 220e07aef4a34dca9f31ae0c5bb994e5c594125d (diff) | |
download | MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.gz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.lz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.xz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.zip |
Merge branch 'feature_updater' into develop
Diffstat (limited to 'mmc_updater/src/UpdateScript.cpp')
-rw-r--r-- | mmc_updater/src/UpdateScript.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/mmc_updater/src/UpdateScript.cpp b/mmc_updater/src/UpdateScript.cpp new file mode 100644 index 00000000..849a2217 --- /dev/null +++ b/mmc_updater/src/UpdateScript.cpp @@ -0,0 +1,99 @@ +#include "UpdateScript.h" + +#include "Log.h" +#include "StringUtils.h" + +#include "tinyxml/tinyxml.h" + +std::string elementText(const TiXmlElement* element) +{ + if (!element) + { + return std::string(); + } + return element->GetText(); +} + +UpdateScript::UpdateScript() +{ +} + +void UpdateScript::parse(const std::string& path) +{ + m_path.clear(); + + TiXmlDocument document(path); + if (document.LoadFile()) + { + m_path = path; + + LOG(Info,"Loaded script from " + path); + + const TiXmlElement* updateNode = document.RootElement(); + parseUpdate(updateNode); + } + else + { + LOG(Error,"Unable to load script " + path); + } +} + +bool UpdateScript::isValid() const +{ + return !m_path.empty(); +} + +void UpdateScript::parseUpdate(const TiXmlElement* updateNode) +{ + const TiXmlElement* installNode = updateNode->FirstChildElement("install"); + if (installNode) + { + const TiXmlElement* installFileNode = installNode->FirstChildElement("file"); + while (installFileNode) + { + m_filesToInstall.push_back(parseFile(installFileNode)); + installFileNode = installFileNode->NextSiblingElement("file"); + } + } + + const TiXmlElement* uninstallNode = updateNode->FirstChildElement("uninstall"); + if (uninstallNode) + { + const TiXmlElement* uninstallFileNode = uninstallNode->FirstChildElement("file"); + while (uninstallFileNode) + { + m_filesToUninstall.push_back(uninstallFileNode->GetText()); + uninstallFileNode = uninstallFileNode->NextSiblingElement("file"); + } + } +} + +UpdateScriptFile UpdateScript::parseFile(const TiXmlElement* element) +{ + UpdateScriptFile file; + // The name within the update files folder. + file.source = elementText(element->FirstChildElement("source")); + // The path to install to. + file.dest = elementText(element->FirstChildElement("dest")); + + std::string modeString = elementText(element->FirstChildElement("mode")); + sscanf(modeString.c_str(),"%i",&file.permissions); + + return file; +} + +const std::vector<UpdateScriptFile>& UpdateScript::filesToInstall() const +{ + return m_filesToInstall; +} + +const std::vector<std::string>& UpdateScript::filesToUninstall() const +{ + return m_filesToUninstall; +} + +const std::string UpdateScript::path() const +{ + return m_path; +} + |