mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
feat: add DLU_CONFIG_DIR env var (#1370)
* feat: add DLU_CONFIG_DIR env var * fix: PascalCase
This commit is contained in:
@@ -10,8 +10,23 @@ dConfig::dConfig(const std::string& filepath) {
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
std::filesystem::path GetConfigDir() {
|
||||
std::filesystem::path config_dir = BinaryPathFinder::GetBinaryDir();
|
||||
if (const char* env_p = std::getenv("DLU_CONFIG_DIR")) {
|
||||
config_dir /= env_p;
|
||||
}
|
||||
return config_dir;
|
||||
}
|
||||
|
||||
const bool dConfig::Exists(const std::string& filepath) {
|
||||
std::filesystem::path config_dir = GetConfigDir();
|
||||
return std::filesystem::exists(config_dir / filepath);
|
||||
}
|
||||
|
||||
void dConfig::LoadConfig() {
|
||||
std::ifstream in(BinaryPathFinder::GetBinaryDir() / m_ConfigFilePath);
|
||||
std::filesystem::path config_dir = GetConfigDir();
|
||||
|
||||
std::ifstream in(config_dir / m_ConfigFilePath);
|
||||
if (!in.good()) return;
|
||||
|
||||
std::string line{};
|
||||
@@ -19,7 +34,7 @@ void dConfig::LoadConfig() {
|
||||
if (!line.empty() && line.front() != '#') ProcessLine(line);
|
||||
}
|
||||
|
||||
std::ifstream sharedConfig(BinaryPathFinder::GetBinaryDir() / "sharedconfig.ini", std::ios::in);
|
||||
std::ifstream sharedConfig(config_dir / "sharedconfig.ini", std::ios::in);
|
||||
if (!sharedConfig.good()) return;
|
||||
|
||||
line.clear();
|
||||
|
@@ -7,6 +7,11 @@ class dConfig {
|
||||
public:
|
||||
dConfig(const std::string& filepath);
|
||||
|
||||
/**
|
||||
* Checks whether the specified filepath exists
|
||||
*/
|
||||
static const bool Exists(const std::string& filepath);
|
||||
|
||||
/**
|
||||
* Gets the specified key from the config. Returns an empty string if the value is not found.
|
||||
*
|
||||
|
Reference in New Issue
Block a user