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

47 lines
1.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
namespace fs = std::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 )
{
// get global config
auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName );
if( !fs::exists( configFile ) )
{
2018-11-27 22:48:58 +01:00
if( !copyDefaultConfig( configName ) )
return false;
}
2018-06-10 16:28:03 +00:00
m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) );
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 )
{
fs::path configPath( m_configFolderRoot );
configPath /= configName;
2018-06-10 16:28:03 +00:00
if( !fs::exists( configPath.string() + m_configDefaultSuffix ) )
{
// no default file :(
return false;
}
2018-06-10 16:28:03 +00:00
fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
2018-06-10 16:28:03 +00:00
return true;
}