1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 22:57:45 +00:00
sapphire/src/common/Config/ConfigMgr.cpp

73 lines
2.1 KiB
C++
Raw Normal View History

2018-06-10 16:28:03 +00:00
#include "ConfigMgr.h"
#include <iostream>
#include <fstream>
#include <experimental/filesystem>
2018-06-10 16:28:03 +00:00
/**
* 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 )
{
// std::stringstream configStream;
2018-06-10 16:28:03 +00:00
// get global config
auto configDir = std::experimental::filesystem::path( m_configFolderRoot );
2018-06-10 16:28:03 +00:00
// if( !std::experimental::filesystem::exists( configDir ) )
// {
// return false;
// }
2018-06-10 16:28:03 +00:00
// auto globalConfig = std::experimental::filesystem::path( configDir / m_globalConfigFile );
// if( !std::experimental::filesystem::exists( globalConfig ) )
// {
// if( !copyDefaultConfig( globalConfig.filename().string() ) )
// return false;
// }
2018-06-10 16:28:03 +00:00
// std::ifstream globalConfigFile( globalConfig.c_str() );
// configStream << globalConfigFile.rdbuf();
2018-06-10 16:28:03 +00:00
// // add some newlines just in case there's no newline at the end of the global file
// configStream << "\n\n";
2018-06-10 16:28:03 +00:00
// // get local config
// auto localConfig = ;
// if( !std::experimental::filesystem::exists( localConfig ) )
// {
// if( !copyDefaultConfig( localConfig.filename().string() ) )
// return false;
// }
// std::ifstream configFile( localConfig.c_str() );
// configStream << configFile.rdbuf();
2018-06-10 16:28:03 +00:00
// // parse the trxee and we're fuckin done
// //boost::property_tree::read_ini( configStream, m_propTree );
m_pInih = std::unique_ptr< INIReader >( new INIReader(
std::experimental::filesystem::path( configDir / configName ) ) );
if( m_pInih->ParseError() < 0 )
return false;
2018-06-10 16:28:03 +00:00
return true;
2018-06-10 16:28:03 +00:00
}
bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName )
{
std::experimental::filesystem::path configPath( m_configFolderRoot );
configPath /= configName;
2018-06-10 16:28:03 +00:00
if( !std::experimental::filesystem::exists( configPath.string() + m_configDefaultSuffix ) )
{
// no default file :(
return false;
}
2018-06-10 16:28:03 +00:00
std::experimental::filesystem::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
2018-06-10 16:28:03 +00:00
return true;
}