From: Côme Chilliet Date: Fri, 6 Jan 2017 13:46:01 +0000 (+0100) Subject: Creating map saving folder if needed X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=7ed95b0f483ca64a550e391f8151d7ceb30acc18 Creating map saving folder if needed --- diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index b11e12a..f3ac22c 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -177,12 +177,18 @@ void ch_map(const char *args) void ch_save(const char *args) { - std::string map_path = Folders::getUserDataPath() + "/Maps/" + args; + std::string map_path = Folders::getUserDataPath() + "/Maps"; + Folders::makeDirectory(map_path); + map_path = map_path + "/" + args; int mapvers = 12; FILE *tfile; tfile = fopen( map_path.c_str(), "wb" ); + if (tfile == NULL) { + perror((std::string("Couldn't open file ") + map_path + " for saving").c_str()); + return; + } fpackf(tfile, "Bi", mapvers); fpackf(tfile, "Bi", maptype); fpackf(tfile, "Bi", hostile); diff --git a/Source/Utils/Folders.hpp b/Source/Utils/Folders.hpp index d812d10..2399506 100644 --- a/Source/Utils/Folders.hpp +++ b/Source/Utils/Folders.hpp @@ -30,7 +30,7 @@ along with Lugaru. If not, see . struct FileNotFoundException: public std::exception { std::string errorText; - + FileNotFoundException (const std::string& filename) : errorText(filename + " could not be found") {} @@ -66,10 +66,11 @@ public: static inline std::string getUserSavePath() { return getUserDataPath() + "/users"; } + static bool makeDirectory(const std::string& path); + private: static const char* getHomeDirectory(); static std::string getGenericDirectory(const char* ENVVAR, const std::string& fallback); - static bool makeDirectory(const std::string& path); }; #endif /* _FOLDERS_H_ */