]> git.jsancho.org Git - lugaru.git/commitdiff
Creating map saving folder if needed
authorCôme Chilliet <come@chilliet.eu>
Fri, 6 Jan 2017 13:46:01 +0000 (14:46 +0100)
committerCôme Chilliet <come@chilliet.eu>
Fri, 6 Jan 2017 13:46:01 +0000 (14:46 +0100)
Source/Devtools/ConsoleCmds.cpp
Source/Utils/Folders.hpp

index b11e12a7fb528b2b43e9ac62bf56fe3572afa239..f3ac22c0fbeaf594f225d5191e5c43d38fdfc1a1 100644 (file)
@@ -177,12 +177,18 @@ void ch_map(const char *args)
 
 void ch_save(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" );
 
     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);
     fpackf(tfile, "Bi", mapvers);
     fpackf(tfile, "Bi", maptype);
     fpackf(tfile, "Bi", hostile);
index d812d10295db6fcc8b05785002e253d7306af48a..2399506cb7076efd8773fef434ad91dd1389ddbd 100644 (file)
@@ -30,7 +30,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 struct FileNotFoundException: public std::exception
 {
     std::string errorText;
 struct FileNotFoundException: public std::exception
 {
     std::string errorText;
-    
+
     FileNotFoundException (const std::string& filename)
     : errorText(filename + " could not be found")
     {}
     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 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);
 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_ */
 };
 
 #endif /* _FOLDERS_H_ */