From 3f6353af5afe1542a50c33eb0bb554ea25653258 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 26 Feb 2013 23:07:30 +0100 Subject: [PATCH] Add VFSFileSystem for Android to be able to mount flash0: inside the APK --- file/file_util.cpp | 8 ++++++++ file/file_util.h | 1 + file/zip_read.cpp | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/file/file_util.cpp b/file/file_util.cpp index db169e3245..25ad3eb741 100644 --- a/file/file_util.cpp +++ b/file/file_util.cpp @@ -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; diff --git a/file/file_util.h b/file/file_util.h index 5a118b457c..b17a804d07 100644 --- a/file/file_util.h +++ b/file/file_util.h @@ -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) diff --git a/file/zip_read.cpp b/file/zip_read.cpp index fc2460e8ff..70880f1032 100644 --- a/file/zip_read.cpp +++ b/file/zip_read.cpp @@ -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 *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