(tasks) Use hashes

This commit is contained in:
twinaphex 2015-06-14 17:11:48 +02:00
parent 25372dfb56
commit a86977de3a
3 changed files with 51 additions and 26 deletions

View File

@ -28,6 +28,8 @@
#define CB_DB_SCAN_FILE 0x70ce56d2U
#define CB_DB_SCAN_FOLDER 0xde2bef8eU
#define HASH_EXTENSION_ZIP 0x0b88c7d8U
#ifdef HAVE_LIBRETRODB
#ifdef HAVE_ZLIB
@ -78,35 +80,40 @@ static int database_info_iterate_playlist(
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
uint32_t extension_hash = 0;
char parent_dir[PATH_MAX_LENGTH] = {0};
path_parent_dir(parent_dir);
if (!strcmp(path_get_extension(name), "zip"))
extension_hash = djb2_calculate(path_get_extension(name));
switch (extension_hash)
{
case HASH_EXTENSION_ZIP:
#ifdef HAVE_ZLIB
db->type = DATABASE_TYPE_ITERATE_ZIP;
memset(&db->state, 0, sizeof(zlib_transfer_t));
db_state->zip_name[0] = '\0';
db->state.type = ZLIB_TRANSFER_INIT;
db->type = DATABASE_TYPE_ITERATE_ZIP;
memset(&db->state, 0, sizeof(zlib_transfer_t));
db_state->zip_name[0] = '\0';
db->state.type = ZLIB_TRANSFER_INIT;
return 1;
return 1;
#endif
}
else
{
ssize_t ret;
int read_from = read_file(name, (void**)&db_state->buf, &ret);
default:
{
ssize_t ret;
int read_from = read_file(name, (void**)&db_state->buf, &ret);
if (read_from != 1 || ret <= 0)
return 0;
if (read_from != 1 || ret <= 0)
return 0;
#ifdef HAVE_ZLIB
db_state->crc = zlib_crc32_calculate(db_state->buf, ret);
db_state->crc = zlib_crc32_calculate(db_state->buf, ret);
#endif
db->type = DATABASE_TYPE_CRC_LOOKUP;
return 1;
db->type = DATABASE_TYPE_CRC_LOOKUP;
return 1;
}
break;
}
return 0;

View File

@ -15,14 +15,18 @@
#include <string.h>
#include <compat/strl.h>
#include <retro_miscellaneous.h>
#include <queues/message_queue.h>
#include <string/string_list.h>
#include <compat/strl.h>
#include <rhash.h>
#include "../runloop_data.h"
#include "tasks.h"
#define CB_MENU_WALLPAPER 0xb476e505U
#define CB_MENU_BOXART 0x68b307cdU
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
@ -386,7 +390,7 @@ static int cb_nbio_image_menu_boxart(void *data, size_t len)
static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
{
char elem0[PATH_MAX_LENGTH] = {0};
char elem1[PATH_MAX_LENGTH] = {0};
uint32_t cb_type_hash = 0;
struct nbio_t* handle = NULL;
struct string_list *str_list = NULL;
const char *path = NULL;
@ -411,7 +415,7 @@ static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
if (str_list->size > 0)
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
if (str_list->size > 1)
strlcpy(elem1, str_list->elems[1].data, sizeof(elem1));
cb_type_hash = djb2_calculate(str_list->elems[1].data);
handle = nbio_open(elem0, NBIO_READ);
@ -425,13 +429,15 @@ static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
nbio->is_finished = false;
nbio->cb = &cb_nbio_default;
if (elem1[0] != '\0')
switch (cb_type_hash)
{
#if defined(HAVE_MENU) && defined(HAVE_RPNG)
if (!strcmp(elem1, "cb_menu_wallpaper"))
case CB_MENU_WALLPAPER:
nbio->cb = &cb_nbio_image_menu_wallpaper;
else if (!strcmp(elem1, "cb_menu_boxart"))
break;
case CB_MENU_BOXART:
nbio->cb = &cb_nbio_image_menu_boxart;
break;
#endif
}

View File

@ -19,12 +19,16 @@
#include <string/string_list.h>
#include <compat/strl.h>
#include <file/file_path.h>
#include <rhash.h>
#include "../file_ops.h"
#include "../general.h"
#include "../runloop_data.h"
#include "tasks.h"
#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU
#define CB_CORE_UPDATER_LIST 0x32fd4f01U
extern char core_updater_path[PATH_MAX_LENGTH];
int cb_core_updater_list(void *data_, size_t len);
@ -150,6 +154,7 @@ static int rarch_main_data_http_iterate_transfer_parse(http_handle_t *http)
return 0;
}
static int cb_http_conn_default(void *data_, size_t len)
{
http_handle_t *http = (http_handle_t*)data_;
@ -169,10 +174,17 @@ static int cb_http_conn_default(void *data_, size_t len)
if (http->connection.elem1[0] != '\0')
{
if (!strcmp(http->connection.elem1, "cb_core_updater_download"))
http->cb = &cb_core_updater_download;
if (!strcmp(http->connection.elem1, "cb_core_updater_list"))
http->cb = &cb_core_updater_list;
uint32_t label_hash = djb2_calculate(http->connection.elem1);
switch (label_hash)
{
case CB_CORE_UPDATER_DOWNLOAD:
http->cb = &cb_core_updater_download;
break;
case CB_CORE_UPDATER_LIST:
http->cb = &cb_core_updater_list;
break;
}
}
return 0;