From b103f297752b170ee4ade6e0e9085c6d31c020ca Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 18 Jul 2020 00:35:26 -0400 Subject: added --multiple to allow launching multiple instances --- src/singleinstance.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/singleinstance.cpp') diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index aa62d40a..d38095df 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -28,33 +28,38 @@ static const int s_Timeout = 5000; using MOBase::reportError; -SingleInstance::SingleInstance(bool forcePrimary, QObject *parent) : - QObject(parent), m_PrimaryInstance(false) +SingleInstance::SingleInstance(Flags flags, QObject *parent) : + QObject(parent), m_Ephemeral(false), m_OwnsSM(false) { m_SharedMem.setKey(s_Key); + if (!m_SharedMem.create(1)) { - if (forcePrimary) { + if (flags.testFlag(ForcePrimary)) { while (m_SharedMem.error() == QSharedMemory::AlreadyExists) { Sleep(500); if (m_SharedMem.create(1)) { - m_PrimaryInstance = true; + m_OwnsSM = true; break; } } } if (m_SharedMem.error() == QSharedMemory::AlreadyExists) { - m_SharedMem.attach(); - m_PrimaryInstance = false; + if (!flags.testFlag(AllowMultiple)) { + m_SharedMem.attach(); + m_Ephemeral = true; + } } + if ((m_SharedMem.error() != QSharedMemory::NoError) && (m_SharedMem.error() != QSharedMemory::AlreadyExists)) { throw MOBase::MyException(tr("SHM error: %1").arg(m_SharedMem.errorString())); } } else { - m_PrimaryInstance = true; + m_OwnsSM = true; } - if (m_PrimaryInstance) { + + if (m_OwnsSM) { connect(&m_Server, SIGNAL(newConnection()), this, SLOT(receiveMessage()), Qt::QueuedConnection); // has to be called before listen m_Server.setSocketOptions(QLocalServer::WorldAccessOption); @@ -65,7 +70,7 @@ SingleInstance::SingleInstance(bool forcePrimary, QObject *parent) : void SingleInstance::sendMessage(const QString &message) { - if (m_PrimaryInstance) { + if (m_OwnsSM) { // nobody there to receive the message return; } -- cgit v1.3.1 From 75cc2ffead148ab2409cd1ef469613d2e9b80e17 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 18 Jul 2020 04:06:18 -0400 Subject: removed unused `update` parameter moved --multiple to CommandLine --- src/commandline.cpp | 44 ++++++++++++++++++++++++++++++++++---------- src/commandline.h | 4 ++++ src/main.cpp | 7 +------ src/singleinstance.cpp | 10 ---------- src/singleinstance.h | 12 +----------- 5 files changed, 40 insertions(+), 37 deletions(-) (limited to 'src/singleinstance.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index 588b5085..f84906e9 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -15,8 +15,6 @@ std::optional CommandLine::run(const std::wstring& line) { try { - po::variables_map vm; - auto args = po::split_winmain(line); if (!args.empty()) { // remove program name @@ -29,10 +27,10 @@ std::optional CommandLine::run(const std::wstring& line) .allow_unregistered() .run(); - po::store(parsed, vm); + po::store(parsed, m_vm); - if (vm.count("command")) { - const auto commandName = vm["command"].as(); + if (m_vm.count("command")) { + const auto commandName = m_vm["command"].as(); for (auto&& c : m_commands) { if (c->name() == commandName) { @@ -55,20 +53,20 @@ std::optional CommandLine::run(const std::wstring& line) parsed = parser.run(); - po::store(parsed, vm); + po::store(parsed, m_vm); - if (vm.count("help")) { + if (m_vm.count("help")) { env::Console console; std::cout << usage(c.get()) << "\n"; return 0; } - return c->run(line, vm, opts); + return c->run(line, m_vm, opts); } } } - if (vm.count("help")) { + if (m_vm.count("help")) { env::Console console; std::cout << usage() << "\n"; return 0; @@ -91,7 +89,8 @@ std::optional CommandLine::run(const std::wstring& line) void CommandLine::createOptions() { m_visibleOptions.add_options() - ("help", "shows this message"); + ("help", "shows this message") + ("multiple", "allows multiple instances of MO to run; see below"); po::options_description options; options.add_options() @@ -137,9 +136,34 @@ std::string CommandLine::usage(const Command* c) const << "Global options:\n" << m_visibleOptions << "\n"; + if (!c) { + oss << "\n" << more() << "\n"; + } + return oss.str(); } +bool CommandLine::multiple() const +{ + return (m_vm.count("multiple") > 0); +} + +std::string CommandLine::more() const +{ + return + "--multiple can be used to allow multiple instances of MO to run\n" + "simultaneously. This is unsupported and can create all sorts of weird\n" + "problems. To minimize the problems:\n" + "\n" + " 1) Never have multiple MO instances opened that manage the same game\n" + " instance.\n" + " 2) If an executable is launched from an instance, only this instance\n" + " may launch executables until all instances are closed.\n" + "\n" + "It is recommended to close _all_ instances of MO as soon as multiple\n" + "instances become unnecessary."; +} + std::string Command::name() const { diff --git a/src/commandline.h b/src/commandline.h index b45a86c6..deeb9923 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -94,12 +94,16 @@ public: std::optional run(const std::wstring& line); std::string usage(const Command* c=nullptr) const; + bool multiple() const; + private: po::options_description m_visibleOptions, m_allOptions; po::positional_options_description m_positional; std::vector> m_commands; + po::variables_map m_vm; void createOptions(); + std::string more() const; }; } // namespace diff --git a/src/main.cpp b/src/main.cpp index 68dcfe11..a1a4be01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -852,12 +852,7 @@ int main(int argc, char *argv[]) SingleInstance::Flags siFlags = SingleInstance::NoFlags; - if (arguments.contains("update")) { - arguments.removeAll("update"); - siFlags |= SingleInstance::ForcePrimary; - } - - if (arguments.contains("--multiple")) { + if (cl.multiple()) { arguments.removeAll("--multiple"); siFlags |= SingleInstance::AllowMultiple; } diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index d38095df..e32c8de1 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -34,16 +34,6 @@ SingleInstance::SingleInstance(Flags flags, QObject *parent) : m_SharedMem.setKey(s_Key); if (!m_SharedMem.create(1)) { - if (flags.testFlag(ForcePrimary)) { - while (m_SharedMem.error() == QSharedMemory::AlreadyExists) { - Sleep(500); - if (m_SharedMem.create(1)) { - m_OwnsSM = true; - break; - } - } - } - if (m_SharedMem.error() == QSharedMemory::AlreadyExists) { if (!flags.testFlag(AllowMultiple)) { m_SharedMem.attach(); diff --git a/src/singleinstance.h b/src/singleinstance.h index 5c7cdf85..d500a056 100644 --- a/src/singleinstance.h +++ b/src/singleinstance.h @@ -40,19 +40,9 @@ public: { NoFlags = 0x00, - - // when set, this will be treated as the primary instance even if - // another instance is running. This is used after an update since the - // other instance is assumed to be in the process of quitting - // - // todo: this makes no sense. The second instance after an update needs - // to delete the files from before the update so the first instance - // needs to quit first anyway - ForcePrimary = 0x01, - // if another instance is running, run this one disconnected from the // shared memory - AllowMultiple = 0x02 + AllowMultiple = 0x01 }; using Flags = QFlags; -- cgit v1.3.1 From 9435202034cafb05ffc11aed48ff57536bce73f7 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 22 Jul 2020 23:27:01 -0400 Subject: removed flags from SingleInstance because there's only one left refactoring in main.cpp: - moved stuff to loglist.cpp and moapplication.cpp - split main() into a few functions --- src/env.cpp | 13 ++- src/env.h | 3 +- src/loglist.cpp | 26 ++++++ src/loglist.h | 1 + src/main.cpp | 225 ++++++++++++++++++++++++------------------------- src/moapplication.cpp | 19 ++--- src/moapplication.h | 20 ++--- src/singleinstance.cpp | 4 +- src/singleinstance.h | 18 +--- src/spawn.cpp | 2 +- 10 files changed, 174 insertions(+), 157 deletions(-) (limited to 'src/singleinstance.cpp') diff --git a/src/env.cpp b/src/env.cpp index bf75c9fa..9f0acbbd 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -400,11 +400,18 @@ QString path() return get("PATH"); } -QString addPath(const QString& s) +QString appendToPath(const QString& s) { auto old = path(); - set("PATH", get("PATH") + ";" + s); - return old; + set("PATH", old + ";" + s); + return old; +} + +QString prependToPath(const QString& s) +{ + auto old = path(); + set("PATH", s + ";" + old); + return old; } QString setPath(const QString& s) diff --git a/src/env.h b/src/env.h index 9bec1713..a563f2c3 100644 --- a/src/env.h +++ b/src/env.h @@ -236,7 +236,8 @@ QString get(const QString& name); QString set(const QString& name, const QString& value); QString path(); -QString addPath(const QString& s); +QString appendToPath(const QString& s); +QString prependToPath(const QString& s); QString setPath(const QString& s); diff --git a/src/loglist.cpp b/src/loglist.cpp index 7a64ecad..167b61ef 100644 --- a/src/loglist.cpp +++ b/src/loglist.cpp @@ -327,3 +327,29 @@ void initLogging() qInstallMessageHandler(qtLogCallback); } + +bool createAndMakeWritable(const std::wstring &subPath) { + QString const dataPath = qApp->property("dataPath").toString(); + QString fullPath = dataPath + "/" + QString::fromStdWString(subPath); + + if (!QDir(fullPath).exists() && !QDir().mkdir(fullPath)) { + QMessageBox::critical(nullptr, QObject::tr("Error"), + QObject::tr("Failed to create \"%1\". Your user " + "account probably lacks permission.") + .arg(fullPath)); + return false; + } else { + return true; + } +} + +bool setLogDirectory(const QString& dir) +{ + const auto logFile = dir + "/logs/mo_interface.log"; + + if (!createAndMakeWritable(AppConfig::logPath())) { + return false; + } + + log::getDefault().setFile(MOBase::log::File::single(logFile.toStdWString())); +} diff --git a/src/loglist.h b/src/loglist.h index 7387eb50..0745ed3e 100644 --- a/src/loglist.h +++ b/src/loglist.h @@ -84,5 +84,6 @@ private: void initLogging(); +bool setLogDirectory(const QString& dir); #endif // LOGBUFFER_H diff --git a/src/main.cpp b/src/main.cpp index e52b252b..864d26a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,13 @@ along with Mod Organizer. If not, see . #include #include -#pragma comment(linker, "/manifestDependency:\"name='dlls' processorArchitecture='x86' version='1.0.0.0' type='win32' \"") +// see addDllsToPath() below +#pragma comment(linker, "/manifestDependency:\"" \ + "name='dlls' " \ + "processorArchitecture='x86' " \ + "version='1.0.0.0' " \ + "type='win32' \"") + using namespace MOBase; using namespace MOShared; @@ -47,21 +53,6 @@ void sanityChecks(const env::Environment& env); int checkIncompatibleModule(const env::Module& m); int checkPathsForSanity(MOBase::IPluginGame& game, const Settings& s); -bool createAndMakeWritable(const std::wstring &subPath) { - QString const dataPath = qApp->property("dataPath").toString(); - QString fullPath = dataPath + "/" + QString::fromStdWString(subPath); - - if (!QDir(fullPath).exists() && !QDir().mkdir(fullPath)) { - QMessageBox::critical(nullptr, QObject::tr("Error"), - QObject::tr("Failed to create \"%1\". Your user " - "account probably lacks permission.") - .arg(fullPath)); - return false; - } else { - return true; - } -} - void purgeOldFiles() { // remove the temporary backup directory in case we're restarting after an @@ -305,36 +296,47 @@ MOBase::IPluginGame *determineCurrentGame( } -// extend path to include dll directory so plugins don't need a manifest -// (using AddDllDirectory would be an alternative to this but it seems fairly -// complicated esp. -// since it isn't easily accessible on Windows < 8 -// SetDllDirectory replaces other search directories and this seems to -// propagate to child processes) -void setupPath() +// This adds the `dlls` directory to the path so the dlls can be found. How +// MO is able to find dlls in there is a bit convoluted: +// +// Dependencies on DLLs can be baked into an executable by passing a +// `manifestdependency` option to the linker. This can be done on the command +// line or with a pragma. Typically, the dependency will not be a hardcoded +// filename, but an assembly name, such as Microsoft.Windows.Common-Controls. +// +// When Windows loads the exe, it will look for this assembly in a variety of +// places, such as in the WinSxS folder, but also in the program's folder. It +// will look for `assemblyname.dll` or `assemblyname/assemblyname.dll` and try +// to load that. +// +// If these files don't exist, then the loader gets creative and looks for +// `assemblyname.manifest` and `assemblyname/assemblyname.manifest`. A manifest +// file is just an XML file that can contain a list of DLLs to load for this +// assembly. +// +// In MO's case, there's a `pragma` at the beginning of this file which adds +// `dlls` as an "assembly" dependency. This is a bit of a hack to just force +// the loader to eventually find `dlls/dlls.manifest`, which contains the list +// of all the DLLs MO requires to load. +// +// This file was handwritten in `modorganizer/src/dlls.manifest.qt5` and +// is copied and renamed in CMakeLists.txt into `bin/dlls/dlls.manifest`. Note +// that the useless and incorrect .qt5 extension is removed. +// +void addDllsToPath() { - static const int BUFSIZE = 4096; - - QCoreApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath() + "/dlls") + QCoreApplication::libraryPaths()); + const auto dllsPath = QDir::toNativeSeparators( + QCoreApplication::applicationDirPath() + "/dlls"); - boost::scoped_array oldPath(new TCHAR[BUFSIZE]); - DWORD offset = ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), BUFSIZE); - if (offset > BUFSIZE) { - oldPath.reset(new TCHAR[offset]); - ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), offset); - } - - std::wstring newPath(ToWString(QDir::toNativeSeparators( - QCoreApplication::applicationDirPath())) + L"\\dlls"); - newPath += L";"; - newPath += oldPath.get(); + QCoreApplication::setLibraryPaths( + QStringList(dllsPath) + QCoreApplication::libraryPaths()); - ::SetEnvironmentVariableW(L"PATH", newPath.c_str()); + env::prependToPath(dllsPath); } int runApplication( MOApplication &application, const cl::CommandLine& cl, - SingleInstance &instance, const QString &splashPath) + SingleInstance &instance, const QString &dataPath) { TimeThis tt("runApplication() to exec()"); @@ -343,7 +345,6 @@ int runApplication( createVersionInfo().displayString(3), GITID, QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString()); - const QString dataPath = application.property("dataPath").toString(); log::info("data path: {}", dataPath); if (InstanceManager::isPortablePath(dataPath)) { @@ -429,8 +430,14 @@ int runApplication( checkPathsForSanity(*game, settings); bool useSplash = settings.useSplash(); + QString splashPath; if (useSplash) { + splashPath = dataPath + "/splash.png"; + if (!QFile::exists(dataPath + "/splash.png")) { + splashPath = ":/MO/gui/splash"; + } + if (splashPath.startsWith(':')) { // currently using MO splash, see if the plugin contains one QString pluginSplash @@ -599,111 +606,101 @@ int runApplication( return 1; } -int main(int argc, char *argv[]) +int forwardToPrimary(SingleInstance& instance, const cl::CommandLine& cl) { - cl::CommandLine cl; - - const auto r = cl.run(GetCommandLineW()); - if (r) - return *r; - - TimeThis tt("main to runApplication()"); - - // in loglist.cpp - initLogging(); + if (cl.shortcut().isValid()) { + instance.sendMessage(cl.shortcut().toString()); + } else if (cl.nxmLink()) { + instance.sendMessage(*cl.nxmLink()); + } else { + QMessageBox::information( + nullptr, QObject::tr("Mod Organizer"), + QObject::tr("An instance of Mod Organizer is already running")); + } - //Make sure the configured temp folder exists - QDir tempDir = QDir::temp(); - if (!tempDir.exists()) - tempDir.root().mkpath(tempDir.canonicalPath()); + return 0; +} - //Should allow for better scaling of ui with higher resolution displays - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +void resetForRestart(cl::CommandLine& cl) +{ + LogModel::instance().clear(); + ResetExitFlag(); - MOApplication application(argc, argv); - QStringList arguments = application.arguments(); + // make sure the log file isn't locked in case MO was restarted and + // the previous instance gets deleted + log::getDefault().setFile({}); - SetThisThreadName("main"); + // don't reprocess command line + cl.clear(); +} - setupPath(); +QString determineDataPath(const cl::CommandLine& cl) +{ + try + { + InstanceManager& instanceManager = InstanceManager::instance(); + if (cl.instance()) + instanceManager.overrideInstance(*cl.instance()); - SingleInstance::Flags siFlags = SingleInstance::NoFlags; + return instanceManager.determineDataPath(); + } + catch (const std::exception &e) + { + if (strcmp(e.what(),"Canceled")) { + QMessageBox::critical(nullptr, QObject::tr("Failed to set up instance"), e.what()); + } - if (cl.multiple()) { - arguments.removeAll("--multiple"); - siFlags |= SingleInstance::AllowMultiple; + return {}; } +} - SingleInstance instance(siFlags); - if (instance.ephemeral()) { - if (cl.shortcut().isValid()) { - instance.sendMessage(cl.shortcut().toString()); - return 0; - } else if (cl.nxmLink()) { - instance.sendMessage(*cl.nxmLink()); - return 0; - } else if (arguments.size() == 1) { - QMessageBox::information( - nullptr, QObject::tr("Mod Organizer"), - QObject::tr("An instance of Mod Organizer is already running")); - return 0; - } - } // we continue for the primary instance OR if MO was called with parameters +int main(int argc, char *argv[]) +{ + cl::CommandLine cl; - do { - LogModel::instance().clear(); - ResetExitFlag(); + if (auto r=cl.run(GetCommandLineW())) { + return *r; + } - // make sure the log file isn't locked in case MO was restarted and - // the previous instance gets deleted - log::getDefault().setFile({}); + TimeThis tt("main to runApplication()"); + SetThisThreadName("main"); - QString dataPath; + initLogging(); + auto application = MOApplication::create(argc, argv); + addDllsToPath(); - try { - InstanceManager& instanceManager = InstanceManager::instance(); + SingleInstance instance(cl.multiple()); + if (instance.ephemeral()) { + return forwardToPrimary(instance, cl); + } - if (cl.instance()) - instanceManager.overrideInstance(*cl.instance()); + for (;;) + { + // resets things when MO is "restarted" + resetForRestart(cl); - dataPath = instanceManager.determineDataPath(); - } catch (const std::exception &e) { - if (strcmp(e.what(),"Canceled")) - QMessageBox::critical(nullptr, QObject::tr("Failed to set up instance"), e.what()); + const QString dataPath = determineDataPath(cl); + if (dataPath.isEmpty()) { return 1; } - application.setProperty("dataPath", dataPath); - - // initialize dump collection only after "dataPath" since the crashes are stored under it - setUnhandledExceptionHandler(); - const auto logFile = - qApp->property("dataPath").toString() + "/logs/mo_interface.log"; + application.setProperty("dataPath", dataPath); + setExceptionHandler(); - if (!createAndMakeWritable(AppConfig::logPath())) { + if (!setLogDirectory(dataPath)) { reportError("Failed to create log folder"); InstanceManager::instance().clearCurrentInstance(); return 1; } - log::getDefault().setFile(MOBase::log::File::single(logFile.toStdWString())); - log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW())); - QString splash = dataPath + "/splash.png"; - if (!QFile::exists(dataPath + "/splash.png")) { - splash = ":/MO/gui/splash"; - } - tt.stop(); - const int result = runApplication(application, cl, instance, splash); + const int result = runApplication(application, cl, instance, dataPath); if (result != RestartExitCode) { return result; } - - argc = 1; - cl.clear(); - } while (true); + } } diff --git a/src/moapplication.cpp b/src/moapplication.cpp index dd49bf53..d95d544a 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -24,16 +24,10 @@ along with Mod Organizer. If not, see . #include "shared/appconfig.h" #include #include -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) -#include -#include -#endif #include #include #include #include - - #include @@ -77,7 +71,7 @@ public: }; -MOApplication::MOApplication(int &argc, char **argv) +MOApplication::MOApplication(int argc, char** argv) : QApplication(argc, argv) { connect(&m_StyleWatcher, &QFileSystemWatcher::fileChanged, [&](auto&& file){ @@ -89,8 +83,13 @@ MOApplication::MOApplication(int &argc, char **argv) setStyle(new ProxyStyle(style())); } +MOApplication MOApplication::create(int argc, char** argv) +{ + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + return MOApplication(argc, argv); +} -bool MOApplication::setStyleFile(const QString &styleName) +bool MOApplication::setStyleFile(const QString& styleName) { // remove all files from watch QStringList currentWatch = m_StyleWatcher.files(); @@ -114,7 +113,7 @@ bool MOApplication::setStyleFile(const QString &styleName) } -bool MOApplication::notify(QObject *receiver, QEvent *event) +bool MOApplication::notify(QObject* receiver, QEvent* event) { try { return QApplication::notify(receiver, event); @@ -134,7 +133,7 @@ bool MOApplication::notify(QObject *receiver, QEvent *event) } -void MOApplication::updateStyle(const QString &fileName) +void MOApplication::updateStyle(const QString& fileName) { if (QStyleFactory::keys().contains(fileName)) { setStyle(QStyleFactory::create(fileName)); diff --git a/src/moapplication.h b/src/moapplication.h index 9db130af..3ed71fb6 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -24,27 +24,25 @@ along with Mod Organizer. If not, see . #include -class MOApplication : public QApplication { -Q_OBJECT -public: - - MOApplication(int &argc, char **argv); +class MOApplication : public QApplication +{ + Q_OBJECT - virtual bool notify (QObject *receiver, QEvent *event); +public: + static MOApplication create(int argc, char** argv); + virtual bool notify (QObject* receiver, QEvent* event); public slots: - - bool setStyleFile(const QString &style); + bool setStyleFile(const QString& style); private slots: - - void updateStyle(const QString &fileName); + void updateStyle(const QString& fileName); private: - QFileSystemWatcher m_StyleWatcher; QString m_DefaultStyle; + MOApplication(int argc, char** argv); }; diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index e32c8de1..bd7ccc43 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -28,14 +28,14 @@ static const int s_Timeout = 5000; using MOBase::reportError; -SingleInstance::SingleInstance(Flags flags, QObject *parent) : +SingleInstance::SingleInstance(bool allowMultiple, QObject *parent) : QObject(parent), m_Ephemeral(false), m_OwnsSM(false) { m_SharedMem.setKey(s_Key); if (!m_SharedMem.create(1)) { if (m_SharedMem.error() == QSharedMemory::AlreadyExists) { - if (!flags.testFlag(AllowMultiple)) { + if (!allowMultiple) { m_SharedMem.attach(); m_Ephemeral = true; } diff --git a/src/singleinstance.h b/src/singleinstance.h index d500a056..5f6c3633 100644 --- a/src/singleinstance.h +++ b/src/singleinstance.h @@ -36,19 +36,9 @@ class SingleInstance : public QObject Q_OBJECT public: - enum Flag - { - NoFlags = 0x00, - - // if another instance is running, run this one disconnected from the - // shared memory - AllowMultiple = 0x01 - }; - - using Flags = QFlags; - - - explicit SingleInstance(Flags flags, QObject *parent = 0); + // `allowMultiple`: if another instance is running, run this one + // disconnected from the shared memory + explicit SingleInstance(bool allowMultiple, QObject *parent = 0); /** * @return true if this instance's job is to forward data to the primary @@ -97,6 +87,4 @@ private: }; -Q_DECLARE_OPERATORS_FOR_FLAGS(SingleInstance::Flags); - #endif // SINGLEINSTANCE_H diff --git a/src/spawn.cpp b/src/spawn.cpp index 2016bb23..a9ecb61e 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -488,7 +488,7 @@ DWORD spawn(const SpawnParameters& sp, HANDLE& processHandle) } const QString moPath = QCoreApplication::applicationDirPath(); - const auto oldPath = env::addPath(QDir::toNativeSeparators(moPath)); + const auto oldPath = env::appendToPath(QDir::toNativeSeparators(moPath)); PROCESS_INFORMATION pi = {}; BOOL success = FALSE; -- cgit v1.3.1