mirror of
https://github.com/libretro/RetroArch
synced 2024-12-26 21:29:08 +00:00
Add Cheat File Save As
This commit is contained in:
parent
d81e7b9fc7
commit
38066b6ec7
61
cheats.c
61
cheats.c
@ -18,7 +18,7 @@
|
||||
#include "general.h"
|
||||
#include "dynamic.h"
|
||||
#include <file/config_file.h>
|
||||
#include <file/config_file_macros.h>
|
||||
#include <file/file_path.h>
|
||||
#include <compat/strl.h>
|
||||
#include <compat/posix_string.h>
|
||||
|
||||
@ -43,6 +43,65 @@ void cheat_manager_apply_cheats(cheat_manager_t *handle)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cheat_manager_save:
|
||||
* @path : Path to cheats file (relative path).
|
||||
*
|
||||
* Saves cheats to file on disk.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool cheat_manager_save(cheat_manager_t *handle, const char *path)
|
||||
{
|
||||
bool ret;
|
||||
unsigned i;
|
||||
char buf[PATH_MAX_LENGTH];
|
||||
char cheats_file[PATH_MAX_LENGTH];
|
||||
config_file_t *conf = NULL;
|
||||
|
||||
fill_pathname_join(buf, g_settings.cheat_database,
|
||||
path, sizeof(buf));
|
||||
|
||||
fill_pathname_noext(cheats_file, buf, ".cht", sizeof(cheats_file));
|
||||
|
||||
conf = config_file_new(cheats_file);
|
||||
|
||||
if (!conf)
|
||||
conf = config_file_new(NULL);
|
||||
|
||||
if (!conf)
|
||||
return false;
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
config_set_int(conf, "cheats", handle->size);
|
||||
|
||||
for (i = 0; i < handle->size; i++)
|
||||
{
|
||||
char key[64], desc_key[256], code_key[256], enable_key[256];
|
||||
char *tmp = NULL;
|
||||
bool tmp_bool = false;
|
||||
|
||||
snprintf(key, sizeof(key), "cheat%u", i);
|
||||
snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i);
|
||||
snprintf(code_key, sizeof(code_key), "cheat%u_code", i);
|
||||
snprintf(enable_key, sizeof(enable_key), "cheat%u_enable", i);
|
||||
|
||||
if (handle->cheats[i].desc)
|
||||
config_set_string(conf, desc_key, handle->cheats[i].desc);
|
||||
else
|
||||
config_set_string(conf, desc_key, handle->cheats[i].code);
|
||||
config_set_string(conf, code_key, handle->cheats[i].code);
|
||||
config_set_bool(conf, enable_key, handle->cheats[i].state);
|
||||
}
|
||||
|
||||
ret = config_file_write(conf, cheats_file);
|
||||
config_file_free(conf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
cheat_manager_t *cheat_manager_load(const char *path)
|
||||
{
|
||||
unsigned cheats = 0, i;
|
||||
|
10
cheats.h
10
cheats.h
@ -44,6 +44,16 @@ cheat_manager_t *cheat_manager_new(unsigned size);
|
||||
|
||||
cheat_manager_t *cheat_manager_load(const char *path);
|
||||
|
||||
/**
|
||||
* cheat_manager_save:
|
||||
* @path : Path to cheats file (absolute path).
|
||||
*
|
||||
* Saves cheats to file on disk.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool cheat_manager_save(cheat_manager_t *handle, const char *path);
|
||||
|
||||
bool cheat_manager_realloc(cheat_manager_t *handle, unsigned new_size);
|
||||
|
||||
void cheat_manager_free(cheat_manager_t *handle);
|
||||
|
@ -434,6 +434,17 @@ static int action_ok_shader_preset_save_as(const char *path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_ok_cheat_file_save_as(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
if (!driver.menu)
|
||||
return -1;
|
||||
|
||||
menu_input_key_start_line(driver.menu, "Cheat Filename",
|
||||
label, type, idx, menu_input_st_string_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_ok_remap_file_save_as(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
@ -2064,6 +2075,8 @@ static int deferred_push_core_cheat_options(void *data, void *userdata,
|
||||
menu_list_clear(list);
|
||||
menu_list_push(list, "Cheat File Load", "cheat_file_load",
|
||||
MENU_SETTING_ACTION, 0);
|
||||
menu_list_push(list, "Cheat File Save As",
|
||||
"cheat_file_save_as", MENU_SETTING_ACTION, 0);
|
||||
menu_list_push(list, "Cheat Passes", "cheat_num_passes",
|
||||
0, 0);
|
||||
menu_list_push(list, "Apply Cheat Changes", "cheat_apply_changes",
|
||||
@ -2673,6 +2686,8 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
|
||||
cbs->action_ok = action_ok_cheat_apply_changes;
|
||||
else if (!strcmp(label, "video_shader_preset_save_as"))
|
||||
cbs->action_ok = action_ok_shader_preset_save_as;
|
||||
else if (!strcmp(label, "cheat_file_save_as"))
|
||||
cbs->action_ok = action_ok_cheat_file_save_as;
|
||||
else if (!strcmp(label, "remap_file_save_as"))
|
||||
cbs->action_ok = action_ok_remap_file_save_as;
|
||||
else if (!strcmp(label, "core_list"))
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "menu.h"
|
||||
#include "menu_action.h"
|
||||
#include "menu_shader.h"
|
||||
#include "../cheats.h"
|
||||
#include "../performance.h"
|
||||
#include "../settings_data.h"
|
||||
#include "../input/input_joypad.h"
|
||||
@ -107,6 +108,8 @@ void menu_input_st_string_callback(void *userdata, const char *str)
|
||||
menu_shader_manager_save_preset(str, false);
|
||||
else if (!strcmp(menu->keyboard.label_setting, "remap_file_save_as"))
|
||||
input_remapping_save_file(str);
|
||||
else if (!strcmp(menu->keyboard.label_setting, "cheat_file_save_as"))
|
||||
cheat_manager_save(g_extern.cheat, str);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user