Research saving (for free game) in PHYSFS

dev-mp
krzys-h 2014-11-10 18:49:00 +01:00
parent 169e860240
commit 025419324b
1 changed files with 27 additions and 17 deletions

View File

@ -34,6 +34,7 @@
#include "common/resources/resourcemanager.h" #include "common/resources/resourcemanager.h"
#include "common/resources/inputstream.h" #include "common/resources/inputstream.h"
#include "common/resources/outputstream.h"
#include "graphics/engine/camera.h" #include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h" #include "graphics/engine/cloud.h"
@ -6006,15 +6007,17 @@ void CRobotMain::WriteFreeParam()
if (m_gamerName == "") return; if (m_gamerName == "") return;
char filename[MAX_FNAME]; COutputStream file;
sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); file.open(std::string(GetPHYSFSSavegameDir())+"/"+m_gamerName+"/research.gam");
FILE* file = fopen(filename, "w"); if(!file.is_open())
if (file == NULL) return; {
CLogger::GetInstancePointer()->Error("Unable to write free game unlock state\n");
return;
}
char line[100]; file << "research=" << m_freeResearch << " build=" << m_freeBuild << "\n";
sprintf(line, "research=%d build=%d\n", m_freeResearch, m_freeBuild);
fputs(line, file); file.close();
fclose(file);
} }
//! Reads the global parameters for free play //! Reads the global parameters for free play
@ -6025,16 +6028,23 @@ void CRobotMain::ReadFreeParam()
if (m_gamerName == "") return; if (m_gamerName == "") return;
char filename[MAX_FNAME]; if(!CResourceManager::Exists(std::string(GetPHYSFSSavegameDir())+"/"+m_gamerName+"/research.gam"))
sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); return;
FILE* file = fopen(filename, "r");
if (file == NULL) return;
char line[100]; CInputStream file;
if (fgets(line, 100, file) != NULL) file.open(std::string(GetPHYSFSSavegameDir())+"/"+m_gamerName+"/research.gam");
sscanf(line, "research=%d build=%d\n", &m_freeResearch, &m_freeBuild); if(!file.is_open())
{
CLogger::GetInstancePointer()->Error("Unable to read free game unlock state\n");
return;
}
fclose(file); std::string line;
file >> line;
sscanf(line.c_str(), "research=%d build=%d\n", &m_freeResearch, &m_freeBuild);
file.close();
} }