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 <experimental/filesystem>
|
||||
|
||||
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
|
||||
|
@ -11,10 +13,14 @@
|
|||
bool Core::ConfigMgr::loadConfig( const std::string& configName )
|
||||
{
|
||||
// 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(
|
||||
std::experimental::filesystem::path( configDir / configName ).string() ) );
|
||||
if( !fs::exists( configFile ) )
|
||||
{
|
||||
copyDefaultConfig( configName );
|
||||
}
|
||||
|
||||
m_pInih = std::unique_ptr< INIReader >( new INIReader( configFile.string() ) );
|
||||
|
||||
if( m_pInih->ParseError() < 0 )
|
||||
return false;
|
||||
|
@ -24,16 +30,16 @@ bool Core::ConfigMgr::loadConfig( 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;
|
||||
|
||||
if( !std::experimental::filesystem::exists( configPath.string() + m_configDefaultSuffix ) )
|
||||
if( !fs::exists( configPath.string() + m_configDefaultSuffix ) )
|
||||
{
|
||||
// no default file :(
|
||||
return false;
|
||||
}
|
||||
|
||||
std::experimental::filesystem::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
||||
fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue