mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Config: Implement reading config overrides from subdirectory (#29068)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -73,6 +73,10 @@ namespace fs = boost::filesystem;
|
||||
#define _TRINITY_CORE_CONFIG "worldserver.conf"
|
||||
#endif
|
||||
|
||||
#ifndef _TRINITY_CORE_CONFIG_DIR
|
||||
#define _TRINITY_CORE_CONFIG_DIR "worldserver.conf.d"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "ServiceWin32.h"
|
||||
char serviceName[] = "worldserver";
|
||||
@@ -119,7 +123,7 @@ void WorldUpdateLoop();
|
||||
void ClearOnlineAccounts();
|
||||
void ShutdownCLIThread(std::thread* cliThread);
|
||||
bool LoadRealmInfo();
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& cfg_service);
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, fs::path& configDir, std::string& winServiceAction);
|
||||
|
||||
/// Launch the Trinity server
|
||||
extern int main(int argc, char** argv)
|
||||
@@ -127,9 +131,10 @@ extern int main(int argc, char** argv)
|
||||
signal(SIGABRT, &Trinity::AbortHandler);
|
||||
|
||||
auto configFile = fs::absolute(_TRINITY_CORE_CONFIG);
|
||||
std::string configService;
|
||||
auto configDir = fs::absolute(_TRINITY_CORE_CONFIG_DIR);
|
||||
std::string winServiceAction;
|
||||
|
||||
auto vm = GetConsoleArguments(argc, argv, configFile, configService);
|
||||
auto vm = GetConsoleArguments(argc, argv, configFile, configDir, winServiceAction);
|
||||
// exit if help or version is enabled
|
||||
if (vm.count("help") || vm.count("version"))
|
||||
return 0;
|
||||
@@ -139,12 +144,12 @@ extern int main(int argc, char** argv)
|
||||
std::shared_ptr<void> protobufHandle(nullptr, [](void*) { google::protobuf::ShutdownProtobufLibrary(); });
|
||||
|
||||
#ifdef _WIN32
|
||||
if (configService.compare("install") == 0)
|
||||
if (winServiceAction == "install")
|
||||
return WinServiceInstall() ? 0 : 1;
|
||||
else if (configService.compare("uninstall") == 0)
|
||||
if (winServiceAction == "uninstall")
|
||||
return WinServiceUninstall() ? 0 : 1;
|
||||
else if (configService.compare("run") == 0)
|
||||
return WinServiceRun() ? 0 : 0;
|
||||
if (winServiceAction == "run")
|
||||
return WinServiceRun() ? 0 : 1;
|
||||
|
||||
Optional<UINT> newTimerResolution;
|
||||
boost::system::error_code dllError;
|
||||
@@ -194,6 +199,20 @@ extern int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> loadedConfigFiles;
|
||||
std::vector<std::string> configDirErrors;
|
||||
bool additionalConfigFileLoadSuccess = sConfigMgr->LoadAdditionalDir(configDir.generic_string(), true, loadedConfigFiles, configDirErrors);
|
||||
for (std::string const& loadedConfigFile : loadedConfigFiles)
|
||||
printf("Loaded additional config file %s\n", loadedConfigFile.c_str());
|
||||
|
||||
if (!additionalConfigFileLoadSuccess)
|
||||
{
|
||||
for (std::string const& configDirError : configDirErrors)
|
||||
printf("Error in additional config files: %s\n", configDirError.c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> overriddenKeys = sConfigMgr->OverrideWithEnvVariablesIfAny();
|
||||
|
||||
std::shared_ptr<Trinity::Asio::IoContext> ioContext = std::make_shared<Trinity::Asio::IoContext>();
|
||||
@@ -677,23 +696,22 @@ void ClearOnlineAccounts()
|
||||
|
||||
/// @}
|
||||
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService)
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, fs::path& configDir, [[maybe_unused]] std::string& winServiceAction)
|
||||
{
|
||||
// Silences warning about configService not be used if the OS is not Windows
|
||||
(void)configService;
|
||||
|
||||
options_description all("Allowed options");
|
||||
all.add_options()
|
||||
("help,h", "print usage message")
|
||||
("version,v", "print version build info")
|
||||
("config,c", value<fs::path>(&configFile)->default_value(fs::absolute(_TRINITY_CORE_CONFIG)),
|
||||
"use <arg> as configuration file")
|
||||
("config-dir,cd", value<fs::path>(&configDir)->default_value(fs::absolute(_TRINITY_CORE_CONFIG_DIR)),
|
||||
"use <arg> as directory with additional config files")
|
||||
("update-databases-only,u", "updates databases only")
|
||||
;
|
||||
#ifdef _WIN32
|
||||
options_description win("Windows platform specific options");
|
||||
win.add_options()
|
||||
("service,s", value<std::string>(&configService)->default_value(""), "Windows service options: [install | uninstall]")
|
||||
("service,s", value<std::string>(&winServiceAction)->default_value(""), "Windows service options: [install | uninstall]")
|
||||
;
|
||||
|
||||
all.add(win);
|
||||
|
||||
Reference in New Issue
Block a user