#include "ConfigMgr.h" #include #include #include namespace fs = std::experimental::filesystem; /** * Loads an ini file and parses it * @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini * @return true if loading was successful */ bool Core::ConfigMgr::loadConfig( const std::string& configName ) { // get global config auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName ); if( !fs::exists( configFile ) ) { if( !copyDefaultConfig( configName ) ) return false; } m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) ); if( m_pInih->ParseError() < 0 ) return false; return true; } bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName ) { fs::path configPath( m_configFolderRoot ); configPath /= configName; if( !fs::exists( configPath.string() + m_configDefaultSuffix ) ) { // no default file :( return false; } fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath ); return true; }