Add VFSFileSystem for Android to be able to mount flash0: inside the APK

This commit is contained in:
Henrik Rydgard 2013-02-26 23:07:30 +01:00
parent 17c8eb1ae7
commit 3f6353af5a
3 changed files with 24 additions and 1 deletions

View File

@ -167,6 +167,13 @@ bool getFileInfo(const char *path, FileInfo *fileInfo)
fileInfo->fullName = path;
#ifdef _WIN32
fileInfo->size = 0;
FILE *f = fopen(path, "rb");
if (f) {
fseek(f, 0, SEEK_END);
fileInfo->size = ftell(f);
fclose(f);
}
DWORD attributes = GetFileAttributes(path);
fileInfo->isDirectory = (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
fileInfo->isWritable = (attributes & FILE_ATTRIBUTE_READONLY) == 0;
@ -185,6 +192,7 @@ bool getFileInfo(const char *path, FileInfo *fileInfo)
fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
fileInfo->isWritable = false;
fileInfo->size = file_info.st_size;
// HACK: approximation
if (file_info.st_mode & 0200)
fileInfo->isWritable = true;

View File

@ -19,6 +19,7 @@ struct FileInfo
bool exists;
bool isDirectory;
bool isWritable;
size_t size;
bool operator <(const FileInfo &other) const {
if (isDirectory && !other.isDirectory)

View File

@ -77,7 +77,7 @@ ZipAssetReader::~ZipAssetReader() {
}
uint8_t *ZipAssetReader::ReadAsset(const char *path, size_t *size) {
char temp_path[256];
char temp_path[1024];
strcpy(temp_path, in_zip_path_);
strcat(temp_path, path);
return ReadFromZip(zip_file_, temp_path, size);
@ -142,10 +142,24 @@ bool ZipAssetReader::GetFileListing(const char *path, std::vector<FileInfo> *lis
bool ZipAssetReader::GetFileInfo(const char *path, FileInfo *info)
{
struct zip_stat zstat;
char temp_path[1024];
strcpy(temp_path, in_zip_path_);
strcat(temp_path, path);
if (0 != zip_stat(zip_file_, temp_path, ZIP_FL_NOCASE, &zstat))
{
ELOG("Failed doing zip_stat on %s, bailing", path);
info->exists = false;
info->size = 0;
return false;
}
info->fullName = path;
info->exists = true; // TODO
info->isWritable = false;
info->isDirectory = false; // TODO
info->size = zstat.size;
return true;
}
#endif