mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Rough implementation of game loading from database
This commit is contained in:
parent
8b551ccddf
commit
d9094506c7
@ -263,6 +263,10 @@ void menu_free(void *data)
|
||||
if (driver.menu_ctx && driver.menu_ctx->free)
|
||||
driver.menu_ctx->free(menu);
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
menu_database_free(menu);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
libretro_free_system_info(&g_extern.menu.info);
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "menu_list.h"
|
||||
#include "menu_entries.h"
|
||||
#include "../database_info.h"
|
||||
#include "../playlist.h"
|
||||
#include <string.h>
|
||||
|
||||
int menu_database_populate_query(file_list_t *list, const char *path,
|
||||
@ -40,3 +41,27 @@ int menu_database_populate_query(file_list_t *list, const char *path,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void menu_database_playlist_free(menu_handle_t *menu)
|
||||
{
|
||||
if (menu->db_playlist)
|
||||
content_playlist_free(menu->db_playlist);
|
||||
menu->db_playlist = NULL;
|
||||
}
|
||||
|
||||
void menu_database_free(menu_handle_t *menu)
|
||||
{
|
||||
menu_database_playlist_free(menu);
|
||||
}
|
||||
|
||||
bool menu_database_realloc(menu_handle_t *menu, const char *path)
|
||||
{
|
||||
menu_database_playlist_free(menu);
|
||||
menu->db_playlist = content_playlist_init(path,
|
||||
1000);
|
||||
|
||||
if (!menu->db_playlist)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define _MENU_DATABASE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <boolean.h>
|
||||
#include <file/file_list.h>
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
#include "../libretrodb/libretrodb.h"
|
||||
@ -29,6 +30,10 @@ extern "C" {
|
||||
int menu_database_populate_query(file_list_t *list, const char *path,
|
||||
const char *query);
|
||||
|
||||
void menu_database_free(menu_handle_t *menu);
|
||||
|
||||
bool menu_database_realloc(menu_handle_t *menu, const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "menu_animation.h"
|
||||
#include "menu_list.h"
|
||||
#include "../settings_list.h"
|
||||
#include "../playlist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -142,6 +143,8 @@ typedef struct
|
||||
rarch_setting_t *list_settings;
|
||||
tween_t* tweens;
|
||||
unsigned numtweens;
|
||||
|
||||
content_playlist_t *db_playlist;
|
||||
} menu_handle_t;
|
||||
|
||||
typedef struct menu_file_list_cbs
|
||||
|
@ -130,6 +130,8 @@ unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2] = {
|
||||
unsigned menu_current_gx_resolution = GX_RESOLUTIONS_640_480;
|
||||
#endif
|
||||
|
||||
static unsigned rdb_entry_start_game_selection_ptr;
|
||||
|
||||
static int archive_open(void)
|
||||
{
|
||||
char cat_path[PATH_MAX_LENGTH];
|
||||
@ -245,6 +247,16 @@ int menu_action_setting_set_current_string(
|
||||
return menu_action_generic_setting(setting);
|
||||
}
|
||||
|
||||
static int action_ok_rdb_playlist_entry(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
if (!driver.menu)
|
||||
return -1;
|
||||
|
||||
rarch_playlist_load_content(driver.menu->db_playlist,
|
||||
rdb_entry_start_game_selection_ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int action_ok_playlist_entry(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
@ -827,8 +839,10 @@ static int deferred_push_rdb_entry_detail(void *data, void *userdata,
|
||||
const char *path, const char *label, unsigned type)
|
||||
{
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
content_playlist_t *playlist;
|
||||
char query[PATH_MAX_LENGTH];
|
||||
unsigned i;
|
||||
char path_rdl[PATH_MAX_LENGTH], path_base[PATH_MAX_LENGTH];
|
||||
unsigned i, j;
|
||||
int ret = 0;
|
||||
database_info_list_t *db_info = NULL;
|
||||
file_list_t *list = (file_list_t*)data;
|
||||
@ -858,6 +872,17 @@ static int deferred_push_rdb_entry_detail(void *data, void *userdata,
|
||||
goto done;
|
||||
}
|
||||
|
||||
strlcpy(path_base, path_basename(path), sizeof(path_base));
|
||||
path_remove_extension(path_base);
|
||||
strlcat(path_base, ".rdl", sizeof(path_base));
|
||||
|
||||
fill_pathname_join(path_rdl, g_settings.content_database, path_base,
|
||||
sizeof(path_rdl));
|
||||
|
||||
menu_database_realloc(driver.menu, path_rdl);
|
||||
|
||||
playlist = driver.menu->db_playlist;
|
||||
|
||||
for (i = 0; i < db_info->count; i++)
|
||||
{
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
@ -866,6 +891,50 @@ static int deferred_push_rdb_entry_detail(void *data, void *userdata,
|
||||
if (!db_info_entry)
|
||||
continue;
|
||||
|
||||
if (playlist)
|
||||
{
|
||||
for (j = 0; j < playlist->size; j++)
|
||||
{
|
||||
char elem0[PATH_MAX_LENGTH], elem1[PATH_MAX_LENGTH];
|
||||
bool match_found = false;
|
||||
struct string_list *str_list = string_split(
|
||||
playlist->entries[j].core_name, "|");
|
||||
|
||||
if (!str_list)
|
||||
continue;;
|
||||
|
||||
if (str_list && str_list->size > 0)
|
||||
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
||||
if (str_list && str_list->size > 1)
|
||||
strlcpy(elem1, str_list->elems[1].data, sizeof(elem1));
|
||||
|
||||
if (!strcmp(elem1, "crc"))
|
||||
{
|
||||
if (!strcmp(db_info_entry->crc32, elem0))
|
||||
match_found = true;
|
||||
}
|
||||
else if (!strcmp(elem1, "sha1"))
|
||||
{
|
||||
if (!strcmp(db_info_entry->sha1, elem0))
|
||||
match_found = true;
|
||||
}
|
||||
else if (!strcmp(elem1, "md5"))
|
||||
{
|
||||
if (!strcmp(db_info_entry->md5, elem0))
|
||||
match_found = true;
|
||||
}
|
||||
|
||||
string_list_free(str_list);
|
||||
|
||||
if (!match_found)
|
||||
continue;
|
||||
|
||||
rdb_entry_start_game_selection_ptr = j;
|
||||
menu_list_push(list, "Start game", "rdb_entry_start_game",
|
||||
MENU_FILE_PLAYLIST_ENTRY, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (db_info_entry->name)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "Name: %s", db_info_entry->name);
|
||||
@ -1014,6 +1083,8 @@ static int deferred_push_rdb_entry_detail(void *data, void *userdata,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (db_info->count < 1)
|
||||
menu_list_push(list,
|
||||
@ -4978,7 +5049,10 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
|
||||
cbs->action_ok = action_ok_video_resolution;
|
||||
break;
|
||||
case MENU_FILE_PLAYLIST_ENTRY:
|
||||
cbs->action_ok = action_ok_playlist_entry;
|
||||
if (!strcmp(label, "rdb_entry_start_game"))
|
||||
cbs->action_ok = action_ok_rdb_playlist_entry;
|
||||
else
|
||||
cbs->action_ok = action_ok_playlist_entry;
|
||||
break;
|
||||
case MENU_FILE_CONTENTLIST_ENTRY:
|
||||
cbs->action_ok = action_ok_push_generic_list;
|
||||
|
29
playlist.c
29
playlist.c
@ -23,22 +23,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct content_playlist_entry
|
||||
{
|
||||
char *path;
|
||||
char *core_path;
|
||||
char *core_name;
|
||||
};
|
||||
|
||||
struct content_playlist
|
||||
{
|
||||
struct content_playlist_entry *entries;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
|
||||
char *conf_path;
|
||||
};
|
||||
|
||||
/**
|
||||
* content_playlist_get_index:
|
||||
* @playlist : Playlist handle.
|
||||
@ -71,8 +55,7 @@ void content_playlist_get_index(content_playlist_t *playlist,
|
||||
*
|
||||
* Frees playlist entry.
|
||||
**/
|
||||
static void content_playlist_free_entry(
|
||||
struct content_playlist_entry *entry)
|
||||
static void content_playlist_free_entry(content_playlist_entry_t *entry)
|
||||
{
|
||||
if (!entry)
|
||||
return;
|
||||
@ -110,7 +93,7 @@ void content_playlist_push(content_playlist_t *playlist,
|
||||
|
||||
for (i = 0; i < playlist->size; i++)
|
||||
{
|
||||
struct content_playlist_entry tmp;
|
||||
content_playlist_entry_t tmp;
|
||||
bool equal_path = (!path && !playlist->entries[i].path) ||
|
||||
(path && playlist->entries[i].path &&
|
||||
!strcmp(path,playlist->entries[i].path));
|
||||
@ -131,7 +114,7 @@ void content_playlist_push(content_playlist_t *playlist,
|
||||
/* Seen it before, bump to top. */
|
||||
tmp = playlist->entries[i];
|
||||
memmove(playlist->entries + 1, playlist->entries,
|
||||
i * sizeof(struct content_playlist_entry));
|
||||
i * sizeof(content_playlist_entry_t));
|
||||
playlist->entries[0] = tmp;
|
||||
|
||||
return;
|
||||
@ -144,7 +127,7 @@ void content_playlist_push(content_playlist_t *playlist,
|
||||
}
|
||||
|
||||
memmove(playlist->entries + 1, playlist->entries,
|
||||
(playlist->cap - 1) * sizeof(struct content_playlist_entry));
|
||||
(playlist->cap - 1) * sizeof(content_playlist_entry_t));
|
||||
|
||||
playlist->entries[0].path = path ? strdup(path) : NULL;
|
||||
playlist->entries[0].core_path = strdup(core_path);
|
||||
@ -234,7 +217,7 @@ static bool content_playlist_read_file(
|
||||
{
|
||||
char buf[3][1024];
|
||||
unsigned i;
|
||||
struct content_playlist_entry *entry = NULL;
|
||||
content_playlist_entry_t *entry = NULL;
|
||||
char *last = NULL;
|
||||
FILE *file = fopen(path, "r");
|
||||
|
||||
@ -291,7 +274,7 @@ content_playlist_t *content_playlist_init(const char *path, size_t size)
|
||||
if (!playlist)
|
||||
return NULL;
|
||||
|
||||
playlist->entries = (struct content_playlist_entry*)calloc(size,
|
||||
playlist->entries = (content_playlist_entry_t*)calloc(size,
|
||||
sizeof(*playlist->entries));
|
||||
if (!playlist->entries)
|
||||
goto error;
|
||||
|
16
playlist.h
16
playlist.h
@ -24,7 +24,21 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct content_playlist content_playlist_t;
|
||||
typedef struct content_playlist_entry
|
||||
{
|
||||
char *path;
|
||||
char *core_path;
|
||||
char *core_name;
|
||||
} content_playlist_entry_t;
|
||||
|
||||
typedef struct content_playlist
|
||||
{
|
||||
struct content_playlist_entry *entries;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
|
||||
char *conf_path;
|
||||
} content_playlist_t;
|
||||
|
||||
/**
|
||||
* content_playlist_init:
|
||||
|
Loading…
x
Reference in New Issue
Block a user