mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 13:20:43 +00:00
(task_patch.c) Cleanups
This commit is contained in:
parent
0185f71bab
commit
71499abf1f
@ -506,47 +506,36 @@ static enum patch_error ips_apply_patch(
|
|||||||
|
|
||||||
static bool apply_patch_content(uint8_t **buf,
|
static bool apply_patch_content(uint8_t **buf,
|
||||||
ssize_t *size, const char *patch_desc, const char *patch_path,
|
ssize_t *size, const char *patch_desc, const char *patch_path,
|
||||||
patch_func_t func)
|
patch_func_t func, void *patch_data, ssize_t patch_size)
|
||||||
{
|
{
|
||||||
size_t target_size;
|
size_t target_size;
|
||||||
ssize_t patch_size;
|
|
||||||
void *patch_data = NULL;
|
|
||||||
enum patch_error err = PATCH_UNKNOWN;
|
enum patch_error err = PATCH_UNKNOWN;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
uint8_t *patched_content = NULL;
|
uint8_t *patched_content = NULL;
|
||||||
ssize_t ret_size = *size;
|
ssize_t ret_size = *size;
|
||||||
uint8_t *ret_buf = *buf;
|
uint8_t *ret_buf = *buf;
|
||||||
|
|
||||||
if (!path_is_valid(patch_path))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!filestream_read_file(patch_path, &patch_data, &patch_size))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (patch_size < 0)
|
if (patch_size < 0)
|
||||||
{
|
|
||||||
free(patch_data);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!path_file_exists(patch_path))
|
if (!path_file_exists(patch_path))
|
||||||
{
|
|
||||||
free(patch_data);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
RARCH_LOG("Found %s file in \"%s\", attempting to patch ...\n",
|
RARCH_LOG("Found %s file in \"%s\", attempting to patch ...\n",
|
||||||
patch_desc, patch_path);
|
patch_desc, patch_path);
|
||||||
|
|
||||||
target_size = ret_size * 4; /* Just to be sure. */
|
target_size = ret_size * 4; /* Just to be sure. */
|
||||||
|
|
||||||
patched_content = (uint8_t*)malloc(target_size);
|
patched_content = (uint8_t*)malloc(target_size);
|
||||||
|
|
||||||
if (!patched_content)
|
if (!patched_content)
|
||||||
{
|
{
|
||||||
RARCH_ERR("%s\n",
|
RARCH_ERR("%s\n",
|
||||||
msg_hash_to_str(MSG_FAILED_TO_ALLOCATE_MEMORY_FOR_PATCHED_CONTENT));
|
msg_hash_to_str(MSG_FAILED_TO_ALLOCATE_MEMORY_FOR_PATCHED_CONTENT));
|
||||||
goto error;
|
|
||||||
|
*buf = ret_buf;
|
||||||
|
*size = ret_size;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = func((const uint8_t*)patch_data, patch_size, ret_buf,
|
err = func((const uint8_t*)patch_data, patch_size, ret_buf,
|
||||||
@ -569,27 +558,32 @@ static bool apply_patch_content(uint8_t **buf,
|
|||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
free(ret_buf);
|
free(ret_buf);
|
||||||
*buf = patched_content;
|
*buf = patched_content;
|
||||||
*size = target_size;
|
*size = target_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(patch_data);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
|
||||||
*buf = ret_buf;
|
|
||||||
*size = ret_size;
|
|
||||||
free(patch_data);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool try_bps_patch(bool allow_bps, const char *name_bps,
|
static bool try_bps_patch(bool allow_bps, const char *name_bps,
|
||||||
uint8_t **buf, ssize_t *size)
|
uint8_t **buf, ssize_t *size)
|
||||||
{
|
{
|
||||||
if (allow_bps && !string_is_empty(name_bps))
|
if (allow_bps && !string_is_empty(name_bps))
|
||||||
return apply_patch_content(buf, size, "BPS", name_bps,
|
if (path_is_valid(name_bps))
|
||||||
bps_apply_patch);
|
{
|
||||||
|
ssize_t patch_size;
|
||||||
|
bool ret = false;
|
||||||
|
void *patch_data = NULL;
|
||||||
|
|
||||||
|
if (!filestream_read_file(name_bps, &patch_data, &patch_size))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ret = apply_patch_content(
|
||||||
|
buf, size, "BPS", name_bps,
|
||||||
|
bps_apply_patch, patch_data, patch_size);
|
||||||
|
free(patch_data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,8 +591,21 @@ static bool try_ups_patch(bool allow_ups, const char *name_ups,
|
|||||||
uint8_t **buf, ssize_t *size)
|
uint8_t **buf, ssize_t *size)
|
||||||
{
|
{
|
||||||
if (allow_ups && !string_is_empty(name_ups))
|
if (allow_ups && !string_is_empty(name_ups))
|
||||||
return apply_patch_content(buf, size, "UPS", name_ups,
|
if (path_is_valid(name_ups))
|
||||||
ups_apply_patch);
|
{
|
||||||
|
ssize_t patch_size;
|
||||||
|
bool ret = false;
|
||||||
|
void *patch_data = NULL;
|
||||||
|
|
||||||
|
if (!filestream_read_file(name_ups, &patch_data, &patch_size))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ret = apply_patch_content(
|
||||||
|
buf, size, "UPS", name_ups,
|
||||||
|
ups_apply_patch, patch_data, patch_size);
|
||||||
|
free(patch_data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,7 +613,21 @@ static bool try_ips_patch(bool allow_ips,
|
|||||||
const char *name_ips, uint8_t **buf, ssize_t *size)
|
const char *name_ips, uint8_t **buf, ssize_t *size)
|
||||||
{
|
{
|
||||||
if (allow_ips && !string_is_empty(name_ips))
|
if (allow_ips && !string_is_empty(name_ips))
|
||||||
return apply_patch_content(buf, size, "IPS", name_ips, ips_apply_patch);
|
if (path_is_valid(name_ips))
|
||||||
|
{
|
||||||
|
ssize_t patch_size;
|
||||||
|
bool ret = false;
|
||||||
|
void *patch_data = NULL;
|
||||||
|
|
||||||
|
if (!filestream_read_file(name_ips, &patch_data, &patch_size))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ret = apply_patch_content(
|
||||||
|
buf, size, "IPS", name_ips,
|
||||||
|
ips_apply_patch, patch_data, patch_size);
|
||||||
|
free(patch_data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user