Skip to content

Commit

Permalink
Add savestate info messagebox showing date/time modified
Browse files Browse the repository at this point in the history
  • Loading branch information
neil4 committed Sep 1, 2024
1 parent 0e68a23 commit 6275403
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 11 deletions.
11 changes: 1 addition & 10 deletions command_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,17 +689,8 @@ static void event_main_state(unsigned cmd)
{
char *path = string_alloc(PATH_MAX_LENGTH);
char *msg = string_alloc(PATH_MAX_LENGTH);
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();

if (settings->state_slot > 0)
snprintf(path, PATH_MAX_LENGTH, "%s%d",
global->savestate_name, settings->state_slot);
else if (settings->state_slot < 0)
snprintf(path, PATH_MAX_LENGTH, "%s.auto",
global->savestate_name);
else
strlcpy(path, global->savestate_name, PATH_MAX_LENGTH);
get_savestate_path(path);

if (pretro_serialize_size())
{
Expand Down
23 changes: 23 additions & 0 deletions libretro-common/file/file_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,26 @@ void fill_short_pathname_representation(char* out_rep,
else
strlcpy(out_rep,path_short, size);
}

time_t path_modified_time(char *path)
{
#ifdef _WIN32
FILETIME mtime;
ULARGE_INTEGER ularge;
HANDLE file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

GetFileTime(file, NULL, NULL, &mtime);
CloseHandle(file);

ularge.LowPart = mtime.dwLowDateTime;
ularge.HighPart = mtime.dwHighDateTime;

return (time_t)((ularge.QuadPart - 116444736000000000ULL) / 10000000ULL);
#else
struct stat info;
stat(path, &info);

return info.st_mtime;
#endif
}
2 changes: 2 additions & 0 deletions libretro-common/include/file/file_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ void fill_pathname_slash(char *path, size_t size);
void fill_pathname_application_path(char *buf, size_t size);
#endif

time_t path_modified_time(char *path);

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 29 additions & 1 deletion menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <file/file_path.h>
#include <file/config_file.h>
#include <string/stdstring.h>

#include "menu.h"
#include "menu_input.h"
Expand All @@ -36,6 +37,7 @@
#include "../preempt.h"
#include "drivers/rgui.h"
#include "../core_history.h"
#include "../retroarch.h"

#if defined(__CELLOS_LV2__)
#include <sdk_version.h>
Expand Down Expand Up @@ -2601,7 +2603,7 @@ static rarch_setting_t setting_string_setting_options(enum setting_type type,
}

static INLINE void setting_get_dl_core_info(char *s, size_t len,
const char* path)
const char* path)
{
global_t *global = global_get_ptr();
char key[NAME_MAX_LENGTH];
Expand All @@ -2611,6 +2613,28 @@ static INLINE void setting_get_dl_core_info(char *s, size_t len,
snprintf(s, len, "-- No description available for this core --");
}

static void setting_get_savestate_info(char *s, size_t len)
{
char *path = string_alloc(PATH_MAX_LENGTH);
settings_t *settings = config_get_ptr();

get_savestate_path(path);

if (path_exists(path))
{
time_t mtime = path_modified_time(path);
char buf[32];

strftime(buf, 32, "%b %d %Y %H:%M:%S", localtime(&mtime));
snprintf(s, len, "State %i date/time modified:\n%s",
settings->state_slot, buf);
}
else
snprintf(s, len, "State %i is empty", settings->state_slot);

free(path);
}

static int setting_get_description_compare_label(uint32_t label_hash,
settings_t *settings, char *s, size_t len,
const char *path, unsigned type, unsigned entry_idx)
Expand Down Expand Up @@ -3761,6 +3785,10 @@ static int setting_get_description_compare_label(uint32_t label_hash,
"content is running or if\n"
"file updates are disabled.");
break;
case MENU_LABEL_SAVESTATE:
case MENU_LABEL_LOADSTATE:
setting_get_savestate_info(s, len);
break;
default:
return -1;
}
Expand Down
15 changes: 15 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,3 +1552,18 @@ bool rarch_clear_all_thread_waits(unsigned clear_threads, void* data)

return true;
}

void get_savestate_path(char *path)
{
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();

if (settings->state_slot > 0)
snprintf(path, PATH_MAX_LENGTH, "%s%d",
global->savestate_name, settings->state_slot);
else if (settings->state_slot < 0)
snprintf(path, PATH_MAX_LENGTH, "%s.auto",
global->savestate_name);
else
strlcpy(path, global->savestate_name, PATH_MAX_LENGTH);
}
2 changes: 2 additions & 0 deletions retroarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ int rarch_info_get_capabilities(enum rarch_capabilities type, char *s, size_t le

bool rarch_clear_all_thread_waits(unsigned clear_threads, void* data);

void get_savestate_path(char *path);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 6275403

Please sign in to comment.