mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-23 04:01:59 +00:00
Change the syntax of the backwards-compatible update scripts.
Instead of moving the whole <update> section to an embedded <update-v3> node, just use a different name for the <install> section since older clients will ignore the new <packages> section. For older clients: * The <install> section lists the packages to download. This will exist in addition to the <packages> section. * The real <install> section listing the files to install is renamed to <install-v3>
This commit is contained in:
parent
78b3c14260
commit
da2614d427
3 changed files with 94 additions and 65 deletions
|
@ -16,3 +16,19 @@ inline bool strToBool(const std::string& str)
|
||||||
{
|
{
|
||||||
return str == "true" || atoi(str.c_str()) != 0;
|
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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,15 @@
|
||||||
|
|
||||||
#include "tinyxml/tinyxml.h"
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
|
std::string elementText(const TiXmlElement* element)
|
||||||
|
{
|
||||||
|
if (!element)
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
return element->GetText();
|
||||||
|
}
|
||||||
|
|
||||||
UpdateScript::UpdateScript()
|
UpdateScript::UpdateScript()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -21,18 +30,7 @@ void UpdateScript::parse(const std::string& path)
|
||||||
LOG(Info,"Loaded script from " + path);
|
LOG(Info,"Loaded script from " + path);
|
||||||
|
|
||||||
const TiXmlElement* updateNode = document.RootElement();
|
const TiXmlElement* updateNode = document.RootElement();
|
||||||
const TiXmlElement* v3UpdateNode = updateNode->FirstChildElement("update-v3");
|
parseUpdate(updateNode);
|
||||||
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 <update-v3> node.
|
|
||||||
parseUpdate(v3UpdateNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parseUpdate(updateNode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -47,6 +45,8 @@ bool UpdateScript::isValid() const
|
||||||
|
|
||||||
void UpdateScript::parseUpdate(const TiXmlElement* updateNode)
|
void UpdateScript::parseUpdate(const TiXmlElement* updateNode)
|
||||||
{
|
{
|
||||||
|
bool isV2Compatible = strToBool(notNullString(updateNode->Attribute("v2-compatible")));
|
||||||
|
|
||||||
const TiXmlElement* depsNode = updateNode->FirstChildElement("dependencies");
|
const TiXmlElement* depsNode = updateNode->FirstChildElement("dependencies");
|
||||||
const TiXmlElement* depFileNode = depsNode->FirstChildElement("file");
|
const TiXmlElement* depFileNode = depsNode->FirstChildElement("file");
|
||||||
while (depFileNode)
|
while (depFileNode)
|
||||||
|
@ -55,7 +55,22 @@ void UpdateScript::parseUpdate(const TiXmlElement* updateNode)
|
||||||
depFileNode = depFileNode->NextSiblingElement("file");
|
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 <install>
|
||||||
|
// section instead of the <packages> section. The <install> section
|
||||||
|
// in this case lists the packages and the real list of files to install
|
||||||
|
// is in the <install-v3> section
|
||||||
|
installNodeName = "install-v3";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
installNodeName = "install";
|
||||||
|
}
|
||||||
|
|
||||||
|
const TiXmlElement* installNode = updateNode->FirstChildElement(installNodeName);
|
||||||
if (installNode)
|
if (installNode)
|
||||||
{
|
{
|
||||||
const TiXmlElement* installFileNode = installNode->FirstChildElement("file");
|
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 UpdateScript::parseFile(const TiXmlElement* element)
|
||||||
{
|
{
|
||||||
UpdateScriptFile file;
|
UpdateScriptFile file;
|
||||||
|
|
|
@ -1,46 +1,53 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<update version="3">
|
|
||||||
<!-- Update script designed for backwards compatibility with MD <= 1.0.
|
|
||||||
The packages to download are listed as if they were ordinary files
|
|
||||||
to install in a top-level <install> section.
|
|
||||||
|
|
||||||
The standard V3 version of the update XML format is then wrapped inside
|
<!-- The v2-compatible attribute lets the update script parser
|
||||||
an <update-v3> element.
|
know that it is dealing with a script structured for backwards
|
||||||
!-->
|
compatibility with the MD <= 1.0 updater.
|
||||||
<update-v3>
|
!-->
|
||||||
<targetVersion>2.0</targetVersion>
|
<update version="3" v2-compatible="true">
|
||||||
<platform>Test</platform>
|
<targetVersion>2.0</targetVersion>
|
||||||
<dependencies>
|
<platform>Test</platform>
|
||||||
<!-- The new updater is standalone and has no dependencies,
|
<dependencies>
|
||||||
except for standard system libraries.
|
<!-- The new updater is standalone and has no dependencies,
|
||||||
!-->
|
except for standard system libraries and itself.
|
||||||
</dependencies>
|
!-->
|
||||||
<packages>
|
</dependencies>
|
||||||
<package>
|
<packages>
|
||||||
<name>app-pkg</name>
|
<package>
|
||||||
<hash>$APP_PACKAGE_HASH</hash>
|
<name>app-pkg</name>
|
||||||
<size>$APP_PACKAGE_SIZE</size>
|
<hash>$APP_PACKAGE_HASH</hash>
|
||||||
<source>http://some/dummy/URL</source>
|
<size>$APP_PACKAGE_SIZE</size>
|
||||||
</package>
|
<source>http://some/dummy/URL</source>
|
||||||
</packages>
|
</package>
|
||||||
<install>
|
</packages>
|
||||||
<file>
|
|
||||||
<name>app</name>
|
<!-- For compatibility with the update download in MD <= 1.0,
|
||||||
<hash>$UPDATED_APP_HASH</hash>
|
an <install> section lists the packages to download and
|
||||||
<size>$UPDATED_APP_SIZE</size>
|
the real list of files to install is in the <install-v3>
|
||||||
<permissions>30549</permissions>
|
section. !-->
|
||||||
<package>app-pkg</package>
|
<install>
|
||||||
<is-main-binary>true</is-main-binary>
|
<!-- A duplicate of the <packages> section should appear here,
|
||||||
</file>
|
except that each package is listed using the same structure
|
||||||
<!-- Test symlink !-->
|
as files in the install-v3/files section.
|
||||||
<file>
|
!-->
|
||||||
<name>test-dir/app-symlink</name>
|
</install>
|
||||||
<target>../app</target>
|
<install-v3>
|
||||||
</file>
|
<file>
|
||||||
</install>
|
<name>$APP_FILENAME</name>
|
||||||
<uninstall>
|
<hash>$UPDATED_APP_HASH</hash>
|
||||||
<!-- TODO - List some files to uninstall here !-->
|
<size>$UPDATED_APP_SIZE</size>
|
||||||
<file>file-to-uninstall.txt</file>
|
<permissions>30549</permissions>
|
||||||
</uninstall>
|
<package>app-pkg</package>
|
||||||
</update-v3>
|
<is-main-binary>true</is-main-binary>
|
||||||
|
</file>
|
||||||
|
<!-- Test symlink !-->
|
||||||
|
<file>
|
||||||
|
<name>test-dir/app-symlink</name>
|
||||||
|
<target>../app</target>
|
||||||
|
</file>
|
||||||
|
</install-v3>
|
||||||
|
<uninstall>
|
||||||
|
<!-- TODO - List some files to uninstall here !-->
|
||||||
|
<file>file-to-uninstall.txt</file>
|
||||||
|
</uninstall>
|
||||||
</update>
|
</update>
|
||||||
|
|
Loading…
Reference in a new issue