Browse Source

Manager: Search config file recursively from the working directory

master
Riyyi 3 years ago
parent
commit
c853dfcf24
  1. 19
      src/config.cpp
  2. 4
      src/config.h

19
src/config.cpp

@ -12,8 +12,27 @@ Config::Config(s)
: m_workingDirectory(std::filesystem::current_path()) : m_workingDirectory(std::filesystem::current_path())
, m_workingDirectorySize(m_workingDirectory.string().size()) , m_workingDirectorySize(m_workingDirectory.string().size())
{ {
findConfigFile();
} }
Config::~Config() Config::~Config()
{ {
} }
// -----------------------------------------
void Config::findConfigFile()
{
std::string configFileName = "manafiles.json";
for (const auto& path : std::filesystem::recursive_directory_iterator { m_workingDirectory }) {
const auto& file = path.path().string();
if (file.find(configFileName) + configFileName.size() == file.size()) {
m_config = file;
}
}
#ifndef NDEBUG
printf("Found config file @ %s\n", m_config.c_str() + m_workingDirectorySize + 1);
#endif
}

4
src/config.h

@ -24,10 +24,14 @@ public:
bool verbose() const { return m_verbose; } bool verbose() const { return m_verbose; }
private: private:
void findConfigFile();
bool m_verbose { false }; bool m_verbose { false };
std::filesystem::path m_workingDirectory {}; std::filesystem::path m_workingDirectory {};
size_t m_workingDirectorySize { 0 }; size_t m_workingDirectorySize { 0 };
std::filesystem::path m_config;
}; };
#endif // CONFIG_H #endif // CONFIG_H

Loading…
Cancel
Save