all repos — mgba @ 08b0a7c60f9129c06314d2dc9de3eb6eadbb2b15

mGBA Game Boy Advance Emulator

VFS: Improve zip file detection
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Aug 2016 02:30:25 -0700
commit

08b0a7c60f9129c06314d2dc9de3eb6eadbb2b15

parent

59b4d22833281f2758be30b8cedea35338daff25

2 files changed, 20 insertions(+), 12 deletions(-)

jump to
M CHANGESCHANGES

@@ -73,6 +73,7 @@ - 3DS: Adjustable filering

- 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:
M src/util/vfs/vfs-zip.csrc/util/vfs/vfs-zip.c

@@ -5,6 +5,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/vfs.h" +#include "util/string.h" + #ifdef USE_LIBZIP #include <zip.h>

@@ -52,7 +54,7 @@ struct VDirZip {

struct VDir d; unzFile z; struct VDirEntryZip dirent; - bool hasNextFile; + bool atStart; }; struct VFileZip {

@@ -181,7 +183,7 @@ vd->d.deleteFile = _vdzDeleteFile;

vd->z = z; #ifndef USE_LIBZIP - vd->hasNextFile = true; + vd->atStart = true; #endif vd->dirent.d.name = _vdezName;

@@ -441,8 +443,10 @@ }

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 @@ }

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 @@ if (status < 0) {

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 @@ }

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