summaryrefslogtreecommitdiffstats
path: root/src/common/profile.cpp
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-10-19 16:18:36 +0200
committerkrzys-h <krzys_h@interia.pl>2014-10-19 16:18:36 +0200
commit0245fdc6c328edf65b4fd9f45be4f440ef92b6eb (patch)
treed8237bdeacdee273c2eabaefc14f21637c1f489a /src/common/profile.cpp
parentd7ef0a1a5f7cee44eb8faaafefb7bb78e69be1f6 (diff)
parent83abb8ca8e74176d64944e9681d74aa11ef6cdf9 (diff)
downloadcolobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.tar.gz
colobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.tar.bz2
colobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.zip
Merge branch 'dev-physfs' into dev
Conflicts: src/app/app.cpp
Diffstat (limited to 'src/common/profile.cpp')
-rw-r--r--src/common/profile.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/src/common/profile.cpp b/src/common/profile.cpp
index fa7aa26..92fc1d6 100644
--- a/src/common/profile.cpp
+++ b/src/common/profile.cpp
@@ -20,10 +20,13 @@
#include "common/profile.h"
+#include "common/resources/inputstream.h"
+#include "common/resources/outputstream.h"
#include "app/system.h"
#include "common/logger.h"
+#include <memory>
#include <utility>
#include <cstring>
#include <boost/property_tree/ini_parser.hpp>
@@ -51,16 +54,34 @@ void CProfile::SetUseCurrentDirectory(bool useCurrentDirectory)
m_useCurrentDirectory = useCurrentDirectory;
}
-std::string CProfile::GetIniFileLocation()
-{
- return m_useCurrentDirectory ? "colobot.ini" : GetSystemUtils()->GetProfileFileLocation();
-}
-
bool CProfile::Init()
{
try
{
- bp::ini_parser::read_ini(GetIniFileLocation(), m_propertyTree);
+ std::unique_ptr<std::istream> stream;
+ bool good;
+ if (m_useCurrentDirectory)
+ {
+ std::ifstream* inputStream = new std::ifstream("./colobot.ini");
+ stream = std::unique_ptr<std::istream>(inputStream);
+ good = inputStream->good();
+ }
+ else
+ {
+ CInputStream* inputStream = new CInputStream("colobot.ini");
+ stream = std::unique_ptr<std::istream>(inputStream);
+ good = inputStream->is_open();
+ }
+
+ if (good)
+ {
+ bp::ini_parser::read_ini(*stream, m_propertyTree);
+ }
+ else
+ {
+ GetLogger()->Error("Error on parsing profile: failed to open file\n");
+ return false;
+ }
}
catch (std::exception & e)
{
@@ -76,7 +97,30 @@ bool CProfile::Save()
{
try
{
- bp::ini_parser::write_ini(GetIniFileLocation(), m_propertyTree);
+ std::unique_ptr<std::ostream> stream;
+ bool good;
+ if (m_useCurrentDirectory)
+ {
+ std::ofstream* outputStream = new std::ofstream("./colobot.ini");
+ stream = std::unique_ptr<std::ostream>(outputStream);
+ good = outputStream->good();
+ }
+ else
+ {
+ COutputStream* outputStream = new COutputStream("colobot.ini");
+ stream = std::unique_ptr<std::ostream>(outputStream);
+ good = outputStream->is_open();
+ }
+
+ if (good)
+ {
+ bp::ini_parser::write_ini(*stream, m_propertyTree);
+ }
+ else
+ {
+ GetLogger()->Error("Error on storing profile: failed to open file\n");
+ return false;
+ }
}
catch (std::exception & e)
{