From 7ed95b0f483ca64a550e391f8151d7ceb30acc18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Fri, 6 Jan 2017 14:46:01 +0100 Subject: [PATCH] Creating map saving folder if needed --- Source/Devtools/ConsoleCmds.cpp | 8 +++++++- Source/Utils/Folders.hpp | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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_ */ -- 2.39.5