diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2014-10-07 22:05:16 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2014-10-07 22:22:59 +0200 |
commit | 12feb49098b3fdcaa489ceb557a4461b5cdebcf9 (patch) | |
tree | 51a42503b196276b2e186d4d7b53f15542d15687 /src/common/profile.cpp | |
parent | 502f7a8a5fc90b5b490e65e0c1f8cc60c2d40957 (diff) | |
download | colobot-12feb49098b3fdcaa489ceb557a4461b5cdebcf9.tar.gz colobot-12feb49098b3fdcaa489ceb557a4461b5cdebcf9.tar.bz2 colobot-12feb49098b3fdcaa489ceb557a4461b5cdebcf9.zip |
Fixes in unit tests
Diffstat (limited to 'src/common/profile.cpp')
-rw-r--r-- | src/common/profile.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 5ecb804..2cb20f3 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -23,6 +23,7 @@ #include "common/logger.h" +#include <memory> #include <utility> #include <cstring> #include <boost/property_tree/ini_parser.hpp> @@ -54,15 +55,25 @@ bool CProfile::Init() { try { - CInputStream stream; - stream.open("colobot.ini"); - if(stream.is_open()) { - bp::ini_parser::read_ini(stream, m_propertyTree); - } else { + std::unique_ptr<std::istream> stream; + if (m_useCurrentDirectory) + { + stream = std::unique_ptr<std::istream>(new std::ifstream("./colobot.ini")); + } + else + { + stream = std::unique_ptr<std::istream>(new CInputStream("colobot.ini")); + } + + if (stream->good()) + { + bp::ini_parser::read_ini(*stream, m_propertyTree); + } + else + { GetLogger()->Error("Error on parsing profile: failed to open file\n"); return false; } - stream.close(); } catch (std::exception & e) { @@ -78,15 +89,25 @@ bool CProfile::Save() { try { - COutputStream stream; - stream.open("colobot.ini"); - if(stream.is_open()) { - bp::ini_parser::write_ini(stream, m_propertyTree); - } else { + std::unique_ptr<std::ostream> stream; + if (m_useCurrentDirectory) + { + stream = std::unique_ptr<std::ostream>(new std::ofstream("./colobot.ini")); + } + else + { + stream = std::unique_ptr<std::ostream>(new COutputStream("colobot.ini")); + } + + if (stream->good()) + { + bp::ini_parser::write_ini(*stream, m_propertyTree); + } + else + { GetLogger()->Error("Error on storing profile: failed to open file\n"); return false; } - stream.close(); } catch (std::exception & e) { |