From 9a3cd67c3bb2f7d0d4b83f6a5ac8bbcfedf4207b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 24 Jul 2014 23:38:13 +0200 Subject: Saving colobot.ini through physfs --- src/common/profile.cpp | 30 +++++++++++++++++++---------- src/common/resources/outputstreambuffer.cpp | 1 + src/common/resources/resourcemanager.cpp | 23 +++++++++++----------- 3 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src/common') diff --git a/src/common/profile.cpp b/src/common/profile.cpp index ee3e873..9947769 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -18,6 +18,8 @@ #include "common/profile.h" #include "common/logger.h" +#include "common/resources/inputstream.h" +#include "common/resources/outputstream.h" #include "app/system.h" @@ -47,11 +49,15 @@ bool CProfile::InitCurrentDirectory() { try { - #if DEV_BUILD - bp::ini_parser::read_ini("colobot.ini", m_propertyTree); - #else - bp::ini_parser::read_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); - #endif + CInputStream stream; + stream.open("colobot.ini"); + if(stream.is_open()) { + 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) { @@ -67,11 +73,15 @@ bool CProfile::SaveCurrentDirectory() { try { - #if DEV_BUILD - bp::ini_parser::write_ini("colobot.ini", m_propertyTree); - #else - bp::ini_parser::write_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); - #endif + COutputStream stream; + stream.open("colobot.ini"); + if(stream.is_open()) { + 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) { diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp index e611d13..22ed7cb 100644 --- a/src/common/resources/outputstreambuffer.cpp +++ b/src/common/resources/outputstreambuffer.cpp @@ -43,6 +43,7 @@ void COutputStreamBuffer::open(const std::string &filename) void COutputStreamBuffer::close() { + sync(); if (is_open()) PHYSFS_close(m_file); } diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 5e8627d..be5baa8 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -18,15 +18,16 @@ #include "common/resources/resourcemanager.h" #include "common/config.h" +#include "common/logger.h" #include CResourceManager::CResourceManager(const char *argv0) { - if (PHYSFS_init(argv0)) + if (!PHYSFS_init(argv0)) { - // TODO error + CLogger::GetInstancePointer()->Error("Error while initializing physfs\n"); } } @@ -35,9 +36,9 @@ CResourceManager::~CResourceManager() { if (PHYSFS_isInit()) { - if (PHYSFS_deinit()) + if (!PHYSFS_deinit()) { - // TODO error + CLogger::GetInstancePointer()->Error("Error while deinitializing physfs\n"); } } } @@ -47,9 +48,9 @@ bool CResourceManager::AddLocation(const std::string &location, bool prepend) { if (PHYSFS_isInit()) { - if (PHYSFS_mount(location.c_str(), nullptr, prepend ? 0 : 1)) + if (!PHYSFS_mount(location.c_str(), nullptr, prepend ? 0 : 1)) { - // TODO error + CLogger::GetInstancePointer()->Error("Error while mounting \"%s\"\n", location.c_str()); } } @@ -61,9 +62,9 @@ bool CResourceManager::RemoveLocation(const std::string &location) { if (PHYSFS_isInit()) { - if (PHYSFS_removeFromSearchPath(location.c_str())) + if (!PHYSFS_removeFromSearchPath(location.c_str())) { - // TODO error + CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str()); } } @@ -75,9 +76,9 @@ bool CResourceManager::SetSaveLocation(const std::string &location) { if (PHYSFS_isInit()) { - if (PHYSFS_setWriteDir(location.c_str())) + if (!PHYSFS_setWriteDir(location.c_str())) { - // TODO error + CLogger::GetInstancePointer()->Error("Error while setting save location to \"%s\"\n", location.c_str()); } } @@ -96,7 +97,7 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) SDL_RWops *handler = SDL_AllocRW(); if (!handler) { - // TODO error + CLogger::GetInstancePointer()->Error("Unable to allocate SDL_RWops for \"%s\"\n", filename.c_str()); return nullptr; } -- cgit v1.2.3-1-g7c22