Increased zip archive opening speed

This commit is contained in:
TheFloW 2016-08-24 20:13:06 +02:00
parent 68c2b07589
commit 69264e97b3
2 changed files with 23 additions and 25 deletions

View File

@ -184,7 +184,7 @@ int extractArchivePath(char *src, char *dst, uint32_t *value, uint32_t max, void
entry = entry->next;
}
fileListEmpty(&list);
} else {
SceUID fdsrc = archiveFileOpen(src, SCE_O_RDONLY, 0);
@ -249,8 +249,12 @@ int archiveFileGetstat(const char *file, SceIoStat *stat) {
for (i = 0; i < archive_list.length; i++) {
if (archive_entry->name_length == name_length && strcmp(archive_entry->name, archive_path) == 0) {
if (stat) {
// TODO: more stat
//stat->st_mode =
//stat->st_attr =
stat->st_size = archive_entry->size;
memcpy(&stat->st_ctime, &archive_entry->time, sizeof(SceDateTime));
memcpy(&stat->st_atime, &archive_entry->time, sizeof(SceDateTime));
memcpy(&stat->st_mtime, &archive_entry->time, sizeof(SceDateTime));
}
return 0;
@ -280,11 +284,7 @@ int archiveFileOpen(const char *file, int flags, SceMode mode) {
// Set pos
unzGoToFilePos64(uf, (unz64_file_pos *)&archive_entry->reserved);
// File info
char name[MAX_PATH_LENGTH];
unz_file_info64 file_info;
unzGetCurrentFileInfo64(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
// Open
res = unzOpenCurrentFile(uf);
if (res < 0)
return res;
@ -335,10 +335,7 @@ int archiveClose() {
return 0;
}
// TODO: improve this, it's slow...
int archiveOpen(char *file) {
int res;
// Start position of the archive path
archive_path_start = strlen(file) + 1;
@ -351,22 +348,23 @@ int archiveOpen(char *file) {
if (!uf)
return -1;
// Go to first entry
res = unzGoToFirstFile(uf);
if (res < 0)
return res;
// Clear archive list
memset(&archive_list, 0, sizeof(FileList));
// Go through all files
do {
int res;
char name[MAX_PATH_LENGTH];
unz_file_info64 file_info;
res = unzGoToFirstFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
if (res < 0)
return res;
while (res >= 0) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
// File info
unz_file_info64 file_info;
unzGetCurrentFileInfo64(uf, &file_info, entry->name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
strcpy(entry->name, name);
entry->is_folder = 0;
entry->name_length = file_info.size_filename;
entry->size = file_info.uncompressed_size;
@ -379,8 +377,8 @@ int archiveOpen(char *file) {
fileListAddEntry(&archive_list, entry, SORT_BY_NAME_AND_FOLDER);
// Next
res = unzGoToNextFile(uf);
} while (res >= 0);
res = unzGoToNextFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0);
}
return 0;
}

View File

@ -80,7 +80,7 @@ static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPO
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
typedef struct
typedef struct
{
SceUID fd;
int error;
@ -120,7 +120,7 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in
fd = sceIoOpen(filename, mode_fopen, 0777);
return file_build_ioposix(fd, filename);
}
return NULL;
}
@ -298,7 +298,7 @@ void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = fopen_file_func;
pzlib_filefunc_def->zopen64_file = (void (*))fopen_file_func;
pzlib_filefunc_def->zopendisk64_file = fopendisk_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
@ -307,4 +307,4 @@ void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}
}