summaryrefslogtreecommitdiffstats
path: root/mmc_updater/src/UpdateScript.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-12-02 00:55:24 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-02 00:55:24 +0100
commit6aa9bd0f77dcb5128167fae62e32aa5252fe85c6 (patch)
tree632994a61888929af9289927d338bd19a2b3f32c /mmc_updater/src/UpdateScript.cpp
parent613699b3626aea750093ab7eaaeccaa28c0e87c6 (diff)
downloadMultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.gz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.lz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.xz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.zip
Renew the updater branch
Now with some actual consensus on what the updater will do!
Diffstat (limited to 'mmc_updater/src/UpdateScript.cpp')
-rw-r--r--mmc_updater/src/UpdateScript.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/mmc_updater/src/UpdateScript.cpp b/mmc_updater/src/UpdateScript.cpp
new file mode 100644
index 00000000..606163dd
--- /dev/null
+++ b/mmc_updater/src/UpdateScript.cpp
@@ -0,0 +1,98 @@
+#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;
+ file.path = elementText(element->FirstChildElement("name"));
+
+ std::string modeString = elementText(element->FirstChildElement("permissions"));
+ sscanf(modeString.c_str(),"%i",&file.permissions);
+
+ file.linkTarget = elementText(element->FirstChildElement("target"));
+ file.isMainBinary = strToBool(elementText(element->FirstChildElement("is-main-binary")));
+ 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;
+}
+