From 6ca1ebc349528d5f6fc9194c590a17ecbe9fa444 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 6 Nov 2020 17:28:01 -0500 Subject: comments interpret a first argument starting with -- as an error instead of an exe name/binary --- src/commandline.cpp | 55 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index 3f8a6b1a..ff1be764 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -13,6 +13,8 @@ std::string pad_right(std::string s, std::size_t n, char c=' ') return s; } +// formats the list of pairs in two columns +// std::string table( const std::vector>& v, std::size_t indent, std::size_t spacing) @@ -60,6 +62,9 @@ std::optional CommandLine::run(const std::wstring& line) args.erase(args.begin()); } + // parsing the first part of the command line, including global options and + // command name, but not the rest, which will be collected below + auto parsed = po::wcommand_line_parser(args) .options(m_allOptions) .positional(m_positional) @@ -69,20 +74,29 @@ std::optional CommandLine::run(const std::wstring& line) po::store(parsed, m_vm); po::notify(m_vm); + // collect options past the command name auto opts = po::collect_unrecognized( parsed.options, po::include_positional); if (m_vm.count("command")) { + // there's a word as the first argument; this may be a command name or + // an old style exe name/binary + const auto commandName = m_vm["command"].as(); + // look for the command by name first for (auto&& c : m_commands) { if (c->name() == commandName) { + // this is a command + // remove the command name itself opts.erase(opts.begin()); try { + // parse the the remainder of the command line according to the + // command's options po::wcommand_line_parser parser(opts); auto co = c->allOptions(); @@ -106,6 +120,7 @@ std::optional CommandLine::run(const std::wstring& line) return 0; } + // run the command return c->run(line, m_vm, opts); } catch(po::error& e) @@ -122,6 +137,11 @@ std::optional CommandLine::run(const std::wstring& line) } } + + // the first word on the command line is not a valid command, try the other + // stuff; this is handled in main.cpp + + // look for help if (m_vm.count("help")) { env::Console console; std::cout << usage() << "\n"; @@ -130,12 +150,25 @@ std::optional CommandLine::run(const std::wstring& line) if (!opts.empty()) { const auto qs = QString::fromStdWString(opts[0]); + + if (qs.startsWith("--")) { + // assume that for something like `ModOrganizer.exe --bleh`, it's just + // a bad option instead of an executable that starts with "--" + env::Console console; + std::cerr << "\nUnrecognized option " << qs.toStdString() << "\n"; + + return 1; + } + + // try as an moshorcut:// m_shortcut = qs; if (!m_shortcut.isValid()) { + // not a shortcut, try a link if (isNxmLink(qs)) { m_nxmLink = qs; } else { + // assume an executable name/binary m_executable = qs; } } @@ -182,6 +215,7 @@ void CommandLine::createOptions() ("command", po::value(), "command") ("subargs", po::value >(), "args"); + // one command name, followed by any arguments for that command m_positional .add("command", 1) .add("subargs", -1); @@ -210,6 +244,7 @@ std::string CommandLine::usage(const Command* c) const << "\n" << "Commands:\n"; + // name and description for all commands std::vector> v; for (auto&& c : m_commands) { v.push_back({c->name(), c->description()}); @@ -224,6 +259,7 @@ std::string CommandLine::usage(const Command* c) const << "Global options:\n" << m_visibleOptions << "\n"; + // show the more text unless this is usage for a specific command if (!c) { oss << "\n" << more() << "\n"; } @@ -247,6 +283,8 @@ std::optional CommandLine::profile() const std::optional CommandLine::instance() const { + // note that moshortcut:// overrides -i + if (m_shortcut.isValid() && m_shortcut.hasInstance()) { return m_shortcut.instance(); } else if (m_vm.count("instance")) { @@ -369,21 +407,6 @@ po::positional_options_description Command::getPositional() const } -std::string Command::usage() const -{ - std::ostringstream oss; - - oss - << "\n" - << "Usage:\n" - << " ModOrganizer.exe [options] [[command] [command-options]]\n" - << "\n" - << "Options:\n" - << visibleOptions() << "\n"; - - return oss.str(); -} - std::optional Command::run( const std::wstring& originalLine, po::variables_map vm, @@ -569,8 +592,6 @@ std::optional ExeCommand::doRun() const auto args = vm()["arguments"].as(); const auto cwd = vm()["cwd"].as(); - - return 0; } -- cgit v1.3.1 From 90ea45328d72f9664ace3cfbdce700dbe7a1d016 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 7 Nov 2020 16:16:47 -0500 Subject: moved splash stuff to MOSplash comments --- src/commandline.cpp | 3 +++ src/main.cpp | 71 ++----------------------------------------------- src/moapplication.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/moapplication.h | 19 ++++++++++++++ src/settings.h | 18 +++++++++++++ 5 files changed, 115 insertions(+), 69 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index ff1be764..dc8cf53f 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -592,6 +592,8 @@ std::optional ExeCommand::doRun() const auto args = vm()["arguments"].as(); const auto cwd = vm()["cwd"].as(); + std::cout << "not implemented\n"; + return 0; } @@ -608,6 +610,7 @@ Command::Meta RunCommand::meta() const std::optional RunCommand::doRun() { + std::cout << "not implemented\n"; return {}; } diff --git a/src/main.cpp b/src/main.cpp index a2653685..9d6ed7b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,69 +160,6 @@ void addDllsToPath() env::prependToPath(dllsPath); } -QString getSplashPath( - const Settings& settings, const QString& dataPath, - const MOBase::IPluginGame* game) -{ - if (!settings.useSplash()) { - return {}; - } - - // try splash from instance directory - const QString splashPath = dataPath + "/splash.png"; - if (QFile::exists(dataPath + "/splash.png")) { - QImage image(splashPath); - if (!image.isNull()) { - return splashPath; - } - } - - // try splash from plugin - QString pluginSplash = QString(":/%1/splash").arg(game->gameShortName()); - if (QFile::exists(pluginSplash)) { - QImage image(pluginSplash); - if (!image.isNull()) { - image.save(splashPath); - return pluginSplash; - } - } - - // try default splash from resource - QString defaultSplash = ":/MO/gui/splash"; - if (QFile::exists(defaultSplash)) { - QImage image(defaultSplash); - if (!image.isNull()) { - return defaultSplash; - } - } - - return splashPath; -} - -std::unique_ptr createSplash( - const Settings& settings, const QString& dataPath, - const MOBase::IPluginGame* game) -{ - const auto splashPath = getSplashPath(settings, dataPath, game); - if (splashPath.isEmpty()) { - return {}; - } - - QPixmap image(splashPath); - if (image.isNull()) { - log::error("failed to load splash from {}", splashPath); - return {}; - } - - auto splash = std::make_unique(image); - settings.geometry().centerOnMainWindowMonitor(splash.get()); - - splash->show(); - splash->activateWindow(); - - return splash; -} - std::optional handleCommandLine( const cl::CommandLine& cl, OrganizerCore& organizer) { @@ -554,7 +491,7 @@ int runApplication( return *r; } - auto splash = createSplash(settings, dataPath, currentInstance.gamePlugin()); + MOSplash splash(settings, dataPath, currentInstance.gamePlugin()); QString apiKey; if (GlobalSettings::nexusApiKey(apiKey)) { @@ -589,11 +526,7 @@ int runApplication( mainWindow.show(); mainWindow.activateWindow(); - if (splash) { - // don't pass mainwindow as it just waits half a second for it - // instead of proceding - splash->finish(nullptr); - } + splash.close(); tt.stop(); diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 290666af..659b5a12 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -18,6 +18,8 @@ along with Mod Organizer. If not, see . */ #include "moapplication.h" +#include "settings.h" +#include #include #include #include @@ -147,3 +149,74 @@ void MOApplication::updateStyle(const QString& fileName) } } } + + +MOSplash::MOSplash( + const Settings& settings, const QString& dataPath, + const MOBase::IPluginGame* game) +{ + const auto splashPath = getSplashPath(settings, dataPath, game); + if (splashPath.isEmpty()) { + return; + } + + QPixmap image(splashPath); + if (image.isNull()) { + log::error("failed to load splash from {}", splashPath); + return; + } + + ss_.reset(new QSplashScreen(image)); + settings.geometry().centerOnMainWindowMonitor(ss_.get()); + + ss_->show(); + ss_->activateWindow(); +} + +void MOSplash::close() +{ + if (ss_) { + // don't pass mainwindow as it just waits half a second for it + // instead of proceding + ss_->finish(nullptr); + } +} + +QString MOSplash::getSplashPath( + const Settings& settings, const QString& dataPath, + const MOBase::IPluginGame* game) const +{ + if (!settings.useSplash()) { + return {}; + } + + // try splash from instance directory + const QString splashPath = dataPath + "/splash.png"; + if (QFile::exists(dataPath + "/splash.png")) { + QImage image(splashPath); + if (!image.isNull()) { + return splashPath; + } + } + + // try splash from plugin + QString pluginSplash = QString(":/%1/splash").arg(game->gameShortName()); + if (QFile::exists(pluginSplash)) { + QImage image(pluginSplash); + if (!image.isNull()) { + image.save(splashPath); + return pluginSplash; + } + } + + // try default splash from resource + QString defaultSplash = ":/MO/gui/splash"; + if (QFile::exists(defaultSplash)) { + QImage image(defaultSplash); + if (!image.isNull()) { + return defaultSplash; + } + } + + return splashPath; +} diff --git a/src/moapplication.h b/src/moapplication.h index c67c4622..0ee04492 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -23,6 +23,8 @@ along with Mod Organizer. If not, see . #include #include +class Settings; +namespace MOBase { class IPluginGame; } class MOApplication : public QApplication { @@ -46,4 +48,21 @@ private: }; +class MOSplash +{ +public: + MOSplash( + const Settings& settings, const QString& dataPath, + const MOBase::IPluginGame* game); + + void close(); + +private: + std::unique_ptr ss_; + + QString getSplashPath( + const Settings& settings, const QString& dataPath, + const MOBase::IPluginGame* game) const; +}; + #endif // MOAPPLICATION_H diff --git a/src/settings.h b/src/settings.h index c8325ba2..fc7789f0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -195,6 +195,10 @@ private: class WidgetSettings { public: + // globalInstance is forwarded from the Settings constructor; WidgetSettings + // has the callbacks used by QuestionBoxMemory and those are global, so they + // should only be set by the global instance + // WidgetSettings(QSettings& s, bool globalInstance); // selected index for a combobox @@ -671,6 +675,20 @@ class Settings : public QObject Q_OBJECT; public: + // there is one Settings global object for MO when an instance is loaded, but + // other Settings objects are required in several places, such as in the + // Instance class, the instance dialogs, etc. + // + // any Settings object created with globalInstance==false won't set the + // singleton + // + // only WidgetSettings need to know whether it created from a globalInstance, + // see its constructor + // + // @param path path to an ini file + // @param globalInsance whether this is the global instance; creates the + // singleton and asserts if it already exists + // Settings(const QString& path, bool globalInstance=false); ~Settings(); -- cgit v1.3.1 From ba7d24faef49858b9721c2ade0f3ea4a7ba4d96d Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 7 Nov 2020 17:21:13 -0500 Subject: moved handleCommandLine() to CommandLine::setupCore() --- src/commandline.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/commandline.h | 22 ++++++++++++++++++++++ src/main.cpp | 51 +-------------------------------------------------- 3 files changed, 76 insertions(+), 50 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index dc8cf53f..3d0e901d 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -1,10 +1,15 @@ #include "commandline.h" #include "env.h" +#include "organizercore.h" #include "shared/util.h" +#include +#include namespace cl { +using namespace MOBase; + std::string pad_right(std::string s, std::size_t n, char c=' ') { if (s.size() < n) @@ -195,6 +200,54 @@ std::optional CommandLine::run(const std::wstring& line) } } +std::optional CommandLine::setupCore(OrganizerCore& organizer) const +{ + // if we have a command line parameter, it is either a nxm link or + // a binary to start + if (m_shortcut.isValid()) { + if (m_shortcut.hasExecutable()) { + try { + organizer.processRunner() + .setFromShortcut(m_shortcut) + .setWaitForCompletion() + .run(); + + return 0; + } + catch (const std::exception &e) { + reportError( + QObject::tr("failed to start shortcut: %1").arg(e.what())); + return 1; + } + } + } else if (m_nxmLink) { + log::debug("starting download from command line: {}", *m_nxmLink); + organizer.externalMessage(*m_nxmLink); + } else if (m_executable) { + const QString exeName = *m_executable; + log::debug("starting {} from command line", exeName); + + try + { + // pass the remaining parameters to the binary + organizer.processRunner() + .setFromFileOrExecutable(exeName, m_untouched) + .setWaitForCompletion() + .run(); + + return 0; + } + catch (const std::exception &e) + { + reportError( + QObject::tr("failed to start application: %1").arg(e.what())); + return 1; + } + } + + return {}; +} + void CommandLine::clear() { m_vm.clear(); diff --git a/src/commandline.h b/src/commandline.h index 478ee8ea..baa0bfb9 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -4,6 +4,8 @@ #include #include +class OrganizerCore; + namespace cl { @@ -193,6 +195,18 @@ protected: // if moshortcut:// is detected and has an instance, it will override -i if both // are given // +// +// the command is used in two phases: +// +// 1) run() is called in main() shortly after startup; it parses the command +// line and runs the given command, if any +// +// 2) if the command did not request to exit, the instance is loaded +// in main() et al. and setupCore() is called; it handles moshortcut, +// nxm links and starting executables/binaries +// +// either can return an exit code, which will make MO exit immediately +// class CommandLine { public: @@ -206,6 +220,14 @@ public: // std::optional run(const std::wstring& line); + // handles moshortcut, nxm links and starting processes + // + // returns an empty optional if execution should continue, or a return code + // if MO must quit + // + std::optional setupCore(OrganizerCore& organizer) const; + + // clears parsed options, used when MO is "restarted" so the options aren't // processed again // diff --git a/src/main.cpp b/src/main.cpp index e0326b27..55fedc7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,55 +115,6 @@ void setExceptionHandlers() g_prevTerminateHandler = std::set_terminate(onTerminate); } -std::optional handleCommandLine( - const cl::CommandLine& cl, OrganizerCore& organizer) -{ - // if we have a command line parameter, it is either a nxm link or - // a binary to start - if (cl.shortcut().isValid()) { - if (cl.shortcut().hasExecutable()) { - try { - organizer.processRunner() - .setFromShortcut(cl.shortcut()) - .setWaitForCompletion() - .run(); - - return 0; - } - catch (const std::exception &e) { - reportError( - QObject::tr("failed to start shortcut: %1").arg(e.what())); - return 1; - } - } - } else if (cl.nxmLink()) { - log::debug("starting download from command line: {}", *cl.nxmLink()); - organizer.externalMessage(*cl.nxmLink()); - } else if (cl.executable()) { - const QString exeName = *cl.executable(); - log::debug("starting {} from command line", exeName); - - try - { - // pass the remaining parameters to the binary - organizer.processRunner() - .setFromFileOrExecutable(exeName, cl.untouched()) - .setWaitForCompletion() - .run(); - - return 0; - } - catch (const std::exception &e) - { - reportError( - QObject::tr("failed to start application: %1").arg(e.what())); - return 1; - } - } - - return {}; -} - int runApplication( MOApplication &application, const cl::CommandLine& cl, SingleInstance &instance, const QString &dataPath, @@ -274,7 +225,7 @@ int runApplication( organizer.setCurrentProfile(currentInstance.profileName()); - if (auto r=handleCommandLine(cl, organizer)) { + if (auto r=cl.setupCore(organizer)) { return *r; } -- cgit v1.3.1 From a5469ae4e0668c36e4bf36bf7395fa25073b0bc6 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:07:15 -0500 Subject: renamed SingleInstance to MOMultiProcess rewrote some comments to avoid using "instance" --- src/commandline.cpp | 5 ++--- src/main.cpp | 16 ++++++++-------- src/moapplication.cpp | 12 ++++++------ src/moapplication.h | 6 +++--- src/singleinstance.cpp | 36 ++++++++---------------------------- src/singleinstance.h | 48 ++++++++++++++---------------------------------- 6 files changed, 41 insertions(+), 82 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index 3d0e901d..fd2fcb51 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -144,7 +144,8 @@ std::optional CommandLine::run(const std::wstring& line) // the first word on the command line is not a valid command, try the other - // stuff; this is handled in main.cpp + // stuff; this is used in setupCore() below when called from + // MOApplication::doOneRun() // look for help if (m_vm.count("help")) { @@ -202,8 +203,6 @@ std::optional CommandLine::run(const std::wstring& line) std::optional CommandLine::setupCore(OrganizerCore& organizer) const { - // if we have a command line parameter, it is either a nxm link or - // a binary to start if (m_shortcut.isValid()) { if (m_shortcut.hasExecutable()) { try { diff --git a/src/main.cpp b/src/main.cpp index 8f99cf1d..440489d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ using namespace MOBase; thread_local LPTOP_LEVEL_EXCEPTION_FILTER g_prevExceptionFilter = nullptr; thread_local std::terminate_handler g_prevTerminateHandler = nullptr; -int forwardToPrimary(SingleInstance& instance, const cl::CommandLine& cl); +int forwardToPrimary(MOMultiProcess& multiProcess, const cl::CommandLine& cl); int main(int argc, char *argv[]) { @@ -32,22 +32,22 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); MOApplication app(cl, argc, argv); - SingleInstance instance(cl.multiple()); - if (instance.ephemeral()) { - return forwardToPrimary(instance, cl); + MOMultiProcess multiProcess(cl.multiple()); + if (multiProcess.ephemeral()) { + return forwardToPrimary(multiProcess, cl); } tt.stop(); - return app.run(instance); + return app.run(multiProcess); } -int forwardToPrimary(SingleInstance& instance, const cl::CommandLine& cl) +int forwardToPrimary(MOMultiProcess& multiProcess, const cl::CommandLine& cl) { if (cl.shortcut().isValid()) { - instance.sendMessage(cl.shortcut().toString()); + multiProcess.sendMessage(cl.shortcut().toString()); } else if (cl.nxmLink()) { - instance.sendMessage(*cl.nxmLink()); + multiProcess.sendMessage(*cl.nxmLink()); } else { QMessageBox::information( nullptr, QObject::tr("Mod Organizer"), diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 3f17e436..db559421 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -147,7 +147,7 @@ MOApplication::MOApplication(cl::CommandLine& cl, int& argc, char** argv) addDllsToPath(); } -int MOApplication::run(SingleInstance& singleInstance) +int MOApplication::run(MOMultiProcess& multiProcess) { TimeThis tt("MOApplication run() to doOneRun()"); @@ -174,7 +174,7 @@ int MOApplication::run(SingleInstance& singleInstance) resetForRestart(); tt.stop(); - const auto r = doOneRun(singleInstance); + const auto r = doOneRun(multiProcess); if (r == RestartExitCode) { continue; } @@ -189,7 +189,7 @@ int MOApplication::run(SingleInstance& singleInstance) } } -int MOApplication::doOneRun(SingleInstance& singleInstance) +int MOApplication::doOneRun(MOMultiProcess& multiProcess) { TimeThis tt("MOApplication::doOneRun() instances"); @@ -217,7 +217,7 @@ int MOApplication::doOneRun(SingleInstance& singleInstance) createVersionInfo().displayString(3), GITID, QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString()); - if (singleInstance.secondary()) { + if (multiProcess.secondary()) { log::debug("another instance of MO is running but --multiple was given"); } @@ -228,7 +228,7 @@ int MOApplication::doOneRun(SingleInstance& singleInstance) tt.start("MOApplication::doOneRun() settings"); // deleting old files, only for the main instance - if (!singleInstance.secondary()) { + if (!multiProcess.secondary()) { purgeOldFiles(); } @@ -365,7 +365,7 @@ int MOApplication::doOneRun(SingleInstance& singleInstance) QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), this, SLOT(setStyleFile(QString))); - QObject::connect(&singleInstance, SIGNAL(messageSent(QString)), &organizer, + QObject::connect(&multiProcess, SIGNAL(messageSent(QString)), &organizer, SLOT(externalMessage(QString))); diff --git a/src/moapplication.h b/src/moapplication.h index 7423c897..91b8023a 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -24,7 +24,7 @@ along with Mod Organizer. If not, see . #include class Settings; -class SingleInstance; +class MOMultiProcess; class Instance; class PluginContainer; @@ -40,7 +40,7 @@ public: // sets up everything, creates the main window and runs it // - int run(SingleInstance& si); + int run(MOMultiProcess& multiProcess); virtual bool notify(QObject* receiver, QEvent* event); @@ -55,7 +55,7 @@ private: QString m_DefaultStyle; cl::CommandLine& m_cl; - int doOneRun(SingleInstance& singleInstance); + int doOneRun(MOMultiProcess& multiProcess); std::optional getCurrentInstance(); std::optional setupInstanceLoop(Instance& currentInstance, PluginContainer& pc); diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index bd7ccc43..401381fd 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -1,22 +1,3 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - #include "singleinstance.h" #include "utility.h" #include @@ -28,7 +9,7 @@ static const int s_Timeout = 5000; using MOBase::reportError; -SingleInstance::SingleInstance(bool allowMultiple, QObject *parent) : +MOMultiProcess::MOMultiProcess(bool allowMultiple, QObject *parent) : QObject(parent), m_Ephemeral(false), m_OwnsSM(false) { m_SharedMem.setKey(s_Key); @@ -58,7 +39,7 @@ SingleInstance::SingleInstance(bool allowMultiple, QObject *parent) : } -void SingleInstance::sendMessage(const QString &message) +void MOMultiProcess::sendMessage(const QString &message) { if (m_OwnsSM) { // nobody there to receive the message @@ -72,19 +53,19 @@ void SingleInstance::sendMessage(const QString &message) Sleep(250); } - // other instance may be just starting up + // other process may be just starting up socket.connectToServer(s_Key, QIODevice::WriteOnly); connected = socket.waitForConnected(s_Timeout); } if (!connected) { - reportError(tr("failed to connect to running instance: %1").arg(socket.errorString())); + reportError(tr("failed to connect to running process: %1").arg(socket.errorString())); return; } socket.write(message.toUtf8()); if (!socket.waitForBytesWritten(s_Timeout)) { - reportError(tr("failed to communicate with running instance: %1").arg(socket.errorString())); + reportError(tr("failed to communicate with running process: %1").arg(socket.errorString())); return; } @@ -92,8 +73,7 @@ void SingleInstance::sendMessage(const QString &message) socket.waitForDisconnected(); } - -void SingleInstance::receiveMessage() +void MOMultiProcess::receiveMessage() { QLocalSocket *socket = m_Server.nextPendingConnection(); if (!socket) { @@ -108,10 +88,10 @@ void SingleInstance::receiveMessage() if (av <= 0) { MOBase::log::error( - "failed to receive data from secondary instance: {}", + "failed to receive data from secondary process: {}", socket->errorString()); - reportError(tr("failed to receive data from secondary instance: %1").arg(socket->errorString())); + reportError(tr("failed to receive data from secondary process: %1").arg(socket->errorString())); return; } } diff --git a/src/singleinstance.h b/src/singleinstance.h index 5f6c3633..810e63d2 100644 --- a/src/singleinstance.h +++ b/src/singleinstance.h @@ -1,24 +1,5 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - -#ifndef SINGLEINSTANCE_H -#define SINGLEINSTANCE_H +#ifndef MODORGANIZER_MOMULTIPROCESS_INCLUDED +#define MODORGANIZER_MOMULTIPROCESS_INCLUDED #include #include @@ -26,30 +7,29 @@ along with Mod Organizer. If not, see . /** - * used to ensure only a single instance of Mod Organizer is started and to - * allow ephemeral instances to send messages to the primary (visible) one. - * This way, other instances can start a download in the primary one + * used to ensure only a single process of Mod Organizer is started and to + * allow ephemeral processes to send messages to the primary (visible) one. + * This way, other processes can start a download in the primary one **/ -class SingleInstance : public QObject +class MOMultiProcess : public QObject { - Q_OBJECT public: - // `allowMultiple`: if another instance is running, run this one + // `allowMultiple`: if another process is running, run this one // disconnected from the shared memory - explicit SingleInstance(bool allowMultiple, QObject *parent = 0); + explicit MOMultiProcess(bool allowMultiple, QObject *parent = 0); /** - * @return true if this instance's job is to forward data to the primary - * instance through shared memory + * @return true if this process's job is to forward data to the primary + * process through shared memory **/ bool ephemeral() const { return m_Ephemeral; } - // returns true if this is not the primary instance, but was allowed because + // returns true if this is not the primary process, but was allowed because // of the AllowMultiple flag // bool secondary() const @@ -58,7 +38,7 @@ public: } /** - * send a message to the primary instance. This can be used to transmit download urls + * send a message to the primary process. This can be used to transmit download urls * * @param message message to send **/ @@ -67,7 +47,7 @@ public: signals: /** - * @brief emitted when an ephemeral instance has sent a message (to us) + * @brief emitted when an ephemeral process has sent a message (to us) * * @param message the message we received **/ @@ -87,4 +67,4 @@ private: }; -#endif // SINGLEINSTANCE_H +#endif // MODORGANIZER_MOMULTIPROCESS_INCLUDED -- cgit v1.3.1