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/moapplication.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'src/moapplication.h')
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
--
cgit v1.3.1
From 1b7384f7cb3dc32063e588c174265b8c46cfa629 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 7 Nov 2020 17:55:25 -0500
Subject: moved most of the stuff from main.cpp into MOApplication
---
src/main.cpp | 288 +----------------------------------------------
src/moapplication.cpp | 303 ++++++++++++++++++++++++++++++++++++++++++++++++--
src/moapplication.h | 20 +++-
3 files changed, 315 insertions(+), 296 deletions(-)
(limited to 'src/moapplication.h')
diff --git a/src/main.cpp b/src/main.cpp
index 40512006..72d598a8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -45,21 +45,6 @@ along with Mod Organizer. If not, see .
using namespace MOBase;
using namespace MOShared;
-void purgeOldFiles()
-{
- // remove the temporary backup directory in case we're restarting after an
- // update
- QString backupDirectory = qApp->applicationDirPath() + "/update_backup";
- if (QDir(backupDirectory).exists()) {
- shellDelete(QStringList(backupDirectory));
- }
-
- // cycle log file
- removeOldFiles(
- qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::logPath()),
- "usvfs*.log", 5, QDir::Name);
-}
-
thread_local LPTOP_LEVEL_EXCEPTION_FILTER g_prevExceptionFilter = nullptr;
thread_local std::terminate_handler g_prevTerminateHandler = nullptr;
@@ -111,180 +96,6 @@ void setExceptionHandlers()
g_prevTerminateHandler = std::set_terminate(onTerminate);
}
-int runApplication(
- MOApplication &application, const cl::CommandLine& cl,
- SingleInstance &instance, const QString &dataPath,
- Instance& currentInstance)
-{
- TimeThis tt("runApplication() to exec()");
-
- log::info(
- "starting Mod Organizer version {} revision {} in {}, usvfs: {}",
- createVersionInfo().displayString(3), GITID,
- QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString());
-
- log::info("data path: {}", dataPath);
-
- log::info("working directory: {}", QDir::currentPath());
-
- if (!instance.secondary()) {
- purgeOldFiles();
- }
-
- QWindowsWindowFunctions::setWindowActivationBehavior(
- QWindowsWindowFunctions::AlwaysActivateWindow);
-
- try
- {
- Settings settings(
- dataPath + "/" + QString::fromStdWString(AppConfig::iniFileName()),
- true);
-
- log::getDefault().setLevel(settings.diagnostics().logLevel());
-
- log::debug("using ini at '{}'", settings.filename());
-
- if (instance.secondary()) {
- log::debug("another instance of MO is running but --multiple was given");
- }
-
- // global crashDumpType sits in OrganizerCore to make a bit less ugly to
- // update it when the settings are changed during runtime
- OrganizerCore::setGlobalCrashDumpsType(settings.diagnostics().crashDumpsType());
-
- env::Environment env;
- env.dump(settings);
- settings.dump();
- sanity::checkEnvironment(env);
-
- const auto moduleNotification = env.onModuleLoaded(qApp, [](auto&& m) {
- log::debug("loaded module {}", m.toString());
- sanity::checkIncompatibleModule(m);
- });
-
- // this must outlive `organizer`
- std::unique_ptr pluginContainer;
-
- log::debug("initializing nexus interface");
- NexusInterface ni(&settings);
-
- log::debug("initializing core");
- OrganizerCore organizer(settings);
- if (!organizer.bootstrap()) {
- reportError("failed to set up data paths");
- InstanceManager::singleton().clearCurrentInstance();
- return 1;
- }
-
- log::debug("initializing plugins");
- pluginContainer = std::make_unique(&organizer);
- pluginContainer->loadPlugins();
-
- for (;;)
- {
- const auto setupResult = setupInstance(currentInstance, *pluginContainer);
-
- if (setupResult == SetupInstanceResults::Okay) {
- break;
- } else if (setupResult == SetupInstanceResults::TryAgain) {
- continue;
- } else if (setupResult == SetupInstanceResults::SelectAnother) {
- InstanceManager::singleton().clearCurrentInstance();
- return RestartExitCode;
- } else {
- return 1;
- }
- }
-
- if (currentInstance.isPortable()) {
- log::debug("this is a portable instance");
- }
-
- sanity::checkPaths(*currentInstance.gamePlugin(), settings);
-
- organizer.setManagedGame(currentInstance.gamePlugin());
- organizer.createDefaultProfile();
-
- log::info(
- "using game plugin '{}' ('{}', variant {}, steam id '{}') at {}",
- currentInstance.gamePlugin()->gameName(),
- currentInstance.gamePlugin()->gameShortName(),
- (settings.game().edition().value_or("").isEmpty() ?
- "(none)" : *settings.game().edition()),
- currentInstance.gamePlugin()->steamAPPId(),
- currentInstance.gamePlugin()->gameDirectory().absolutePath());
-
-
- CategoryFactory::instance().loadCategories();
- organizer.updateExecutablesList();
- organizer.updateModInfoFromDisc();
-
- organizer.setCurrentProfile(currentInstance.profileName());
-
- if (auto r=cl.setupCore(organizer)) {
- return *r;
- }
-
- MOSplash splash(settings, dataPath, currentInstance.gamePlugin());
-
- QString apiKey;
- if (GlobalSettings::nexusApiKey(apiKey)) {
- ni.getAccessManager()->apiCheck(apiKey);
- }
-
- log::debug("initializing tutorials");
- TutorialManager::init(
- qApp->applicationDirPath() + "/"
- + QString::fromStdWString(AppConfig::tutorialsPath()) + "/",
- &organizer);
-
- if (!application.setStyleFile(settings.interface().styleName().value_or(""))) {
- // disable invalid stylesheet
- settings.interface().setStyleName("");
- }
-
- int res = 1;
-
- {
- // scope to control lifetime of mainwindow
- // set up main window and its data structures
- MainWindow mainWindow(settings, organizer, *pluginContainer);
-
- // qt resets the thread name somewhere when creating the main window
- MOShared::SetThisThreadName("main");
-
- ni.getAccessManager()->setTopLevelWidget(&mainWindow);
-
- QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), &application,
- SLOT(setStyleFile(QString)));
- QObject::connect(&instance, SIGNAL(messageSent(QString)), &organizer,
- SLOT(externalMessage(QString)));
-
- log::debug("displaying main window");
- mainWindow.show();
- mainWindow.activateWindow();
-
- splash.close();
-
- tt.stop();
-
- res = application.exec();
- mainWindow.close();
-
- ni.getAccessManager()->setTopLevelWidget(nullptr);
- }
-
- settings.geometry().resetIfNeeded();
- return res;
- }
- catch (const std::exception &e)
- {
- reportError(e.what());
- }
-
- return 1;
-}
-
int forwardToPrimary(SingleInstance& instance, const cl::CommandLine& cl)
{
if (cl.shortcut().isValid()) {
@@ -300,118 +111,25 @@ int forwardToPrimary(SingleInstance& instance, const cl::CommandLine& cl)
return 0;
}
-void resetForRestart(cl::CommandLine& cl)
-{
- LogModel::instance().clear();
- ResetExitFlag();
-
- // make sure the log file isn't locked in case MO was restarted and
- // the previous instance gets deleted
- log::getDefault().setFile({});
-
- // don't reprocess command line
- cl.clear();
-}
-
-int doOneRun(
- cl::CommandLine& cl, MOApplication& application, SingleInstance& instance)
-{
- TimeThis tt("doOneRun() to runApplication()");
-
- // resets things when MO is "restarted"
- resetForRestart(cl);
-
- auto& m = InstanceManager::singleton();
- auto currentInstance = m.currentInstance();
-
- if (!currentInstance)
- {
- currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
- }
- else
- {
- if (!QDir(currentInstance->directory()).exists()) {
- // the previously used instance doesn't exist anymore
-
- if (m.hasAnyInstances()) {
- MOShared::criticalOnTop(QObject::tr(
- "Instance at '%1' not found. Select another instance.")
- .arg(currentInstance->directory()));
- } else {
- MOShared::criticalOnTop(QObject::tr(
- "Instance at '%1' not found. You must create a new instance")
- .arg(currentInstance->directory()));
- }
-
- currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
- }
- }
-
- const QString dataPath = currentInstance->directory();
- application.setProperty("dataPath", dataPath);
-
- setExceptionHandlers();
-
- if (!setLogDirectory(dataPath)) {
- reportError("Failed to create log folder");
- InstanceManager::singleton().clearCurrentInstance();
- return 1;
- }
-
- log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
-
- tt.stop();
-
- return runApplication(application, cl, instance, dataPath, *currentInstance);
-}
int main(int argc, char *argv[])
{
MOShared::SetThisThreadName("main");
cl::CommandLine cl;
-
if (auto r=cl.run(GetCommandLineW())) {
return *r;
}
- TimeThis tt("main() to doOneRun()");
-
initLogging();
- auto application = MOApplication::create(argc, argv);
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ MOApplication app(cl, argc, argv);
SingleInstance instance(cl.multiple());
if (instance.ephemeral()) {
return forwardToPrimary(instance, cl);
}
- tt.stop();
-
- if (cl.instance())
- InstanceManager::singleton().overrideInstance(*cl.instance());
-
- if (cl.profile()) {
- InstanceManager::singleton().overrideProfile(*cl.profile());
- }
-
- // makes plugin data path available to plugins, see
- // IOrganizer::getPluginDataPath()
- MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath());
-
- for (;;)
- {
- const auto r = doOneRun(cl, application, instance);
- if (r == RestartExitCode) {
- continue;
- }
-
- return r;
- }
+ return app.run(instance);
}
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index 43d787f5..b4ba7da6 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -20,6 +20,18 @@ along with Mod Organizer. If not, see .
#include "moapplication.h"
#include "settings.h"
#include "env.h"
+#include "commandline.h"
+#include "instancemanager.h"
+#include "organizercore.h"
+#include "thread_utils.h"
+#include "loglist.h"
+#include "singleinstance.h"
+#include "nexusinterface.h"
+#include "nxmaccessmanager.h"
+#include "tutorialmanager.h"
+#include "sanitychecks.h"
+#include "mainwindow.h"
+#include "shared/error_report.h"
#include "shared/util.h"
#include
#include
@@ -42,7 +54,7 @@ along with Mod Organizer. If not, see .
"type='win32' \"")
using namespace MOBase;
-
+using namespace MOShared;
class ProxyStyle : public QProxyStyle {
public:
@@ -120,8 +132,8 @@ void addDllsToPath()
}
-MOApplication::MOApplication(int& argc, char** argv)
- : QApplication(argc, argv)
+MOApplication::MOApplication(cl::CommandLine& cl, int& argc, char** argv)
+ : QApplication(argc, argv), m_cl(cl)
{
connect(&m_StyleWatcher, &QFileSystemWatcher::fileChanged, [&](auto&& file){
log::debug("style file '{}' changed, reloading", file);
@@ -133,11 +145,288 @@ MOApplication::MOApplication(int& argc, char** argv)
addDllsToPath();
}
-MOApplication MOApplication::create(int& argc, char** argv)
+int MOApplication::run(SingleInstance& singleInstance)
+{
+ auto& m = InstanceManager::singleton();
+
+ if (m_cl.instance())
+ m.overrideInstance(*m_cl.instance());
+
+ if (m_cl.profile()) {
+ m.overrideProfile(*m_cl.profile());
+ }
+
+ // makes plugin data path available to plugins, see
+ // IOrganizer::getPluginDataPath()
+ MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath());
+
+ for (;;)
+ {
+ const auto r = doOneRun(singleInstance);
+ if (r == RestartExitCode) {
+ continue;
+ }
+
+ return r;
+ }
+}
+
+int MOApplication::doOneRun(SingleInstance& singleInstance)
{
- QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ TimeThis tt("doOneRun() to runApplication()");
+
+ // resets things when MO is "restarted"
+ resetForRestart();
+
+ auto& m = InstanceManager::singleton();
+ auto currentInstance = m.currentInstance();
+
+ if (!currentInstance)
+ {
+ currentInstance = selectInstance();
+ if (!currentInstance) {
+ return 1;
+ }
+ }
+ else
+ {
+ if (!QDir(currentInstance->directory()).exists()) {
+ // the previously used instance doesn't exist anymore
+
+ if (m.hasAnyInstances()) {
+ MOShared::criticalOnTop(QObject::tr(
+ "Instance at '%1' not found. Select another instance.")
+ .arg(currentInstance->directory()));
+ } else {
+ MOShared::criticalOnTop(QObject::tr(
+ "Instance at '%1' not found. You must create a new instance")
+ .arg(currentInstance->directory()));
+ }
+
+ currentInstance = selectInstance();
+ if (!currentInstance) {
+ return 1;
+ }
+ }
+ }
+
+ const QString dataPath = currentInstance->directory();
+ setProperty("dataPath", dataPath);
+
+ setExceptionHandlers();
+
+ if (!setLogDirectory(dataPath)) {
+ reportError("Failed to create log folder");
+ InstanceManager::singleton().clearCurrentInstance();
+ return 1;
+ }
+
+ log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
+
+ tt.stop();
- return MOApplication(argc, argv);
+ return runApplication(singleInstance, dataPath, *currentInstance);
+}
+
+int MOApplication::runApplication(
+ SingleInstance& singleInstance,
+ const QString &dataPath, Instance& currentInstance)
+{
+ TimeThis tt("runApplication() to exec()");
+
+ log::info(
+ "starting Mod Organizer version {} revision {} in {}, usvfs: {}",
+ createVersionInfo().displayString(3), GITID,
+ QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString());
+
+ log::info("data path: {}", dataPath);
+
+ log::info("working directory: {}", QDir::currentPath());
+
+ if (!singleInstance.secondary()) {
+ purgeOldFiles();
+ }
+
+ QWindowsWindowFunctions::setWindowActivationBehavior(
+ QWindowsWindowFunctions::AlwaysActivateWindow);
+
+ try
+ {
+ Settings settings(
+ dataPath + "/" + QString::fromStdWString(AppConfig::iniFileName()),
+ true);
+
+ log::getDefault().setLevel(settings.diagnostics().logLevel());
+
+ log::debug("using ini at '{}'", settings.filename());
+
+ if (singleInstance.secondary()) {
+ log::debug("another instance of MO is running but --multiple was given");
+ }
+
+ // global crashDumpType sits in OrganizerCore to make a bit less ugly to
+ // update it when the settings are changed during runtime
+ OrganizerCore::setGlobalCrashDumpsType(settings.diagnostics().crashDumpsType());
+
+ env::Environment env;
+ env.dump(settings);
+ settings.dump();
+ sanity::checkEnvironment(env);
+
+ const auto moduleNotification = env.onModuleLoaded(qApp, [](auto&& m) {
+ log::debug("loaded module {}", m.toString());
+ sanity::checkIncompatibleModule(m);
+ });
+
+ // this must outlive `organizer`
+ std::unique_ptr pluginContainer;
+
+ log::debug("initializing nexus interface");
+ NexusInterface ni(&settings);
+
+ log::debug("initializing core");
+ OrganizerCore organizer(settings);
+ if (!organizer.bootstrap()) {
+ reportError("failed to set up data paths");
+ InstanceManager::singleton().clearCurrentInstance();
+ return 1;
+ }
+
+ log::debug("initializing plugins");
+ pluginContainer = std::make_unique(&organizer);
+ pluginContainer->loadPlugins();
+
+ for (;;)
+ {
+ const auto setupResult = setupInstance(currentInstance, *pluginContainer);
+
+ if (setupResult == SetupInstanceResults::Okay) {
+ break;
+ } else if (setupResult == SetupInstanceResults::TryAgain) {
+ continue;
+ } else if (setupResult == SetupInstanceResults::SelectAnother) {
+ InstanceManager::singleton().clearCurrentInstance();
+ return RestartExitCode;
+ } else {
+ return 1;
+ }
+ }
+
+ if (currentInstance.isPortable()) {
+ log::debug("this is a portable instance");
+ }
+
+ sanity::checkPaths(*currentInstance.gamePlugin(), settings);
+
+ organizer.setManagedGame(currentInstance.gamePlugin());
+ organizer.createDefaultProfile();
+
+ log::info(
+ "using game plugin '{}' ('{}', variant {}, steam id '{}') at {}",
+ currentInstance.gamePlugin()->gameName(),
+ currentInstance.gamePlugin()->gameShortName(),
+ (settings.game().edition().value_or("").isEmpty() ?
+ "(none)" : *settings.game().edition()),
+ currentInstance.gamePlugin()->steamAPPId(),
+ currentInstance.gamePlugin()->gameDirectory().absolutePath());
+
+
+ CategoryFactory::instance().loadCategories();
+ organizer.updateExecutablesList();
+ organizer.updateModInfoFromDisc();
+
+ organizer.setCurrentProfile(currentInstance.profileName());
+
+ if (auto r=m_cl.setupCore(organizer)) {
+ return *r;
+ }
+
+ MOSplash splash(settings, dataPath, currentInstance.gamePlugin());
+
+ QString apiKey;
+ if (GlobalSettings::nexusApiKey(apiKey)) {
+ ni.getAccessManager()->apiCheck(apiKey);
+ }
+
+ log::debug("initializing tutorials");
+ TutorialManager::init(
+ qApp->applicationDirPath() + "/"
+ + QString::fromStdWString(AppConfig::tutorialsPath()) + "/",
+ &organizer);
+
+ if (!setStyleFile(settings.interface().styleName().value_or(""))) {
+ // disable invalid stylesheet
+ settings.interface().setStyleName("");
+ }
+
+ int res = 1;
+
+ {
+ // scope to control lifetime of mainwindow
+ // set up main window and its data structures
+ MainWindow mainWindow(settings, organizer, *pluginContainer);
+
+ // qt resets the thread name somewhere when creating the main window
+ MOShared::SetThisThreadName("main");
+
+ ni.getAccessManager()->setTopLevelWidget(&mainWindow);
+
+ QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), this,
+ SLOT(setStyleFile(QString)));
+ QObject::connect(&singleInstance, SIGNAL(messageSent(QString)), &organizer,
+ SLOT(externalMessage(QString)));
+
+ log::debug("displaying main window");
+ mainWindow.show();
+ mainWindow.activateWindow();
+
+ splash.close();
+
+ tt.stop();
+
+ res = exec();
+ mainWindow.close();
+
+ ni.getAccessManager()->setTopLevelWidget(nullptr);
+ }
+
+ settings.geometry().resetIfNeeded();
+ return res;
+ }
+ catch (const std::exception &e)
+ {
+ reportError(e.what());
+ }
+
+ return 1;
+}
+
+void MOApplication::purgeOldFiles()
+{
+ // remove the temporary backup directory in case we're restarting after an
+ // update
+ QString backupDirectory = qApp->applicationDirPath() + "/update_backup";
+ if (QDir(backupDirectory).exists()) {
+ shellDelete(QStringList(backupDirectory));
+ }
+
+ // cycle log file
+ removeOldFiles(
+ qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::logPath()),
+ "usvfs*.log", 5, QDir::Name);
+}
+
+void MOApplication::resetForRestart()
+{
+ LogModel::instance().clear();
+ ResetExitFlag();
+
+ // make sure the log file isn't locked in case MO was restarted and
+ // the previous instance gets deleted
+ log::getDefault().setFile({});
+
+ // don't reprocess command line
+ m_cl.clear();
}
bool MOApplication::setStyleFile(const QString& styleName)
@@ -163,7 +452,6 @@ bool MOApplication::setStyleFile(const QString& styleName)
return true;
}
-
bool MOApplication::notify(QObject* receiver, QEvent* event)
{
try {
@@ -183,7 +471,6 @@ bool MOApplication::notify(QObject* receiver, QEvent* event)
}
}
-
void MOApplication::updateStyle(const QString& fileName)
{
if (QStyleFactory::keys().contains(fileName)) {
diff --git a/src/moapplication.h b/src/moapplication.h
index 0ee04492..c1512d9b 100644
--- a/src/moapplication.h
+++ b/src/moapplication.h
@@ -24,15 +24,21 @@ along with Mod Organizer. If not, see .
#include
class Settings;
+class SingleInstance;
+class Instance;
+
namespace MOBase { class IPluginGame; }
+namespace cl { class CommandLine; }
class MOApplication : public QApplication
{
Q_OBJECT
public:
- static MOApplication create(int& argc, char** argv);
- virtual bool notify (QObject* receiver, QEvent* event);
+ MOApplication(cl::CommandLine& cl, int& argc, char** argv);
+
+ int run(SingleInstance& si);
+ virtual bool notify(QObject* receiver, QEvent* event);
public slots:
bool setStyleFile(const QString& style);
@@ -43,8 +49,16 @@ private slots:
private:
QFileSystemWatcher m_StyleWatcher;
QString m_DefaultStyle;
+ cl::CommandLine& m_cl;
+
+ int doOneRun(SingleInstance& singleInstance);
+
+ int runApplication(
+ SingleInstance& singleInstance,
+ const QString &dataPath, Instance& currentInstance);
- MOApplication(int& argc, char** argv);
+ void purgeOldFiles();
+ void resetForRestart();
};
--
cgit v1.3.1
From b4f6275c3ef888551e14e5d64739e1c32978b8e8 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 7 Nov 2020 18:14:24 -0500
Subject: split getCurrentInstance()
---
src/moapplication.cpp | 54 ++++++++++++++++++++++++++++-----------------------
src/moapplication.h | 5 +++++
2 files changed, 35 insertions(+), 24 deletions(-)
(limited to 'src/moapplication.h')
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index b4ba7da6..24cafd05 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -160,8 +160,13 @@ int MOApplication::run(SingleInstance& singleInstance)
// IOrganizer::getPluginDataPath()
MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath());
+ // MO runs in a loop because it can be restarted in several ways, such as
+ // when switching instances or changing some settings
for (;;)
{
+ // resets things when MO is "restarted"
+ resetForRestart();
+
const auto r = doOneRun(singleInstance);
if (r == RestartExitCode) {
continue;
@@ -175,18 +180,37 @@ int MOApplication::doOneRun(SingleInstance& singleInstance)
{
TimeThis tt("doOneRun() to runApplication()");
- // resets things when MO is "restarted"
- resetForRestart();
+ auto currentInstance = getCurrentInstance();
+ if (!currentInstance) {
+ return 1;
+ }
+
+ const QString dataPath = currentInstance->directory();
+ setProperty("dataPath", dataPath);
+
+ setExceptionHandlers();
+
+ if (!setLogDirectory(dataPath)) {
+ reportError("Failed to create log folder");
+ InstanceManager::singleton().clearCurrentInstance();
+ return 1;
+ }
+
+ log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
+
+ tt.stop();
+
+ return runApplication(singleInstance, dataPath, *currentInstance);
+}
+std::optional MOApplication::getCurrentInstance()
+{
auto& m = InstanceManager::singleton();
auto currentInstance = m.currentInstance();
if (!currentInstance)
{
currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
}
else
{
@@ -204,28 +228,10 @@ int MOApplication::doOneRun(SingleInstance& singleInstance)
}
currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
}
}
- const QString dataPath = currentInstance->directory();
- setProperty("dataPath", dataPath);
-
- setExceptionHandlers();
-
- if (!setLogDirectory(dataPath)) {
- reportError("Failed to create log folder");
- InstanceManager::singleton().clearCurrentInstance();
- return 1;
- }
-
- log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
-
- tt.stop();
-
- return runApplication(singleInstance, dataPath, *currentInstance);
+ return currentInstance;
}
int MOApplication::runApplication(
diff --git a/src/moapplication.h b/src/moapplication.h
index c1512d9b..8cbb5f28 100644
--- a/src/moapplication.h
+++ b/src/moapplication.h
@@ -37,7 +37,10 @@ class MOApplication : public QApplication
public:
MOApplication(cl::CommandLine& cl, int& argc, char** argv);
+ // sets up everything, creates the main window and runs it
+ //
int run(SingleInstance& si);
+
virtual bool notify(QObject* receiver, QEvent* event);
public slots:
@@ -53,6 +56,8 @@ private:
int doOneRun(SingleInstance& singleInstance);
+ std::optional getCurrentInstance();
+
int runApplication(
SingleInstance& singleInstance,
const QString &dataPath, Instance& currentInstance);
--
cgit v1.3.1
From dd5367f488de7cd312e53705ffc970a723951ca2 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 7 Nov 2020 19:30:54 -0500
Subject: fixed AppConfig::logFileName so it can be used refactored
MOApplication so everything is in doOneRun()
---
src/loglist.cpp | 5 +-
src/moapplication.cpp | 335 ++++++++++++++++++++++++-----------------------
src/moapplication.h | 7 +-
src/shared/appconfig.inc | 2 +-
4 files changed, 179 insertions(+), 170 deletions(-)
(limited to 'src/moapplication.h')
diff --git a/src/loglist.cpp b/src/loglist.cpp
index fad4678c..8df21111 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -345,7 +345,10 @@ bool createAndMakeWritable(const std::wstring &subPath) {
bool setLogDirectory(const QString& dir)
{
- const auto logFile = dir + "/logs/mo_interface.log";
+ const auto logFile =
+ dir + "/" +
+ QString::fromStdWString(AppConfig::logPath()) + "/" +
+ QString::fromStdWString(AppConfig::logFileName());
if (!createAndMakeWritable(AppConfig::logPath())) {
return false;
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index bb7b4922..885abc37 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -164,27 +164,36 @@ int MOApplication::run(SingleInstance& singleInstance)
// when switching instances or changing some settings
for (;;)
{
- // resets things when MO is "restarted"
- resetForRestart();
+ try
+ {
+ // resets things when MO is "restarted"
+ resetForRestart();
- const auto r = doOneRun(singleInstance);
- if (r == RestartExitCode) {
- continue;
- }
+ const auto r = doOneRun(singleInstance);
+ if (r == RestartExitCode) {
+ continue;
+ }
- return r;
+ return r;
+ }
+ catch (const std::exception &e)
+ {
+ reportError(e.what());
+ return 1;
+ }
}
}
int MOApplication::doOneRun(SingleInstance& singleInstance)
{
- TimeThis tt("doOneRun() to runApplication()");
-
+ // figuring out the current instance
auto currentInstance = getCurrentInstance();
if (!currentInstance) {
return 1;
}
+ // first time the data path is available, set the global property and log
+ // directory, then log a bunch of debug stuff
const QString dataPath = currentInstance->directory();
setProperty("dataPath", dataPath);
@@ -196,57 +205,20 @@ int MOApplication::doOneRun(SingleInstance& singleInstance)
log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
- tt.stop();
-
- return runApplication(singleInstance, dataPath, *currentInstance);
-}
-
-std::optional MOApplication::getCurrentInstance()
-{
- auto& m = InstanceManager::singleton();
- auto currentInstance = m.currentInstance();
-
- if (!currentInstance)
- {
- currentInstance = selectInstance();
- }
- else
- {
- if (!QDir(currentInstance->directory()).exists()) {
- // the previously used instance doesn't exist anymore
-
- if (m.hasAnyInstances()) {
- MOShared::criticalOnTop(QObject::tr(
- "Instance at '%1' not found. Select another instance.")
- .arg(currentInstance->directory()));
- } else {
- MOShared::criticalOnTop(QObject::tr(
- "Instance at '%1' not found. You must create a new instance")
- .arg(currentInstance->directory()));
- }
-
- currentInstance = selectInstance();
- }
- }
-
- return currentInstance;
-}
-
-int MOApplication::runApplication(
- SingleInstance& singleInstance,
- const QString &dataPath, Instance& currentInstance)
-{
- TimeThis tt("runApplication() to exec()");
-
log::info(
"starting Mod Organizer version {} revision {} in {}, usvfs: {}",
createVersionInfo().displayString(3), GITID,
QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString());
- log::info("data path: {}", dataPath);
+ if (singleInstance.secondary()) {
+ log::debug("another instance of MO is running but --multiple was given");
+ }
+ log::info("data path: {}", currentInstance->directory());
log::info("working directory: {}", QDir::currentPath());
+
+ // deleting old files, only for the main instance
if (!singleInstance.secondary()) {
purgeOldFiles();
}
@@ -254,155 +226,192 @@ int MOApplication::runApplication(
QWindowsWindowFunctions::setWindowActivationBehavior(
QWindowsWindowFunctions::AlwaysActivateWindow);
- try
- {
- Settings settings(
- dataPath + "/" + QString::fromStdWString(AppConfig::iniFileName()),
- true);
- log::getDefault().setLevel(settings.diagnostics().logLevel());
+ // loading settings
+ Settings settings(currentInstance->iniPath(), true);
+ log::getDefault().setLevel(settings.diagnostics().logLevel());
+ log::debug("using ini at '{}'", settings.filename());
- log::debug("using ini at '{}'", settings.filename());
+ OrganizerCore::setGlobalCoreDumpType(settings.diagnostics().coreDumpType());
- if (singleInstance.secondary()) {
- log::debug("another instance of MO is running but --multiple was given");
- }
- // global crashDumpType sits in OrganizerCore to make a bit less ugly to
- // update it when the settings are changed during runtime
- OrganizerCore::setGlobalCoreDumpType(settings.diagnostics().coreDumpType());
+ // logging and checking
+ env::Environment env;
+ env.dump(settings);
+ settings.dump();
+ sanity::checkEnvironment(env);
- env::Environment env;
- env.dump(settings);
- settings.dump();
- sanity::checkEnvironment(env);
+ const auto moduleNotification = env.onModuleLoaded(qApp, [](auto&& m) {
+ log::debug("loaded module {}", m.toString());
+ sanity::checkIncompatibleModule(m);
+ });
- const auto moduleNotification = env.onModuleLoaded(qApp, [](auto&& m) {
- log::debug("loaded module {}", m.toString());
- sanity::checkIncompatibleModule(m);
- });
- // this must outlive `organizer`
- std::unique_ptr pluginContainer;
+ // this must outlive `organizer`
+ std::unique_ptr pluginContainer;
- log::debug("initializing nexus interface");
- NexusInterface ni(&settings);
+ // nexus interface
+ log::debug("initializing nexus interface");
+ NexusInterface ni(&settings);
- log::debug("initializing core");
- OrganizerCore organizer(settings);
- if (!organizer.bootstrap()) {
- reportError("failed to set up data paths");
- InstanceManager::singleton().clearCurrentInstance();
- return 1;
- }
+ // organizer core
+ log::debug("initializing core");
+ OrganizerCore organizer(settings);
+ if (!organizer.bootstrap()) {
+ reportError("failed to set up data paths");
+ InstanceManager::singleton().clearCurrentInstance();
+ return 1;
+ }
- log::debug("initializing plugins");
- pluginContainer = std::make_unique(&organizer);
- pluginContainer->loadPlugins();
+ // plugins
+ log::debug("initializing plugins");
+ pluginContainer = std::make_unique(&organizer);
+ pluginContainer->loadPlugins();
- for (;;)
- {
- const auto setupResult = setupInstance(currentInstance, *pluginContainer);
+ // instance
+ if (auto r=setupInstanceLoop(*currentInstance, *pluginContainer)) {
+ return *r;
+ }
- if (setupResult == SetupInstanceResults::Okay) {
- break;
- } else if (setupResult == SetupInstanceResults::TryAgain) {
- continue;
- } else if (setupResult == SetupInstanceResults::SelectAnother) {
- InstanceManager::singleton().clearCurrentInstance();
- return RestartExitCode;
- } else {
- return 1;
- }
- }
+ if (currentInstance->isPortable()) {
+ log::debug("this is a portable instance");
+ }
- if (currentInstance.isPortable()) {
- log::debug("this is a portable instance");
- }
+ sanity::checkPaths(*currentInstance->gamePlugin(), settings);
- sanity::checkPaths(*currentInstance.gamePlugin(), settings);
+ // setting up organizer core
+ organizer.setManagedGame(currentInstance->gamePlugin());
+ organizer.createDefaultProfile();
- organizer.setManagedGame(currentInstance.gamePlugin());
- organizer.createDefaultProfile();
+ log::info(
+ "using game plugin '{}' ('{}', variant {}, steam id '{}') at {}",
+ currentInstance->gamePlugin()->gameName(),
+ currentInstance->gamePlugin()->gameShortName(),
+ (settings.game().edition().value_or("").isEmpty() ?
+ "(none)" : *settings.game().edition()),
+ currentInstance->gamePlugin()->steamAPPId(),
+ currentInstance->gamePlugin()->gameDirectory().absolutePath());
+
+ CategoryFactory::instance().loadCategories();
+ organizer.updateExecutablesList();
+ organizer.updateModInfoFromDisc();
+ organizer.setCurrentProfile(currentInstance->profileName());
+
+ // checking command line
+ if (auto r=m_cl.setupCore(organizer)) {
+ return *r;
+ }
- log::info(
- "using game plugin '{}' ('{}', variant {}, steam id '{}') at {}",
- currentInstance.gamePlugin()->gameName(),
- currentInstance.gamePlugin()->gameShortName(),
- (settings.game().edition().value_or("").isEmpty() ?
- "(none)" : *settings.game().edition()),
- currentInstance.gamePlugin()->steamAPPId(),
- currentInstance.gamePlugin()->gameDirectory().absolutePath());
+ // show splash
+ MOSplash splash(
+ settings, currentInstance->directory(), currentInstance->gamePlugin());
+ // start an api check
+ QString apiKey;
+ if (GlobalSettings::nexusApiKey(apiKey)) {
+ ni.getAccessManager()->apiCheck(apiKey);
+ }
- CategoryFactory::instance().loadCategories();
- organizer.updateExecutablesList();
- organizer.updateModInfoFromDisc();
+ // tutorials
+ log::debug("initializing tutorials");
+ TutorialManager::init(
+ qApp->applicationDirPath() + "/"
+ + QString::fromStdWString(AppConfig::tutorialsPath()) + "/",
+ &organizer);
+
+ // styling
+ if (!setStyleFile(settings.interface().styleName().value_or(""))) {
+ // disable invalid stylesheet
+ settings.interface().setStyleName("");
+ }
- organizer.setCurrentProfile(currentInstance.profileName());
- if (auto r=m_cl.setupCore(organizer)) {
- return *r;
- }
+ int res = 1;
+
+ {
+ MainWindow mainWindow(settings, organizer, *pluginContainer);
- MOSplash splash(settings, dataPath, currentInstance.gamePlugin());
+ // qt resets the thread name somewhere when creating the main window
+ MOShared::SetThisThreadName("main");
- QString apiKey;
- if (GlobalSettings::nexusApiKey(apiKey)) {
- ni.getAccessManager()->apiCheck(apiKey);
- }
+ // the nexus interface can show dialogs, make sure they're parented to the
+ // main window
+ ni.getAccessManager()->setTopLevelWidget(&mainWindow);
- log::debug("initializing tutorials");
- TutorialManager::init(
- qApp->applicationDirPath() + "/"
- + QString::fromStdWString(AppConfig::tutorialsPath()) + "/",
- &organizer);
+ QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), this,
+ SLOT(setStyleFile(QString)));
- if (!setStyleFile(settings.interface().styleName().value_or(""))) {
- // disable invalid stylesheet
- settings.interface().setStyleName("");
- }
+ QObject::connect(&singleInstance, SIGNAL(messageSent(QString)), &organizer,
+ SLOT(externalMessage(QString)));
- int res = 1;
- {
- // scope to control lifetime of mainwindow
- // set up main window and its data structures
- MainWindow mainWindow(settings, organizer, *pluginContainer);
+ log::debug("displaying main window");
+ mainWindow.show();
+ mainWindow.activateWindow();
+ splash.close();
- // qt resets the thread name somewhere when creating the main window
- MOShared::SetThisThreadName("main");
+ res = exec();
+ mainWindow.close();
- ni.getAccessManager()->setTopLevelWidget(&mainWindow);
+ // main window is about to be destroyed
+ ni.getAccessManager()->setTopLevelWidget(nullptr);
+ }
- QObject::connect(&mainWindow, SIGNAL(styleChanged(QString)), this,
- SLOT(setStyleFile(QString)));
- QObject::connect(&singleInstance, SIGNAL(messageSent(QString)), &organizer,
- SLOT(externalMessage(QString)));
+ // reset geometry if the flag was set from the settings dialog
+ settings.geometry().resetIfNeeded();
- log::debug("displaying main window");
- mainWindow.show();
- mainWindow.activateWindow();
+ return res;
+}
- splash.close();
+std::optional MOApplication::getCurrentInstance()
+{
+ auto& m = InstanceManager::singleton();
+ auto currentInstance = m.currentInstance();
- tt.stop();
+ if (!currentInstance)
+ {
+ currentInstance = selectInstance();
+ }
+ else
+ {
+ if (!QDir(currentInstance->directory()).exists()) {
+ // the previously used instance doesn't exist anymore
- res = exec();
- mainWindow.close();
+ if (m.hasAnyInstances()) {
+ MOShared::criticalOnTop(QObject::tr(
+ "Instance at '%1' not found. Select another instance.")
+ .arg(currentInstance->directory()));
+ } else {
+ MOShared::criticalOnTop(QObject::tr(
+ "Instance at '%1' not found. You must create a new instance")
+ .arg(currentInstance->directory()));
+ }
- ni.getAccessManager()->setTopLevelWidget(nullptr);
+ currentInstance = selectInstance();
}
-
- settings.geometry().resetIfNeeded();
- return res;
}
- catch (const std::exception &e)
+
+ return currentInstance;
+}
+
+std::optional MOApplication::setupInstanceLoop(
+ Instance& currentInstance, PluginContainer& pc)
+{
+ for (;;)
{
- reportError(e.what());
- }
+ const auto setupResult = setupInstance(currentInstance, pc);
- return 1;
+ if (setupResult == SetupInstanceResults::Okay) {
+ return {};
+ } else if (setupResult == SetupInstanceResults::TryAgain) {
+ continue;
+ } else if (setupResult == SetupInstanceResults::SelectAnother) {
+ InstanceManager::singleton().clearCurrentInstance();
+ return RestartExitCode;
+ } else {
+ return 1;
+ }
+ }
}
void MOApplication::purgeOldFiles()
diff --git a/src/moapplication.h b/src/moapplication.h
index 8cbb5f28..7423c897 100644
--- a/src/moapplication.h
+++ b/src/moapplication.h
@@ -26,6 +26,7 @@ along with Mod Organizer. If not, see .
class Settings;
class SingleInstance;
class Instance;
+class PluginContainer;
namespace MOBase { class IPluginGame; }
namespace cl { class CommandLine; }
@@ -57,11 +58,7 @@ private:
int doOneRun(SingleInstance& singleInstance);
std::optional getCurrentInstance();
-
- int runApplication(
- SingleInstance& singleInstance,
- const QString &dataPath, Instance& currentInstance);
-
+ std::optional setupInstanceLoop(Instance& currentInstance, PluginContainer& pc);
void purgeOldFiles();
void resetForRestart();
};
diff --git a/src/shared/appconfig.inc b/src/shared/appconfig.inc
index 807f1d69..5839c2f4 100644
--- a/src/shared/appconfig.inc
+++ b/src/shared/appconfig.inc
@@ -11,7 +11,7 @@ APPPARAM(std::wstring, logPath, L"logs")
APPPARAM(std::wstring, dumpsDir, L"crashDumps")
APPPARAM(std::wstring, defaultProfileName, L"Default")
APPPARAM(std::wstring, profileTweakIni, L"profile_tweaks.ini")
-APPPARAM(std::wstring, logFileName, L"ModOrganizer.log")
+APPPARAM(std::wstring, logFileName, L"mo_interface.log")
APPPARAM(std::wstring, iniFileName, L"ModOrganizer.ini")
APPPARAM(std::wstring, proxyDLLTarget, L"steam_api.dll")
APPPARAM(std::wstring, proxyDLLOrig, L"steam_api_orig.dll") // needs to be identical to the value used in proxydll-project
--
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/moapplication.h')
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