From ec13bba4da9f996e4b5b43c587d938b78d1b8dd7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 6 Jul 2022 16:34:13 +0800 Subject: [PATCH] Revise classes startup sequence 1. Initialize Logger class earlier so that it can record messages from other classes (for debugging purpose). 2. Deprioritize WebUI port adjustment. It is not a high priority in here. 3. Slightly deprioritize file logger initialization. --- src/app/application.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 45e6dc43a..5c7f3cb53 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -147,6 +147,8 @@ Application::Application(int &argc, char **argv) QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE); #endif + Logger::initInstance(); + const auto portableProfilePath = Path(QCoreApplication::applicationDirPath()) / DEFAULT_PORTABLE_MODE_PROFILE_DIR; const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty() && portableProfilePath.exists(); @@ -158,35 +160,34 @@ Application::Application(int &argc, char **argv) m_instanceManager = new ApplicationInstanceManager(Profile::instance()->location(SpecialFolder::Config), this); - Logger::initInstance(); SettingsStorage::initInstance(); Preferences::initInstance(); initializeTranslation(); - if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value - Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort); - connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); connect(m_instanceManager, &ApplicationInstanceManager::messageReceived, this, &Application::processMessage); #if defined(Q_OS_WIN) && !defined(DISABLE_GUI) connect(this, &QGuiApplication::commitDataRequest, this, &Application::shutdownCleanup, Qt::DirectConnection); #endif - if (isFileLoggerEnabled()) - m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast(fileLoggerAgeType())); - - Logger::instance()->addMessage(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(QStringLiteral(QBT_VERSION))); + LogMsg(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(QStringLiteral(QBT_VERSION))); if (portableModeEnabled) { - Logger::instance()->addMessage(tr("Running in portable mode. Auto detected profile folder at: %1").arg(profileDir.toString())); + LogMsg(tr("Running in portable mode. Auto detected profile folder at: %1").arg(profileDir.toString())); if (m_commandLineArgs.relativeFastresumePaths) - Logger::instance()->addMessage(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg(u"--relative-fastresume"_qs), Log::WARNING); // to avoid translating the `--relative-fastresume` string + LogMsg(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg(u"--relative-fastresume"_qs), Log::WARNING); // to avoid translating the `--relative-fastresume` string } else { - Logger::instance()->addMessage(tr("Using config directory: %1").arg(Profile::instance()->location(SpecialFolder::Config).toString())); + LogMsg(tr("Using config directory: %1").arg(Profile::instance()->location(SpecialFolder::Config).toString())); } + + if (isFileLoggerEnabled()) + m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast(fileLoggerAgeType())); + + if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value + Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort); } Application::~Application()