mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-26 05:16:18 +00:00
Load content runtime data 'on demand' (#8717)
* Load content runtime data 'on demand' * Fix LGTM warning
This commit is contained in:
parent
5a9c0da282
commit
10ef7dd561
@ -49,6 +49,7 @@
|
||||
#include "../tasks/tasks_internal.h"
|
||||
|
||||
#include "../../playlist.h"
|
||||
#include "../../runtime_file.h"
|
||||
|
||||
#define default_sublabel_macro(func_name, lbl) \
|
||||
static int (func_name)(file_list_t *list, unsigned type, unsigned i, const char *label, const char *path, char *s, size_t len) \
|
||||
@ -852,16 +853,6 @@ static int action_bind_sublabel_playlist_entry(
|
||||
settings_t *settings = config_get_ptr();
|
||||
playlist_t *playlist = NULL;
|
||||
const struct playlist_entry *entry = NULL;
|
||||
const char *core_name = NULL;
|
||||
unsigned runtime_hours = 0;
|
||||
unsigned runtime_minutes = 0;
|
||||
unsigned runtime_seconds = 0;
|
||||
unsigned last_played_year = 0;
|
||||
unsigned last_played_month = 0;
|
||||
unsigned last_played_day = 0;
|
||||
unsigned last_played_hour = 0;
|
||||
unsigned last_played_minute = 0;
|
||||
unsigned last_played_second = 0;
|
||||
|
||||
if (!settings->bools.playlist_show_sublabels || string_is_equal(settings->arrays.menu_driver, "ozone"))
|
||||
return 0;
|
||||
@ -877,17 +868,15 @@ static int action_bind_sublabel_playlist_entry(
|
||||
|
||||
/* Read playlist entry */
|
||||
playlist_get_index(playlist, i, &entry);
|
||||
|
||||
core_name = entry->core_name;
|
||||
|
||||
/* Only add sublabel if a core is currently assigned */
|
||||
if (string_is_empty(core_name) || string_is_equal(core_name, file_path_str(FILE_PATH_DETECT)))
|
||||
if (string_is_empty(entry->core_name) || string_is_equal(entry->core_name, file_path_str(FILE_PATH_DETECT)))
|
||||
return 0;
|
||||
|
||||
/* Add core name */
|
||||
snprintf(s, len, "%s %s",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE),
|
||||
core_name);
|
||||
entry->core_name);
|
||||
|
||||
/* Get runtime info *if* required runtime log is enabled
|
||||
* *and* this is a valid playlist type */
|
||||
@ -907,16 +896,12 @@ static int action_bind_sublabel_playlist_entry(
|
||||
!string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_HORIZONTAL_MENU)))
|
||||
return 0;
|
||||
|
||||
/* Any available runtime values are now copied to the content
|
||||
* history playlist when it is parsed by menu_displaylist, so
|
||||
* we can extract them directly via index */
|
||||
playlist_get_runtime_index(playlist, i, NULL, NULL,
|
||||
&runtime_hours, &runtime_minutes, &runtime_seconds,
|
||||
&last_played_year, &last_played_month, &last_played_day,
|
||||
&last_played_hour, &last_played_minute, &last_played_second);
|
||||
/* Check whether runtime info should be loaded from log file */
|
||||
if (entry->runtime_status == PLAYLIST_RUNTIME_UNKNOWN)
|
||||
runtime_update_playlist(playlist, i);
|
||||
|
||||
/* Check whether a non-zero runtime has been recorded */
|
||||
if ((runtime_hours > 0) || (runtime_minutes > 0) || (runtime_seconds > 0))
|
||||
/* Check whether runtime info is valid */
|
||||
if (entry->runtime_status == PLAYLIST_RUNTIME_VALID)
|
||||
{
|
||||
int n = 0;
|
||||
char tmp[64];
|
||||
@ -925,7 +910,7 @@ static int action_bind_sublabel_playlist_entry(
|
||||
tmp[0] = '\0';
|
||||
n = snprintf(tmp, sizeof(tmp), "\n%s %02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME),
|
||||
runtime_hours, runtime_minutes, runtime_seconds);
|
||||
entry->runtime_hours, entry->runtime_minutes, entry->runtime_seconds);
|
||||
|
||||
if ((n < 0) || (n >= 64))
|
||||
n = 0; /* Silence GCC warnings... */
|
||||
@ -937,8 +922,8 @@ static int action_bind_sublabel_playlist_entry(
|
||||
tmp[0] = '\0';
|
||||
n = snprintf(tmp, sizeof(tmp), "\n%s %04u/%02u/%02u - %02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
|
||||
last_played_year, last_played_month, last_played_day,
|
||||
last_played_hour, last_played_minute, last_played_second);
|
||||
entry->last_played_year, entry->last_played_month, entry->last_played_day,
|
||||
entry->last_played_hour, entry->last_played_minute, entry->last_played_second);
|
||||
|
||||
if ((n < 0) || (n >= 64))
|
||||
n = 0; /* Silence GCC warnings... */
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "../../menu_animation.h"
|
||||
#include "../../menu_input.h"
|
||||
#include "../../playlist.h"
|
||||
#include "../../runtime_file.h"
|
||||
|
||||
#include "../../widgets/menu_input_dialog.h"
|
||||
#include "../../widgets/menu_osk.h"
|
||||
@ -1125,18 +1126,14 @@ void ozone_update_content_metadata(ozone_handle_t *ozone)
|
||||
{
|
||||
size_t selection = menu_navigation_get_selection();
|
||||
playlist_t *playlist = playlist_get_cached();
|
||||
const struct playlist_entry *entry = NULL;
|
||||
const char *core_name = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
menu_thumbnail_get_core_name(ozone->thumbnail_path_data, &core_name);
|
||||
|
||||
if (ozone->is_playlist && playlist)
|
||||
{
|
||||
const char *core_label = NULL;
|
||||
playlist_get_index(playlist, selection, &entry);
|
||||
const char *core_name = NULL;
|
||||
const char *core_label = NULL;
|
||||
|
||||
core_name = entry->core_name;
|
||||
menu_thumbnail_get_core_name(ozone->thumbnail_path_data, &core_name);
|
||||
|
||||
/* Fill core name */
|
||||
if (!core_name || string_is_equal(core_name, "DETECT"))
|
||||
@ -1157,38 +1154,32 @@ void ozone_update_content_metadata(ozone_handle_t *ozone)
|
||||
/* Fill play time if applicable */
|
||||
if (settings->bools.content_runtime_log || settings->bools.content_runtime_log_aggregate)
|
||||
{
|
||||
unsigned runtime_hours = 0;
|
||||
unsigned runtime_minutes = 0;
|
||||
unsigned runtime_seconds = 0;
|
||||
const struct playlist_entry *entry = NULL;
|
||||
|
||||
unsigned last_played_year = 0;
|
||||
unsigned last_played_month = 0;
|
||||
unsigned last_played_day = 0;
|
||||
unsigned last_played_hour = 0;
|
||||
unsigned last_played_minute = 0;
|
||||
unsigned last_played_second = 0;
|
||||
playlist_get_index(playlist, selection, &entry);
|
||||
|
||||
playlist_get_runtime_index(playlist, selection, NULL, NULL,
|
||||
&runtime_hours, &runtime_minutes, &runtime_seconds,
|
||||
&last_played_year, &last_played_month, &last_played_day,
|
||||
&last_played_hour, &last_played_minute, &last_played_second);
|
||||
if (entry->runtime_status == PLAYLIST_RUNTIME_UNKNOWN)
|
||||
runtime_update_playlist(playlist, selection);
|
||||
|
||||
snprintf(ozone->selection_playtime, sizeof(ozone->selection_playtime), "%s %02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME), runtime_hours, runtime_minutes, runtime_seconds);
|
||||
|
||||
if (last_played_year == 0 && last_played_month == 0 && last_played_day == 0
|
||||
&& last_played_hour == 0 && last_played_minute == 0 && last_played_second == 0)
|
||||
if (entry->runtime_status == PLAYLIST_RUNTIME_VALID)
|
||||
{
|
||||
snprintf(ozone->selection_lastplayed, sizeof(ozone->selection_lastplayed), "%s %s",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER));
|
||||
snprintf(ozone->selection_playtime, sizeof(ozone->selection_playtime), "%s %02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME),
|
||||
entry->runtime_hours, entry->runtime_minutes, entry->runtime_seconds);
|
||||
|
||||
snprintf(ozone->selection_lastplayed, sizeof(ozone->selection_lastplayed), "%s %04u/%02u/%02u -\n%02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
|
||||
entry->last_played_year, entry->last_played_month, entry->last_played_day,
|
||||
entry->last_played_hour, entry->last_played_minute, entry->last_played_second);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(ozone->selection_lastplayed, sizeof(ozone->selection_lastplayed), "%s %04u/%02u/%02u -\n%02u:%02u:%02u",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
|
||||
last_played_year, last_played_month, last_played_day,
|
||||
last_played_hour, last_played_minute, last_played_second);
|
||||
snprintf(ozone->selection_playtime, sizeof(ozone->selection_playtime), "%s 00:00:00",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME));
|
||||
|
||||
snprintf(ozone->selection_lastplayed, sizeof(ozone->selection_lastplayed), "%s %s",
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
|
||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -94,7 +94,6 @@
|
||||
#include "../wifi/wifi_driver.h"
|
||||
#include "../tasks/tasks_internal.h"
|
||||
#include "../dynamic.h"
|
||||
#include "../runtime_file.h"
|
||||
|
||||
static char new_path_entry[4096] = {0};
|
||||
static char new_lbl_entry[4096] = {0};
|
||||
@ -813,29 +812,13 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
|
||||
char label_spacer[PL_LABEL_SPACER_MAXLEN];
|
||||
size_t list_size = playlist_size(playlist);
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool is_rgui = string_is_equal(settings->arrays.menu_driver, "rgui");
|
||||
bool get_runtime = false;
|
||||
bool show_inline_core_name = false;
|
||||
unsigned pl_sublabel_runtime_type = settings->uints.playlist_sublabel_runtime_type;
|
||||
|
||||
label_spacer[0] = '\0';
|
||||
|
||||
if (list_size == 0)
|
||||
goto error;
|
||||
|
||||
/* Check whether runtime logging info should be parsed */
|
||||
if (((pl_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE) &&
|
||||
settings->bools.content_runtime_log) ||
|
||||
((pl_sublabel_runtime_type == PLAYLIST_RUNTIME_AGGREGATE) &&
|
||||
settings->bools.content_runtime_log_aggregate))
|
||||
{
|
||||
/* Runtime logging is valid for every type of playlist *apart from*
|
||||
* images/music/video history */
|
||||
get_runtime = !(string_is_equal(path_playlist, "images_history") ||
|
||||
string_is_equal(path_playlist, "music_history") ||
|
||||
string_is_equal(path_playlist, "video_history"));
|
||||
}
|
||||
|
||||
/* Check whether core name should be added to playlist entries */
|
||||
if (!string_is_equal(settings->arrays.menu_driver, "ozone") &&
|
||||
!settings->bools.playlist_show_sublabels &&
|
||||
@ -846,7 +829,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
|
||||
|
||||
/* Get spacer for menu entry labels (<content><spacer><core>)
|
||||
* > Note: Only required when showing inline core names */
|
||||
if (is_rgui)
|
||||
if (string_is_equal(settings->arrays.menu_driver, "rgui"))
|
||||
strlcpy(label_spacer, PL_LABEL_SPACER_RGUI, sizeof(label_spacer));
|
||||
else
|
||||
strlcpy(label_spacer, PL_LABEL_SPACER_DEFAULT, sizeof(label_spacer));
|
||||
@ -891,49 +874,6 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
|
||||
/* Read playlist entry */
|
||||
playlist_get_index(playlist, i, &entry);
|
||||
|
||||
/* Extract any available runtime values, if required */
|
||||
if (get_runtime)
|
||||
{
|
||||
runtime_log_t *runtime_log = runtime_log_init(entry->path, entry->core_path,
|
||||
pl_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE);
|
||||
|
||||
if (runtime_log)
|
||||
{
|
||||
/* Check whether a non-zero runtime has been recorded */
|
||||
if (runtime_log_has_runtime(runtime_log))
|
||||
{
|
||||
unsigned runtime_hours;
|
||||
unsigned runtime_minutes;
|
||||
unsigned runtime_seconds;
|
||||
unsigned last_played_year;
|
||||
unsigned last_played_month;
|
||||
unsigned last_played_day;
|
||||
unsigned last_played_hour;
|
||||
unsigned last_played_minute;
|
||||
unsigned last_played_second;
|
||||
|
||||
/* Read current runtime */
|
||||
runtime_log_get_runtime_hms(runtime_log,
|
||||
&runtime_hours, &runtime_minutes, &runtime_seconds);
|
||||
|
||||
/* Read last played timestamp */
|
||||
runtime_log_get_last_played(runtime_log,
|
||||
&last_played_year, &last_played_month, &last_played_day,
|
||||
&last_played_hour, &last_played_minute, &last_played_second);
|
||||
|
||||
/* Update playlist entry */
|
||||
playlist_update_runtime(playlist, i, NULL, NULL,
|
||||
runtime_hours, runtime_minutes, runtime_seconds,
|
||||
last_played_year, last_played_month, last_played_day,
|
||||
last_played_hour, last_played_minute, last_played_second,
|
||||
false);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
free(runtime_log);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string_is_empty(entry->path))
|
||||
{
|
||||
/* Standard playlist entry
|
||||
|
132
playlist.c
132
playlist.c
@ -236,40 +236,6 @@ void playlist_get_index(playlist_t *playlist,
|
||||
*entry = &playlist->entries[idx];
|
||||
}
|
||||
|
||||
void playlist_get_runtime_index(playlist_t *playlist,
|
||||
size_t idx,
|
||||
const char **path, const char **core_path,
|
||||
unsigned *runtime_hours, unsigned *runtime_minutes, unsigned *runtime_seconds,
|
||||
unsigned *last_played_year, unsigned *last_played_month, unsigned *last_played_day,
|
||||
unsigned *last_played_hour, unsigned *last_played_minute, unsigned *last_played_second)
|
||||
{
|
||||
if (!playlist)
|
||||
return;
|
||||
|
||||
if (path)
|
||||
*path = playlist->entries[idx].path;
|
||||
if (core_path)
|
||||
*core_path = playlist->entries[idx].core_path;
|
||||
if (runtime_hours)
|
||||
*runtime_hours = playlist->entries[idx].runtime_hours;
|
||||
if (runtime_minutes)
|
||||
*runtime_minutes = playlist->entries[idx].runtime_minutes;
|
||||
if (runtime_seconds)
|
||||
*runtime_seconds = playlist->entries[idx].runtime_seconds;
|
||||
if (last_played_year)
|
||||
*last_played_year = playlist->entries[idx].last_played_year;
|
||||
if (last_played_month)
|
||||
*last_played_month = playlist->entries[idx].last_played_month;
|
||||
if (last_played_day)
|
||||
*last_played_day = playlist->entries[idx].last_played_day;
|
||||
if (last_played_hour)
|
||||
*last_played_hour = playlist->entries[idx].last_played_hour;
|
||||
if (last_played_minute)
|
||||
*last_played_minute = playlist->entries[idx].last_played_minute;
|
||||
if (last_played_second)
|
||||
*last_played_second = playlist->entries[idx].last_played_second;
|
||||
}
|
||||
|
||||
/**
|
||||
* playlist_delete_index:
|
||||
* @playlist : Playlist handle.
|
||||
@ -380,6 +346,7 @@ static void playlist_free_entry(struct playlist_entry *entry)
|
||||
entry->subsystem_ident = NULL;
|
||||
entry->subsystem_name = NULL;
|
||||
entry->subsystem_roms = NULL;
|
||||
entry->runtime_status = PLAYLIST_RUNTIME_UNKNOWN;
|
||||
entry->runtime_hours = 0;
|
||||
entry->runtime_minutes = 0;
|
||||
entry->runtime_seconds = 0;
|
||||
@ -452,10 +419,7 @@ void playlist_update(playlist_t *playlist, size_t idx,
|
||||
}
|
||||
|
||||
void playlist_update_runtime(playlist_t *playlist, size_t idx,
|
||||
const char *path, const char *core_path,
|
||||
unsigned runtime_hours, unsigned runtime_minutes, unsigned runtime_seconds,
|
||||
unsigned last_played_year, unsigned last_played_month, unsigned last_played_day,
|
||||
unsigned last_played_hour, unsigned last_played_minute, unsigned last_played_second,
|
||||
const struct playlist_entry *update_entry,
|
||||
bool register_update)
|
||||
{
|
||||
struct playlist_entry *entry = NULL;
|
||||
@ -465,83 +429,87 @@ void playlist_update_runtime(playlist_t *playlist, size_t idx,
|
||||
|
||||
entry = &playlist->entries[idx];
|
||||
|
||||
if (path && (path != entry->path))
|
||||
if (update_entry->path && (update_entry->path != entry->path))
|
||||
{
|
||||
if (entry->path != NULL)
|
||||
free(entry->path);
|
||||
entry->path = strdup(path);
|
||||
entry->path = NULL;
|
||||
entry->path = strdup(update_entry->path);
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (core_path && (core_path != entry->core_path))
|
||||
if (update_entry->core_path && (update_entry->core_path != entry->core_path))
|
||||
{
|
||||
if (entry->core_path != NULL)
|
||||
free(entry->core_path);
|
||||
entry->core_path = NULL;
|
||||
entry->core_path = strdup(core_path);
|
||||
entry->core_path = strdup(update_entry->core_path);
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (runtime_hours != entry->runtime_hours)
|
||||
if (update_entry->runtime_status != entry->runtime_status)
|
||||
{
|
||||
entry->runtime_hours = runtime_hours;
|
||||
entry->runtime_status = update_entry->runtime_status;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (runtime_minutes != entry->runtime_minutes)
|
||||
if (update_entry->runtime_hours != entry->runtime_hours)
|
||||
{
|
||||
entry->runtime_minutes = runtime_minutes;
|
||||
entry->runtime_hours = update_entry->runtime_hours;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (runtime_seconds != entry->runtime_seconds)
|
||||
if (update_entry->runtime_minutes != entry->runtime_minutes)
|
||||
{
|
||||
entry->runtime_seconds = runtime_seconds;
|
||||
entry->runtime_minutes = update_entry->runtime_minutes;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_year != entry->last_played_year)
|
||||
if (update_entry->runtime_seconds != entry->runtime_seconds)
|
||||
{
|
||||
entry->last_played_year = last_played_year;
|
||||
entry->runtime_seconds = update_entry->runtime_seconds;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_month != entry->last_played_month)
|
||||
if (update_entry->last_played_year != entry->last_played_year)
|
||||
{
|
||||
entry->last_played_month = last_played_month;
|
||||
entry->last_played_year = update_entry->last_played_year;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_day != entry->last_played_day)
|
||||
if (update_entry->last_played_month != entry->last_played_month)
|
||||
{
|
||||
entry->last_played_day = last_played_day;
|
||||
entry->last_played_month = update_entry->last_played_month;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_hour != entry->last_played_hour)
|
||||
if (update_entry->last_played_day != entry->last_played_day)
|
||||
{
|
||||
entry->last_played_hour = last_played_hour;
|
||||
entry->last_played_day = update_entry->last_played_day;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_minute != entry->last_played_minute)
|
||||
if (update_entry->last_played_hour != entry->last_played_hour)
|
||||
{
|
||||
entry->last_played_minute = last_played_minute;
|
||||
entry->last_played_hour = update_entry->last_played_hour;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (last_played_second != entry->last_played_second)
|
||||
if (update_entry->last_played_minute != entry->last_played_minute)
|
||||
{
|
||||
entry->last_played_second = last_played_second;
|
||||
entry->last_played_minute = update_entry->last_played_minute;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
|
||||
if (update_entry->last_played_second != entry->last_played_second)
|
||||
{
|
||||
entry->last_played_second = update_entry->last_played_second;
|
||||
playlist->modified = playlist->modified || register_update;
|
||||
}
|
||||
}
|
||||
|
||||
bool playlist_push_runtime(playlist_t *playlist,
|
||||
const char *path, const char *core_path,
|
||||
unsigned runtime_hours, unsigned runtime_minutes, unsigned runtime_seconds,
|
||||
unsigned last_played_year, unsigned last_played_month, unsigned last_played_day,
|
||||
unsigned last_played_hour, unsigned last_played_minute, unsigned last_played_second)
|
||||
const struct playlist_entry *entry)
|
||||
{
|
||||
size_t i;
|
||||
char real_path[PATH_MAX_LENGTH];
|
||||
@ -550,24 +518,24 @@ bool playlist_push_runtime(playlist_t *playlist,
|
||||
real_path[0] = '\0';
|
||||
real_core_path[0] = '\0';
|
||||
|
||||
if (!playlist)
|
||||
if (!playlist || !entry)
|
||||
return false;
|
||||
|
||||
if (string_is_empty(core_path))
|
||||
if (string_is_empty(entry->core_path))
|
||||
{
|
||||
RARCH_ERR("cannot push NULL or empty core path into the playlist.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get 'real' path */
|
||||
if (!string_is_empty(path))
|
||||
if (!string_is_empty(entry->path))
|
||||
{
|
||||
strlcpy(real_path, path, sizeof(real_path));
|
||||
strlcpy(real_path, entry->path, sizeof(real_path));
|
||||
path_resolve_realpath(real_path, sizeof(real_path));
|
||||
}
|
||||
|
||||
/* Get 'real' core path */
|
||||
strlcpy(real_core_path, core_path, sizeof(real_core_path));
|
||||
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
||||
if (!string_is_equal(real_core_path, file_path_str(FILE_PATH_DETECT)))
|
||||
path_resolve_realpath(real_core_path, sizeof(real_core_path));
|
||||
|
||||
@ -609,10 +577,10 @@ bool playlist_push_runtime(playlist_t *playlist,
|
||||
|
||||
if (playlist->size == playlist->cap)
|
||||
{
|
||||
struct playlist_entry *entry = &playlist->entries[playlist->cap - 1];
|
||||
struct playlist_entry *last_entry = &playlist->entries[playlist->cap - 1];
|
||||
|
||||
if (entry)
|
||||
playlist_free_entry(entry);
|
||||
if (last_entry)
|
||||
playlist_free_entry(last_entry);
|
||||
playlist->size--;
|
||||
}
|
||||
|
||||
@ -629,15 +597,16 @@ bool playlist_push_runtime(playlist_t *playlist,
|
||||
if (!string_is_empty(real_core_path))
|
||||
playlist->entries[0].core_path = strdup(real_core_path);
|
||||
|
||||
playlist->entries[0].runtime_hours = runtime_hours;
|
||||
playlist->entries[0].runtime_minutes = runtime_minutes;
|
||||
playlist->entries[0].runtime_seconds = runtime_seconds;
|
||||
playlist->entries[0].last_played_year = last_played_year;
|
||||
playlist->entries[0].last_played_month = last_played_month;
|
||||
playlist->entries[0].last_played_day = last_played_day;
|
||||
playlist->entries[0].last_played_hour = last_played_hour;
|
||||
playlist->entries[0].last_played_minute = last_played_minute;
|
||||
playlist->entries[0].last_played_second = last_played_second;
|
||||
playlist->entries[0].runtime_status = entry->runtime_status;
|
||||
playlist->entries[0].runtime_hours = entry->runtime_hours;
|
||||
playlist->entries[0].runtime_minutes = entry->runtime_minutes;
|
||||
playlist->entries[0].runtime_seconds = entry->runtime_seconds;
|
||||
playlist->entries[0].last_played_year = entry->last_played_year;
|
||||
playlist->entries[0].last_played_month = entry->last_played_month;
|
||||
playlist->entries[0].last_played_day = entry->last_played_day;
|
||||
playlist->entries[0].last_played_hour = entry->last_played_hour;
|
||||
playlist->entries[0].last_played_minute = entry->last_played_minute;
|
||||
playlist->entries[0].last_played_second = entry->last_played_second;
|
||||
}
|
||||
|
||||
playlist->size++;
|
||||
@ -842,6 +811,7 @@ bool playlist_push(playlist_t *playlist,
|
||||
playlist->entries[0].subsystem_ident = NULL;
|
||||
playlist->entries[0].subsystem_name = NULL;
|
||||
playlist->entries[0].subsystem_roms = NULL;
|
||||
playlist->entries[0].runtime_status = PLAYLIST_RUNTIME_UNKNOWN;
|
||||
playlist->entries[0].runtime_hours = 0;
|
||||
playlist->entries[0].runtime_minutes = 0;
|
||||
playlist->entries[0].runtime_seconds = 0;
|
||||
|
25
playlist.h
25
playlist.h
@ -28,6 +28,13 @@ RETRO_BEGIN_DECLS
|
||||
|
||||
typedef struct content_playlist playlist_t;
|
||||
|
||||
enum playlist_runtime_status
|
||||
{
|
||||
PLAYLIST_RUNTIME_UNKNOWN = 0,
|
||||
PLAYLIST_RUNTIME_MISSING,
|
||||
PLAYLIST_RUNTIME_VALID
|
||||
};
|
||||
|
||||
struct playlist_entry
|
||||
{
|
||||
char *path;
|
||||
@ -39,6 +46,7 @@ struct playlist_entry
|
||||
char *subsystem_ident;
|
||||
char *subsystem_name;
|
||||
struct string_list *subsystem_roms;
|
||||
enum playlist_runtime_status runtime_status;
|
||||
unsigned runtime_hours;
|
||||
unsigned runtime_minutes;
|
||||
unsigned runtime_seconds;
|
||||
@ -100,13 +108,6 @@ void playlist_get_index(playlist_t *playlist,
|
||||
size_t idx,
|
||||
const struct playlist_entry **entry);
|
||||
|
||||
void playlist_get_runtime_index(playlist_t *playlist,
|
||||
size_t idx,
|
||||
const char **path, const char **core_path,
|
||||
unsigned *runtime_hours, unsigned *runtime_minutes, unsigned *runtime_seconds,
|
||||
unsigned *last_played_year, unsigned *last_played_month, unsigned *last_played_day,
|
||||
unsigned *last_played_hour, unsigned *last_played_minute, unsigned *last_played_second);
|
||||
|
||||
/**
|
||||
* playlist_delete_index:
|
||||
* @playlist : Playlist handle.
|
||||
@ -130,10 +131,7 @@ bool playlist_push(playlist_t *playlist,
|
||||
const struct playlist_entry *entry);
|
||||
|
||||
bool playlist_push_runtime(playlist_t *playlist,
|
||||
const char *path, const char *core_path,
|
||||
unsigned runtime_hours, unsigned runtime_minutes, unsigned runtime_seconds,
|
||||
unsigned last_played_year, unsigned last_played_month, unsigned last_played_day,
|
||||
unsigned last_played_hour, unsigned last_played_minute, unsigned last_played_second);
|
||||
const struct playlist_entry *entry);
|
||||
|
||||
void playlist_update(playlist_t *playlist, size_t idx,
|
||||
const struct playlist_entry *update_entry);
|
||||
@ -144,10 +142,7 @@ void playlist_update(playlist_t *playlist, size_t idx,
|
||||
* display purposes), we do not always want this function
|
||||
* to trigger a re-write of the playlist file. */
|
||||
void playlist_update_runtime(playlist_t *playlist, size_t idx,
|
||||
const char *path, const char *core_path,
|
||||
unsigned runtime_hours, unsigned runtime_minutes, unsigned runtime_seconds,
|
||||
unsigned last_played_year, unsigned last_played_month, unsigned last_played_day,
|
||||
unsigned last_played_hour, unsigned last_played_minute, unsigned last_played_second,
|
||||
const struct playlist_entry *update_entry,
|
||||
bool register_update);
|
||||
|
||||
void playlist_get_index_by_path(playlist_t *playlist,
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "verbosity.h"
|
||||
|
||||
#include "runtime_file.h"
|
||||
#include "menu/menu_defines.h"
|
||||
|
||||
#define LOG_FILE_RUNTIME_FORMAT_STR "%u:%02u:%02u"
|
||||
#define LOG_FILE_LAST_PLAYED_FORMAT_STR "%04u-%02u-%02u %02u:%02u:%02u"
|
||||
@ -791,3 +792,59 @@ void runtime_log_convert_usec2hms(retro_time_t usec,
|
||||
*seconds -= *minutes * 60;
|
||||
*minutes -= *hours * 60;
|
||||
}
|
||||
|
||||
|
||||
/* Playlist manipulation */
|
||||
|
||||
/* Updates specified playlist entry runtime values with
|
||||
* contents of associated log file */
|
||||
void runtime_update_playlist(playlist_t *playlist, size_t idx)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
runtime_log_t *runtime_log = NULL;
|
||||
const struct playlist_entry *entry = NULL;
|
||||
struct playlist_entry update_entry = {0};
|
||||
|
||||
/* Sanity check */
|
||||
if (!playlist || !settings)
|
||||
return;
|
||||
|
||||
if (idx >= playlist_get_size(playlist))
|
||||
return;
|
||||
|
||||
/* Set fallback playlist 'runtime_status'
|
||||
* (saves 'if' checks later...) */
|
||||
update_entry.runtime_status = PLAYLIST_RUNTIME_MISSING;
|
||||
|
||||
/* Read current playlist entry */
|
||||
playlist_get_index(playlist, idx, &entry);
|
||||
|
||||
/* Attempt to open log file */
|
||||
runtime_log = runtime_log_init(entry->path, entry->core_path,
|
||||
(settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE));
|
||||
|
||||
if (runtime_log)
|
||||
{
|
||||
/* Check whether a non-zero runtime has been recorded */
|
||||
if (runtime_log_has_runtime(runtime_log))
|
||||
{
|
||||
/* Read current runtime */
|
||||
runtime_log_get_runtime_hms(runtime_log,
|
||||
&update_entry.runtime_hours, &update_entry.runtime_minutes, &update_entry.runtime_seconds);
|
||||
|
||||
/* Read last played timestamp */
|
||||
runtime_log_get_last_played(runtime_log,
|
||||
&update_entry.last_played_year, &update_entry.last_played_month, &update_entry.last_played_day,
|
||||
&update_entry.last_played_hour, &update_entry.last_played_minute, &update_entry.last_played_second);
|
||||
|
||||
/* Playlist entry now contains valid runtime data */
|
||||
update_entry.runtime_status = PLAYLIST_RUNTIME_VALID;
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
free(runtime_log);
|
||||
}
|
||||
|
||||
/* Update playlist */
|
||||
playlist_update_runtime(playlist, idx, &update_entry, false);
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <time.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#include "playlist.h"
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
typedef struct
|
||||
@ -128,6 +130,12 @@ void runtime_log_convert_hms2usec(unsigned hours, unsigned minutes, unsigned sec
|
||||
/* Convert from microseconds to hours, minutes, seconds */
|
||||
void runtime_log_convert_usec2hms(retro_time_t usec, unsigned *hours, unsigned *minutes, unsigned *seconds);
|
||||
|
||||
/* Playlist manipulation */
|
||||
|
||||
/* Updates specified playlist entry runtime values with
|
||||
* contents of associated log file */
|
||||
void runtime_update_playlist(playlist_t *playlist, size_t idx);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user