Cmd.line arg --skipsa to skip "single application check". Allows to run multiple clients on one machine.

This commit is contained in:
Klaus Basan
2019-03-05 22:02:17 +01:00
committed by Mat Sutcliffe
parent 4e20c20274
commit f080f0bb86
2 changed files with 36 additions and 22 deletions

View File

@@ -983,6 +983,11 @@ namespace BlackCore
"shared");
this->addParserOption(m_cmdSharedDir);
// Skip single application check
m_cmdSkipSingleApp = QCommandLineOption({ "skipsa", "skipsingleapp" },
QCoreApplication::translate("application", "Skip the single app.test."));
this->addParserOption(m_cmdSkipSingleApp);
// reset caches upfront
m_cmdClearCache = QCommandLineOption({ "ccache", "clearcache" },
QCoreApplication::translate("application", "Clear (reset) the caches."));
@@ -990,7 +995,7 @@ namespace BlackCore
// test crashpad upload
m_cmdTestCrashpad = QCommandLineOption({ "testcp", "testcrashpad" },
QCoreApplication::translate("application", "Simulate crashpad situation."));
QCoreApplication::translate("application", "Trigger crashpad situation."));
this->addParserOption(m_cmdTestCrashpad);
}
@@ -1321,6 +1326,11 @@ namespace BlackCore
return this->isParserOptionSet("installer");
}
bool CApplication::skipSingleApplicationCheck() const
{
return this->isParserOptionSet(m_cmdSkipSingleApp);
}
bool CApplication::isParserOptionSet(const QCommandLineOption &option) const
{
return m_parser.isSet(option);
@@ -1354,12 +1364,6 @@ namespace BlackCore
return false;
}
if (m_singleApplication && m_alreadyRunning)
{
this->cmdLineErrorMessage("Program must only run once");
return false;
}
// we call parse because we also want to display a GUI error message when applicable
const QStringList args(QCoreApplication::instance()->arguments());
if (!m_parser.parse(args))
@@ -1368,6 +1372,12 @@ namespace BlackCore
return false;
}
if (m_singleApplication && m_alreadyRunning && !this->skipSingleApplicationCheck())
{
this->cmdLineErrorMessage("Program must only run once");
return false;
}
// help/version
if (m_parser.isSet(m_cmdHelp))
{

View File

@@ -270,6 +270,9 @@ namespace BlackCore
//! Called by installer?
bool isInstallerOptionSet() const;
//! Skip the single application check
bool skipSingleApplicationCheck() const;
//! Delegates to QCommandLineParser::isSet
bool isParserOptionSet(const QCommandLineOption &option) const;
@@ -625,21 +628,22 @@ namespace BlackCore
static void registerMetadata();
// cmd parsing
QList<QCommandLineOption> m_allOptions; //!< all registered options
QCommandLineParser m_parser; //!< cmd parser
QCommandLineOption m_cmdHelp {"help"}; //!< help option
QCommandLineOption m_cmdVersion {"version"}; //!< version option
QCommandLineOption m_cmdDBusAddress {"emptyDBus"}; //!< DBus address
QCommandLineOption m_cmdDevelopment {"dev"}; //!< Development flag
QCommandLineOption m_cmdSharedDir {"shared"}; //!< Shared directory
QCommandLineOption m_cmdClearCache {"clearcache"}; //!< Clear cache
QCommandLineOption m_cmdTestCrashpad {"testcrashpad"}; //!< Test a crasphpad upload
bool m_parsed = false; //!< Parsing accomplished?
bool m_started = false; //!< started with success?
bool m_singleApplication = true; //!< only one instance of that application
bool m_alreadyRunning = false; //!< Application already running
std::atomic_bool m_shutdown { false }; //!< is being shutdown?
std::atomic_bool m_shutdownInProgress { false }; //!< shutdown in progress?
QList<QCommandLineOption> m_allOptions; //!< All registered options
QCommandLineParser m_parser; //!< cmd parser
QCommandLineOption m_cmdHelp {"help"}; //!< help option
QCommandLineOption m_cmdVersion {"version"}; //!< version option
QCommandLineOption m_cmdDBusAddress {"emptyDBus"}; //!< DBus address
QCommandLineOption m_cmdDevelopment {"dev"}; //!< Development flag
QCommandLineOption m_cmdSharedDir {"shared"}; //!< Shared directory
QCommandLineOption m_cmdClearCache {"clearcache"}; //!< Clear cache
QCommandLineOption m_cmdTestCrashpad {"testcrashpad"}; //!< Test a crasphpad upload
QCommandLineOption m_cmdSkipSingleApp {"skipsa"}; //!< Skip test for single application
bool m_parsed = false; //!< Parsing accomplished?
bool m_started = false; //!< Started with success?
bool m_singleApplication = true; //!< Only one instance of that application
bool m_alreadyRunning = false; //!< Application already running
std::atomic_bool m_shutdown { false }; //!< Is being shutdown?
std::atomic_bool m_shutdownInProgress { false }; //!< shutdown in progress?
private:
//! Problem with network access manager