mirror of
https://github.com/libretro/RetroArch.git
synced 2024-05-20 13:27:22 -04:00
Cleanups
This commit is contained in:
parent
b89a750d43
commit
c2b81881ae
156
core_backup.c
156
core_backup.c
|
@ -244,11 +244,11 @@ error:
|
||||||
* Returns true if successful */
|
* Returns true if successful */
|
||||||
bool core_backup_get_backup_crc(char *backup_path, uint32_t *crc)
|
bool core_backup_get_backup_crc(char *backup_path, uint32_t *crc)
|
||||||
{
|
{
|
||||||
struct string_list *metadata_list = NULL;
|
|
||||||
enum core_backup_type backup_type;
|
enum core_backup_type backup_type;
|
||||||
|
struct string_list *metadata_list = NULL;
|
||||||
|
|
||||||
if (string_is_empty(backup_path) || !crc)
|
if (string_is_empty(backup_path) || !crc)
|
||||||
goto error;
|
return false;
|
||||||
|
|
||||||
/* Get backup type */
|
/* Get backup type */
|
||||||
backup_type = core_backup_get_backup_type(backup_path);
|
backup_type = core_backup_get_backup_type(backup_path);
|
||||||
|
@ -340,69 +340,64 @@ enum core_backup_type core_backup_get_core_path(
|
||||||
char *core_path, size_t len)
|
char *core_path, size_t len)
|
||||||
{
|
{
|
||||||
const char *backup_filename = NULL;
|
const char *backup_filename = NULL;
|
||||||
char *core_filename = NULL;
|
|
||||||
enum core_backup_type backup_type = CORE_BACKUP_TYPE_INVALID;
|
|
||||||
|
|
||||||
if (string_is_empty(backup_path) || string_is_empty(dir_libretro))
|
if (string_is_empty(backup_path) || string_is_empty(dir_libretro))
|
||||||
return backup_type;
|
return CORE_BACKUP_TYPE_INVALID;
|
||||||
|
|
||||||
backup_filename = path_basename(backup_path);
|
backup_filename = path_basename(backup_path);
|
||||||
|
|
||||||
if (string_is_empty(backup_filename))
|
if (!string_is_empty(backup_filename))
|
||||||
return backup_type;
|
|
||||||
|
|
||||||
/* Check backup type */
|
|
||||||
switch (core_backup_get_backup_type(backup_path))
|
|
||||||
{
|
{
|
||||||
case CORE_BACKUP_TYPE_ARCHIVE:
|
/* Check backup type */
|
||||||
{
|
switch (core_backup_get_backup_type(backup_path))
|
||||||
char *period = NULL;
|
{
|
||||||
|
case CORE_BACKUP_TYPE_ARCHIVE:
|
||||||
|
{
|
||||||
|
/* This is an archived backup with timestamp/crc
|
||||||
|
* metadata in the filename */
|
||||||
|
char *core_filename = strdup(backup_filename);
|
||||||
|
/* Find the location of the second period */
|
||||||
|
char *period = strchr(core_filename, '.');
|
||||||
|
if (!period || (*(++period) == '\0'))
|
||||||
|
{
|
||||||
|
free(core_filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is an archived backup with timestamp/crc
|
if (!(period = strchr(period, '.')))
|
||||||
* metadata in the filename */
|
{
|
||||||
core_filename = strdup(backup_filename);
|
free(core_filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find the location of the second period */
|
/* Trim everything after (and including) the
|
||||||
period = strchr(core_filename, '.');
|
* second period */
|
||||||
if (!period || (*(++period) == '\0'))
|
*period = '\0';
|
||||||
break;
|
|
||||||
|
|
||||||
period = strchr(period, '.');
|
if (string_is_empty(core_filename))
|
||||||
if (!period)
|
{
|
||||||
break;
|
free(core_filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Trim everything after (and including) the
|
/* All good - build core path */
|
||||||
* second period */
|
fill_pathname_join_special(core_path, dir_libretro,
|
||||||
*period = '\0';
|
core_filename, len);
|
||||||
|
free(core_filename);
|
||||||
if (string_is_empty(core_filename))
|
}
|
||||||
break;
|
return CORE_BACKUP_TYPE_ARCHIVE;
|
||||||
|
case CORE_BACKUP_TYPE_LIB:
|
||||||
/* All good - build core path */
|
/* This is a plain dynamic library file */
|
||||||
fill_pathname_join_special(core_path, dir_libretro,
|
fill_pathname_join_special(core_path, dir_libretro,
|
||||||
core_filename, len);
|
backup_filename, len);
|
||||||
|
return CORE_BACKUP_TYPE_LIB;
|
||||||
backup_type = CORE_BACKUP_TYPE_ARCHIVE;
|
default:
|
||||||
}
|
/* Backup is invalid */
|
||||||
break;
|
break;
|
||||||
case CORE_BACKUP_TYPE_LIB:
|
}
|
||||||
/* This is a plain dynamic library file */
|
|
||||||
fill_pathname_join_special(core_path, dir_libretro,
|
|
||||||
backup_filename, len);
|
|
||||||
backup_type = CORE_BACKUP_TYPE_LIB;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Backup is invalid */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_filename)
|
return CORE_BACKUP_TYPE_INVALID;
|
||||||
{
|
|
||||||
free(core_filename);
|
|
||||||
core_filename = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return backup_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************/
|
/*************************/
|
||||||
|
@ -426,7 +421,7 @@ static bool core_backup_add_entry(core_backup_list_t *backup_list,
|
||||||
|| string_is_empty(core_filename)
|
|| string_is_empty(core_filename)
|
||||||
|| string_is_empty(backup_path)
|
|| string_is_empty(backup_path)
|
||||||
|| (backup_list->size >= backup_list->capacity))
|
|| (backup_list->size >= backup_list->capacity))
|
||||||
goto error;
|
return false;
|
||||||
|
|
||||||
backup_filename = strdup(path_basename(backup_path));
|
backup_filename = strdup(path_basename(backup_path));
|
||||||
|
|
||||||
|
@ -529,9 +524,7 @@ core_backup_list_t *core_backup_list_init(
|
||||||
dir_list_sort(dir_list, true);
|
dir_list_sort(dir_list, true);
|
||||||
|
|
||||||
/* Create core backup list */
|
/* Create core backup list */
|
||||||
backup_list = (core_backup_list_t*)malloc(sizeof(*backup_list));
|
if (!(backup_list = (core_backup_list_t*)malloc(sizeof(*backup_list))))
|
||||||
|
|
||||||
if (!backup_list)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
backup_list->entries = NULL;
|
backup_list->entries = NULL;
|
||||||
|
@ -542,10 +535,8 @@ core_backup_list_t *core_backup_list_init(
|
||||||
* (Note: Set this to the full size of the directory
|
* (Note: Set this to the full size of the directory
|
||||||
* list - this may be larger than we need, but saves
|
* list - this may be larger than we need, but saves
|
||||||
* many inefficiencies later) */
|
* many inefficiencies later) */
|
||||||
entries = (core_backup_list_entry_t*)
|
if (!(entries = (core_backup_list_entry_t*)
|
||||||
calloc(dir_list->size, sizeof(*entries));
|
calloc(dir_list->size, sizeof(*entries))))
|
||||||
|
|
||||||
if (!entries)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
backup_list->entries = entries;
|
backup_list->entries = entries;
|
||||||
|
@ -695,48 +686,3 @@ bool core_backup_list_get_crc(
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fetches a string representation of a backup
|
|
||||||
* list entry timestamp.
|
|
||||||
* Returns false in the event of an error */
|
|
||||||
bool core_backup_list_get_entry_timestamp_str(
|
|
||||||
const core_backup_list_entry_t *entry,
|
|
||||||
enum core_backup_date_separator_type date_separator,
|
|
||||||
char *timestamp, size_t len)
|
|
||||||
{
|
|
||||||
const char *format_str = "%04u-%02u-%02u %02u:%02u:%02u";
|
|
||||||
|
|
||||||
if (!entry || (len < 20))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* Get time format string */
|
|
||||||
if (date_separator == CORE_BACKUP_DATE_SEPARATOR_SLASH)
|
|
||||||
format_str = "%04u/%02u/%02u %02u:%02u:%02u";
|
|
||||||
else if (date_separator == CORE_BACKUP_DATE_SEPARATOR_PERIOD)
|
|
||||||
format_str = "%04u.%02u.%02u %02u:%02u:%02u";
|
|
||||||
|
|
||||||
snprintf(timestamp, len,
|
|
||||||
format_str,
|
|
||||||
entry->date.year,
|
|
||||||
entry->date.month,
|
|
||||||
entry->date.day,
|
|
||||||
entry->date.hour,
|
|
||||||
entry->date.minute,
|
|
||||||
entry->date.second);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fetches a string representation of a backup
|
|
||||||
* list entry crc value.
|
|
||||||
* Returns false in the event of an error */
|
|
||||||
bool core_backup_list_get_entry_crc_str(
|
|
||||||
const core_backup_list_entry_t *entry,
|
|
||||||
char *crc, size_t len)
|
|
||||||
{
|
|
||||||
if (!entry || (len < 9))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
snprintf(crc, len, "%08lx", (unsigned long)entry->crc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -157,21 +157,6 @@ bool core_backup_list_get_crc(
|
||||||
uint32_t crc, enum core_backup_mode backup_mode,
|
uint32_t crc, enum core_backup_mode backup_mode,
|
||||||
const core_backup_list_entry_t **entry);
|
const core_backup_list_entry_t **entry);
|
||||||
|
|
||||||
/* Fetches a string representation of a backup
|
|
||||||
* list entry timestamp.
|
|
||||||
* Returns false in the event of an error */
|
|
||||||
bool core_backup_list_get_entry_timestamp_str(
|
|
||||||
const core_backup_list_entry_t *entry,
|
|
||||||
enum core_backup_date_separator_type date_separator,
|
|
||||||
char *timestamp, size_t len);
|
|
||||||
|
|
||||||
/* Fetches a string representation of a backup
|
|
||||||
* list entry crc value.
|
|
||||||
* Returns false in the event of an error */
|
|
||||||
bool core_backup_list_get_entry_crc_str(
|
|
||||||
const core_backup_list_entry_t *entry,
|
|
||||||
char *crc, size_t len);
|
|
||||||
|
|
||||||
RETRO_END_DECLS
|
RETRO_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -885,6 +885,31 @@ end:
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fetches a string representation of a backup
|
||||||
|
* list entry timestamp.
|
||||||
|
* Returns false in the event of an error */
|
||||||
|
static size_t core_backup_list_get_entry_timestamp_str(
|
||||||
|
const core_backup_list_entry_t *entry,
|
||||||
|
enum core_backup_date_separator_type date_separator,
|
||||||
|
char *timestamp, size_t len)
|
||||||
|
{
|
||||||
|
const char *format_str = "%04u-%02u-%02u %02u:%02u:%02u";
|
||||||
|
/* Get time format string */
|
||||||
|
if (date_separator == CORE_BACKUP_DATE_SEPARATOR_SLASH)
|
||||||
|
format_str = "%04u/%02u/%02u %02u:%02u:%02u";
|
||||||
|
else if (date_separator == CORE_BACKUP_DATE_SEPARATOR_PERIOD)
|
||||||
|
format_str = "%04u.%02u.%02u %02u:%02u:%02u";
|
||||||
|
|
||||||
|
return snprintf(timestamp, len,
|
||||||
|
format_str,
|
||||||
|
entry->date.year,
|
||||||
|
entry->date.month,
|
||||||
|
entry->date.day,
|
||||||
|
entry->date.hour,
|
||||||
|
entry->date.minute,
|
||||||
|
entry->date.second);
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned menu_displaylist_parse_core_backup_list(
|
static unsigned menu_displaylist_parse_core_backup_list(
|
||||||
file_list_t *list, const char *core_path,
|
file_list_t *list, const char *core_path,
|
||||||
settings_t *settings, bool restore)
|
settings_t *settings, bool restore)
|
||||||
|
@ -936,8 +961,7 @@ static unsigned menu_displaylist_parse_core_backup_list(
|
||||||
/* Get timestamp and crc strings */
|
/* Get timestamp and crc strings */
|
||||||
core_backup_list_get_entry_timestamp_str(
|
core_backup_list_get_entry_timestamp_str(
|
||||||
entry, date_separator, timestamp, sizeof(timestamp));
|
entry, date_separator, timestamp, sizeof(timestamp));
|
||||||
core_backup_list_get_entry_crc_str(
|
snprintf(crc, sizeof(crc), "%08lx", (unsigned long)entry->crc);
|
||||||
entry, crc, sizeof(crc));
|
|
||||||
|
|
||||||
/* Append 'auto backup' tag to timestamp, if required */
|
/* Append 'auto backup' tag to timestamp, if required */
|
||||||
if (entry->backup_mode == CORE_BACKUP_MODE_AUTO)
|
if (entry->backup_mode == CORE_BACKUP_MODE_AUTO)
|
||||||
|
|
Loading…
Reference in a new issue