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') 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