mirror of https://github.com/mgba-emu/mgba.git
VFS: Improve zip file detection
This commit is contained in:
parent
59b4d22833
commit
08b0a7c60f
1
CHANGES
1
CHANGES
|
@ -73,6 +73,7 @@ Misc:
|
||||||
- PSP2: Screenshots are now saved into the Photo Gallery
|
- PSP2: Screenshots are now saved into the Photo Gallery
|
||||||
- Qt: Make reseting when pasued frame-accurate
|
- Qt: Make reseting when pasued frame-accurate
|
||||||
- GBA Video: Optimize compositing cases slightly
|
- GBA Video: Optimize compositing cases slightly
|
||||||
|
- VFS: Improve zip file detection
|
||||||
|
|
||||||
0.4.1: (2016-07-11)
|
0.4.1: (2016-07-11)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "util/vfs.h"
|
#include "util/vfs.h"
|
||||||
|
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
#ifdef USE_LIBZIP
|
#ifdef USE_LIBZIP
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ struct VDirZip {
|
||||||
struct VDir d;
|
struct VDir d;
|
||||||
unzFile z;
|
unzFile z;
|
||||||
struct VDirEntryZip dirent;
|
struct VDirEntryZip dirent;
|
||||||
bool hasNextFile;
|
bool atStart;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VFileZip {
|
struct VFileZip {
|
||||||
|
@ -181,7 +183,7 @@ struct VDir* VDirOpenZip(const char* path, int flags) {
|
||||||
vd->z = z;
|
vd->z = z;
|
||||||
|
|
||||||
#ifndef USE_LIBZIP
|
#ifndef USE_LIBZIP
|
||||||
vd->hasNextFile = true;
|
vd->atStart = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vd->dirent.d.name = _vdezName;
|
vd->dirent.d.name = _vdezName;
|
||||||
|
@ -441,8 +443,10 @@ const char* _vdezName(struct VDirEntry* vde) {
|
||||||
|
|
||||||
static enum VFSType _vdezType(struct VDirEntry* vde) {
|
static enum VFSType _vdezType(struct VDirEntry* vde) {
|
||||||
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
||||||
UNUSED(vdez);
|
if (endswith(vde->name(vde), "/")) {
|
||||||
return VFS_UNKNOWN;
|
return VFS_DIRECTORY;
|
||||||
|
}
|
||||||
|
return VFS_FILE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bool _vfzClose(struct VFile* vf) {
|
bool _vfzClose(struct VFile* vf) {
|
||||||
|
@ -569,23 +573,24 @@ bool _vdzClose(struct VDir* vd) {
|
||||||
|
|
||||||
void _vdzRewind(struct VDir* vd) {
|
void _vdzRewind(struct VDir* vd) {
|
||||||
struct VDirZip* vdz = (struct VDirZip*) 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 VDirEntry* _vdzListNext(struct VDir* vd) {
|
||||||
struct VDirZip* vdz = (struct VDirZip*) 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vdz->atStart = false;
|
||||||
|
}
|
||||||
unz_file_info64 info;
|
unz_file_info64 info;
|
||||||
int status = unzGetCurrentFileInfo64(vdz->z, &info, vdz->dirent.name, sizeof(vdz->dirent.name), 0, 0, 0, 0);
|
int status = unzGetCurrentFileInfo64(vdz->z, &info, vdz->dirent.name, sizeof(vdz->dirent.name), 0, 0, 0, 0);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
vdz->dirent.fileSize = info.uncompressed_size;
|
vdz->dirent.fileSize = info.uncompressed_size;
|
||||||
if (unzGoToNextFile(vdz->z) == UNZ_END_OF_LIST_OF_FILE) {
|
|
||||||
vdz->hasNextFile = false;
|
|
||||||
}
|
|
||||||
return &vdz->dirent.d;
|
return &vdz->dirent.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +663,9 @@ const char* _vdezName(struct VDirEntry* vde) {
|
||||||
|
|
||||||
static enum VFSType _vdezType(struct VDirEntry* vde) {
|
static enum VFSType _vdezType(struct VDirEntry* vde) {
|
||||||
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
||||||
UNUSED(vdez);
|
if (endswith(vdez->name, "/")) {
|
||||||
return VFS_UNKNOWN;
|
return VFS_DIRECTORY;
|
||||||
|
}
|
||||||
|
return VFS_FILE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue