Explorar o código

Merge pull request #913 from dgough/next

Fixed opening absolute paths with the FileSystem class
Darryl Gough %!s(int64=12) %!d(string=hai) anos
pai
achega
6688025de7
Modificáronse 2 ficheiros con 34 adicións e 12 borrados
  1. 2 0
      gameplay/android/jni/Android.mk
  2. 32 12
      gameplay/src/FileSystem.cpp

+ 2 - 0
gameplay/android/jni/Android.mk

@@ -180,6 +180,7 @@ LOCAL_SRC_FILES := \
     lua/lua_Global.cpp \
     lua/lua_Global.cpp \
     lua/lua_HeightField.cpp \
     lua/lua_HeightField.cpp \
     lua/lua_Image.cpp \
     lua/lua_Image.cpp \
+    lua/lua_ImageControl.cpp \
     lua/lua_ImageFormat.cpp \
     lua/lua_ImageFormat.cpp \
     lua/lua_Joint.cpp \
     lua/lua_Joint.cpp \
     lua/lua_Joystick.cpp \
     lua/lua_Joystick.cpp \
@@ -262,6 +263,7 @@ LOCAL_SRC_FILES := \
     lua/lua_Technique.cpp \
     lua/lua_Technique.cpp \
     lua/lua_Terrain.cpp \
     lua/lua_Terrain.cpp \
     lua/lua_TerrainFlags.cpp \
     lua/lua_TerrainFlags.cpp \
+    lua/lua_TerrainListener.cpp \
     lua/lua_TextBox.cpp \
     lua/lua_TextBox.cpp \
     lua/lua_Texture.cpp \
     lua/lua_Texture.cpp \
     lua/lua_TextureFilter.cpp \
     lua/lua_TextureFilter.cpp \

+ 32 - 12
gameplay/src/FileSystem.cpp

@@ -86,6 +86,27 @@ static bool androidFileExists(const char* filePath)
 static std::string __resourcePath("./");
 static std::string __resourcePath("./");
 static std::map<std::string, std::string> __aliases;
 static std::map<std::string, std::string> __aliases;
 
 
+/**
+ * Gets the fully resolved path.
+ * If the path is relative then it will be prefixed with the resource path.
+ * Aliases will be converted to a relative path.
+ * 
+ * @param path The path to resolve.
+ * @param fullPath The full resolved path. (out param)
+ */
+static void getFullPath(const char* path, std::string& fullPath)
+{
+    if (FileSystem::isAbsolutePath(path))
+    {
+        fullPath.assign(path);
+    }
+    else
+    {
+        fullPath.assign(__resourcePath);
+        fullPath += FileSystem::resolvePath(path);
+    }
+}
+
 /**
 /**
  * 
  * 
  * @script{ignore}
  * @script{ignore}
@@ -297,13 +318,13 @@ bool FileSystem::fileExists(const char* filePath)
     }
     }
 #endif
 #endif
 
 
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(filePath);
+    std::string fullPath;
+    getFullPath(filePath, fullPath);
 
 
     gp_stat_struct s;
     gp_stat_struct s;
 
 
 #ifdef WIN32
 #ifdef WIN32
-    if (stat(fullPath.c_str(), &s) != 0)
+    if (!isAbsolutePath(filePath) && stat(fullPath.c_str(), &s) != 0)
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -352,12 +373,12 @@ Stream* FileSystem::open(const char* path, size_t mode)
         return FileStreamAndroid::create(resolvePath(path), modeStr);
         return FileStreamAndroid::create(resolvePath(path), modeStr);
     }
     }
 #else
 #else
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(path);
+    std::string fullPath;
+    getFullPath(path, fullPath);
     
     
 #ifdef WIN32
 #ifdef WIN32
     gp_stat_struct s;
     gp_stat_struct s;
-    if (stat(fullPath.c_str(), &s) != 0 && (mode & WRITE) == 0)
+    if (!isAbsolutePath(path) && stat(fullPath.c_str(), &s) != 0 && (mode & WRITE) == 0)
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -386,15 +407,15 @@ FILE* FileSystem::openFile(const char* filePath, const char* mode)
     GP_ASSERT(filePath);
     GP_ASSERT(filePath);
     GP_ASSERT(mode);
     GP_ASSERT(mode);
 
 
-    std::string fullPath(__resourcePath);
-    fullPath += resolvePath(filePath);
+    std::string fullPath;
+    getFullPath(filePath, fullPath);
 
 
     createFileFromAsset(filePath);
     createFileFromAsset(filePath);
     
     
     FILE* fp = fopen(fullPath.c_str(), mode);
     FILE* fp = fopen(fullPath.c_str(), mode);
     
     
 #ifdef WIN32
 #ifdef WIN32
-    if (fp == NULL)
+    if (fp == NULL && !isAbsolutePath(filePath))
     {
     {
         fullPath = __resourcePath;
         fullPath = __resourcePath;
         fullPath += "../../gameplay/";
         fullPath += "../../gameplay/";
@@ -452,11 +473,10 @@ bool FileSystem::isAbsolutePath(const char* filePath)
     if (filePath == 0 || filePath[0] == '\0')
     if (filePath == 0 || filePath[0] == '\0')
         return false;
         return false;
 #ifdef WIN32
 #ifdef WIN32
-    if (strlen(filePath) >= 2)
+    if (filePath[1] != '\0')
     {
     {
         char first = filePath[0];
         char first = filePath[0];
-        if (filePath[1] == ':' && ((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')))
-            return true;
+        return (filePath[1] == ':' && ((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z')));
     }
     }
     return false;
     return false;
 #else
 #else