From: Matthias Braun Date: Tue, 27 Dec 2005 21:46:00 +0000 (+0000) Subject: create directory for savegames if it doesn't exist yet X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=607f0915105868a3d5d2d325d7bb028a9dd8b6b3;p=supertux.git create directory for savegames if it doesn't exist yet SVN-Revision: 2957 --- diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 97900ec0f..257cbc83d 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -1055,6 +1055,19 @@ WorldMap::savegame(const std::string& filename) if(filename == "") return; + std::string dir = FileSystem::dirname(filename); + if(PHYSFS_exists(dir.c_str()) == 0 && PHYSFS_mkdir(dir.c_str()) == 0) { + std::ostringstream msg; + msg << "Couldn't create directory '" << dir << "' for savegame:" + << PHYSFS_getLastError(); + throw std::runtime_error(msg.str()); + } + if(!PHYSFS_isDirectory(dir.c_str())) { + std::ostringstream msg; + msg << "'" << dir << "' is not a directory."; + throw std::runtime_error(msg.str()); + } + lisp::Writer writer(filename); int nb_solved_levels = 0, total_levels = 0;