]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Utils/Folders.cpp
Console: Return gracefully when loading missing level
[lugaru.git] / Source / Utils / Folders.cpp
index 21322c1596e192821765e8159811efa77f72a68a..3fa04025823b3502f4959ebc50e8a5fb83d6b57f 100644 (file)
@@ -117,11 +117,11 @@ const char* Folders::getHomeDirectory()
 bool Folders::makeDirectory(const std::string& path) {
 #ifdef _WIN32
     int status = CreateDirectory(path.c_str(), NULL);
-    return status != 0 || GetLastError() == ERROR_ALREADY_EXISTS;
+    return ((status != 0) || (GetLastError() == ERROR_ALREADY_EXISTS));
 #else
     errno = 0;
     int status = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
-    return status == 0 || errno == EEXIST;
+    return ((status == 0) || (errno == EEXIST));
 #endif
 }
 
@@ -133,3 +133,15 @@ FILE* Folders::openMandatoryFile(const std::string& filename, const char* mode)
     }
     return tfile;
 }
+
+bool Folders::file_exists(const std::string& filepath)
+{
+    FILE* file;
+    file = fopen(filepath.c_str(), "rb");
+    if (file == NULL) {
+        return false;
+    } else {
+        fclose(file);
+        return true;
+    }
+}