diff --git a/src/StringUtils.h b/src/StringUtils.h index 828d116..8986c43 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -16,3 +16,19 @@ inline bool strToBool(const std::string& str) { return str == "true" || atoi(str.c_str()) != 0; } + +/** Returns @p text if non-null or a pointer + * to an empty null-terminated string otherwise. + */ +inline const char* notNullString(const char* text) +{ + if (text) + { + return text; + } + else + { + return ""; + } +} + diff --git a/src/UpdateScript.cpp b/src/UpdateScript.cpp index c9e2d69..eb1c2c6 100644 --- a/src/UpdateScript.cpp +++ b/src/UpdateScript.cpp @@ -5,6 +5,15 @@ #include "tinyxml/tinyxml.h" +std::string elementText(const TiXmlElement* element) +{ + if (!element) + { + return std::string(); + } + return element->GetText(); +} + UpdateScript::UpdateScript() { } @@ -21,18 +30,7 @@ void UpdateScript::parse(const std::string& path) LOG(Info,"Loaded script from " + path); const TiXmlElement* updateNode = document.RootElement(); - const TiXmlElement* v3UpdateNode = updateNode->FirstChildElement("update-v3"); - if (v3UpdateNode) - { - // this XML file is structured for backwards compatibility - // with Mendeley Desktop <= 1.0 clients. The normal update XML contents - // are wrapped in an node. - parseUpdate(v3UpdateNode); - } - else - { - parseUpdate(updateNode); - } + parseUpdate(updateNode); } else { @@ -47,6 +45,8 @@ bool UpdateScript::isValid() const void UpdateScript::parseUpdate(const TiXmlElement* updateNode) { + bool isV2Compatible = strToBool(notNullString(updateNode->Attribute("v2-compatible"))); + const TiXmlElement* depsNode = updateNode->FirstChildElement("dependencies"); const TiXmlElement* depFileNode = depsNode->FirstChildElement("file"); while (depFileNode) @@ -55,7 +55,22 @@ void UpdateScript::parseUpdate(const TiXmlElement* updateNode) depFileNode = depFileNode->NextSiblingElement("file"); } - const TiXmlElement* installNode = updateNode->FirstChildElement("install"); + const char* installNodeName; + if (isV2Compatible) + { + // this update script has been generated for backwards compatibility with + // Mendeley Desktop 1.0 which downloads files specified in the + // section instead of the section. The section + // in this case lists the packages and the real list of files to install + // is in the section + installNodeName = "install-v3"; + } + else + { + installNodeName = "install"; + } + + const TiXmlElement* installNode = updateNode->FirstChildElement(installNodeName); if (installNode) { const TiXmlElement* installFileNode = installNode->FirstChildElement("file"); @@ -89,15 +104,6 @@ void UpdateScript::parseUpdate(const TiXmlElement* updateNode) } } -std::string elementText(const TiXmlElement* element) -{ - if (!element) - { - return std::string(); - } - return element->GetText(); -} - UpdateScriptFile UpdateScript::parseFile(const TiXmlElement* element) { UpdateScriptFile file; diff --git a/src/tests/v2_file_list.xml b/src/tests/v2_file_list.xml index a47c6f6..40232bc 100644 --- a/src/tests/v2_file_list.xml +++ b/src/tests/v2_file_list.xml @@ -1,46 +1,53 @@ - - - - 2.0 - Test - - - - - - app-pkg - $APP_PACKAGE_HASH - $APP_PACKAGE_SIZE - http://some/dummy/URL - - - - - app - $UPDATED_APP_HASH - $UPDATED_APP_SIZE - 30549 - app-pkg - true - - - - test-dir/app-symlink - ../app - - - - - file-to-uninstall.txt - - + + + 2.0 + Test + + + + + + app-pkg + $APP_PACKAGE_HASH + $APP_PACKAGE_SIZE + http://some/dummy/URL + + + + + + + + + + $APP_FILENAME + $UPDATED_APP_HASH + $UPDATED_APP_SIZE + 30549 + app-pkg + true + + + + test-dir/app-symlink + ../app + + + + + file-to-uninstall.txt +