[colobot] 193/390: Saving/loading list of finished missions via PHYSFS
Didier Raboud
odyx at moszumanska.debian.org
Fri Jun 12 14:21:44 UTC 2015
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch upstream/latest
in repository colobot.
commit aeaea87d0d5592502cfa1918b1f88b5af7668b56
Author: krzys-h <krzys_h at interia.pl>
Date: Mon Nov 10 19:23:51 2014 +0100
Saving/loading list of finished missions via PHYSFS
---
src/object/robotmain.cpp | 2 +-
src/ui/maindialog.cpp | 55 ++++++++++++++++++++++++------------------------
2 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 48eb2ec..538109e 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -6040,7 +6040,7 @@ void CRobotMain::ReadFreeParam()
}
std::string line;
- file >> line;
+ std::getline(file, line);
sscanf(line.c_str(), "research=%d build=%d\n", &m_freeResearch, &m_freeBuild);
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 5c812a6..d950f98 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -6031,9 +6031,8 @@ Gfx::Color CMainDialog::GetGamerColorBand()
bool CMainDialog::ReadGamerInfo()
{
- FILE* file;
- char line[100];
- int chap, i, numTry, passed;
+ std::string line;
+ int chap, i, numTry, passed;
for ( i=0 ; i<MAXSCENE ; i++ )
{
@@ -6041,20 +6040,25 @@ bool CMainDialog::ReadGamerInfo()
m_sceneInfo[i].bPassed = false;
}
- sprintf(line, "%s/%s/%s.gam", GetSavegameDir().c_str(), m_main->GetGamerName(), m_sceneName);
- file = fopen(line, "r");
- if ( file == NULL ) return false;
-
- if ( fgets(line, 100, file) != NULL )
- {
- sscanf(line, "CurrentChapter=%d CurrentSel=%d\n", &chap, &i);
- m_chap[m_index] = chap-1;
- m_sel[m_index] = i-1;
+ if(!CResourceManager::Exists(GetPHYSFSSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"))
+ return false;
+
+ CInputStream file;
+ file.open(GetPHYSFSSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
+ if(!file.is_open()) {
+ CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
+ return false;
}
+
+ std::getline(file, line);
+ sscanf(line.c_str(), "CurrentChapter=%d CurrentSel=%d\n", &chap, &i);
+ m_chap[m_index] = chap-1;
+ m_sel[m_index] = i-1;
- while ( fgets(line, 100, file) != NULL )
+ while(!file.eof())
{
- sscanf(line, "Chapter %d: Scene %d: numTry=%d passed=%d\n",
+ std::getline(file, line);
+ sscanf(line.c_str(), "Chapter %d: Scene %d: numTry=%d passed=%d\n",
&chap, &i, &numTry, &passed);
i += chap*100;
@@ -6065,7 +6069,7 @@ bool CMainDialog::ReadGamerInfo()
}
}
- fclose(file);
+ file.close();
return true;
}
@@ -6073,28 +6077,25 @@ bool CMainDialog::ReadGamerInfo()
bool CMainDialog::WriteGamerInfo()
{
- FILE* file;
- char line[100];
int i;
- sprintf(line, "%s/%s/%s.gam", GetSavegameDir().c_str(), m_main->GetGamerName(), m_sceneName);
- file = fopen(line, "w");
- if ( file == NULL ) return false;
+ COutputStream file;
+ file.open(GetPHYSFSSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
+ if(!file.is_open()) {
+ CLogger::GetInstancePointer()->Error("Unable to read list of finished missions\n");
+ return false;
+ }
- sprintf(line, "CurrentChapter=%d CurrentSel=%d\n",
- m_chap[m_index]+1, m_sel[m_index]+1);
- fputs(line, file);
+ file << "CurrentChapter=" << m_chap[m_index]+1 << " CurrentSel=" << m_sel[m_index]+1 << "\n";
for ( i=0 ; i<MAXSCENE ; i++ )
{
if ( m_sceneInfo[i].numTry == 0 && !m_sceneInfo[i].bPassed ) continue;
- sprintf(line, "Chapter %d: Scene %d: numTry=%d passed=%d\n",
- i/100, i%100, m_sceneInfo[i].numTry, m_sceneInfo[i].bPassed);
- fputs(line, file);
+ file << "Chapter " << i/100 << ": Scene " << i%100 << ": numTry=" << m_sceneInfo[i].numTry << " passed=1" << m_sceneInfo[i].bPassed << "\n";
}
- fclose(file);
+ file.close();
return true;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list