]> git.lizzy.rs Git - minetest.git/blobdiff - src/porting.cpp
Tune generation responsiveness and cheat inhibition on server
[minetest.git] / src / porting.cpp
index f2ca601eb3098ad0d0a4dec210249b91c112a697..17d71a33e944f7ace885fb7a28f9f727311bfde4 100644 (file)
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "debug.h"
 #include "filesys.h"
 #include "log.h"
+#include "utility_string.h"
 
 #ifdef __APPLE__
        #include "CoreFoundation/CoreFoundation.h"
@@ -123,8 +124,9 @@ void signal_handler_init(void)
        Path mangler
 */
 
-std::string path_share = ".." DIR_DELIM "share";
-std::string path_user = ".." DIR_DELIM "user";
+// Default to RUN_IN_PLACE style relative paths
+std::string path_share = "..";
+std::string path_user = "..";
 
 std::string getDataPath(const char *subpath)
 {
@@ -143,6 +145,13 @@ void pathRemoveFile(char *path, char delim)
        path[i] = 0;
 }
 
+bool detectMSVCBuildDir(char *c_path)
+{
+       std::string path(c_path);
+       const char *ends[] = {"bin\\Release", "bin\\Build", NULL};
+       return (removeStringEnd(path, ends) != "");
+}
+
 void initializePaths()
 {
 #ifdef RUN_IN_PLACE
@@ -166,9 +175,16 @@ void initializePaths()
        len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
        assert(len < buflen);
        pathRemoveFile(buf, '\\');
-
-       path_share = std::string(buf) + "\\..\\share";
-       path_user = std::string(buf) + "\\..\\user";
+       
+       if(detectMSVCBuildDir(buf)){
+               infostream<<"MSVC build directory detected"<<std::endl;
+               path_share = std::string(buf) + "\\..\\..";
+               path_user = std::string(buf) + "\\..\\..";
+       }
+       else{
+               path_share = std::string(buf) + "\\..";
+               path_user = std::string(buf) + "\\..";
+       }
 
        /*
                Linux
@@ -183,8 +199,8 @@ void initializePaths()
        
        pathRemoveFile(buf, '/');
 
-       path_share = std::string(buf) + "/../share";
-       path_user = std::string(buf) + "/../user";
+       path_share = std::string(buf) + "/..";
+       path_user = std::string(buf) + "/..";
        
        /*
                OS X
@@ -194,8 +210,8 @@ void initializePaths()
        //TODO: Get path of executable. This assumes working directory is bin/
        dstream<<"WARNING: Relative path not properly supported on OS X and FreeBSD"
                        <<std::endl;
-       path_share = std::string("../share");
-       path_user = std::string("../user");
+       path_share = std::string("..");
+       path_user = std::string("..");
 
        #endif
 
@@ -222,8 +238,8 @@ void initializePaths()
        assert(len < buflen);
        pathRemoveFile(buf, '\\');
        
-       // Use ".\bin\..\share"
-       path_share = std::string(buf) + "\\..\\share";
+       // Use ".\bin\.."
+       path_share = std::string(buf) + "\\..";
                
        // Use "C:\Documents and Settings\user\Application Data\<PROJECT_NAME>"
        len = GetEnvironmentVariable("APPDATA", buf, buflen);
@@ -246,9 +262,9 @@ void initializePaths()
        path_share = std::string(buf) + "/../share/" + PROJECT_NAME;
        //path_share = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME;
        if (!fs::PathExists(path_share)) {
-               dstream<<"WARNING: data path " << path_share << " not found!";
-               path_share = std::string(buf) + "/../data";
-               dstream<<" Trying " << path_share << std::endl;
+               dstream<<"WARNING: system-wide share not found at \""<<path_share<<"\"";
+               path_share = std::string(buf) + "/..";
+               dstream<<"WARNING: Using \""<<path_share<<"\" instead."<<std::endl;
        }
        
        path_user = std::string(getenv("HOME")) + "/." + PROJECT_NAME;