From 6aa9bd0f77dcb5128167fae62e32aa5252fe85c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 2 Dec 2013 00:55:24 +0100 Subject: Renew the updater branch Now with some actual consensus on what the updater will do! --- mmc_updater/src/UpdaterOptions.cpp | 156 +++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 mmc_updater/src/UpdaterOptions.cpp (limited to 'mmc_updater/src/UpdaterOptions.cpp') diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp new file mode 100644 index 00000000..1ea820d2 --- /dev/null +++ b/mmc_updater/src/UpdaterOptions.cpp @@ -0,0 +1,156 @@ +#include "UpdaterOptions.h" + +#include "Log.h" +#include "AnyOption/anyoption.h" +#include "FileUtils.h" +#include "Platform.h" +#include "StringUtils.h" + +#include +#include + +#ifdef PLATFORM_WINDOWS +long long atoll(const char* string) +{ + return _atoi64(string); +} +#endif + +UpdaterOptions::UpdaterOptions() +: mode(UpdateInstaller::Setup) +, waitPid(0) +, showVersion(false) +, forceElevated(false) +, autoClose(false) +{ +} + +UpdateInstaller::Mode stringToMode(const std::string& modeStr) +{ + if (modeStr == "main") + { + return UpdateInstaller::Main; + } + else + { + if (!modeStr.empty()) + { + LOG(Error,"Unknown mode " + modeStr); + } + return UpdateInstaller::Setup; + } +} + +void UpdaterOptions::parseOldFormatArg(const std::string& arg, std::string* key, std::string* value) +{ + size_t pos = arg.find('='); + if (pos != std::string::npos) + { + *key = arg.substr(0,pos); + *value = arg.substr(pos+1); + } +} + +// this is a compatibility function to allow the updater binary +// to be involved by legacy versions of Mendeley Desktop +// which used a different syntax for the updater's command-line +// arguments +void UpdaterOptions::parseOldFormatArgs(int argc, char** argv) +{ + for (int i=0; i < argc; i++) + { + std::string key; + std::string value; + + parseOldFormatArg(argv[i],&key,&value); + + if (key == "CurrentDir") + { + // CurrentDir is the directory containing the main application + // binary. On Mac and Linux this differs from the root of + // the installation directory + +#ifdef PLATFORM_LINUX + // the main binary is in lib/mendeleydesktop/libexec, + // go up 3 levels + installDir = FileUtils::canonicalPath((value + "/../../../").c_str()); +#elif defined(PLATFORM_MAC) + // the main binary is in Contents/MacOS, + // go up 2 levels + installDir = FileUtils::canonicalPath((value + "/../../").c_str()); +#elif defined(PLATFORM_WINDOWS) + // the main binary is in the root of the install directory + installDir = value; +#endif + } + else if (key == "TempDir") + { + packageDir = value; + } + else if (key == "UpdateScriptFileName") + { + scriptPath = value; + } + else if (key == "AppFileName") + { + // TODO - Store app file name + } + else if (key == "PID") + { + waitPid = static_cast(atoll(value.c_str())); + } + else if (key == "--main") + { + mode = UpdateInstaller::Main; + } + } +} + +void UpdaterOptions::parse(int argc, char** argv) +{ + AnyOption parser; + parser.setOption("install-dir"); + parser.setOption("package-dir"); + parser.setOption("script"); + parser.setOption("wait"); + parser.setOption("mode"); + parser.setFlag("version"); + parser.setFlag("force-elevated"); + parser.setFlag("auto-close"); + + parser.processCommandArgs(argc,argv); + + if (parser.getValue("mode")) + { + mode = stringToMode(parser.getValue("mode")); + } + if (parser.getValue("install-dir")) + { + installDir = parser.getValue("install-dir"); + } + if (parser.getValue("package-dir")) + { + packageDir = parser.getValue("package-dir"); + } + if (parser.getValue("script")) + { + scriptPath = parser.getValue("script"); + } + if (parser.getValue("wait")) + { + waitPid = static_cast(atoll(parser.getValue("wait"))); + } + + showVersion = parser.getFlag("version"); + forceElevated = parser.getFlag("force-elevated"); + autoClose = parser.getFlag("auto-close"); + + if (installDir.empty()) + { + // if no --install-dir argument is present, try parsing + // the command-line arguments in the old format (which uses + // a list of 'Key=Value' args) + parseOldFormatArgs(argc,argv); + } +} + -- cgit v1.2.3 From e90f1a27569ac6b9e9782646c9de92fc9534b1d2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 5 Dec 2013 20:32:12 -0600 Subject: Implement update installer --- mmc_updater/src/UpdaterOptions.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mmc_updater/src/UpdaterOptions.cpp') diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp index 1ea820d2..c8f76f6e 100644 --- a/mmc_updater/src/UpdaterOptions.cpp +++ b/mmc_updater/src/UpdaterOptions.cpp @@ -111,6 +111,7 @@ void UpdaterOptions::parse(int argc, char** argv) AnyOption parser; parser.setOption("install-dir"); parser.setOption("package-dir"); + parser.setOption("finish-cmd"); parser.setOption("script"); parser.setOption("wait"); parser.setOption("mode"); @@ -140,6 +141,10 @@ void UpdaterOptions::parse(int argc, char** argv) { waitPid = static_cast(atoll(parser.getValue("wait"))); } + if (parser.getValue("finish-cmd")) + { + finishCmd = parser.getValue("finish-cmd"); + } showVersion = parser.getFlag("version"); forceElevated = parser.getFlag("force-elevated"); -- cgit v1.2.3 From 858916b951e92127c22503826b746d1e70c433f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 7 Dec 2013 03:51:21 +0100 Subject: Fix build failures on Windows. * remove atoll * fix include path of updater depends --- mmc_updater/src/UpdaterOptions.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'mmc_updater/src/UpdaterOptions.cpp') diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp index 1ea820d2..e7809fb8 100644 --- a/mmc_updater/src/UpdaterOptions.cpp +++ b/mmc_updater/src/UpdaterOptions.cpp @@ -9,13 +9,6 @@ #include #include -#ifdef PLATFORM_WINDOWS -long long atoll(const char* string) -{ - return _atoi64(string); -} -#endif - UpdaterOptions::UpdaterOptions() : mode(UpdateInstaller::Setup) , waitPid(0) -- cgit v1.2.3