From 4e44ab99a1b8c0f6c5c893fdc721a237922cb4cc Mon Sep 17 00:00:00 2001 From: meleu Date: Fri, 19 Aug 2016 08:45:58 -0300 Subject: [PATCH 1/5] added fill_str_dated_filename() function This function creates a 'dated' filename prefixed by the string `in_str`, and concatenates extension (`ext`) to it. --- libretro-common/file/file_path.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 2fd572c394..ae970d9a8a 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -423,6 +423,32 @@ void fill_dated_filename(char *out_filename, strlcat(out_filename, ext, size); } +/** + * fill_str_dated_filename: + * @out_filename : output filename + * @in_str : input string + * @ext : extension of output filename + * @size : buffer size of output filename + * + * Creates a 'dated' filename prefixed by the string @in_str, and + * concatenates extension (@ext) to it. + * + * E.g.: + * out_filename = "RetroArch-{year}{month}{day}-{Hour}{Minute}{Second}.{@ext}" + **/ +void fill_str_dated_filename(char *out_filename, + const char *in_str, const char *ext, size_t size) +{ + char format[PATH_MAX_LENGTH] = {0}; + time_t cur_time; + time(&cur_time); + + snprintf(format, sizeof(format), + "%s-%%y%%m%%d-%%H%%M%%S.", in_str); + strftime(out_filename, size, format, localtime(&cur_time)); + strlcat(out_filename, ext, size); +} + /** * path_basedir: * @path : path From e1f4b41bb629b98d3e0a7581909fdeec197e2d10 Mon Sep 17 00:00:00 2001 From: meleu Date: Fri, 19 Aug 2016 08:49:09 -0300 Subject: [PATCH 2/5] added fill_str_dated_filename() prototype --- libretro-common/include/file/file_path.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index b861373b71..08dba54aad 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -194,6 +194,22 @@ void fill_pathname(char *out_path, const char *in_path, void fill_dated_filename(char *out_filename, const char *ext, size_t size); +/** + * fill_str_dated_filename: + * @out_filename : output filename + * @in_str : input string + * @ext : extension of output filename + * @size : buffer size of output filename + * + * Creates a 'dated' filename prefixed by the string @in_str, and + * concatenates extension (@ext) to it. + * + * E.g.: + * out_filename = "RetroArch-{year}{month}{day}-{Hour}{Minute}{Second}.{@ext}" + **/ +void fill_str_dated_filename(char *out_filename, + const char *in_str, const char *ext, size_t size); + /** * fill_pathname_noext: * @out_path : output path From 01abbe3d4d29235c56e07a8ee25873ea985b15f7 Mon Sep 17 00:00:00 2001 From: meleu Date: Fri, 19 Aug 2016 08:53:14 -0300 Subject: [PATCH 3/5] screenshot filename "game name-yymmdd-hhmmss.ext" replaced fill_dated_filename() by fill_str_dated_filename() to add the game name to the screenshot. --- tasks/task_screenshot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 0dbfe70caf..525fbeaeb5 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -78,14 +78,14 @@ static bool screenshot_dump( if (settings->auto_screenshot_filename) { - fill_dated_filename(shotname, IMG_EXT, sizeof(shotname)); - fill_pathname_join(filename, folder, shotname, sizeof(filename)); + fill_str_dated_filename(shotname, path_basename(global_name_base), + IMG_EXT, sizeof(shotname)); } else { snprintf(shotname, sizeof(shotname),"%s.png", path_basename(global_name_base)); - fill_pathname_join(filename, folder, shotname, sizeof(filename)); } + fill_pathname_join(filename, folder, shotname, sizeof(filename)); #ifdef _XBOX1 d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(true); From c92efacebea2ce99c93109a7e7399cd9a5f7ae68 Mon Sep 17 00:00:00 2001 From: meleu Date: Fri, 19 Aug 2016 10:13:33 -0300 Subject: [PATCH 4/5] avoid problems if ROM name has percents As @Alcaro noted here: https://github.com/libretro/RetroArch/pull/3407 --- libretro-common/file/file_path.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index ae970d9a8a..e9100d8cc0 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -439,13 +439,13 @@ void fill_dated_filename(char *out_filename, void fill_str_dated_filename(char *out_filename, const char *in_str, const char *ext, size_t size) { - char format[PATH_MAX_LENGTH] = {0}; + char format[256] = {0}; time_t cur_time; time(&cur_time); - snprintf(format, sizeof(format), - "%s-%%y%%m%%d-%%H%%M%%S.", in_str); - strftime(out_filename, size, format, localtime(&cur_time)); + strncpy(out_filename, in_str, size); + strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", localtime(&cur_time)); + strlcat(out_filename, format, size); strlcat(out_filename, ext, size); } From db204afc9c544053ec04dc6d744988ef10c57b05 Mon Sep 17 00:00:00 2001 From: meleu Date: Fri, 19 Aug 2016 16:31:13 -0300 Subject: [PATCH 5/5] changes based on the @Alcaro suggestions Suggestions made here: https://github.com/libretro/RetroArch/pull/3407 --- libretro-common/file/file_path.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index e9100d8cc0..2f2a7e772d 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -415,8 +415,7 @@ void fill_pathname_parent_dir(char *out_dir, void fill_dated_filename(char *out_filename, const char *ext, size_t size) { - time_t cur_time; - time(&cur_time); + time_t cur_time = time(NULL); strftime(out_filename, size, "RetroArch-%m%d-%H%M%S.", localtime(&cur_time)); @@ -440,11 +439,10 @@ void fill_str_dated_filename(char *out_filename, const char *in_str, const char *ext, size_t size) { char format[256] = {0}; - time_t cur_time; - time(&cur_time); + time_t cur_time = time(NULL); - strncpy(out_filename, in_str, size); strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", localtime(&cur_time)); + strlcpy(out_filename, in_str, size); strlcat(out_filename, format, size); strlcat(out_filename, ext, size); }