summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app/app.cpp20
-rw-r--r--src/common/global.h8
-rw-r--r--src/common/profile.cpp118
-rw-r--r--src/common/profile.h6
-rw-r--r--src/object/robotmain.cpp47
-rw-r--r--src/object/robotmain.h16
-rw-r--r--src/plugins/pluginloader.h2
-rw-r--r--src/plugins/pluginmanager.h6
-rw-r--r--src/script/script.cpp4
-rw-r--r--src/sound/plugins/oalsound/CMakeLists.txt2
-rw-r--r--src/sound/plugins/oalsound/alsound.h6
-rw-r--r--src/sound/plugins/oalsound/buffer.h4
-rw-r--r--src/sound/plugins/oalsound/channel.h2
-rw-r--r--src/sound/plugins/oalsound/check.h2
-rw-r--r--src/sound/sound.h8
-rw-r--r--src/ui/maindialog.cpp183
-rw-r--r--src/ui/maindialog.h49
17 files changed, 296 insertions, 187 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 00977d1..8c2dd43 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -132,7 +132,7 @@ CApplication::CApplication()
m_dataPath = "./data";
- m_language = LANG_ENGLISH;
+ m_language = LANGUAGE_ENGLISH;
m_lowCPU = true;
@@ -215,13 +215,13 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
{
waitLanguage = false;
if (arg == "en")
- m_language = LANG_ENGLISH;
+ m_language = LANGUAGE_ENGLISH;
else if (arg == "de")
- m_language = LANG_GERMAN;
+ m_language = LANGUAGE_GERMAN;
else if (arg == "fr")
- m_language = LANG_FRENCH;
+ m_language = LANGUAGE_FRENCH;
else if (arg == "pl")
- m_language = LANG_POLISH;
+ m_language = LANGUAGE_POLISH;
else
return PARSE_ARGS_FAIL;
continue;
@@ -293,19 +293,19 @@ bool CApplication::Create()
std::string locale = "C";
switch (m_language)
{
- case LANG_ENGLISH:
+ case LANGUAGE_ENGLISH:
locale = "en_US.utf8";
break;
- case LANG_GERMAN:
+ case LANGUAGE_GERMAN:
locale = "de_DE.utf8";
break;
- case LANG_FRENCH:
+ case LANGUAGE_FRENCH:
locale = "fr_FR.utf8";
break;
- case LANG_POLISH:
+ case LANGUAGE_POLISH:
locale = "pl_PL.utf8";
break;
}
@@ -326,7 +326,7 @@ bool CApplication::Create()
// Temporarily -- only in windowed mode
m_deviceConfig.fullScreen = false;
- // Create the sound instance.
+ //Create the sound instance.
if (!GetProfile()->InitCurrentDirectory()) {
GetLogger()->Warn("Config not found. Default values will be used!\n");
m_sound = new CSoundInterface();
diff --git a/src/common/global.h b/src/common/global.h
index 2f2104a..9704a2b 100644
--- a/src/common/global.h
+++ b/src/common/global.h
@@ -29,10 +29,10 @@
*/
enum Language
{
- LANG_ENGLISH = 0,
- LANG_FRENCH = 1,
- LANG_GERMAN = 2,
- LANG_POLISH = 3
+ LANGUAGE_ENGLISH = 0,
+ LANGUAGE_FRENCH = 1,
+ LANGUAGE_GERMAN = 2,
+ LANGUAGE_POLISH = 3
};
/**
diff --git a/src/common/profile.cpp b/src/common/profile.cpp
index 1025567..0881c92 100644
--- a/src/common/profile.cpp
+++ b/src/common/profile.cpp
@@ -18,76 +18,132 @@
#include "common/profile.h"
+#include "common/logger.h"
#include <utility>
#include <cstring>
+#include <boost/property_tree/ini_parser.hpp>
template<> CProfile* CSingleton<CProfile>::mInstance = nullptr;
+namespace bp = boost::property_tree;
CProfile::CProfile()
{
- m_ini = new CSimpleIniA();
- m_ini->SetUnicode();
- m_ini->SetMultiKey();
+ // m_ini = new CSimpleIniA();
+ // m_ini->SetUnicode();
+ // m_ini->SetMultiKey();
}
CProfile::~CProfile()
{
- m_ini->Reset();
- delete m_ini;
+ // m_ini->Reset();
+ // delete m_ini;
}
bool CProfile::InitCurrentDirectory()
{
- bool result = m_ini->LoadFile("colobot.ini") == SI_OK;
- return result;
+ try
+ {
+ bp::ini_parser::read_ini("colobot.ini", m_propertyTree);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // return result;
+ return true;
}
bool CProfile::SetLocalProfileString(std::string section, std::string key, std::string value)
{
- return (m_ini->SetValue(section.c_str(), key.c_str(), value.c_str()) == SI_OK);
+ try
+ {
+ m_propertyTree.put(section + "." + key, value);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // return (m_ini->SetValue(section.c_str(), key.c_str(), value.c_str()) == SI_OK);
+ return true;
}
bool CProfile::GetLocalProfileString(std::string section, std::string key, std::string &buffer)
{
- const char* value = m_ini->GetValue(section.c_str(), key.c_str(), nullptr);
- if (value != nullptr && strlen(value) > 0) {
- buffer = std::string(value);
- return true;
+ try
+ {
+ buffer = m_propertyTree.get<std::string>(section + "." + key);
}
-
- return false;
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ return true;
}
bool CProfile::SetLocalProfileInt(std::string section, std::string key, int value)
{
- return (m_ini->SetLongValue(section.c_str(), key.c_str(), value) == SI_OK);
+ try
+ {
+ m_propertyTree.put(section + "." + key, value);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // return (m_ini->SetLongValue(section.c_str(), key.c_str(), value) == SI_OK);
+ return true;
}
bool CProfile::GetLocalProfileInt(std::string section, std::string key, int &value)
{
- value = m_ini->GetLongValue(section.c_str(), key.c_str(), 0L);
+ try
+ {
+ value = m_propertyTree.get<int>(section + "." + key);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // value = m_ini->GetLongValue(section.c_str(), key.c_str(), 0L);
return true;
}
bool CProfile::SetLocalProfileFloat(std::string section, std::string key, float value)
{
- return (m_ini->SetDoubleValue(section.c_str(), key.c_str(), value) == SI_OK);
+ try
+ {
+ m_propertyTree.put(section + "." + key, value);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // return (m_ini->SetDoubleValue(section.c_str(), key.c_str(), value) == SI_OK);
+ return true;
}
bool CProfile::GetLocalProfileFloat(std::string section, std::string key, float &value)
{
- value = m_ini->GetDoubleValue(section.c_str(), key.c_str(), 0.0d);
+ try
+ {
+ value = m_propertyTree.get<float>(section + "." + key);
+ }
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // value = m_ini->GetDoubleValue(section.c_str(), key.c_str(), 0.0d);
return true;
}
@@ -96,13 +152,27 @@ std::vector< std::string > CProfile::GetLocalProfileSection(std::string section,
{
std::vector< std::string > ret_list;
- CSimpleIniA::TNamesDepend values;
- m_ini->GetAllValues(section.c_str(), key.c_str(), values);
- values.sort(CSimpleIniA::Entry::LoadOrder());
-
- for (auto item : values) {
- ret_list.push_back(item.pItem);
+ try
+ {
+ for(bp::ptree::value_type const & v : m_propertyTree.get_child(section))
+ {
+ if (v.first == key)
+ {
+ ret_list.push_back(v.second.get_value<std::string>());
+ }
+ }
}
+ catch (std::exception & e)
+ {
+ GetLogger()->Info("Error on parsing profile: %s\n", e.what());
+ }
+ // CSimpleIniA::TNamesDepend values;
+ // m_ini->GetAllValues(section.c_str(), key.c_str(), values);
+ // values.sort(CSimpleIniA::Entry::LoadOrder());
+
+ // for (auto item : values) {
+ // ret_list.push_back(item.pItem);
+ // }
return ret_list;
}
diff --git a/src/common/profile.h b/src/common/profile.h
index 7a23d94..de30a63 100644
--- a/src/common/profile.h
+++ b/src/common/profile.h
@@ -21,7 +21,7 @@
#pragma once
-#include "lib/simpleini/SimpleIni.h"
+#include <boost/property_tree/ptree.hpp>
#include "common/singleton.h"
@@ -102,7 +102,9 @@ class CProfile : public CSingleton<CProfile>
std::vector< std::string > GetLocalProfileSection(std::string section, std::string key);
private:
- CSimpleIniA *m_ini;
+ // bpt::ptree m_pt;
+ boost::property_tree::ptree m_propertyTree;
+ // CSimpleIniA *m_ini;
};
//! Global function to get profile instance
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index d6f2d2d..3bc886b 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -109,7 +109,7 @@ float g_unit; // conversion factor
static CBotClass* m_pClassFILE;
static CBotProgram* m_pFuncFile;
static int m_CompteurFileOpen = 0;
-static char* m_filesDir;
+static std::string m_filesDir;
@@ -135,7 +135,7 @@ void PrepareFilename(CBotString &filename)
filename = filename.Mid(pos+1); // also removes the drive letter C:
}
- filename = CBotString(m_filesDir) + CBotString("/") + filename;
+ filename = CBotString(m_filesDir.c_str()) + CBotString("/") + filename;
}
@@ -1097,8 +1097,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_app->SetLowCPU(false); // high CPU for simulation
- char* read = m_dialog->GetSceneRead();
- bool loading = (read[0] != 0);
+ bool loading = (m_dialog->GetSceneRead()[0] != 0);
m_map->CreateMap();
CreateScene(m_dialog->GetSceneSoluce(), false, false); // interactive scene
@@ -3457,9 +3456,12 @@ void CRobotMain::Convert()
char* base = m_dialog->GetSceneName();
int rank = m_dialog->GetSceneRank();
+ //TODO change line to string
char line[500];
+ std::string tempLine;
- m_dialog->BuildSceneName(line, base, rank);
+ m_dialog->BuildSceneName(tempLine, base, rank);
+ strcpy(line, tempLine.c_str());
FILE* file = fopen(line, "r");
if (file == NULL) return;
@@ -3676,10 +3678,10 @@ void CRobotMain::ScenePerso()
//! Creates the whole scene
void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
- char* base = m_dialog->GetSceneName();
- int rank = m_dialog->GetSceneRank();
- char* read = m_dialog->GetSceneRead();
- char* stack = m_dialog->GetStackRead();
+ char* base = m_dialog->GetSceneName();
+ int rank = m_dialog->GetSceneRank();
+ const char* read = m_dialog->GetSceneRead().c_str();
+ const char* stack = m_dialog->GetStackRead().c_str();
m_dialog->SetUserDir(base, rank);
/*
@@ -3756,8 +3758,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
memset(name, 0, 200);
memset(dir, 0, 100);
memset(op, 0, 100);
-
- m_dialog->BuildSceneName(line, base, rank);
+ std::string tempLine;
+ m_dialog->BuildSceneName(tempLine, base, rank);
+ strcpy(line, tempLine.c_str());
FILE* file = fopen(line, "r");
if (file == NULL) return;
@@ -5504,7 +5507,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError)
}
//! Load all programs of the robot
-void CRobotMain::LoadFileScript(CObject *obj, char* filename, int objRank,
+void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank,
int &nbError)
{
if (objRank == -1) return;
@@ -5572,7 +5575,7 @@ void CRobotMain::SaveOneScript(CObject *obj)
//! Saves all programs of the robot.
//! If a program does not exist, the corresponding file is destroyed.
-void CRobotMain::SaveFileScript(CObject *obj, char* filename, int objRank)
+void CRobotMain::SaveFileScript(CObject *obj, const char* filename, int objRank)
{
if (objRank == -1) return;
@@ -5779,7 +5782,7 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd)
}
//! Saves the current game
-bool CRobotMain::IOWriteScene(char *filename, char *filecbot, char *info)
+bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *info)
{
FILE* file = fopen(filename, "w");
if (file == NULL) return false;
@@ -5877,7 +5880,7 @@ bool CRobotMain::IOWriteScene(char *filename, char *filecbot, char *info)
}
//! Resumes the game
-CObject* CRobotMain::IOReadObject(char *line, char* filename, int objRank)
+CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank)
{
Math::Vector pos = OpDir(line, "pos")*g_unit;
Math::Vector dir = OpDir(line, "angle")*(Math::PI/180.0f);
@@ -5957,7 +5960,7 @@ CObject* CRobotMain::IOReadObject(char *line, char* filename, int objRank)
}
//! Resumes some part of the game
-CObject* CRobotMain::IOReadScene(char *filename, char *filecbot)
+CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
{
m_base = false;
@@ -6510,19 +6513,19 @@ bool CRobotMain::GetCheatRadar()
return m_cheatRadar;
}
-char* CRobotMain::GetSavegameDir()
+const char* CRobotMain::GetSavegameDir()
{
- return m_dialog->GetSavegameDir();
+ return m_dialog->GetSavegameDir().c_str();
}
-char* CRobotMain::GetPublicDir()
+const char* CRobotMain::GetPublicDir()
{
- return m_dialog->GetPublicDir();
+ return m_dialog->GetPublicDir().c_str();
}
-char* CRobotMain::GetFilesDir()
+const char* CRobotMain::GetFilesDir()
{
- return m_dialog->GetFilesDir();
+ return m_dialog->GetFilesDir().c_str();
}
diff --git a/src/object/robotmain.h b/src/object/robotmain.h
index 0a5a5a2..8724b90 100644
--- a/src/object/robotmain.h
+++ b/src/object/robotmain.h
@@ -295,9 +295,9 @@ public:
bool GetSceneSoluce();
bool GetShowAll();
bool GetCheatRadar();
- char* GetSavegameDir();
- char* GetPublicDir();
- char* GetFilesDir();
+ const char* GetSavegameDir();
+ const char* GetPublicDir();
+ const char* GetFilesDir();
void SetGamerName(const char *name);
char* GetGamerName();
@@ -324,10 +324,10 @@ public:
void CompileScript(bool soluce);
void LoadOneScript(CObject *pObj, int &nerror);
- void LoadFileScript(CObject *pObj, char* filename, int objRank, int &nerror);
+ void LoadFileScript(CObject *pObj, const char* filename, int objRank, int &nerror);
void SaveAllScript();
void SaveOneScript(CObject *pObj);
- void SaveFileScript(CObject *pObj, char* filename, int objRank);
+ void SaveFileScript(CObject *pObj, const char* filename, int objRank);
bool SaveFileStack(CObject *pObj, FILE *file, int objRank);
bool ReadFileStack(CObject *pObj, FILE *file, int objRank);
@@ -339,10 +339,10 @@ public:
void ReadFreeParam();
bool IsBusy();
- bool IOWriteScene(char *filename, char *filecbot, char *info);
- CObject* IOReadScene(char *filename, char *filecbot);
+ bool IOWriteScene(const char *filename, const char *filecbot, char *info);
+ CObject* IOReadScene(const char *filename, const char *filecbot);
void IOWriteObject(FILE *file, CObject* pObj, const char *cmd);
- CObject* IOReadObject(char *line, char* filename, int objRank);
+ CObject* IOReadObject(char *line, const char* filename, int objRank);
int CreateSpot(Math::Vector pos, Gfx::Color color);
diff --git a/src/plugins/pluginloader.h b/src/plugins/pluginloader.h
index 40b19da..3dfa20b 100644
--- a/src/plugins/pluginloader.h
+++ b/src/plugins/pluginloader.h
@@ -26,7 +26,7 @@
#include <ltdl.h>
#include <string>
-#include <common/logger.h>
+#include "common/logger.h"
#include "plugininterface.h"
diff --git a/src/plugins/pluginmanager.h b/src/plugins/pluginmanager.h
index e425c62..7a69820 100644
--- a/src/plugins/pluginmanager.h
+++ b/src/plugins/pluginmanager.h
@@ -27,10 +27,10 @@
#include <set>
#include <vector>
-#include <common/logger.h>
-#include <common/profile.h>
+#include "common/logger.h"
+#include "common/profile.h"
-#include <common/singleton.h>
+#include "common/singleton.h"
#include "pluginloader.h"
diff --git a/src/script/script.cpp b/src/script/script.cpp
index b29c625..5dbab56 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -2415,7 +2415,7 @@ bool CScript::rAbsTime(CBotVar* var, CBotVar* result, int& exception, void* user
// Prepares a file name.
-void PrepareFilename(CBotString &filename, char *dir)
+void PrepareFilename(CBotString &filename, const char *dir)
{
int pos;
@@ -2447,7 +2447,7 @@ bool CScript::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* u
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
CBotString cbs;
const char* filename;
- char* dir;
+ const char* dir;
cbs = var->GetValString();
dir = script->m_main->GetFilesDir();
diff --git a/src/sound/plugins/oalsound/CMakeLists.txt b/src/sound/plugins/oalsound/CMakeLists.txt
index e36f3ac..12ab5e3 100644
--- a/src/sound/plugins/oalsound/CMakeLists.txt
+++ b/src/sound/plugins/oalsound/CMakeLists.txt
@@ -4,6 +4,7 @@ set(SOURCES
alsound.cpp
buffer.cpp
channel.cpp
+ logger.cpp
)
SET (CMAKE_CXX_FLAGS "-Wall -g -std=c++0x -fPIC")
@@ -17,7 +18,6 @@ set(OPENAL_LIBRARIES
alut
)
-
include_directories(../../..)
include_directories(.)
add_library(openalsound SHARED ${SOURCES})
diff --git a/src/sound/plugins/oalsound/alsound.h b/src/sound/plugins/oalsound/alsound.h
index 01ccc71..a1128e0 100644
--- a/src/sound/plugins/oalsound/alsound.h
+++ b/src/sound/plugins/oalsound/alsound.h
@@ -24,9 +24,9 @@
#include <AL/alut.h>
-#include <common/iman.h>
-#include <common/logger.h>
-#include <sound/sound.h>
+#include "common/iman.h"
+#include "common/logger.h"
+#include "sound/sound.h"
#include "buffer.h"
#include "channel.h"
diff --git a/src/sound/plugins/oalsound/buffer.h b/src/sound/plugins/oalsound/buffer.h
index 6eefe72..8c4a2d3 100644
--- a/src/sound/plugins/oalsound/buffer.h
+++ b/src/sound/plugins/oalsound/buffer.h
@@ -22,8 +22,8 @@
#include <AL/alut.h>
-#include <sound/sound.h>
-#include <common/logger.h>
+#include "sound/sound.h"
+#include "common/logger.h"
#include "check.h"
diff --git a/src/sound/plugins/oalsound/channel.h b/src/sound/plugins/oalsound/channel.h
index 3099931..165ff50 100644
--- a/src/sound/plugins/oalsound/channel.h
+++ b/src/sound/plugins/oalsound/channel.h
@@ -25,7 +25,7 @@
#include <AL/al.h>
#include <AL/alc.h>
-#include <sound/sound.h>
+#include "sound/sound.h"
#include "buffer.h"
#include "check.h"
diff --git a/src/sound/plugins/oalsound/check.h b/src/sound/plugins/oalsound/check.h
index cb6b4a1..cf3e468 100644
--- a/src/sound/plugins/oalsound/check.h
+++ b/src/sound/plugins/oalsound/check.h
@@ -21,7 +21,7 @@
#include <AL/al.h>
#include <AL/alc.h>
-#include <common/logger.h>
+#include "common/logger.h"
static ALenum CODE = AL_NO_ERROR;
diff --git a/src/sound/sound.h b/src/sound/sound.h
index 11138c3..1f3fea9 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -24,12 +24,12 @@
#pragma once
-#include <math/vector.h>
+#include "math/vector.h"
-#include <common/iman.h>
-#include <common/logger.h>
+#include "common/iman.h"
+#include "common/logger.h"
-#include <plugins/plugininterface.h>
+#include "plugins/plugininterface.h"
#include <string>
#include <iostream>
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 6395acf..3be934a 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -18,6 +18,7 @@
#include "ui/maindialog.h"
+#include "app/app.h"
#include "common/global.h"
#include "common/event.h"
#include "common/logger.h"
@@ -46,8 +47,11 @@
#include <stdio.h>
#include <string.h>
-// #include <boost/filesystem.hpp>
+#include <sstream>
+#include <iomanip>
+#include <boost/filesystem.hpp>
+//TODO Get rid of all sprintf's
namespace Ui
{
@@ -58,7 +62,7 @@ const int KEY_TOTAL = 21; // total number of keys redefinable
const float WELCOME_LENGTH = 2.0f;
-
+const int MAX_FNAME = 255; // TODO: remove after rewrite to std::string
static int perso_color[3*10*3] =
{
@@ -97,7 +101,7 @@ static int perso_color[3*10*3] =
0, 0, 0, //
};
-
+namespace fs = boost::filesystem;
// Constructor of robot application.
@@ -169,11 +173,12 @@ CMainDialog::CMainDialog(CInstanceManager* iMan)
m_partiTime[i] = 0.0f;
}
- strcpy(m_sceneDir, "levels");
- strcpy(m_savegameDir, "savegame");
- strcpy(m_publicDir, "program");
- strcpy(m_userDir, "user");
- strcpy(m_filesDir, "files");
+
+ m_sceneDir = "levels";
+ m_savegameDir = "savegame";
+ m_publicDir = "program";
+ m_userDir = "user";
+ m_filesDir = "files";
m_bDialog = false;
}
@@ -3573,7 +3578,7 @@ void CMainDialog::SetUserDir(char *base, int rank)
if ( strcmp(base, "user") == 0 && rank >= 100 )
{
- sprintf(dir, "%s/%s", m_userDir, m_userList[rank/100-1]);
+ sprintf(dir, "%s/%s", m_userDir.c_str(), m_userList[rank/100-1]);
UserDir(true, dir);
}
else
@@ -3584,17 +3589,22 @@ void CMainDialog::SetUserDir(char *base, int rank)
// Builds the file name of a mission.
-void CMainDialog::BuildSceneName(char *filename, char *base, int rank)
+void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank)
{
- std::string dataDir = m_app->GetDataDirPath();
-
+ std::ostringstream rankStream;
if ( strcmp(base, "user") == 0 )
{
- sprintf(filename, "%s/%s/%s/scene%.2d.txt", dataDir.c_str(), m_userDir, m_userList[rank/100-1], rank%100);
+ //TODO: Change this to point user dir acocrding to operating system
+ rankStream << std::setfill('0') << std::setw(2) << rank%100;
+ filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";
+ // sprintf(filename, "%s\\%s\\scene%.2d.txt", m_userDir.c_str(), m_userList[rank/100-1], rank%100);
}
else
{
- sprintf(filename, "%s/%s/%s%.3d.txt", dataDir.c_str(), m_sceneDir, base, rank);
+ rankStream << std::setfill('0') << std::setw(3) << rank;
+ filename = base + rankStream.str() + ".txt";
+ filename = CApplication::GetInstance().GetDataFilePath(DIR_LEVEL, filename);
+ // sprintf(filename, "%s\\%s%.3d.txt", m_sceneDir, base, rank);
}
}
@@ -3607,7 +3617,7 @@ void CMainDialog::BuildResumeName(char *filename, char *base, int rank)
// Returns the name of the file or save the files.
-char* CMainDialog::GetFilesDir()
+std::string & CMainDialog::GetFilesDir()
{
return m_filesDir;
}
@@ -3635,9 +3645,10 @@ void CMainDialog::ReadNameList()
nbFilenames = 0;
- sprintf(dir, "./%s", m_savegameDir);
+ //TODO list files
+ // sprintf(dir, ".\\%s", m_savegameDir);
- // if (! boost::filesystem::exists(dir))
+ // if (! fs::exists(dir))
// {
// GetLogger()->Error("Savegame dir does not exist %s\n",dir);
// }
@@ -3645,7 +3656,6 @@ void CMainDialog::ReadNameList()
// {
// GetLogger()->Info("Opening file");
// }
- //TODO list files
// hFile = _findfirst(dir, &fBuffer);
// if ( hFile != -1 )
@@ -3852,7 +3862,7 @@ void CMainDialog::NameSelect()
GetGamerFace(m_main->GetGamerName());
- // TODO: SetLocalProfileString("Gamer", "LastName", m_main->GetGamerName());
+ GetProfile()->SetLocalProfileString("Gamer", "LastName", m_main->GetGamerName());
}
// Creates a new player.
@@ -3866,6 +3876,7 @@ void CMainDialog::NameCreate()
char c;
int len, i, j;
+ GetLogger()->Debug("Creating new player\n");
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
@@ -3904,7 +3915,7 @@ void CMainDialog::NameCreate()
// TODO: _mkdir(m_savegameDir); // if does not exist yet!
- sprintf(dir, "%s/%s", m_savegameDir, name);
+ sprintf(dir, "%s/%s", m_savegameDir.c_str(), name);
// TODO: if ( _mkdir(dir) != 0 )
{
m_sound->Play(SOUND_TZOING);
@@ -3983,7 +3994,7 @@ void CMainDialog::NameDelete()
gamer = pl->GetName(sel);
// Deletes all the contents of the file.
- sprintf(dir, "%s/%s", m_savegameDir, gamer);
+ sprintf(dir, "%s/%s", m_savegameDir.c_str(), gamer);
if ( !RemoveDir(dir) )
{
m_sound->Play(SOUND_TZOING);
@@ -4295,10 +4306,13 @@ void CMainDialog::DefPerso()
bool CMainDialog::IsIOReadScene()
{
FILE* file;
- char filename[100];
+ // char filename[100];
+ std::string filename;
- sprintf(filename, "%s/%s/save%c%.3d/data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], 0);
- file = fopen(filename, "r");
+ //TODO: Change this to point user dir acocrding to operating system
+ filename = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + "000/data.sav";
+ // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], 0);
+ file = fopen(filename.c_str(), "r");
if ( file == NULL ) return false;
fclose(file);
return true;
@@ -4311,7 +4325,7 @@ void CMainDialog::IOReadName()
FILE* file;
CWindow* pw;
CEdit* pe;
- char filename[MAX_FNAME];
+ std::string filename;
char op[100];
char line[500];
char resume[100];
@@ -4326,7 +4340,7 @@ void CMainDialog::IOReadName()
sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1);
BuildSceneName(filename, m_sceneName, (m_chap[m_index]+1)*100);
- file = fopen(filename, "r");
+ file = fopen(filename.c_str(), "r");
if ( file != NULL )
{
while ( fgets(line, 500, file) != NULL )
@@ -4367,7 +4381,6 @@ void CMainDialog::IOReadList()
FILE* file = NULL;
CWindow* pw;
CList* pl;
- char filename[100];
char line[500];
char name[100];
int i, j;
@@ -4381,8 +4394,13 @@ void CMainDialog::IOReadList()
for ( j=0 ; j<999 ; j++ )
{
- sprintf(filename, "%s/%s/save%c%.3d/data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j);
- file = fopen(filename, "r");
+ std::string filename;
+ std::ostringstream rankStream;
+ rankStream << std::setfill('0') << std::setw(3) << j;
+ filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav";
+
+ // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j);
+ file = fopen(filename.c_str(), "r");
if ( file == NULL ) break;
while ( fgets(line, 500, file) != NULL )
@@ -4429,7 +4447,6 @@ void CMainDialog::IOUpdateList()
CList* pl;
CButton* pb;
CImage* pi;
- char filename[100];
int sel, max;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@@ -4442,14 +4459,18 @@ void CMainDialog::IOUpdateList()
sel = pl->GetSelect();
max = pl->GetTotal();
- sprintf(filename, "%s/%s/save%c%.3d/screen.png", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ std::string filename;
+ std::ostringstream rankStream;
+ rankStream << std::setfill('0') << std::setw(3) << sel;
+ filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/screen.png";
+ // sprintf(filename, "%s\\%s\\save%c%.3d\\screen.png", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
if ( m_phase == PHASE_WRITE ||
m_phase == PHASE_WRITEs )
{
if ( sel < max-1 )
{
- pi->SetFilenameImage(filename);
+ pi->SetFilenameImage(filename.c_str());
}
else
{
@@ -4464,7 +4485,7 @@ void CMainDialog::IOUpdateList()
}
else
{
- pi->SetFilenameImage(filename);
+ pi->SetFilenameImage(filename.c_str());
}
}
@@ -4534,8 +4555,6 @@ bool CMainDialog::IOWriteScene()
CWindow* pw;
CList* pl;
CEdit* pe;
- char filename[100];
- char filecbot[100];
char info[100];
int sel;
@@ -4549,19 +4568,28 @@ bool CMainDialog::IOWriteScene()
sel = pl->GetSelect();
if ( sel == -1 ) return false;
- // TODO: _mkdir("Savegame"); // if doesn't exist yet!
- sprintf(filename, "%s/%s", m_savegameDir, m_main->GetGamerName());
- // TODO: _mkdir(filename);
- sprintf(filename, "%s/%s/save%c%.3d", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
- // TODO: _mkdir(filename);
+ std::string directoryName;
+ std::string fileName;
+ std::string fileCBot;
+ std::ostringstream selectStream;
+
+ //TODO: Change this to point user dir according to operating system
+ // sprintf(filename, "%s\\%s\\save%c%.3d", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ GetLogger()->Info("Creating save directory\n");
+ selectStream << std::setfill('0') << std::setw(3) << sel;
+ directoryName = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + selectStream.str();
+ if (!fs::exists(directoryName))
+ {
+ fs::create_directories(directoryName);
+ }
- sprintf(filename, "%s/%s/save%c%.3d/data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
- sprintf(filecbot, "%s/%s/save%c%.3d/cbot.run", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ fileName = directoryName + "/data.sav";
+ fileCBot = directoryName + "/cbot.run";
pe->GetText(info, 100);
- m_main->IOWriteScene(filename, filecbot, info);
+ m_main->IOWriteScene(fileName.c_str(), fileCBot.c_str(), info);
m_shotDelay = 3;
- sprintf(m_shotName, "%s/%s/save%c%.3d/screen.png", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ m_shotName = directoryName + "/screen.png";
return true;
}
@@ -4573,8 +4601,6 @@ bool CMainDialog::IOReadScene()
FILE* file;
CWindow* pw;
CList* pl;
- char filename[100];
- char filecbot[100];
char line[500];
char dir[100];
int sel, i;
@@ -4587,10 +4613,19 @@ bool CMainDialog::IOReadScene()
sel = pl->GetSelect();
if ( sel == -1 ) return false;
- sprintf(filename, "%s/%s/save%c%.3d/data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
- sprintf(filecbot, "%s/%s/save%c%.3d/cbot.run", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ //TODO: Change this to point user dir according to operating system
+ // sprintf(filename, "%s\\%s\\save%c%.3d", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
+ std::string fileName;
+ std::string fileCbot;
+ std::string directoryName;
+ std::ostringstream selectStream;
+ selectStream << std::setfill('0') << std::setw(3) << sel;
+ directoryName = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + selectStream.str();
- file = fopen(filename, "r");
+ fileName = directoryName + "/data.sav";
+ fileCbot = directoryName + "/cbot.run";
+
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL ) return false;
while ( fgets(line, 500, file) != NULL )
@@ -4635,8 +4670,8 @@ bool CMainDialog::IOReadScene()
m_chap[m_index] = (m_sceneRank/100)-1;
m_sel[m_index] = (m_sceneRank%100)-1;
- strcpy(m_sceneRead, filename);
- strcpy(m_stackRead, filecbot);
+ m_sceneRead = fileName;
+ m_stackRead = fileCbot;
return true;
}
@@ -4685,7 +4720,7 @@ void CMainDialog::UpdateSceneChap(int &chap)
CList* pl;
long hFile;
//struct _finddata_t fileBuffer;
- char filename[MAX_FNAME];
+ std::string fileName;
char op[100];
char line[500];
char name[100];
@@ -4740,8 +4775,8 @@ void CMainDialog::UpdateSceneChap(int &chap)
for ( j=0 ; j<m_userTotal ; j++ )
{
- BuildSceneName(filename, m_sceneName, (j+1)*100);
- file = fopen(filename, "r");
+ BuildSceneName(fileName, m_sceneName, (j+1)*100);
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL )
{
strcpy(name, m_userList[j]);
@@ -4791,8 +4826,8 @@ void CMainDialog::UpdateSceneChap(int &chap)
if ( m_phase == PHASE_MISSION && j >= 4 ) break;
if ( m_phase == PHASE_TRAINER && j >= 1 ) break;
#endif */
- BuildSceneName(filename, m_sceneName, (j+1)*100);
- file = fopen(filename, "r");
+ BuildSceneName(fileName, m_sceneName, (j+1)*100);
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL ) break;
BuildResumeName(name, m_sceneName, j+1); // default name
@@ -4859,7 +4894,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
FILE* file = NULL;
CWindow* pw;
CList* pl;
- char filename[MAX_FNAME];
+ std::string fileName;
char op[100];
char line[500];
char name[100];
@@ -4894,8 +4929,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
if ( m_phase == PHASE_MISSION && j >= 3 ) break;
if ( m_phase == PHASE_TRAINER && j >= 5 ) break;
#endif */
- BuildSceneName(filename, m_sceneName, (chap+1)*100+(j+1));
- file = fopen(filename, "r");
+ BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL ) break;
BuildResumeName(name, m_sceneName, j+1); // default name
@@ -4942,8 +4977,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
#endif*/
}
- BuildSceneName(filename, m_sceneName, (chap+1)*100+(j+1));
- file = fopen(filename, "r");
+ BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL )
{
m_maxList = j;
@@ -5008,7 +5043,7 @@ void CMainDialog::UpdateSceneResume(int rank)
CWindow* pw;
CEdit* pe;
CCheck* pc;
- char filename[MAX_FNAME];
+ std::string fileName;
char op[100];
char line[500];
char name[500];
@@ -5039,8 +5074,8 @@ void CMainDialog::UpdateSceneResume(int rank)
}
}
- BuildSceneName(filename, m_sceneName, rank);
- file = fopen(filename, "r");
+ BuildSceneName(fileName, m_sceneName, rank);
+ file = fopen(fileName.c_str(), "r");
if ( file == NULL ) return;
name[0] = 0;
@@ -6522,12 +6557,12 @@ bool CMainDialog::IsDialog()
void CMainDialog::SetSceneRead(const char* name)
{
- strcpy(m_sceneRead, name);
+ m_sceneRead = name;
}
// Returns the name of the scene to read.
-char* CMainDialog::GetSceneRead()
+std::string & CMainDialog::GetSceneRead()
{
return m_sceneRead;
}
@@ -6536,12 +6571,12 @@ char* CMainDialog::GetSceneRead()
void CMainDialog::SetStackRead(const char* name)
{
- strcpy(m_stackRead, name);
+ m_stackRead = name;
}
// Returns the name of the scene to read.
-char* CMainDialog::GetStackRead()
+std::string & CMainDialog::GetStackRead()
{
return m_stackRead;
}
@@ -6595,14 +6630,14 @@ bool CMainDialog::GetSceneSoluce()
// Returns the name of the folder to save.
-char* CMainDialog::GetSavegameDir()
+std::string & CMainDialog::GetSavegameDir()
{
return m_savegameDir;
}
// Returns the name of public folder.
-char* CMainDialog::GetPublicDir()
+std::string & CMainDialog::GetPublicDir()
{
return m_publicDir;
}
@@ -6653,7 +6688,7 @@ void CMainDialog::WriteGamerPerso(char *gamer)
char filename[100];
char line[100];
- sprintf(filename, "%s/%s/face.gam", m_savegameDir, gamer);
+ sprintf(filename, "%s/%s/face.gam", m_savegameDir.c_str(), gamer);
file = fopen(filename, "w");
if ( file == NULL ) return;
@@ -6682,7 +6717,7 @@ void CMainDialog::ReadGamerPerso(char *gamer)
m_perso.face = 0;
DefPerso();
- sprintf(filename, "%s/%s/face.gam", m_savegameDir, gamer);
+ sprintf(filename, "%s/%s/face.gam", m_savegameDir.c_str(), gamer);
file = fopen(filename, "r");
if ( file == NULL ) return;
@@ -6787,7 +6822,7 @@ bool CMainDialog::ReadGamerInfo()
m_sceneInfo[i].bPassed = false;
}
- sprintf(line, "%s/%s/%s.gam", m_savegameDir, m_main->GetGamerName(), m_sceneName);
+ sprintf(line, "%s/%s/%s.gam", m_savegameDir.c_str(), m_main->GetGamerName(), m_sceneName);
file = fopen(line, "r");
if ( file == NULL ) return false;
@@ -6823,7 +6858,7 @@ bool CMainDialog::WriteGamerInfo()
char line[100];
int i;
- sprintf(line, "%s/%s/%s.gam", m_savegameDir, m_main->GetGamerName(), m_sceneName);
+ sprintf(line, "%s/%s/%s.gam", m_savegameDir.c_str(), m_main->GetGamerName(), m_sceneName);
file = fopen(line, "w");
if ( file == NULL ) return false;
diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h
index 8b0ef81..c67ca37 100644
--- a/src/ui/maindialog.h
+++ b/src/ui/maindialog.h
@@ -43,7 +43,6 @@ class CControl;
const int USERLISTMAX = 100;
const int MAXSCENE = 1000;
-const int MAX_FNAME = 255; // TODO: remove after rewrite to std::string
struct SceneInfo
{
@@ -71,18 +70,18 @@ public:
bool EventProcess(const Event &event);
void ChangePhase(Phase phase);
- void SetSceneRead(const char* name);
- void SetStackRead(const char* name);
- void SetSceneName(const char* name);
- void SetSceneRank(int rank);
- char* GetSceneRead();
- char* GetStackRead();
- char* GetSceneName();
- int GetSceneRank();
- char* GetSceneDir();
- bool GetSceneSoluce();
- char* GetSavegameDir();
- char* GetPublicDir();
+ void SetSceneRead(const char* name);
+ void SetStackRead(const char* name);
+ void SetSceneName(const char* name);
+ void SetSceneRank(int rank);
+ std::string & GetSceneRead();
+ std::string & GetStackRead();
+ char* GetSceneName();
+ int GetSceneRank();
+ char* GetSceneDir();
+ bool GetSceneSoluce();
+ std::string & GetSavegameDir();
+ std::string & GetPublicDir();
bool GetTooltip();
bool GetGlint();
@@ -91,10 +90,10 @@ public:
bool GetNiceReset();
bool GetHimselfDamage();
- void SetUserDir(char *base, int rank);
- void BuildSceneName(char *filename, char *base, int rank);
- void BuildResumeName(char *filename, char *base, int rank);
- char* GetFilesDir();
+ void SetUserDir(char *base, int rank);
+ void BuildSceneName(std::string &filename, char *base, int rank);
+ void BuildResumeName(char *filename, char *base, int rank);
+ std::string & GetFilesDir();
void StartAbort();
void StartDeleteObject();
@@ -193,19 +192,19 @@ protected:
int m_persoTab; // perso: tab selected
float m_persoAngle; // perso: angle of presentation
- char m_sceneDir[MAX_FNAME]; // scene folder
- char m_savegameDir[MAX_FNAME]; // savegame folder
- char m_publicDir[MAX_FNAME]; // program folder
- char m_userDir[MAX_FNAME]; // user folder
- char m_filesDir[MAX_FNAME]; // case files
+ std::string m_sceneDir; // scene folder
+ std::string m_savegameDir; // savegame folder
+ std::string m_publicDir; // program folder
+ std::string m_userDir; // user folder
+ std::string m_filesDir; // case files
int m_index; // 0..4
int m_chap[10]; // selected chapter (0..8)
int m_sel[10]; // chosen mission (0..98)
int m_maxList;
int m_accessChap;
- char m_sceneRead[100]; // name of the scene to read
- char m_stackRead[100]; // name of the scene to read
+ std::string m_sceneRead; // name of the scene to read
+ std::string m_stackRead; // name of the scene to read
char m_sceneName[20]; // name of the scene to play
int m_sceneRank; // rank of the scene to play
bool m_bSceneSoluce; // shows the solution
@@ -219,7 +218,7 @@ protected:
char m_userList[USERLISTMAX][100];
int m_shotDelay; // number of frames before copy
- char m_shotName[100]; // generate a file name
+ std::string m_shotName; // generate a file name
int m_setupSelDevice;
int m_setupSelMode;