From 8e52521e6d3aeceddf2ce048610b446ea57dee52 Mon Sep 17 00:00:00 2001 From: Kai Sterker Date: Fri, 25 Sep 2009 23:36:32 +0200 Subject: [PATCH] FIXED savegame handling and its Python wrapper --- src/base/savegame.cc | 39 ++++++++++++++++------------- src/py-wrappers/adonthell/py_base.i | 3 +++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/base/savegame.cc b/src/base/savegame.cc index 1ad1496..b75c807 100644 --- a/src/base/savegame.cc +++ b/src/base/savegame.cc @@ -139,16 +139,6 @@ bool savegame::save (const s_int32 & slot, const std::string & desc, const u_int return false; } -#ifdef WIN32 - if (mkdir (filepath.c_str())) -#else - if (mkdir (filepath.c_str(), 0700)) -#endif - { - fprintf (stderr, "*** savegame::save: failed to create directory\n %s\n", filepath.c_str ()); - return false; - } - // we'll need a new gamedata record data = new savegame_data (filepath, desc, gametime); Games.push_back (data); @@ -157,21 +147,22 @@ bool savegame::save (const s_int32 & slot, const std::string & desc, const u_int { // we have to update the gamedata record data->update (desc, gametime); - // and clean the directory before saving - cleanup (data->directory()); } + // prepare the directory before saving + cleanup (data->directory()); + // save game data u_int32 current = 1; u_int32 size = Serializer().size(); std::list::iterator i; for (i = Serializer().begin(); i != Serializer().end(); i++) { - // if (!(*i)->save (data->directory())) - // { + if (!(*i)->save (data->directory())) + { // TODO: cleanup - // return false; - // } + return false; + } if (ProgressCallback != NULL) { @@ -257,6 +248,17 @@ void savegame::cleanup (const std::string & name) closedir (dir); } + else + { +#ifdef WIN32 + if (mkdir (name.c_str())) +#else + if (mkdir (name.c_str(), 0700)) +#endif + { + fprintf (stderr, "*** savegame::save: failed to create directory\n %s\n", name.c_str ()); + } + } } // get game at given slot @@ -266,10 +268,10 @@ savegame_data *savegame::get (const s_int32 & slot) if (slot == NEW_SAVE) return NULL; s_int32 real_slot = slot + SPECIAL_SLOT_COUNT; - if (slot < 0 || slot >= count()) + if (real_slot < 0 || real_slot >= Games.size()) { fprintf (stderr, "*** savegame::get: slot %i out of range [%i, %i[\n", - slot, -SPECIAL_SLOT_COUNT, count()-SPECIAL_SLOT_COUNT); + slot, -SPECIAL_SLOT_COUNT, count()); return NULL; } @@ -335,3 +337,4 @@ std::list& savegame::Serializer () static std::list *Serializer = new std::list(); return *Serializer; } + diff --git a/src/py-wrappers/adonthell/py_base.i b/src/py-wrappers/adonthell/py_base.i index be6ff9b..0f32955 100644 --- a/src/py-wrappers/adonthell/py_base.i +++ b/src/py-wrappers/adonthell/py_base.i @@ -42,6 +42,7 @@ namespace base } else { + Load = NULL; fprintf (stderr, "*** serializer: '%s' has no method 'load'!\n", instance->ob_type->tp_name); } Py_XDECREF (load); @@ -128,6 +129,8 @@ namespace base { // typemap to let C++ have ownership of cfg_option* given to configuration::add_option () %typemap(in) cfg_option *value "if ((SWIG_ConvertPtr ($input, (void **) &$1, $1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) SWIG_fail;" + + %typemap(in) serializer_base *serializer "if ((SWIG_ConvertPtr ($input, (void **) &$1, $1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) SWIG_fail;" } // typemap for passing a FILE* from Python