Merge remote-tracking branch 'origin/dev' into dev-graphics

dev-ui
adiblol 2012-09-30 03:20:52 +02:00
commit af4ff31b4e
1 changed files with 530 additions and 537 deletions

View File

@ -50,6 +50,7 @@
#include <sstream>
#include <iomanip>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
//TODO Get rid of all sprintf's
@ -3599,17 +3600,15 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank)
std::ostringstream rankStream;
if ( strcmp(base, "user") == 0 )
{
//TODO: Change this to point user dir acocrding to operating system
//TODO: Change this to point user dir according 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
{
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);
}
}
@ -3639,7 +3638,8 @@ void CMainDialog::ReadNameList()
bool bDo;
char dir[MAX_FNAME];
char temp[MAX_FNAME];
char filenames[MAX_FNAME][100];
// char filenames[MAX_FNAME][100];
std::vector<std::string> fileNames;
int nbFilenames, i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -3650,51 +3650,36 @@ void CMainDialog::ReadNameList()
nbFilenames = 0;
//TODO list files
// sprintf(dir, ".\\%s", m_savegameDir);
// if (! fs::exists(dir))
// {
// GetLogger()->Error("Savegame dir does not exist %s\n",dir);
// }
// else
// {
// GetLogger()->Info("Opening file");
// }
// hFile = _findfirst(dir, &fBuffer);
// if ( hFile != -1 )
// {
// do
// {
// if ( (fBuffer.attrib & _A_SUBDIR) && fBuffer.name[0] != '.' )
// {
// strcpy(filenames[nbFilenames++], fBuffer.name);
// }
// }
// while ( _findnext(hFile, &fBuffer) == 0 && nbFilenames < 100 );
// }
// do // sorts all names:
// {
// bDo = false;
// for ( i=0 ; i<nbFilenames-1 ; i++ )
// {
// if ( strcmp(filenames[i], filenames[i+1]) > 0 )
// {
// strcpy(temp, filenames[i]);
// strcpy(filenames[i], filenames[i+1]);
// strcpy(filenames[i+1], temp);
// bDo = true;
// }
// }
// }
// while ( bDo );
strcpy(filenames[nbFilenames++], "Test");
for ( i=0 ; i<nbFilenames ; i++ )
try
{
pl->SetName(i, filenames[i]);
if (! fs::exists(m_savegameDir) && fs::is_directory(m_savegameDir))
{
GetLogger()->Error("Savegame dir does not exist %s\n",dir);
}
else
{
fs::directory_iterator dirIt(m_savegameDir), dirEndIt;
BOOST_FOREACH (const fs::path & p, std::make_pair(dirIt, dirEndIt))
{
if (fs::is_directory(p))
{
fileNames.push_back(p.leaf().string());
}
}
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error on listing savegame directory : %s\n", e.what());
return;
}
fileNames.push_back("Test");
for ( i=0 ; i<fileNames.size() ; ++i )
{
pl->SetName(i, fileNames.at(i).c_str());
}
}
@ -3877,7 +3862,7 @@ void CMainDialog::NameCreate()
CWindow* pw;
CEdit* pe;
char name[100];
char dir[100];
std::string dir;
char c;
int len, i, j;
@ -3920,8 +3905,13 @@ void CMainDialog::NameCreate()
// TODO: _mkdir(m_savegameDir); // if does not exist yet!
sprintf(dir, "%s/%s", m_savegameDir.c_str(), name);
// TODO: if ( _mkdir(dir) != 0 )
dir = m_savegameDir + "/" + name;
if (!fs::exists(dir))
{
fs::create_directories(dir);
}
else
{
m_sound->Play(SOUND_TZOING);
pe->SetText(name);
@ -3938,40 +3928,27 @@ void CMainDialog::NameCreate()
// Deletes a folder and all its offspring.
bool RemoveDir(char *dirname)
bool RemoveDir(char *dirName)
{
try
{
/* TODO: remove dir
long hFile;
struct _finddata_t fBuffer;
char filename[100];
sprintf(filename, "%s/*", dirname);
hFile = _findfirst(filename, &fBuffer);
if ( hFile != -1 )
if (!fs::exists(dirName) && fs::is_directory(dirName))
{
do
{
if ( fBuffer.name[0] != '.' )
{
if ( fBuffer.attrib & _A_SUBDIR )
{
sprintf(filename, "%s/%s", dirname, fBuffer.name);
RemoveDir(filename);
GetLogger()->Error("Directory does not exist %s\n",dirName);
return false;
}
else
{
sprintf(filename, "%s/%s", dirname, fBuffer.name);
remove(filename);
}
}
}
while ( _findnext(hFile, &fBuffer) == 0 );
fs::remove_all(dirName);
}
if ( _rmdir(dirname) != 0 )
}
catch (std::exception & e)
{
GetLogger()->Error("Error on removing directory %s : %s\n", dirName, e.what());
return false;
}*/
}
return true;
}
@ -4518,6 +4495,22 @@ void CMainDialog::IODeleteScene()
return;
}
std::ostringstream rankStream;
std::string fileName;
rankStream << std::setfill('0') << std::setw(3) << sel;
fileName = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str();
try
{
if (fs::exists(fileName) && fs::is_directory(fileName))
{
fs::remove_all(fileName);
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error on removing directory %s : %s\n", e.what());
}
/* TODO: remove files
// Deletes all the contents of the file.
sprintf(dir, "%s/%s/save%c%.3d/*", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], sel);
@ -4580,7 +4573,7 @@ bool CMainDialog::IOWriteScene()
//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");
GetLogger()->Debug("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))