|
|
@@ -86,6 +86,27 @@ static bool androidFileExists(const char* filePath)
|
|
|
static std::string __resourcePath("./");
|
|
|
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}
|
|
|
@@ -297,13 +318,13 @@ bool FileSystem::fileExists(const char* filePath)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- std::string fullPath(__resourcePath);
|
|
|
- fullPath += resolvePath(filePath);
|
|
|
+ std::string fullPath;
|
|
|
+ getFullPath(filePath, fullPath);
|
|
|
|
|
|
gp_stat_struct s;
|
|
|
|
|
|
#ifdef WIN32
|
|
|
- if (stat(fullPath.c_str(), &s) != 0)
|
|
|
+ if (!isAbsolutePath(filePath) && stat(fullPath.c_str(), &s) != 0)
|
|
|
{
|
|
|
fullPath = __resourcePath;
|
|
|
fullPath += "../../gameplay/";
|
|
|
@@ -352,12 +373,12 @@ Stream* FileSystem::open(const char* path, size_t mode)
|
|
|
return FileStreamAndroid::create(resolvePath(path), modeStr);
|
|
|
}
|
|
|
#else
|
|
|
- std::string fullPath(__resourcePath);
|
|
|
- fullPath += resolvePath(path);
|
|
|
+ std::string fullPath;
|
|
|
+ getFullPath(path, fullPath);
|
|
|
|
|
|
#ifdef WIN32
|
|
|
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 += "../../gameplay/";
|
|
|
@@ -386,15 +407,15 @@ FILE* FileSystem::openFile(const char* filePath, const char* mode)
|
|
|
GP_ASSERT(filePath);
|
|
|
GP_ASSERT(mode);
|
|
|
|
|
|
- std::string fullPath(__resourcePath);
|
|
|
- fullPath += resolvePath(filePath);
|
|
|
+ std::string fullPath;
|
|
|
+ getFullPath(filePath, fullPath);
|
|
|
|
|
|
createFileFromAsset(filePath);
|
|
|
|
|
|
FILE* fp = fopen(fullPath.c_str(), mode);
|
|
|
|
|
|
#ifdef WIN32
|
|
|
- if (fp == NULL)
|
|
|
+ if (fp == NULL && !isAbsolutePath(filePath))
|
|
|
{
|
|
|
fullPath = __resourcePath;
|
|
|
fullPath += "../../gameplay/";
|
|
|
@@ -452,11 +473,10 @@ bool FileSystem::isAbsolutePath(const char* filePath)
|
|
|
if (filePath == 0 || filePath[0] == '\0')
|
|
|
return false;
|
|
|
#ifdef WIN32
|
|
|
- if (strlen(filePath) >= 2)
|
|
|
+ if (filePath[1] != '\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;
|
|
|
#else
|