Saving colobot.ini through physfs
parent
17041e718b
commit
9a3cd67c3b
|
@ -102,6 +102,9 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
|
|||
{
|
||||
return app->GetExitCode();
|
||||
}
|
||||
|
||||
manager.SetSaveLocation(systemUtils->GetSaveDir());
|
||||
manager.AddLocation(systemUtils->GetSaveDir(), true);
|
||||
|
||||
int code = 0;
|
||||
|
||||
|
@ -121,6 +124,7 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
|
|||
|
||||
delete app;
|
||||
delete systemUtils;
|
||||
//delete manager;
|
||||
|
||||
logger.Info("Exiting with code %d\n", code);
|
||||
return code;
|
||||
|
|
|
@ -192,7 +192,7 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string CSystemUtils::GetProfileFileLocation()
|
||||
std::string CSystemUtils::GetSaveDir()
|
||||
{
|
||||
return std::string("colobot.ini");
|
||||
return std::string("save");
|
||||
}
|
||||
|
|
|
@ -130,8 +130,8 @@ public:
|
|||
/** The difference is \a after - \a before. */
|
||||
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0;
|
||||
|
||||
//! Returns the profile (colobot.ini) file location
|
||||
virtual std::string GetProfileFileLocation();
|
||||
//! Returns the save dir location
|
||||
virtual std::string GetSaveDir();
|
||||
};
|
||||
|
||||
//! Global function to get CSystemUtils instance
|
||||
|
|
|
@ -95,29 +95,29 @@ long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemT
|
|||
(after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll;
|
||||
}
|
||||
|
||||
std::string CSystemUtilsLinux::GetProfileFileLocation()
|
||||
std::string CSystemUtilsLinux::GetSaveDir()
|
||||
{
|
||||
std::string profileFile;
|
||||
|
||||
// Determine profileFile according to XDG Base Directory Specification
|
||||
char* envXDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
|
||||
if (envXDG_CONFIG_HOME == NULL)
|
||||
std::string savegameDir;
|
||||
|
||||
// Determine savegame dir according to XDG Base Directory Specification
|
||||
char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA");
|
||||
if (envXDG_DATA_HOME == NULL)
|
||||
{
|
||||
char *envHOME = getenv("HOME");
|
||||
if (envHOME == NULL)
|
||||
{
|
||||
profileFile = "colobot.ini";
|
||||
savegameDir = "/tmp/colobot-save";
|
||||
}
|
||||
else
|
||||
{
|
||||
profileFile = std::string(envHOME) + "/.config/colobot.ini";
|
||||
savegameDir = std::string(envHOME) + "/.local/share/colobot";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
profileFile = std::string(envXDG_CONFIG_HOME) + "/colobot.ini";
|
||||
savegameDir = std::string(envXDG_DATA_HOME) + "/colobot";
|
||||
}
|
||||
GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
|
||||
|
||||
return profileFile;
|
||||
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
|
||||
|
||||
return savegameDir;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
virtual long long GetTimeStampExactResolution() override;
|
||||
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
|
||||
|
||||
virtual std::string GetProfileFileLocation() override;
|
||||
virtual std::string GetSaveDir() override;
|
||||
|
||||
private:
|
||||
bool m_zenityAvailable;
|
||||
|
|
|
@ -87,10 +87,11 @@ void CSystemUtilsMacOSX::Init()
|
|||
m_dataPath += "/Contents/Resources";
|
||||
}
|
||||
|
||||
std::string CSystemUtilsMacOSX::GetProfileFileLocation()
|
||||
std::string CSystemUtilsMacOSX::GetSaveDir()
|
||||
{
|
||||
std::string profileFile = m_ASPath + "/colobot.ini";
|
||||
|
||||
GetLogger()->Trace("Profile file is %s\n", profileFile.c_str());
|
||||
return profileFile;
|
||||
std::string savegameDir = m_ASPath;
|
||||
boost::filesystem::create_directories(savegameDir.c_str());
|
||||
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
|
||||
|
||||
return savegameDir;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CSystemUtilsMacOSX : public CSystemUtilsOther
|
|||
public:
|
||||
virtual void Init() override;
|
||||
|
||||
virtual std::string GetProfileFileLocation() override;
|
||||
virtual std::string GetSaveDir() override;
|
||||
private:
|
||||
std::string m_ASPath;
|
||||
std::string m_dataPath;
|
||||
|
|
|
@ -111,20 +111,20 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str)
|
|||
|
||||
}
|
||||
|
||||
std::string CSystemUtilsWindows::GetProfileFileLocation()
|
||||
std::string CSystemUtilsWindows::GetSaveDir()
|
||||
{
|
||||
std::string profileFile;
|
||||
|
||||
std::string savegameDir;
|
||||
|
||||
char* envUSERPROFILE = getenv("USERPROFILE");
|
||||
if (envUSERPROFILE == NULL)
|
||||
{
|
||||
profileFile = "colobot.ini";
|
||||
savegameDir = "save";
|
||||
}
|
||||
else
|
||||
{
|
||||
profileFile = std::string(envUSERPROFILE) + "\\colobot\\colobot.ini";
|
||||
savegameDir = std::string(envUSERPROFILE) + "\\colobot";
|
||||
}
|
||||
GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
|
||||
|
||||
return profileFile;
|
||||
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
|
||||
|
||||
return savegameDir;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual long long GetTimeStampExactResolution() override;
|
||||
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
|
||||
|
||||
virtual std::string GetProfileFileLocation() override;
|
||||
virtual std::string GetSaveDir() override;
|
||||
|
||||
private:
|
||||
std::string UTF8_Encode(const std::wstring &wstr);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ void COutputStreamBuffer::open(const std::string &filename)
|
|||
|
||||
void COutputStreamBuffer::close()
|
||||
{
|
||||
sync();
|
||||
if (is_open())
|
||||
PHYSFS_close(m_file);
|
||||
}
|
||||
|
|
|
@ -18,15 +18,16 @@
|
|||
#include "common/resources/resourcemanager.h"
|
||||
|
||||
#include "common/config.h"
|
||||
#include "common/logger.h"
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue