diff --git a/command.c b/command.c index b6a2957864..0df46885c9 100644 --- a/command.c +++ b/command.c @@ -1961,8 +1961,7 @@ bool command_event(enum event_command cmd, void *data) content_get_status(&contentless, &is_inited); - if (!contentless) - rarch_ctl(RARCH_CTL_CONTENT_RUNTIME_LOG_DEINIT, NULL); + rarch_ctl(RARCH_CTL_CONTENT_RUNTIME_LOG_DEINIT, NULL); command_event(CMD_EVENT_AUTOSAVE_STATE, NULL); command_event(CMD_EVENT_DISABLE_OVERRIDES, NULL); command_event(CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET, NULL); diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 67bbec6bfc..75cb730eab 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -47,7 +47,7 @@ #include "../input/input_driver.h" #include "../tasks/tasks_internal.h" -#include "../../defaults.h" +#include "../../playlist.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) \ @@ -820,9 +820,10 @@ static int action_bind_sublabel_playlist_entry( { settings_t *settings = config_get_ptr(); playlist_t *playlist = NULL; - const char *playlist_path = NULL; - const char *core_path = NULL; const char *core_name = NULL; + unsigned runtime_hours = 0; + unsigned runtime_minutes = 0; + unsigned runtime_seconds = 0; if (!settings->bools.playlist_show_sublabels) return 0; @@ -835,7 +836,7 @@ static int action_bind_sublabel_playlist_entry( return 0; /* Read playlist entry */ - playlist_get_index(playlist, i, &playlist_path, NULL, &core_path, &core_name, NULL, NULL); + playlist_get_index(playlist, i, NULL, NULL, NULL, &core_name, NULL, NULL); /* 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))) @@ -861,50 +862,31 @@ static int action_bind_sublabel_playlist_entry( && !string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_HISTORY_TAB))) return 0; - /* Check that 'content_runtime.lpl' exists, and playlist has - * non-null path/core_path values... */ - if (g_defaults.content_runtime && !string_is_empty(playlist_path) && !string_is_empty(core_path)) - { - unsigned runtime_hours; - unsigned runtime_minutes; - unsigned runtime_seconds; - unsigned j; - - /* This is lame, but unless runtime is added to all playlists - * we can't really do it any other way... - * Search 'content_runtime.lpl' until we find the current - * content+core combo. */ - for (j = 0; j < playlist_get_size(g_defaults.content_runtime); j++) - { - const char *runtime_path = NULL; - const char *runtime_core_path = NULL; - - playlist_get_runtime_index(g_defaults.content_runtime, j, &runtime_path, &runtime_core_path, + /* 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); - - if (string_is_equal(playlist_path, runtime_path) && string_is_equal(core_path, runtime_core_path)) - { - int n = 0; - char tmp[64]; - 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); - - /* Stupid nonsense... GCC will generate warnings if we - * don't do something here... */ - if ((n < 0) || (n >= 64)) - { - n = 0; - } - - if (!string_is_empty(tmp)) - strlcat(s, tmp, len); - - break; - } + + if ((runtime_hours > 0) || (runtime_minutes > 0) || (runtime_seconds > 0)) + { + int n = 0; + char tmp[64]; + 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); + + /* Stupid nonsense... GCC will generate warnings if we + * don't do something here... */ + if ((n < 0) || (n >= 64)) + { + n = 0; } + + if (!string_is_empty(tmp)) + strlcat(s, tmp, len); } return 0; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index f81f17e6b4..7be1fa2e84 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1310,6 +1310,8 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, size_t selection = menu_navigation_get_selection(); 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 = string_is_equal(path_playlist, "history") && g_defaults.content_runtime && settings->bools.content_runtime_log; if (list_size == 0) goto error; @@ -1333,6 +1335,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, size_t path_size = PATH_MAX_LENGTH * sizeof(char); char *path_copy = (char*)malloc(path_size); char *fill_buf = (char*)malloc(path_size); + const char *core_path = NULL; const char *core_name = NULL; const char *path = NULL; const char *label = NULL; @@ -1345,7 +1348,36 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, path = path_copy; playlist_get_index(playlist, i, - &path, &label, NULL, &core_name, NULL, NULL); + &path, &label, &core_path, &core_name, NULL, NULL); + + /* If this is the content history playlist and runtime logging + * is enabled, extract any available runtime values */ + if (get_runtime) + { + unsigned j; + + /* Search 'content_runtime.lpl' until we find the current + * content+core combo */ + for (j = 0; j < playlist_get_size(g_defaults.content_runtime); j++) + { + const char *runtime_path = NULL; + const char *runtime_core_path = NULL; + unsigned runtime_hours; + unsigned runtime_minutes; + unsigned runtime_seconds; + + playlist_get_runtime_index(g_defaults.content_runtime, j, &runtime_path, &runtime_core_path, + &runtime_hours, &runtime_minutes, &runtime_seconds); + + if (string_is_equal(path, runtime_path) && string_is_equal(core_path, runtime_core_path)) + { + playlist_update_runtime(playlist, i, NULL, NULL, + runtime_hours, runtime_minutes, runtime_seconds); + + break; + } + } + } if (core_name) strlcpy(fill_buf, core_name, path_size); @@ -1355,7 +1387,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, * But if it ever were then we must ensure that thumbnail * updates are omitted (since this functionality is * handled elsewhere). */ - if (!is_history && i == selection && !string_is_empty(label) && !string_is_equal(settings->arrays.menu_driver, "rgui")) + if (!is_history && i == selection && !string_is_empty(label) && !is_rgui) { char *content_basename = strdup(label); diff --git a/retroarch.c b/retroarch.c index 6d300c11cf..99115a14cb 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1837,17 +1837,17 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) size_t pos = 0; seconds -= minutes * 60; - seconds -= hours * 60 *60; + minutes -= hours * 60; pos = strlcpy(log, "Content ran for a total of", sizeof(log)); if (hours > 0) - pos += snprintf(log + pos, sizeof(log) - pos, ", %d hours", hours); + pos += snprintf(log + pos, sizeof(log) - pos, ", %u hours", hours); if (minutes > 0) - pos += snprintf(log + pos, sizeof(log) - pos, ", %d minutes", minutes); + pos += snprintf(log + pos, sizeof(log) - pos, ", %u minutes", minutes); - pos += snprintf(log + pos, sizeof(log) - pos, ", %d seconds", seconds); + pos += snprintf(log + pos, sizeof(log) - pos, ", %u seconds", seconds); if (pos < sizeof(log) - 2) { @@ -1873,22 +1873,25 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) unsigned runtime_minutes = 0; unsigned runtime_seconds = 0; - playlist_get_runtime_index(g_defaults.content_runtime, 0, NULL, NULL, &runtime_hours, &runtime_minutes, &runtime_seconds); + playlist_get_runtime_index(g_defaults.content_runtime, 0, NULL, NULL, + &runtime_hours, &runtime_minutes, &runtime_seconds); runtime_seconds += seconds; if (runtime_seconds >= 60) { - runtime_minutes += runtime_seconds / 60; - runtime_seconds -= runtime_minutes * 60; + unsigned new_minutes = runtime_seconds / 60; + runtime_minutes += new_minutes; + runtime_seconds -= new_minutes * 60; } runtime_minutes += minutes; if (runtime_minutes >= 60) { - runtime_hours += runtime_minutes / 60; - runtime_minutes -= runtime_hours * 60; + unsigned new_hours = runtime_minutes / 60; + runtime_hours += new_hours; + runtime_minutes -= new_hours * 60; } runtime_hours += hours;