mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 09:32:52 +00:00
(task_database.c) Rewrite char arrays
This commit is contained in:
parent
4db14dca9a
commit
3090f3ff3a
@ -46,8 +46,10 @@ bool input_remapping_load_file(void *data, const char *path)
|
||||
if (!conf || string_is_empty(path))
|
||||
return false;
|
||||
|
||||
strlcpy(global->name.remapfile, path,
|
||||
sizeof(global->name.remapfile));
|
||||
if (global->name.remapfile
|
||||
&& !string_is_empty(global->name.remapfile))
|
||||
free(global->name.remapfile);
|
||||
global->name.remapfile = strdup(path);
|
||||
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
@ -257,7 +259,10 @@ void input_remapping_set_defaults(bool deinit)
|
||||
|
||||
if (deinit)
|
||||
{
|
||||
global->name.remapfile[0] = '\0';
|
||||
if (global->name.remapfile
|
||||
&& !string_is_empty(global->name.remapfile))
|
||||
free(global->name.remapfile);
|
||||
global->name.remapfile = NULL;
|
||||
rarch_ctl(RARCH_CTL_UNSET_REMAPS_CORE_ACTIVE, NULL);
|
||||
rarch_ctl(RARCH_CTL_UNSET_REMAPS_GAME_ACTIVE, NULL);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
#include <streams/file_stream.h>
|
||||
#include <retro_endianness.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <compat/strl.h>
|
||||
|
||||
#include "libretrodb.h"
|
||||
@ -57,7 +58,7 @@ struct libretrodb
|
||||
uint64_t root;
|
||||
uint64_t count;
|
||||
uint64_t first_index_offset;
|
||||
char path[1024];
|
||||
char *path;
|
||||
};
|
||||
|
||||
struct libretrodb_index
|
||||
@ -205,7 +206,10 @@ void libretrodb_close(libretrodb_t *db)
|
||||
{
|
||||
if (db->fd)
|
||||
filestream_close(db->fd);
|
||||
db->fd = NULL;
|
||||
if (db->path && !string_is_empty(db->path))
|
||||
free(db->path);
|
||||
db->path = NULL;
|
||||
db->fd = NULL;
|
||||
}
|
||||
|
||||
int libretrodb_open(const char *path, libretrodb_t *db)
|
||||
@ -218,8 +222,11 @@ int libretrodb_open(const char *path, libretrodb_t *db)
|
||||
if (!fd)
|
||||
return -errno;
|
||||
|
||||
strlcpy(db->path, path, sizeof(db->path));
|
||||
db->root = filestream_seek(fd, 0, SEEK_CUR);
|
||||
if (db->path && !string_is_empty(db->path))
|
||||
free(db->path);
|
||||
|
||||
db->path = strdup(path);
|
||||
db->root = filestream_seek(fd, 0, SEEK_CUR);
|
||||
|
||||
if ((rv = (int)filestream_read(fd, &header, sizeof(header))) == -1)
|
||||
{
|
||||
@ -421,6 +428,9 @@ void libretrodb_cursor_close(libretrodb_cursor_t *cursor)
|
||||
int libretrodb_cursor_open(libretrodb_t *db, libretrodb_cursor_t *cursor,
|
||||
libretrodb_query_t *q)
|
||||
{
|
||||
if (!db || !db->path || string_is_empty(db->path))
|
||||
return -errno;
|
||||
|
||||
cursor->fd = filestream_open(db->path, RFILE_MODE_READ | RFILE_HINT_MMAP, -1);
|
||||
|
||||
if (!cursor->fd)
|
||||
|
@ -107,7 +107,8 @@ static void menu_action_setting_disp_set_label_remap_file_load(
|
||||
|
||||
*w = 19;
|
||||
strlcpy(s2, path, len2);
|
||||
if (global)
|
||||
if (global && global->name.remapfile
|
||||
&& !string_is_empty(global->name.remapfile))
|
||||
fill_pathname_base(s, global->name.remapfile,
|
||||
len);
|
||||
}
|
||||
|
@ -323,6 +323,12 @@ static void global_free(void)
|
||||
global = global_get_ptr();
|
||||
path_clear_all();
|
||||
dir_clear_all();
|
||||
if (global)
|
||||
{
|
||||
if (global->name.remapfile
|
||||
&& !string_is_empty(global->name.remapfile))
|
||||
free(global->name.remapfile);
|
||||
}
|
||||
memset(global, 0, sizeof(struct global));
|
||||
retroarch_override_setting_free_state();
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ typedef struct global
|
||||
char ups[8192];
|
||||
char bps[8192];
|
||||
char ips[8192];
|
||||
char remapfile[8192];
|
||||
char *remapfile;
|
||||
} name;
|
||||
|
||||
/* Recording. */
|
||||
|
@ -57,15 +57,14 @@ typedef struct database_state_handle
|
||||
|
||||
typedef struct db_handle
|
||||
{
|
||||
database_state_handle_t state;
|
||||
database_info_handle_t *handle;
|
||||
unsigned status;
|
||||
char playlist_directory[4096];
|
||||
char content_database_path[4096];
|
||||
|
||||
bool is_directory;
|
||||
char fullpath[4096];
|
||||
bool scan_started;
|
||||
unsigned status;
|
||||
char *playlist_directory;
|
||||
char *content_database_path;
|
||||
char *fullpath;
|
||||
database_info_handle_t *handle;
|
||||
database_state_handle_t state;
|
||||
} db_handle_t;
|
||||
|
||||
int cue_find_track(const char *cue_path, bool first, size_t *offset, size_t *size,
|
||||
@ -787,8 +786,11 @@ static int database_info_list_iterate_found_match(
|
||||
strlcat(db_playlist_base_str,
|
||||
file_path_str(FILE_PATH_LPL_EXTENSION),
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_join(db_playlist_path, _db->playlist_directory,
|
||||
db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char));
|
||||
|
||||
if (_db->playlist_directory &&
|
||||
!string_is_empty(_db->playlist_directory))
|
||||
fill_pathname_join(db_playlist_path, _db->playlist_directory,
|
||||
db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char));
|
||||
|
||||
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
||||
|
||||
@ -957,10 +959,12 @@ static int task_database_iterate_playlist_lutro(
|
||||
|
||||
db_playlist_path[0] = '\0';
|
||||
|
||||
fill_pathname_join(db_playlist_path,
|
||||
_db->playlist_directory,
|
||||
file_path_str(FILE_PATH_LUTRO_PLAYLIST),
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
if (_db->playlist_directory &&
|
||||
!string_is_empty(_db->playlist_directory))
|
||||
fill_pathname_join(db_playlist_path,
|
||||
_db->playlist_directory,
|
||||
file_path_str(FILE_PATH_LUTRO_PLAYLIST),
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
|
||||
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
||||
|
||||
@ -1119,10 +1123,13 @@ static void task_database_handler(retro_task_t *task)
|
||||
{
|
||||
db->scan_started = true;
|
||||
|
||||
if (db->is_directory)
|
||||
db->handle = database_info_dir_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
||||
else
|
||||
db->handle = database_info_file_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
||||
if (db->fullpath && !string_is_empty(db->fullpath))
|
||||
{
|
||||
if (db->is_directory)
|
||||
db->handle = database_info_dir_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
||||
else
|
||||
db->handle = database_info_file_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
||||
}
|
||||
|
||||
task_free_title(task);
|
||||
|
||||
@ -1141,20 +1148,26 @@ static void task_database_handler(retro_task_t *task)
|
||||
case DATABASE_STATUS_ITERATE_BEGIN:
|
||||
if (dbstate && !dbstate->list)
|
||||
{
|
||||
dbstate->list = dir_list_new_special(
|
||||
db->content_database_path,
|
||||
DIR_LIST_DATABASES, NULL);
|
||||
if (db->content_database_path &&
|
||||
!string_is_empty(db->content_database_path))
|
||||
dbstate->list = dir_list_new_special(
|
||||
db->content_database_path,
|
||||
DIR_LIST_DATABASES, NULL);
|
||||
|
||||
/* If the scan path matches a database path exactly then
|
||||
* save time by only processing that database. */
|
||||
if (dbstate->list && db->is_directory)
|
||||
{
|
||||
size_t i;
|
||||
char *dirname = find_last_slash(db->fullpath) + 1;
|
||||
size_t i;
|
||||
char *dirname = NULL;
|
||||
|
||||
if (db->fullpath &&
|
||||
!string_is_empty(db->fullpath))
|
||||
dirname = find_last_slash(db->fullpath) + 1;
|
||||
|
||||
for (i = 0; i < dbstate->list->size; i++)
|
||||
{
|
||||
char *dbname;
|
||||
char *dbname;
|
||||
char *dbpath = strdup(dbstate->list->elems[i].data);
|
||||
path_remove_extension(dbpath);
|
||||
|
||||
@ -1166,7 +1179,7 @@ static void task_database_handler(retro_task_t *task)
|
||||
free(dbpath);
|
||||
single_list = string_list_new();
|
||||
string_list_append(single_list, dbstate->list->elems[i].data,
|
||||
dbstate->list->elems[i].attr);
|
||||
dbstate->list->elems[i].attr);
|
||||
dir_list_free(dbstate->list);
|
||||
dbstate->list = single_list;
|
||||
break;
|
||||
@ -1227,6 +1240,15 @@ task_finished:
|
||||
|
||||
if (db)
|
||||
{
|
||||
if (db->playlist_directory &&
|
||||
!string_is_empty(db->playlist_directory))
|
||||
free(db->playlist_directory);
|
||||
if (db->content_database_path &&
|
||||
!string_is_empty(db->content_database_path))
|
||||
free(db->content_database_path);
|
||||
if (db->fullpath &&
|
||||
!string_is_empty(db->fullpath))
|
||||
free(db->fullpath);
|
||||
if (db->state.buf)
|
||||
free(db->state.buf);
|
||||
|
||||
@ -1251,18 +1273,16 @@ bool task_push_dbscan(
|
||||
if (!t || !db)
|
||||
goto error;
|
||||
|
||||
t->handler = task_database_handler;
|
||||
t->state = db;
|
||||
t->callback = cb;
|
||||
t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN));
|
||||
t->handler = task_database_handler;
|
||||
t->state = db;
|
||||
t->callback = cb;
|
||||
t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN));
|
||||
|
||||
db->is_directory = directory;
|
||||
|
||||
strlcpy(db->fullpath, fullpath, sizeof(db->fullpath));
|
||||
strlcpy(db->playlist_directory, playlist_directory,
|
||||
sizeof(db->playlist_directory));
|
||||
strlcpy(db->content_database_path, content_database,
|
||||
sizeof(db->content_database_path));
|
||||
db->is_directory = directory;
|
||||
db->playlist_directory = NULL;
|
||||
db->fullpath = strdup(fullpath);
|
||||
db->playlist_directory = strdup(playlist_directory);
|
||||
db->content_database_path = strdup(content_database);
|
||||
|
||||
task_queue_push(t);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user