diff --git a/CHANGES b/CHANGES index 96b44e8bd..156f16a65 100644 --- a/CHANGES +++ b/CHANGES @@ -73,6 +73,7 @@ Misc: - PSP2: Screenshots are now saved into the Photo Gallery - Qt: Make reseting when pasued frame-accurate - GBA Video: Optimize compositing cases slightly + - VFS: Improve zip file detection 0.4.1: (2016-07-11) Bugfixes: diff --git a/src/util/vfs/vfs-zip.c b/src/util/vfs/vfs-zip.c index e06ae7b8e..945f33eec 100644 --- a/src/util/vfs/vfs-zip.c +++ b/src/util/vfs/vfs-zip.c @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/vfs.h" +#include "util/string.h" + #ifdef USE_LIBZIP #include @@ -52,7 +54,7 @@ struct VDirZip { struct VDir d; unzFile z; struct VDirEntryZip dirent; - bool hasNextFile; + bool atStart; }; struct VFileZip { @@ -181,7 +183,7 @@ struct VDir* VDirOpenZip(const char* path, int flags) { vd->z = z; #ifndef USE_LIBZIP - vd->hasNextFile = true; + vd->atStart = true; #endif vd->dirent.d.name = _vdezName; @@ -441,8 +443,10 @@ const char* _vdezName(struct VDirEntry* vde) { static enum VFSType _vdezType(struct VDirEntry* vde) { struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde; - UNUSED(vdez); - return VFS_UNKNOWN; + if (endswith(vde->name(vde), "/")) { + return VFS_DIRECTORY; + } + return VFS_FILE; } #else bool _vfzClose(struct VFile* vf) { @@ -569,13 +573,17 @@ bool _vdzClose(struct VDir* vd) { void _vdzRewind(struct VDir* vd) { struct VDirZip* vdz = (struct VDirZip*) vd; - vdz->hasNextFile = unzGoToFirstFile(vdz->z) == UNZ_OK; + vdz->atStart = unzGoToFirstFile(vdz->z) == UNZ_OK; } struct VDirEntry* _vdzListNext(struct VDir* vd) { struct VDirZip* vdz = (struct VDirZip*) vd; - if (!vdz->hasNextFile) { - return 0; + if (!vdz->atStart) { + if (unzGoToNextFile(vdz->z) == UNZ_END_OF_LIST_OF_FILE) { + return 0; + } + } else { + vdz->atStart = false; } unz_file_info64 info; int status = unzGetCurrentFileInfo64(vdz->z, &info, vdz->dirent.name, sizeof(vdz->dirent.name), 0, 0, 0, 0); @@ -583,9 +591,6 @@ struct VDirEntry* _vdzListNext(struct VDir* vd) { return 0; } vdz->dirent.fileSize = info.uncompressed_size; - if (unzGoToNextFile(vdz->z) == UNZ_END_OF_LIST_OF_FILE) { - vdz->hasNextFile = false; - } return &vdz->dirent.d; } @@ -658,7 +663,9 @@ const char* _vdezName(struct VDirEntry* vde) { static enum VFSType _vdezType(struct VDirEntry* vde) { struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde; - UNUSED(vdez); - return VFS_UNKNOWN; + if (endswith(vdez->name, "/")) { + return VFS_DIRECTORY; + } + return VFS_FILE; } #endif