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