summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MultiMC.cpp23
-rw-r--r--MultiMC.h2
-rw-r--r--depends/util/src/cmdutils.cpp11
-rw-r--r--mmc_updater/src/UpdateInstaller.cpp15
-rw-r--r--mmc_updater/src/UpdateInstaller.h2
-rw-r--r--mmc_updater/src/UpdaterOptions.cpp5
-rw-r--r--mmc_updater/src/UpdaterOptions.h1
-rw-r--r--mmc_updater/src/main.cpp4
-rw-r--r--mmc_updater/src/tests/CMakeLists.txt1
-rw-r--r--mmc_updater/src/tests/TestUpdaterOptions.cpp68
-rw-r--r--mmc_updater/src/tests/TestUpdaterOptions.h8
-rwxr-xr-xpackage/linux/MultiMC1
-rw-r--r--tests/TestUtil.h2
-rw-r--r--tests/tst_DownloadUpdateTask.cpp2
14 files changed, 47 insertions, 98 deletions
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 2bc77e0f..5ca1e1c6 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -37,7 +37,7 @@
using namespace Util::Commandline;
-MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
+MultiMC::MultiMC(int &argc, char **argv, bool root_override)
: QApplication(argc, argv), m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD,
VERSION_CHANNEL, VERSION_BUILD_TYPE}
{
@@ -111,14 +111,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
QString adjustedBy;
// change directory
QString dirParam = args["dir"].toString();
- if (!data_dir_override.isEmpty())
- {
- // the override is used for tests (although dirparam would be enough...)
- // TODO: remove the need for this extra logic
- adjustedBy += "Test override " + data_dir_override;
- dataPath = data_dir_override;
- }
- else if (!dirParam.isEmpty())
+ if (!dirParam.isEmpty())
{
// the dir param. it makes multimc data path point to whatever the user specified
// on command line
@@ -130,6 +123,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
dataPath = applicationDirPath();
adjustedBy += "Fallback to binary path " + dataPath;
}
+
if(!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
{
// BAD STUFF. WHAT DO?
@@ -139,6 +133,11 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override)
return;
}
+ if (root_override)
+ {
+ rootPath = binPath;
+ }
+ else
{
#ifdef Q_OS_LINUX
QDir foo(PathCombine(binPath, ".."));
@@ -539,7 +538,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
#else
#error Unsupported operating system.
#endif
-
+
QStringList args;
// ./updater --install-dir $INSTALL_DIR --package-dir $UPDATEFILES_DIR --script
// $UPDATEFILES_DIR/file_list.xml --wait $PID --mode main
@@ -550,8 +549,10 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
if(flags & DryRun)
args << "--dry-run";
if (flags & RestartOnFinish)
+ {
args << "--finish-cmd" << finishCmd;
-
+ args << "--finish-dir" << data();
+ }
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
diff --git a/MultiMC.h b/MultiMC.h
index ea3034b0..d02099f3 100644
--- a/MultiMC.h
+++ b/MultiMC.h
@@ -58,7 +58,7 @@ public:
};
public:
- MultiMC(int &argc, char **argv, const QString &root = QString());
+ MultiMC(int &argc, char **argv, bool root_override = false);
virtual ~MultiMC();
std::shared_ptr<SettingsObject> settings()
diff --git a/depends/util/src/cmdutils.cpp b/depends/util/src/cmdutils.cpp
index 43a0bcde..b12098dc 100644
--- a/depends/util/src/cmdutils.cpp
+++ b/depends/util/src/cmdutils.cpp
@@ -286,11 +286,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
// we were expecting an argument
{
QString name = expecting.first();
-
+/*
if (map.contains(name))
throw ParsingError(
QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
-
+*/
map[name] = QVariant(arg);
expecting.removeFirst();
@@ -316,10 +316,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
if (m_options.contains(name))
{
+ /*
if (map.contains(name))
throw ParsingError(QString("Option %2%1 was given multiple times")
.arg(name, optionPrefix));
-
+*/
OptionDef *option = m_options[name];
if (option->type == otSwitch)
map[name] = true;
@@ -367,11 +368,11 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix));
OptionDef *option = m_flags[flag];
-
+/*
if (map.contains(option->name))
throw ParsingError(QString("Option %2%1 was given multiple times")
.arg(option->name, optionPrefix));
-
+*/
if (option->type == otSwitch)
map[option->name] = true;
else // if (option->type == otOption)
diff --git a/mmc_updater/src/UpdateInstaller.cpp b/mmc_updater/src/UpdateInstaller.cpp
index aca23ff7..b29c5316 100644
--- a/mmc_updater/src/UpdateInstaller.cpp
+++ b/mmc_updater/src/UpdateInstaller.cpp
@@ -46,6 +46,11 @@ void UpdateInstaller::setFinishCmd(const std::string& cmd)
m_finishCmd = cmd;
}
+void UpdateInstaller::setFinishDir(const std::string &dir)
+{
+ m_finishDir = dir;
+}
+
std::list<std::string> UpdateInstaller::updaterArgs() const
{
std::list<std::string> args;
@@ -63,6 +68,11 @@ std::list<std::string> UpdateInstaller::updaterArgs() const
{
args.push_back("--dry-run");
}
+ if (m_finishDir.size())
+ {
+ args.push_back("--dir");
+ args.push_back(m_finishDir);
+ }
return args;
}
@@ -420,6 +430,11 @@ void UpdateInstaller::restartMainApp()
if (!command.empty())
{
+ if(!m_finishDir.empty())
+ {
+ args.push_back("--dir");
+ args.push_back(m_finishDir);
+ }
LOG(Info,"Starting main application " + command);
if(!m_dryRun)
{
diff --git a/mmc_updater/src/UpdateInstaller.h b/mmc_updater/src/UpdateInstaller.h
index 5cbac561..5920deec 100644
--- a/mmc_updater/src/UpdateInstaller.h
+++ b/mmc_updater/src/UpdateInstaller.h
@@ -34,6 +34,7 @@ class UpdateInstaller
void setAutoClose(bool autoClose);
void setDryRun(bool dryRun);
void setFinishCmd(const std::string& cmd);
+ void setFinishDir(const std::string& dir);
void setObserver(UpdateObserver* observer);
@@ -62,6 +63,7 @@ class UpdateInstaller
std::string m_packageDir;
std::string m_backupDir;
std::string m_finishCmd;
+ std::string m_finishDir;
PLATFORM_PID m_waitPid = 0;
UpdateScript* m_script = nullptr;
UpdateObserver* m_observer = nullptr;
diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp
index 5f9e97d8..abc7c6d7 100644
--- a/mmc_updater/src/UpdaterOptions.cpp
+++ b/mmc_updater/src/UpdaterOptions.cpp
@@ -40,6 +40,7 @@ void UpdaterOptions::parse(int argc, char** argv)
parser.setOption("install-dir");
parser.setOption("package-dir");
parser.setOption("finish-cmd");
+ parser.setOption("finish-dir");
parser.setOption("script");
parser.setOption("wait");
parser.setOption("mode");
@@ -74,6 +75,10 @@ void UpdaterOptions::parse(int argc, char** argv)
{
finishCmd = parser.getValue("finish-cmd");
}
+ if (parser.getValue("finish-dir"))
+ {
+ finishDir = parser.getValue("finish-dir");
+ }
showVersion = parser.getFlag("version");
forceElevated = parser.getFlag("force-elevated");
diff --git a/mmc_updater/src/UpdaterOptions.h b/mmc_updater/src/UpdaterOptions.h
index d9104804..d4345490 100644
--- a/mmc_updater/src/UpdaterOptions.h
+++ b/mmc_updater/src/UpdaterOptions.h
@@ -15,6 +15,7 @@ class UpdaterOptions
std::string packageDir;
std::string scriptPath;
std::string finishCmd;
+ std::string finishDir;
PLATFORM_PID waitPid;
std::string logFile;
bool showVersion;
diff --git a/mmc_updater/src/main.cpp b/mmc_updater/src/main.cpp
index f6b31a32..602c30a6 100644
--- a/mmc_updater/src/main.cpp
+++ b/mmc_updater/src/main.cpp
@@ -138,7 +138,8 @@ int main(int argc, char** argv)
+ ", wait-pid: " + intToStr(options.waitPid)
+ ", script-path: " + options.scriptPath
+ ", mode: " + intToStr(options.mode)
- + ", finish-cmd: " + options.finishCmd);
+ + ", finish-cmd: " + options.finishCmd
+ + ", finish-dir: " + options.finishDir);
installer.setMode(options.mode);
installer.setInstallDir(options.installDir);
@@ -148,6 +149,7 @@ int main(int argc, char** argv)
installer.setForceElevated(options.forceElevated);
installer.setAutoClose(options.autoClose);
installer.setFinishCmd(options.finishCmd);
+ installer.setFinishDir(options.finishDir);
installer.setDryRun(options.dryRun);
if (options.mode == UpdateInstaller::Main)
diff --git a/mmc_updater/src/tests/CMakeLists.txt b/mmc_updater/src/tests/CMakeLists.txt
index 79402245..08501a98 100644
--- a/mmc_updater/src/tests/CMakeLists.txt
+++ b/mmc_updater/src/tests/CMakeLists.txt
@@ -44,5 +44,4 @@ macro(ADD_UPDATER_TEST CLASS)
endmacro()
add_updater_test(TestParseScript)
-add_updater_test(TestUpdaterOptions)
add_updater_test(TestFileUtils)
diff --git a/mmc_updater/src/tests/TestUpdaterOptions.cpp b/mmc_updater/src/tests/TestUpdaterOptions.cpp
deleted file mode 100644
index a4cb7d33..00000000
--- a/mmc_updater/src/tests/TestUpdaterOptions.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#include "TestUpdaterOptions.h"
-
-#include "FileUtils.h"
-#include "Platform.h"
-#include "TestUtils.h"
-#include "UpdaterOptions.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-void TestUpdaterOptions::testOldFormatArgs()
-{
- const int argc = 6;
- char* argv[argc];
- argv[0] = strdup("updater");
-
- std::string currentDir("CurrentDir=");
- const char* appDir = 0;
-
- // CurrentDir is the path to the directory containing the main
- // Mendeley Desktop binary, on Linux and Mac this differs from
- // the root of the install directory
-#ifdef PLATFORM_LINUX
- appDir = "/tmp/path-to-app/lib/mendeleydesktop/libexec/";
- FileUtils::mkpath(appDir);
-#elif defined(PLATFORM_MAC)
- appDir = "/tmp/path-to-app/Contents/MacOS/";
- FileUtils::mkpath(appDir);
-#elif defined(PLATFORM_WINDOWS)
- appDir = "C:/path/to/app/";
-#endif
- currentDir += appDir;
-
- argv[1] = strdup(currentDir.c_str());
- argv[2] = strdup("TempDir=/tmp/updater");
- argv[3] = strdup("UpdateScriptFileName=/tmp/updater/file_list.xml");
- argv[4] = strdup("AppFileName=/path/to/app/theapp");
- argv[5] = strdup("PID=123456");
-
- UpdaterOptions options;
- options.parse(argc,argv);
-
- TEST_COMPARE(options.mode,UpdateInstaller::Setup);
-#ifdef PLATFORM_LINUX
- TEST_COMPARE(options.installDir,"/tmp/path-to-app");
-#elif defined(PLATFORM_MAC)
- // /tmp is a symlink to /private/tmp on Mac
- TEST_COMPARE(options.installDir,"/private/tmp/path-to-app");
-#else
- TEST_COMPARE(options.installDir,"C:/path/to/app/");
-#endif
- TEST_COMPARE(options.packageDir,"/tmp/updater");
- TEST_COMPARE(options.scriptPath,"/tmp/updater/file_list.xml");
- TEST_COMPARE(options.waitPid,123456);
-
- for (int i=0; i < argc; i++)
- {
- free(argv[i]);
- }
-}
-
-int main(int,char**)
-{
- TestList<TestUpdaterOptions> tests;
- tests.addTest(&TestUpdaterOptions::testOldFormatArgs);
- return TestUtils::runTest(tests);
-}
-
diff --git a/mmc_updater/src/tests/TestUpdaterOptions.h b/mmc_updater/src/tests/TestUpdaterOptions.h
deleted file mode 100644
index 5ed102c1..00000000
--- a/mmc_updater/src/tests/TestUpdaterOptions.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-class TestUpdaterOptions
-{
- public:
- void testOldFormatArgs();
-};
-
diff --git a/package/linux/MultiMC b/package/linux/MultiMC
index 7fb72f98..3579913c 100755
--- a/package/linux/MultiMC
+++ b/package/linux/MultiMC
@@ -15,7 +15,6 @@ fi
MMC_DIR="$(dirname "$(readlink -f "$0")")"
-cd "${MMC_DIR}"
echo "MultiMC Dir: ${MMC_DIR}"
# Set up env
diff --git a/tests/TestUtil.h b/tests/TestUtil.h
index 231ce7f6..57d1fdf2 100644
--- a/tests/TestUtil.h
+++ b/tests/TestUtil.h
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) \
{ \
char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \
int argc_ = 1 + _MMC_EXTRA_ARGC; \
- MultiMC app(argc_, argv_/*, QDir::temp().absoluteFilePath("MultiMC_Test")*/); \
+ MultiMC app(argc_, argv_, true); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
diff --git a/tests/tst_DownloadUpdateTask.cpp b/tests/tst_DownloadUpdateTask.cpp
index 3b2c6793..883e90e8 100644
--- a/tests/tst_DownloadUpdateTask.cpp
+++ b/tests/tst_DownloadUpdateTask.cpp
@@ -254,7 +254,7 @@ slots:
pathOrig = path = "MultiMC.app/Foo/Bar/Baz";
qDebug() << "Proper OSX path: " << path;
result = DownloadUpdateTask::fixPathForOSX(path);
- QCOMPARE(path, QString("../../Foo/Bar/Baz"));
+ QCOMPARE(path, QString("Foo/Bar/Baz"));
QCOMPARE(result, true);
// Bad OSX path