From 8e23292e82e6fef5600853fd55e0de16399b338d Mon Sep 17 00:00:00 2001 From: NotAdam Date: Tue, 6 Nov 2018 18:35:02 +1100 Subject: [PATCH] correctly copy default config file if it doesn't exist --- src/common/Config/ConfigMgr.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index 91f8ff42..1fdc9af0 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -3,6 +3,8 @@ #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 @@ -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; }