From eeeafb2c1a8b86ccf91158116c82dae3d5424dae Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 23 Aug 2011 12:59:04 +0100 Subject: [PATCH] Implement restart of main application once the update is installed. * Add support for entries in the update script being marked with a boolean attribute which is set to true for the main binary. * In UpdateInstaller::restartMainApp(), look for the file marked with and restart it after installation. With the current structure, this requires that the main binary is included in the update, which has always been the case up till now. If we find that we want to do updates that do not affect the main binary, the attribute could be replaced with a string value at the top of the XML file. --- src/StringUtils.h | 6 +++++- src/UpdateInstaller.cpp | 24 +++++++++++++++++++++++- src/UpdateScript.cpp | 1 + src/UpdateScript.h | 5 ++++- src/main.cpp | 1 - src/tests/file_list.xml | 1 + src/tests/v2_file_list.xml | 1 + 7 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/StringUtils.h b/src/StringUtils.h index 046bde3..b3544cc 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -2,6 +2,7 @@ #include #include +#include inline std::string intToStr(int i) { @@ -10,4 +11,7 @@ inline std::string intToStr(int i) return stream.str(); } - +inline bool strToBool(const std::string& str) +{ + return str == "true" || atoi(str.c_str()) != 0; +} diff --git a/src/UpdateInstaller.cpp b/src/UpdateInstaller.cpp index d9153b4..7726cae 100644 --- a/src/UpdateInstaller.cpp +++ b/src/UpdateInstaller.cpp @@ -309,6 +309,28 @@ void UpdateInstaller::setObserver(UpdateObserver* observer) void UpdateInstaller::restartMainApp() { - LOG(Warn,"Restarting main app not implemented"); + LOG(Info,"restarting main app"); + std::string command; + std::list args; + + for (std::vector::const_iterator iter = m_script->filesToInstall().begin(); + iter != m_script->filesToInstall().end(); + iter++) + { + if (iter->isMainBinary) + { + command = m_installDir + '/' + iter->path; + } + } + + if (!command.empty()) + { + LOG(Info,"Starting main application " + command); + ProcessUtils::runAsync(command,args); + } + else + { + LOG(Error,"No main binary specified in update script"); + } } diff --git a/src/UpdateScript.cpp b/src/UpdateScript.cpp index 04c307a..49d2868 100644 --- a/src/UpdateScript.cpp +++ b/src/UpdateScript.cpp @@ -102,6 +102,7 @@ UpdateScriptFile UpdateScript::parseFile(const TiXmlElement* element) file.package = elementText(element->FirstChildElement("package")); file.permissions = atoi(elementText(element->FirstChildElement("permissions")).c_str()); file.linkTarget = elementText(element->FirstChildElement("target")); + file.isMainBinary = strToBool(elementText(element->FirstChildElement("is-main-binary"))); return file; } diff --git a/src/UpdateScript.h b/src/UpdateScript.h index c41605b..baa4537 100644 --- a/src/UpdateScript.h +++ b/src/UpdateScript.h @@ -31,19 +31,22 @@ class UpdateScriptFile public: UpdateScriptFile() : permissions(0) + , isMainBinary(false) {} std::string path; std::string package; int permissions; std::string linkTarget; + bool isMainBinary; bool operator==(const UpdateScriptFile& other) const { return path == other.path && package == other.package && permissions == other.permissions && - linkTarget == other.linkTarget; + linkTarget == other.linkTarget && + isMainBinary == other.isMainBinary; } }; diff --git a/src/main.cpp b/src/main.cpp index b77440f..3d8a068 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -78,7 +78,6 @@ void runWithUi(int argc, char** argv, UpdateInstaller* installer) if (dialog.restartApp()) { - LOG(Info,"Restarting app after install"); installer->restartMainApp(); } #else diff --git a/src/tests/file_list.xml b/src/tests/file_list.xml index e4344fd..7b593c0 100644 --- a/src/tests/file_list.xml +++ b/src/tests/file_list.xml @@ -22,6 +22,7 @@ $UPDATED_APP_SIZE 30549 app-pkg + true diff --git a/src/tests/v2_file_list.xml b/src/tests/v2_file_list.xml index 05bdb49..a47c6f6 100644 --- a/src/tests/v2_file_list.xml +++ b/src/tests/v2_file_list.xml @@ -30,6 +30,7 @@ $UPDATED_APP_SIZE 30549 app-pkg + true