mirror of
https://github.com/libretro/RetroArch
synced 2025-02-27 18:41:01 +00:00
Change 'hist' to 'playlist'
This commit is contained in:
parent
eb1d78bab7
commit
4bb87f7b76
142
playlist.c
142
playlist.c
@ -42,17 +42,17 @@ struct content_playlist
|
|||||||
char *conf_path;
|
char *conf_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
void content_playlist_get_index(content_playlist_t *hist,
|
void content_playlist_get_index(content_playlist_t *playlist,
|
||||||
size_t index,
|
size_t index,
|
||||||
const char **path, const char **core_path,
|
const char **path, const char **core_path,
|
||||||
const char **core_name)
|
const char **core_name)
|
||||||
{
|
{
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*path = hist->entries[index].path;
|
*path = playlist->entries[index].path;
|
||||||
*core_path = hist->entries[index].core_path;
|
*core_path = playlist->entries[index].core_path;
|
||||||
*core_name = hist->entries[index].core_name;
|
*core_name = playlist->entries[index].core_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void content_playlist_free_entry(struct content_playlist_entry *entry)
|
static void content_playlist_free_entry(struct content_playlist_entry *entry)
|
||||||
@ -70,114 +70,114 @@ static void content_playlist_free_entry(struct content_playlist_entry *entry)
|
|||||||
memset(entry, 0, sizeof(*entry));
|
memset(entry, 0, sizeof(*entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
void content_playlist_push(content_playlist_t *hist,
|
void content_playlist_push(content_playlist_t *playlist,
|
||||||
const char *path, const char *core_path,
|
const char *path, const char *core_path,
|
||||||
const char *core_name)
|
const char *core_name)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < hist->size; i++)
|
for (i = 0; i < playlist->size; i++)
|
||||||
{
|
{
|
||||||
bool equal_path = (!path && !hist->entries[i].path) ||
|
bool equal_path = (!path && !playlist->entries[i].path) ||
|
||||||
(path && hist->entries[i].path && !strcmp(path, hist->entries[i].path));
|
(path && playlist->entries[i].path && !strcmp(path, playlist->entries[i].path));
|
||||||
|
|
||||||
// Core name can have changed while still being the same core.
|
// Core name can have changed while still being the same core.
|
||||||
// Differentiate based on the core path only.
|
// Differentiate based on the core path only.
|
||||||
if (equal_path && !strcmp(hist->entries[i].core_path, core_path))
|
if (equal_path && !strcmp(playlist->entries[i].core_path, core_path))
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Seen it before, bump to top.
|
// Seen it before, bump to top.
|
||||||
struct content_playlist_entry tmp = hist->entries[i];
|
struct content_playlist_entry tmp = playlist->entries[i];
|
||||||
memmove(hist->entries + 1, hist->entries,
|
memmove(playlist->entries + 1, playlist->entries,
|
||||||
i * sizeof(struct content_playlist_entry));
|
i * sizeof(struct content_playlist_entry));
|
||||||
hist->entries[0] = tmp;
|
playlist->entries[0] = tmp;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hist->size == hist->cap)
|
if (playlist->size == playlist->cap)
|
||||||
{
|
{
|
||||||
content_playlist_free_entry(&hist->entries[hist->cap - 1]);
|
content_playlist_free_entry(&playlist->entries[playlist->cap - 1]);
|
||||||
hist->size--;
|
playlist->size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(hist->entries + 1, hist->entries,
|
memmove(playlist->entries + 1, playlist->entries,
|
||||||
(hist->cap - 1) * sizeof(struct content_playlist_entry));
|
(playlist->cap - 1) * sizeof(struct content_playlist_entry));
|
||||||
|
|
||||||
hist->entries[0].path = path ? strdup(path) : NULL;
|
playlist->entries[0].path = path ? strdup(path) : NULL;
|
||||||
hist->entries[0].core_path = strdup(core_path);
|
playlist->entries[0].core_path = strdup(core_path);
|
||||||
hist->entries[0].core_name = strdup(core_name);
|
playlist->entries[0].core_name = strdup(core_name);
|
||||||
hist->size++;
|
playlist->size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void content_playlist_write_file(content_playlist_t *hist)
|
static void content_playlist_write_file(content_playlist_t *playlist)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
|
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file = fopen(hist->conf_path, "w");
|
file = fopen(playlist->conf_path, "w");
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Couldn't write to content playlist file: %s.\n", hist->conf_path);
|
RARCH_ERR("Couldn't write to content playlist file: %s.\n", playlist->conf_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < hist->size; i++)
|
for (i = 0; i < playlist->size; i++)
|
||||||
{
|
{
|
||||||
fprintf(file, "%s\n%s\n%s\n",
|
fprintf(file, "%s\n%s\n%s\n",
|
||||||
hist->entries[i].path ? hist->entries[i].path : "",
|
playlist->entries[i].path ? playlist->entries[i].path : "",
|
||||||
hist->entries[i].core_path,
|
playlist->entries[i].core_path,
|
||||||
hist->entries[i].core_name);
|
playlist->entries[i].core_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void content_playlist_free(content_playlist_t *hist)
|
void content_playlist_free(content_playlist_t *playlist)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (hist->conf_path)
|
if (playlist->conf_path)
|
||||||
content_playlist_write_file(hist);
|
content_playlist_write_file(playlist);
|
||||||
free(hist->conf_path);
|
free(playlist->conf_path);
|
||||||
|
|
||||||
for (i = 0; i < hist->cap; i++)
|
for (i = 0; i < playlist->cap; i++)
|
||||||
content_playlist_free_entry(&hist->entries[i]);
|
content_playlist_free_entry(&playlist->entries[i]);
|
||||||
free(hist->entries);
|
free(playlist->entries);
|
||||||
|
|
||||||
free(hist);
|
free(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void content_playlist_clear(content_playlist_t *hist)
|
void content_playlist_clear(content_playlist_t *playlist)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < hist->cap; i++)
|
for (i = 0; i < playlist->cap; i++)
|
||||||
content_playlist_free_entry(&hist->entries[i]);
|
content_playlist_free_entry(&playlist->entries[i]);
|
||||||
hist->size = 0;
|
playlist->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t content_playlist_size(content_playlist_t *hist)
|
size_t content_playlist_size(content_playlist_t *playlist)
|
||||||
{
|
{
|
||||||
if (hist)
|
if (playlist)
|
||||||
return hist->size;
|
return playlist->size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool content_playlist_read_file(content_playlist_t *hist, const char *path)
|
static bool content_playlist_read_file(content_playlist_t *playlist, const char *path)
|
||||||
{
|
{
|
||||||
char buf[3][PATH_MAX];
|
char buf[3][PATH_MAX];
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@ -185,13 +185,13 @@ static bool content_playlist_read_file(content_playlist_t *hist, const char *pat
|
|||||||
char *last = NULL;
|
char *last = NULL;
|
||||||
FILE *file = fopen(path, "r");
|
FILE *file = fopen(path, "r");
|
||||||
|
|
||||||
if (!file || !hist)
|
if (!file || !playlist)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Couldn't read content playlist file: %s.\n", path);
|
RARCH_ERR("Couldn't read content playlist file: %s.\n", path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (hist->size = 0; hist->size < hist->cap; )
|
for (playlist->size = 0; playlist->size < playlist->cap; )
|
||||||
{
|
{
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
@ -204,7 +204,7 @@ static bool content_playlist_read_file(content_playlist_t *hist, const char *pat
|
|||||||
*last = '\0';
|
*last = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = &hist->entries[hist->size];
|
entry = &playlist->entries[playlist->size];
|
||||||
|
|
||||||
if (!*buf[1] || !*buf[2])
|
if (!*buf[1] || !*buf[2])
|
||||||
continue;
|
continue;
|
||||||
@ -213,7 +213,7 @@ static bool content_playlist_read_file(content_playlist_t *hist, const char *pat
|
|||||||
entry->path = strdup(buf[0]);
|
entry->path = strdup(buf[0]);
|
||||||
entry->core_path = strdup(buf[1]);
|
entry->core_path = strdup(buf[1]);
|
||||||
entry->core_name = strdup(buf[2]);
|
entry->core_name = strdup(buf[2]);
|
||||||
hist->size++;
|
playlist->size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
@ -224,63 +224,63 @@ end:
|
|||||||
content_playlist_t *content_playlist_init(const char *path, size_t size)
|
content_playlist_t *content_playlist_init(const char *path, size_t size)
|
||||||
{
|
{
|
||||||
RARCH_LOG("Opening playlist: %s.\n", path);
|
RARCH_LOG("Opening playlist: %s.\n", path);
|
||||||
content_playlist_t *hist = (content_playlist_t*)calloc(1, sizeof(*hist));
|
content_playlist_t *playlist = (content_playlist_t*)calloc(1, sizeof(*playlist));
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Cannot initialize content playlist.\n");
|
RARCH_ERR("Cannot initialize content playlist.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hist->entries = (struct content_playlist_entry*)calloc(size, sizeof(*hist->entries));
|
playlist->entries = (struct content_playlist_entry*)calloc(size, sizeof(*playlist->entries));
|
||||||
if (!hist->entries)
|
if (!playlist->entries)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
hist->cap = size;
|
playlist->cap = size;
|
||||||
|
|
||||||
if (!content_playlist_read_file(hist, path))
|
if (!content_playlist_read_file(playlist, path))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
hist->conf_path = strdup(path);
|
playlist->conf_path = strdup(path);
|
||||||
return hist;
|
return playlist;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
content_playlist_free(hist);
|
content_playlist_free(playlist);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* content_playlist_get_path(content_playlist_t *hist, unsigned index)
|
const char* content_playlist_get_path(content_playlist_t *playlist, unsigned index)
|
||||||
{
|
{
|
||||||
const char *path, *core_path, *core_name = NULL;
|
const char *path, *core_path, *core_name = NULL;
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
content_playlist_get_index(hist, index, &path, &core_path, &core_name);
|
content_playlist_get_index(playlist, index, &path, &core_path, &core_name);
|
||||||
|
|
||||||
if (path)
|
if (path)
|
||||||
return path;
|
return path;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *content_playlist_get_core_path(content_playlist_t *hist, unsigned index)
|
const char *content_playlist_get_core_path(content_playlist_t *playlist, unsigned index)
|
||||||
{
|
{
|
||||||
const char *path, *core_path, *core_name = NULL;
|
const char *path, *core_path, *core_name = NULL;
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
content_playlist_get_index(hist, index, &path, &core_path, &core_name);
|
content_playlist_get_index(playlist, index, &path, &core_path, &core_name);
|
||||||
|
|
||||||
if (core_path)
|
if (core_path)
|
||||||
return core_path;
|
return core_path;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *content_playlist_get_core_name(content_playlist_t *hist, unsigned index)
|
const char *content_playlist_get_core_name(content_playlist_t *playlist, unsigned index)
|
||||||
{
|
{
|
||||||
const char *path, *core_path, *core_name = NULL;
|
const char *path, *core_path, *core_name = NULL;
|
||||||
if (!hist)
|
if (!playlist)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
content_playlist_get_index(hist, index, &path, &core_path, &core_name);
|
content_playlist_get_index(playlist, index, &path, &core_path, &core_name);
|
||||||
|
|
||||||
if (core_name)
|
if (core_name)
|
||||||
return core_name;
|
return core_name;
|
||||||
|
16
playlist.h
16
playlist.h
@ -25,26 +25,26 @@ extern "C" {
|
|||||||
typedef struct content_playlist content_playlist_t;
|
typedef struct content_playlist content_playlist_t;
|
||||||
|
|
||||||
content_playlist_t *content_playlist_init(const char *path, size_t size);
|
content_playlist_t *content_playlist_init(const char *path, size_t size);
|
||||||
void content_playlist_free(content_playlist_t *hist);
|
void content_playlist_free(content_playlist_t *playlist);
|
||||||
|
|
||||||
void content_playlist_clear(content_playlist_t *hist);
|
void content_playlist_clear(content_playlist_t *playlist);
|
||||||
|
|
||||||
size_t content_playlist_size(content_playlist_t *hist);
|
size_t content_playlist_size(content_playlist_t *playlist);
|
||||||
|
|
||||||
void content_playlist_get_index(content_playlist_t *hist,
|
void content_playlist_get_index(content_playlist_t *playlist,
|
||||||
size_t index,
|
size_t index,
|
||||||
const char **path, const char **core_path,
|
const char **path, const char **core_path,
|
||||||
const char **core_name);
|
const char **core_name);
|
||||||
|
|
||||||
void content_playlist_push(content_playlist_t *hist,
|
void content_playlist_push(content_playlist_t *playlist,
|
||||||
const char *path, const char *core_path,
|
const char *path, const char *core_path,
|
||||||
const char *core_name);
|
const char *core_name);
|
||||||
|
|
||||||
const char* content_playlist_get_path(content_playlist_t *hist,
|
const char* content_playlist_get_path(content_playlist_t *playlist,
|
||||||
unsigned index);
|
unsigned index);
|
||||||
const char* content_playlist_get_core_path(content_playlist_t *hist,
|
const char* content_playlist_get_core_path(content_playlist_t *playlist,
|
||||||
unsigned index);
|
unsigned index);
|
||||||
const char* content_playlist_get_core_name(content_playlist_t *hist,
|
const char* content_playlist_get_core_name(content_playlist_t *playlist,
|
||||||
unsigned index);
|
unsigned index);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
x
Reference in New Issue
Block a user