VFS: Improve zip file detection

This commit is contained in:
Jeffrey Pfau 2016-08-23 02:30:25 -07:00
parent 59b4d22833
commit 08b0a7c60f
2 changed files with 20 additions and 12 deletions

View File

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

View File

@ -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 <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 @@ 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,23 +573,24 @@ 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) {
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);
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 @@ 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