]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Devtools/ConsoleCmds.cpp
Creating map saving folder if needed
[lugaru.git] / Source / Devtools / ConsoleCmds.cpp
index b9aabcc4dd812757d221d5272bf7deed4c9259d4..f3ac22c0fbeaf594f225d5191e5c43d38fdfc1a1 100644 (file)
@@ -163,19 +163,32 @@ void ch_quit(const char *)
 
 void ch_map(const char *args)
 {
-    Loadlevel(args);
+    if (!LoadLevel(args)) {
+        // FIXME: Reduce code duplication with GameTick (should come from a Console class)
+        for (int k = 14; k >= 1; k--) {
+            consoletext[k] = consoletext[k - 1];
+        }
+        consoletext[0] = std::string("Could not load the requested level '") + args + "', aborting.";
+        consoleselected = 0;
+    }
     whichlevel = -2;
     campaign = 0;
 }
 
 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);