Improve state file path

This commit is contained in:
Robin Jones 2024-05-01 21:12:15 +01:00
parent 8188a240b6
commit 7e2b503ee5
3 changed files with 20 additions and 6 deletions

View File

@ -14,6 +14,11 @@
#include "ed64.h"
#include "ed64_state.h"
#define ED64_STATE_FILE "ed64_state.ini"
#ifndef ED64_OS_DIRECTORY
#define ED64_OS_DIRECTORY "/ED64"
#endif
static ed64_pseudo_writeback_t current_state;
@ -29,6 +34,9 @@ static flashcart_err_t ed64_init (void) {
// older everdrives cannot save during gameplay so we need to the reset method.
// works by checking if a file exists.
// FIXME: should put the file in the OS dir, but different if a clone (ED64P).
char *state_path = "sd:/menu/"ED64_STATE_FILE;
ed64_state_init(state_path);
ed64_state_load(&current_state);
if (current_state.is_expecting_save_writeback == true) {

View File

@ -4,9 +4,7 @@
#include "ed64_state.h"
#include "utils/fs.h"
#ifndef ED64_STATE_FILE_PATH
#define ED64_STATE_FILE_PATH "sd:/menu/ed64_state.ini"
#endif
static char *ed64_state_path = NULL;
static ed64_pseudo_writeback_t init = {
.is_expecting_save_writeback = false,
@ -14,13 +12,19 @@ static ed64_pseudo_writeback_t init = {
.last_save_path = ""
};
void ed64_state_init (char *path) {
if (ed64_state_path) {
free(ed64_state_path);
}
ed64_state_path = strdup(path);
}
void ed64_state_load (ed64_pseudo_writeback_t *state) {
if (!file_exists(ED64_STATE_FILE_PATH)) {
if (!file_exists(ed64_state_path)) {
ed64_state_save(&init);
}
mini_t *ini = mini_try_load(ED64_STATE_FILE_PATH);
mini_t *ini = mini_try_load(ed64_state_path);
state->is_expecting_save_writeback = mini_get_bool(ini, "ed64", "is_expecting_save_writeback", init.is_expecting_save_writeback);
state->is_fram_save_type = mini_get_bool(ini, "ed64", "is_fram_save_type", init.is_fram_save_type);
@ -30,7 +34,7 @@ void ed64_state_load (ed64_pseudo_writeback_t *state) {
}
void ed64_state_save (ed64_pseudo_writeback_t *state) {
mini_t *ini = mini_create(ED64_STATE_FILE_PATH);
mini_t *ini = mini_create(ed64_state_path);
mini_set_bool(ini, "ed64", "is_expecting_save_writeback", state->is_expecting_save_writeback);
mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type);

View File

@ -17,6 +17,8 @@ typedef struct {
char *last_save_path;
} ed64_pseudo_writeback_t;
/** @brief Init ED64 state path */
void ed64_state_init (char *path);
void ed64_state_load (ed64_pseudo_writeback_t *state);
void ed64_state_save (ed64_pseudo_writeback_t *state);