mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refactor: Restructure parsing and setup loading methods
This commit is contained in:
@@ -349,12 +349,7 @@ namespace BlackCore
|
||||
{
|
||||
m_started = false; // reset
|
||||
|
||||
// parse if needed, parsing contains its own error handling
|
||||
if (!m_parsed)
|
||||
{
|
||||
const bool s = this->parseAndStartupCheck();
|
||||
if (!s) { return false; }
|
||||
}
|
||||
Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Call this function after parsing");
|
||||
|
||||
// parsing itself is done
|
||||
CStatusMessageList msgs;
|
||||
@@ -1339,18 +1334,18 @@ namespace BlackCore
|
||||
return m_parser.value(option).trimmed();
|
||||
}
|
||||
|
||||
bool CApplication::parseAndStartupCheck()
|
||||
bool CApplication::parseCommandLineArgsAndLoadSetup()
|
||||
{
|
||||
if (!this->startupCheck()) return false;
|
||||
if (!this->parseCommandLineArguments()) return false;
|
||||
if (!this->loadSetupAndHandleErrors()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CApplication::parseCommandLineArguments()
|
||||
{
|
||||
if (m_parsed) { return m_parsed; } // already done
|
||||
|
||||
// checks
|
||||
const QStringList verifyErrors = CSwiftDirectories::verifyRuntimeDirectoriesAndFiles();
|
||||
if (!verifyErrors.isEmpty() && !m_applicationInfo.isUnitTest())
|
||||
{
|
||||
this->cmdLineErrorMessage("Missing runtime directories/files:", verifyErrors.join(", "));
|
||||
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))
|
||||
@@ -1390,9 +1385,19 @@ namespace BlackCore
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CApplication::parseAndLoadSetup()
|
||||
bool CApplication::startupCheck() const
|
||||
{
|
||||
const QStringList verifyErrors = CSwiftDirectories::verifyRuntimeDirectoriesAndFiles();
|
||||
if (!verifyErrors.isEmpty() && !m_applicationInfo.isUnitTest())
|
||||
{
|
||||
cmdLineErrorMessage("Missing runtime directories/files:", verifyErrors.join(", "));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CApplication::loadSetupAndHandleErrors()
|
||||
{
|
||||
if (!this->parseAndStartupCheck()) return false;
|
||||
const CStatusMessageList msgs = loadSetup();
|
||||
|
||||
if (msgs.isFailure())
|
||||
|
||||
@@ -287,16 +287,13 @@ namespace BlackCore
|
||||
//! Delegates to QCommandLineParser::value
|
||||
QString getParserValue(const QCommandLineOption &option) const;
|
||||
|
||||
//! Parses and handles the standard options such as help, version, parse error
|
||||
//! \note in some cases (error, version, help) application is terminated during this step
|
||||
//! \sa parsingHookIn
|
||||
//! \return true means to continue, false to stop
|
||||
bool parseAndStartupCheck();
|
||||
|
||||
//! Combined function
|
||||
//! \see parseAndStartupCheck
|
||||
//! \see loadSetup
|
||||
bool parseAndLoadSetup();
|
||||
//! Combined function that does a startup check, parses the command line arguments and loads the setup
|
||||
//! \see startupCheck
|
||||
//! \see parseCommandLineArguments
|
||||
//! \see loadSetupAndHandleErrors
|
||||
//! \remark This function cannot automatically called from the constructor because (1) it calls virtual
|
||||
//! functions to show error messages and (2) the some command line arguments are added after constructing the object
|
||||
bool parseCommandLineArgsAndLoadSetup();
|
||||
|
||||
//! Display warning message
|
||||
virtual bool cmdLineWarningMessage(const QString &text, const QString &informativeText = "") const;
|
||||
@@ -712,6 +709,20 @@ namespace BlackCore
|
||||
//! Write meta information into the application directory so other swift versions can display them
|
||||
void tagApplicationDataDirectory();
|
||||
|
||||
//! Check if all required runtime files are in place
|
||||
//! \returns true if the check succeeded
|
||||
bool startupCheck() const;
|
||||
|
||||
//! Loads the setup (bootstrap) and handles/displays warnings and error messages
|
||||
//! \returns true if loading succedded without errors
|
||||
bool loadSetupAndHandleErrors();
|
||||
|
||||
//! Parses and handles the standard options such as help, version, parse error
|
||||
//! \note in some cases (error, version, help) application is terminated during this step
|
||||
//! \sa parsingHookIn
|
||||
//! \return true means to continue, false to stop
|
||||
bool parseCommandLineArguments();
|
||||
|
||||
CInputManager *m_inputManager = nullptr; //!< Input devices and hotkeys
|
||||
QNetworkConfigurationManager *m_networkConfigManager = nullptr; //!< configuration
|
||||
QNetworkAccessManager *m_accessManager = nullptr; //!< single network access manager
|
||||
|
||||
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
|
||||
a.addDBusAddressOption();
|
||||
a.addVatlibOptions();
|
||||
a.addAudioOptions();
|
||||
if (!a.parseAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
|
||||
const QString dBusAdress(a.getCmdDBusAddressValue());
|
||||
a.useContexts(CCoreFacadeConfig::forCoreAllLocalInDBus(dBusAdress));
|
||||
|
||||
@@ -25,8 +25,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
CCrashHandler::instance()->init();
|
||||
CGuiApplication a(CApplicationInfo::swiftMappingTool(), CApplicationInfo::MappingTool, CIcons::swiftDatabase48());
|
||||
if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
a.splashScreen(CIcons::swiftDatabase256());
|
||||
if (!a.parseAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, CDatabaseReaderConfigList::forMappingTool());
|
||||
a.useFacadeNoContexts();
|
||||
if (!a.start())
|
||||
|
||||
@@ -37,10 +37,10 @@ int main(int argc, char *argv[])
|
||||
int r = 0;
|
||||
{
|
||||
CSwiftGuiStdApplication a; // application with contexts
|
||||
if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
a.splashScreen(CIcons::swift256());
|
||||
a.setMinimumSizeInCharacters(60, 42); // experimental
|
||||
if (!a.parseAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
if (!a.hasSetupReader() || !a.start())
|
||||
if (!a.start())
|
||||
{
|
||||
a.gracefulShutdown();
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
|
||||
CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Laucher, CIcons::swiftLauncher1024());
|
||||
a.addVatlibOptions(); // so it can be passed (hand over) to started applications
|
||||
a.addParserOption({ { "i", "installer" }, QCoreApplication::translate("main", "Installer setup.") });
|
||||
if (!a.parseAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, CDatabaseReaderConfigList::forLauncher());
|
||||
a.useFacadeNoContexts();
|
||||
if (!a.start())
|
||||
|
||||
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
|
||||
BLACKTEST_INIT(BlackCoreTest::CTestContext)
|
||||
CApplication a(CApplicationInfo::UnitTest);
|
||||
a.addVatlibOptions();
|
||||
const bool setup = a.parseAndLoadSetup();
|
||||
const bool setup = a.parseCommandLineArgsAndLoadSetup();
|
||||
if (!setup) { qWarning() << "No setup loaded"; }
|
||||
int r = EXIT_FAILURE;
|
||||
if (a.start())
|
||||
|
||||
@@ -124,7 +124,7 @@ int main(int argc, char *argv[])
|
||||
BLACKTEST_INIT(BlackCoreTest::CTestConnectivity)
|
||||
CApplication a(CApplicationInfo::UnitTest);
|
||||
a.addVatlibOptions();
|
||||
const bool setup = a.parseAndLoadSetup();
|
||||
const bool setup = a.parseCommandLineArgsAndLoadSetup();
|
||||
if (!setup) { qWarning() << "No setup loaded"; }
|
||||
int r = EXIT_FAILURE;
|
||||
if (a.start())
|
||||
|
||||
Reference in New Issue
Block a user