[colobot] 190/390: Research saving (for free game) in 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 025419324b4da1e42b03f00f6344eaa285681a36
Author: krzys-h <krzys_h at interia.pl>
Date:   Mon Nov 10 18:49:00 2014 +0100

    Research saving (for free game) in PHYSFS
---
 src/object/robotmain.cpp | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

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

-- 
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