[colobot] 189/390: Removed PHYSFS hacks from Load/SaveFileScript as they are no longer necessary

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 169e8602406bf3e2c364d0deae46af9257fe71c7
Author: krzys-h <krzys_h at interia.pl>
Date:   Mon Nov 10 18:34:29 2014 +0100

    Removed PHYSFS hacks from Load/SaveFileScript as they are no longer necessary
---
 src/object/robotmain.cpp | 54 +++++++++---------------------------------------
 1 file changed, 10 insertions(+), 44 deletions(-)

diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index a5dd6ca..379ec75 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -5336,23 +5336,6 @@ void CRobotMain::FrameShowLimit(float rTime)
 }
 
 
-
-//! Returns a pointer to the last slash in a filename.
-char* SearchLastDir(char *filename)
-{
-    char* p = filename;
-
-    while (*p++ != 0);
-    p --;  // ^on the zero terminator
-
-    while (p != filename)
-    {
-        if (*(--p) == '/' || *p == '\\') return p;
-    }
-    return 0;
-}
-
-
 //! Compiles all scripts of robots
 void CRobotMain::CompileScript(bool soluce)
 {
@@ -5473,23 +5456,13 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank,
     ObjectType type = obj->GetType();
     if (type == OBJECT_HUMAN) return;
 
+    std::string dirname = filename;
+    dirname = dirname.substr(0, dirname.find_last_of("/"));
     
-    std::string fnstr = filename;
-    std::string savedir = CResourceManager::GetSaveLocation()+"/";
-    boost::replace_all(fnstr, "\\", "/");
-    boost::replace_all(savedir, "\\", "/");
-    boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
-    //TODO: Refactor to std::string
-    char fn[MAX_FNAME];
-    strcpy(fn, fnstr.c_str());
-    char* ldir = SearchLastDir(fn);
-    if (ldir == 0) return;
-
+    char fn[MAX_FNAME]; //TODO: Refactor to std::string
     for (int i = 0; i < BRAINMAXSCRIPT; i++)
     {
-        if (brain->GetCompile(i)) continue;
-
-        sprintf(ldir, "/prog%.3d%.1d.txt", objRank, i);
+        sprintf(fn, "%s/prog%.3d%.1d.txt", dirname.c_str(), objRank, i);
         brain->ReadProgram(i, fn);
         if (!brain->GetCompile(i)) nbError++;
     }
@@ -5547,21 +5520,14 @@ void CRobotMain::SaveFileScript(CObject *obj, const char* filename, int objRank)
 
     ObjectType type = obj->GetType();
     if (type == OBJECT_HUMAN) return;
-
-    std::string fnstr = filename;
-    std::string savedir = CResourceManager::GetSaveLocation()+"/";
-    boost::replace_all(fnstr, "\\", "/");
-    boost::replace_all(savedir, "\\", "/");
-    boost::replace_all(fnstr, savedir, ""); //TODO: Refactor to get physfs path here
-    //TODO: Refactor to std::string
-    char fn[MAX_FNAME];
-    strcpy(fn, fnstr.c_str());
-    char* ldir = SearchLastDir(fn);
-    if (ldir == 0) return;
-
+    
+    std::string dirname = filename;
+    dirname = dirname.substr(0, dirname.find_last_of("/"));
+    
+    char fn[MAX_FNAME]; //TODO: Refactor to std::string
     for (int i = 0; i < BRAINMAXSCRIPT; i++)
     {
-        sprintf(ldir, "/prog%.3d%.1d.txt", objRank, i);
+        sprintf(fn, "%s/prog%.3d%.1d.txt", dirname.c_str(), objRank, i);
         brain->WriteProgram(i, fn);
     }
 }

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