mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 15:17:46 +00:00
correctly copy default config file if it doesn't exist
This commit is contained in:
parent
5b2ab13959
commit
8e23292e82
1 changed files with 12 additions and 6 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
|
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an ini file and parses it
|
* Loads an ini file and parses it
|
||||||
* @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini
|
* @param configName the name of ini file relative to m_configFolderRoot to load alongside global.ini
|
||||||
|
@ -11,10 +13,14 @@
|
||||||
bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
||||||
{
|
{
|
||||||
// get global config
|
// get global config
|
||||||
auto configDir = std::experimental::filesystem::path( m_configFolderRoot );
|
auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName );
|
||||||
|
|
||||||
m_pInih = std::unique_ptr< INIReader >( new INIReader(
|
if( !fs::exists( configFile ) )
|
||||||
std::experimental::filesystem::path( configDir / configName ).string() ) );
|
{
|
||||||
|
copyDefaultConfig( configName );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) );
|
||||||
|
|
||||||
if( m_pInih->ParseError() < 0 )
|
if( m_pInih->ParseError() < 0 )
|
||||||
return false;
|
return false;
|
||||||
|
@ -24,16 +30,16 @@ bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
||||||
|
|
||||||
bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
bool Core::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
||||||
{
|
{
|
||||||
std::experimental::filesystem::path configPath( m_configFolderRoot );
|
fs::path configPath( m_configFolderRoot );
|
||||||
configPath /= configName;
|
configPath /= configName;
|
||||||
|
|
||||||
if( !std::experimental::filesystem::exists( configPath.string() + m_configDefaultSuffix ) )
|
if( !fs::exists( configPath.string() + m_configDefaultSuffix ) )
|
||||||
{
|
{
|
||||||
// no default file :(
|
// no default file :(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::experimental::filesystem::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue