diff --git a/src/UpdateInstaller.cpp b/src/UpdateInstaller.cpp index 47865c7..abd0ac7 100644 --- a/src/UpdateInstaller.cpp +++ b/src/UpdateInstaller.cpp @@ -43,24 +43,40 @@ void UpdateInstaller::setScript(UpdateScript* script) m_script = script; } +std::list UpdateInstaller::updaterArgs() const +{ + std::list args; + args.push_back("--install-dir"); + args.push_back(m_installDir); + args.push_back("--package-dir"); + args.push_back(m_packageDir); + args.push_back("--script"); + args.push_back(m_script->path()); + return args; +} + void UpdateInstaller::run() throw () { + std::string updaterPath; + try + { + updaterPath = ProcessUtils::currentProcessPath(); + } + catch (const FileOps::IOException& ex) + { + LOG(Error,"error reading process path with mode " + intToStr(m_mode)); + return; + } + if (m_mode == Setup) { LOG(Info,"Preparing update installation"); LOG(Info,"Waiting for main app process to finish"); ProcessUtils::waitForProcess(m_waitPid); - std::string updaterPath = ProcessUtils::currentProcessPath(); - std::list args; + std::list args = updaterArgs(); args.push_back("--mode"); args.push_back("main"); - args.push_back("--install-dir"); - args.push_back(m_installDir); - args.push_back("--package-dir"); - args.push_back(m_packageDir); - args.push_back("--script"); - args.push_back(m_script->path()); if (!checkAccess()) { @@ -116,6 +132,11 @@ void UpdateInstaller::run() throw () { m_observer->updateFinished(); } + + std::list args = updaterArgs(); + args.push_back("--mode"); + args.push_back("cleanup"); + ProcessUtils::runAsync(updaterPath,args); } else if (m_mode == Cleanup) { @@ -123,6 +144,8 @@ void UpdateInstaller::run() throw () ProcessUtils::waitForProcess(m_waitPid); cleanup(); + + LOG(Info,"Updater files removed"); } } diff --git a/src/UpdateInstaller.h b/src/UpdateInstaller.h index 1d7fb9a..6098420 100644 --- a/src/UpdateInstaller.h +++ b/src/UpdateInstaller.h @@ -2,6 +2,7 @@ #include "UpdateScript.h" +#include #include #include @@ -40,6 +41,8 @@ class UpdateInstaller void installFile(const UpdateScriptFile& file); void backupFile(const std::string& path); + std::list updaterArgs() const; + Mode m_mode; std::string m_installDir; std::string m_packageDir;