|
@@ -87,6 +87,7 @@ static bool androidFileExists(const char* filePath)
|
|
|
|
|
|
|
|
/** @script{ignore} */
|
|
/** @script{ignore} */
|
|
|
static std::string __resourcePath("./");
|
|
static std::string __resourcePath("./");
|
|
|
|
|
+static std::string __assetPath("");
|
|
|
static std::map<std::string, std::string> __aliases;
|
|
static std::map<std::string, std::string> __aliases;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -343,14 +344,18 @@ bool FileSystem::fileExists(const char* filePath)
|
|
|
{
|
|
{
|
|
|
GP_ASSERT(filePath);
|
|
GP_ASSERT(filePath);
|
|
|
|
|
|
|
|
|
|
+ std::string fullPath;
|
|
|
|
|
+
|
|
|
#ifdef __ANDROID__
|
|
#ifdef __ANDROID__
|
|
|
- if (androidFileExists(resolvePath(filePath)))
|
|
|
|
|
|
|
+ fullPath = __assetPath;
|
|
|
|
|
+ fullPath += resolvePath(filePath);
|
|
|
|
|
+
|
|
|
|
|
+ if (androidFileExists(fullPath.c_str()))
|
|
|
{
|
|
{
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- std::string fullPath;
|
|
|
|
|
getFullPath(filePath, fullPath);
|
|
getFullPath(filePath, fullPath);
|
|
|
|
|
|
|
|
gp_stat_struct s;
|
|
gp_stat_struct s;
|
|
@@ -364,17 +369,17 @@ Stream* FileSystem::open(const char* path, size_t streamMode)
|
|
|
if ((streamMode & WRITE) != 0)
|
|
if ((streamMode & WRITE) != 0)
|
|
|
modeStr[0] = 'w';
|
|
modeStr[0] = 'w';
|
|
|
#ifdef __ANDROID__
|
|
#ifdef __ANDROID__
|
|
|
|
|
+ std::string fullPath(__resourcePath);
|
|
|
|
|
+ fullPath += resolvePath(path);
|
|
|
|
|
+
|
|
|
if ((streamMode & WRITE) != 0)
|
|
if ((streamMode & WRITE) != 0)
|
|
|
{
|
|
{
|
|
|
// Open a file on the SD card
|
|
// Open a file on the SD card
|
|
|
- std::string fullPath(__resourcePath);
|
|
|
|
|
- fullPath += resolvePath(path);
|
|
|
|
|
-
|
|
|
|
|
size_t index = fullPath.rfind('/');
|
|
size_t index = fullPath.rfind('/');
|
|
|
if (index != std::string::npos)
|
|
if (index != std::string::npos)
|
|
|
{
|
|
{
|
|
|
std::string directoryPath = fullPath.substr(0, index);
|
|
std::string directoryPath = fullPath.substr(0, index);
|
|
|
- struct stat s;
|
|
|
|
|
|
|
+ gp_stat_struct s;
|
|
|
if (stat(directoryPath.c_str(), &s) != 0)
|
|
if (stat(directoryPath.c_str(), &s) != 0)
|
|
|
makepath(directoryPath, 0777);
|
|
makepath(directoryPath, 0777);
|
|
|
}
|
|
}
|
|
@@ -382,8 +387,19 @@ Stream* FileSystem::open(const char* path, size_t streamMode)
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- // Open a file in the read-only asset directory
|
|
|
|
|
- return FileStreamAndroid::create(resolvePath(path), modeStr);
|
|
|
|
|
|
|
+ // First try the SD card
|
|
|
|
|
+ Stream* stream = FileStream::create(fullPath.c_str(), modeStr);
|
|
|
|
|
+
|
|
|
|
|
+ if (!stream)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Otherwise fall-back to assets loaded via the AssetManager
|
|
|
|
|
+ fullPath = __assetPath;
|
|
|
|
|
+ fullPath += resolvePath(path);
|
|
|
|
|
+
|
|
|
|
|
+ stream = FileStreamAndroid::create(fullPath.c_str(), modeStr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return stream;
|
|
|
}
|
|
}
|
|
|
#else
|
|
#else
|
|
|
std::string fullPath;
|
|
std::string fullPath;
|
|
@@ -456,6 +472,16 @@ bool FileSystem::isAbsolutePath(const char* filePath)
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void FileSystem::setAssetPath(const char* path)
|
|
|
|
|
+{
|
|
|
|
|
+ __assetPath = path;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const char* FileSystem::getAssetPath()
|
|
|
|
|
+{
|
|
|
|
|
+ return __assetPath.c_str();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void FileSystem::createFileFromAsset(const char* path)
|
|
void FileSystem::createFileFromAsset(const char* path)
|
|
|
{
|
|
{
|
|
|
#ifdef __ANDROID__
|
|
#ifdef __ANDROID__
|