From 9815f930d9b9bf4e997c9ad4ae4c2cb5931e24ab Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 21 Mar 2023 21:27:25 +0100 Subject: [PATCH] Setup launcher configuration manager and logging before initializing UI --- apps/launcher/datafilespage.cpp | 2 +- apps/launcher/datafilespage.hpp | 4 ++-- apps/launcher/importpage.cpp | 3 ++- apps/launcher/importpage.hpp | 4 ++-- apps/launcher/main.cpp | 18 +++++++++++++++--- apps/launcher/maindialog.cpp | 12 +++--------- apps/launcher/maindialog.hpp | 11 +++++++---- components/config/gamesettings.cpp | 2 +- components/config/gamesettings.hpp | 4 ++-- 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index f617b07f00..5ff49fb1df 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -122,7 +122,7 @@ namespace Launcher } } -Launcher::DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, +Launcher::DataFilesPage::DataFilesPage(const Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, Config::LauncherSettings& launcherSettings, MainDialog* parent) : QWidget(parent) , mMainDialog(parent) diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index fead7d5d93..033c91f9c7 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -41,7 +41,7 @@ namespace Launcher Ui::DataFilesPage ui; public: - explicit DataFilesPage(Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, + explicit DataFilesPage(const Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, Config::LauncherSettings& launcherSettings, MainDialog* parent = nullptr); QAbstractItemModel* profilesModel() const; @@ -104,7 +104,7 @@ namespace Launcher TextInputDialog* mNewProfileDialog; TextInputDialog* mCloneProfileDialog; - Files::ConfigurationManager& mCfgMgr; + const Files::ConfigurationManager& mCfgMgr; Config::GameSettings& mGameSettings; Config::LauncherSettings& mLauncherSettings; diff --git a/apps/launcher/importpage.cpp b/apps/launcher/importpage.cpp index f7230043f3..af79938756 100644 --- a/apps/launcher/importpage.cpp +++ b/apps/launcher/importpage.cpp @@ -5,13 +5,14 @@ #include #include +#include #include #include "utils/textinputdialog.hpp" using namespace Process; -Launcher::ImportPage::ImportPage(Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, +Launcher::ImportPage::ImportPage(const Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, Config::LauncherSettings& launcherSettings, MainDialog* parent) : QWidget(parent) , mCfgMgr(cfg) diff --git a/apps/launcher/importpage.hpp b/apps/launcher/importpage.hpp index c7742c01df..f3e16e42be 100644 --- a/apps/launcher/importpage.hpp +++ b/apps/launcher/importpage.hpp @@ -26,7 +26,7 @@ namespace Launcher Q_OBJECT public: - ImportPage(Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, + explicit ImportPage(const Files::ConfigurationManager& cfg, Config::GameSettings& gameSettings, Config::LauncherSettings& launcherSettings, MainDialog* parent = nullptr); ~ImportPage() override; @@ -52,7 +52,7 @@ namespace Launcher Process::ProcessInvoker* mWizardInvoker; Process::ProcessInvoker* mImporterInvoker; - Files::ConfigurationManager& mCfgMgr; + const Files::ConfigurationManager& mCfgMgr; Config::GameSettings& mGameSettings; Config::LauncherSettings& mLauncherSettings; diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 4aca9fc69e..4aac90fb6e 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -3,7 +3,11 @@ #include #include +#include +#include + #include +#include #include #ifdef MAC_OS_X_VERSION_MIN_REQUIRED @@ -18,6 +22,14 @@ int runLauncher(int argc, char* argv[]) { Platform::init(); + boost::program_options::variables_map variables; + boost::program_options::options_description description; + Files::ConfigurationManager configurationManager; + configurationManager.addCommonOptions(description); + configurationManager.readConfiguration(variables, description, true); + + setupLogging(configurationManager.getLogPath(), "Launcher"); + try { QApplication app(argc, argv); @@ -34,7 +46,7 @@ int runLauncher(int argc, char* argv[]) QDir::setCurrent(dir.absolutePath()); - Launcher::MainDialog mainWin; + Launcher::MainDialog mainWin(configurationManager); Launcher::FirstRunDialogResult result = mainWin.showFirstRunDialog(); if (result == Launcher::FirstRunDialogResultFailure) @@ -47,9 +59,9 @@ int runLauncher(int argc, char* argv[]) return exitCode; } - catch (std::exception& e) + catch (const std::exception& e) { - std::cerr << "ERROR: " << e.what() << std::endl; + Log(Debug::Error) << "Unexpected exception: " << e.what(); return 0; } } diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 152845e85c..0caf7a576a 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -1,6 +1,7 @@ #include "maindialog.hpp" #include +#include #include #include #include @@ -13,9 +14,6 @@ #include #include -#include -#include - #include #include #include @@ -39,8 +37,9 @@ void cfgError(const QString& title, const QString& msg) msgBox.exec(); } -Launcher::MainDialog::MainDialog(QWidget* parent) +Launcher::MainDialog::MainDialog(const Files::ConfigurationManager& configurationManager, QWidget* parent) : QMainWindow(parent) + , mCfgMgr(configurationManager) , mGameSettings(mCfgMgr) { setupUi(this); @@ -418,12 +417,7 @@ bool Launcher::MainDialog::setupGraphicsSettings() Settings::Manager::clear(); // Ensure to clear previous settings in case we had already loaded settings. try { - boost::program_options::variables_map variables; - boost::program_options::options_description desc; - mCfgMgr.addCommonOptions(desc); - mCfgMgr.readConfiguration(variables, desc, true); Settings::Manager::load(mCfgMgr); - setupLogging(mCfgMgr.getLogPath(), "Launcher"); return true; } catch (std::exception& e) diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 55e11fb517..cc68d52c77 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -2,8 +2,6 @@ #define MAINDIALOG_H #ifndef Q_MOC_RUN -#include - #include #include @@ -17,6 +15,11 @@ class QStackedWidget; class QStringListModel; class QString; +namespace Files +{ + struct ConfigurationManager; +} + namespace Launcher { class GraphicsPage; @@ -41,7 +44,7 @@ namespace Launcher Q_OBJECT public: - explicit MainDialog(QWidget* parent = nullptr); + explicit MainDialog(const Files::ConfigurationManager& configurationManager, QWidget* parent = nullptr); ~MainDialog() override; FirstRunDialogResult showFirstRunDialog(); @@ -93,7 +96,7 @@ namespace Launcher Process::ProcessInvoker* mGameInvoker; Process::ProcessInvoker* mWizardInvoker; - Files::ConfigurationManager mCfgMgr; + const Files::ConfigurationManager& mCfgMgr; Config::GameSettings mGameSettings; Config::LauncherSettings mLauncherSettings; diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index 00329aaa0c..709fb57131 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -21,7 +21,7 @@ namespace } } -Config::GameSettings::GameSettings(Files::ConfigurationManager& cfg) +Config::GameSettings::GameSettings(const Files::ConfigurationManager& cfg) : mCfgMgr(cfg) { } diff --git a/components/config/gamesettings.hpp b/components/config/gamesettings.hpp index 8df0d6aaca..34e3dc73ea 100644 --- a/components/config/gamesettings.hpp +++ b/components/config/gamesettings.hpp @@ -20,7 +20,7 @@ namespace Config class GameSettings { public: - GameSettings(Files::ConfigurationManager& cfg); + explicit GameSettings(const Files::ConfigurationManager& cfg); inline QString value(const QString& key, const QString& defaultValue = QString()) { @@ -85,7 +85,7 @@ namespace Config void clear(); private: - Files::ConfigurationManager& mCfgMgr; + const Files::ConfigurationManager& mCfgMgr; void validatePaths(); QMultiMap mSettings;