Cleanup dump_to_file_desperate

This commit is contained in:
twinaphex 2016-01-27 00:06:06 +01:00
parent b80b5c7be3
commit cce5d3e900

View File

@ -117,7 +117,7 @@ static bool read_content_file(unsigned i, const char *path, void **buf,
* *
* Attempt to save valuable RAM data somewhere. * Attempt to save valuable RAM data somewhere.
**/ **/
static void dump_to_file_desperate(const void *data, static bool dump_to_file_desperate(const void *data,
size_t size, unsigned type) size_t size, unsigned type)
{ {
time_t time_; time_t time_;
@ -132,7 +132,7 @@ static void dump_to_file_desperate(const void *data,
#endif #endif
if (!base) if (!base)
goto error; return false;
snprintf(path, sizeof(path), "%s/RetroArch-recovery-%u", base, type); snprintf(path, sizeof(path), "%s/RetroArch-recovery-%u", base, type);
@ -141,15 +141,11 @@ static void dump_to_file_desperate(const void *data,
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_)); strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
strlcat(path, timebuf, sizeof(path)); strlcat(path, timebuf, sizeof(path));
if (retro_write_file(path, data, size)) if (!retro_write_file(path, data, size))
RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path); return false;
else
goto error;
return; RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path);
return true;
error:
RARCH_WARN("Failed ... Cannot recover save file.\n");
} }
@ -338,8 +334,6 @@ static bool load_ram_file(ram_type_t *ram)
* *
* Save a RAM state from memory to disk. * Save a RAM state from memory to disk.
* *
* In case the file could not be written to, a fallback function
* 'dump_to_file_desperate' will be called.
*/ */
static bool save_ram_file(ram_type_t *ram) static bool save_ram_file(ram_type_t *ram)
{ {
@ -354,7 +348,14 @@ static bool save_ram_file(ram_type_t *ram)
RARCH_ERR("%s.\n", RARCH_ERR("%s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM)); msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
RARCH_WARN("Attempting to recover ...\n"); RARCH_WARN("Attempting to recover ...\n");
dump_to_file_desperate(data, size, ram->type);
/* In case the file could not be written to,
* the fallback function 'dump_to_file_desperate'
* will be called. */
if (!dump_to_file_desperate(data, size, ram->type))
{
RARCH_WARN("Failed ... Cannot recover save file.\n");
}
return false; return false;
} }