Only parse runtime playlist when loading content history playlist (+ bugfixes to original runtime logging)

This commit is contained in:
jdgleaver 2019-02-21 15:48:55 +00:00
parent 0b04312412
commit 1d0cee5fe5
4 changed files with 75 additions and 59 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;