(Task database) Start using zlib_parse_file_iterate in task_database.c

This commit is contained in:
twinaphex 2015-05-27 01:36:15 +02:00
parent 3d924a7556
commit aa56b8e1e3
4 changed files with 47 additions and 22 deletions

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
#include <file/file_extract.h>
#include "libretro-db/libretrodb.h"
#include "playlist.h"
@ -42,6 +43,7 @@ enum database_type
{
DATABASE_TYPE_NONE = 0,
DATABASE_TYPE_ITERATE,
DATABASE_TYPE_ITERATE_ZIP,
DATABASE_TYPE_CRC_LOOKUP,
};
@ -51,6 +53,9 @@ typedef struct
enum database_type type;
size_t list_ptr;
struct string_list *list;
#ifdef HAVE_ZLIB
zlib_transfer_t state;
#endif
} database_info_handle_t;
typedef struct

View File

@ -479,25 +479,6 @@ end:
return ret;
}
enum zlib_transfer_type
{
ZLIB_TRANSFER_NONE = 0,
ZLIB_TRANSFER_INIT,
ZLIB_TRANSFER_ITERATE,
ZLIB_TRANSFER_DEINIT,
ZLIB_TRANSFER_DEINIT_ERROR,
};
typedef struct zlib_transfer
{
void *handle;
const uint8_t *footer;
const uint8_t *directory;
const uint8_t *data;
ssize_t zip_size;
enum zlib_transfer_type type;
const struct zlib_file_backend *backend;
} zlib_transfer_t;
int zlib_parse_file_iterate_step_internal(
zlib_transfer_t *state, char *filename,

View File

@ -34,6 +34,26 @@ typedef struct zlib_handle
uint32_t real_checksum;
} zlib_file_handle_t;
enum zlib_transfer_type
{
ZLIB_TRANSFER_NONE = 0,
ZLIB_TRANSFER_INIT,
ZLIB_TRANSFER_ITERATE,
ZLIB_TRANSFER_DEINIT,
ZLIB_TRANSFER_DEINIT_ERROR,
};
typedef struct zlib_transfer
{
void *handle;
const uint8_t *footer;
const uint8_t *directory;
const uint8_t *data;
int32_t zip_size;
enum zlib_transfer_type type;
const struct zlib_file_backend *backend;
} zlib_transfer_t;
/* Returns true when parsing should continue. False to stop. */
typedef int (*zlib_file_cb)(const char *name, const char *valid_exts,
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,

View File

@ -68,9 +68,11 @@ static int database_info_iterate_playlist(
if (!strcmp(path_get_extension(name), "zip"))
{
#ifdef HAVE_ZLIB
if (!zlib_parse_file(name, NULL, zlib_compare_crc32,
(void*)db_state))
RARCH_LOG("Could not process ZIP file.\n");
db->type = DATABASE_TYPE_ITERATE_ZIP;
memset(&db->state, 0, sizeof(zlib_transfer_t));
db->state.type = ZLIB_TRANSFER_INIT;
return 1;
#endif
}
else
@ -92,6 +94,21 @@ static int database_info_iterate_playlist(
return 0;
}
static int database_info_iterate_playlist_zip(
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
bool returnerr = true;
#ifdef HAVE_ZLIB
if (zlib_parse_file_iterate(&db->state,
&returnerr, name, NULL, zlib_compare_crc32,
(void*)db_state) != 0)
return 0;
#endif
return 1;
}
static int database_info_iterate_next(database_info_handle_t *db)
{
db->list_ptr++;
@ -247,6 +264,8 @@ static int database_info_iterate(database_state_handle_t *state, database_info_h
break;
case DATABASE_TYPE_ITERATE:
return database_info_iterate_playlist(state, db, name);
case DATABASE_TYPE_ITERATE_ZIP:
return database_info_iterate_playlist_zip(state, db, name);
case DATABASE_TYPE_CRC_LOOKUP:
return database_info_iterate_crc_lookup(state, db);
}