mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-25 03:56:54 +01:00
Finish state conversion
for last save path (hopefully not broken).
This commit is contained in:
parent
1daa664fe0
commit
d677712b51
@ -17,11 +17,6 @@
|
||||
|
||||
static ed64_pseudo_writeback_t current_state;
|
||||
|
||||
// FIXME: Use one file using the ed64_pseudo_writeback_t struct.
|
||||
#ifndef LAST_SAVE_FILE_PATH
|
||||
#define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp"
|
||||
#endif
|
||||
|
||||
extern int ed_exit (void);
|
||||
|
||||
static flashcart_err_t ed64_init (void) {
|
||||
@ -42,38 +37,17 @@ static flashcart_err_t ed64_init (void) {
|
||||
current_state.is_warm_start = false;
|
||||
ed64_state_save(¤t_state);
|
||||
|
||||
// finds the last save location
|
||||
FIL lrp_fil;
|
||||
UINT lrp_br;
|
||||
|
||||
if (f_open(&lrp_fil, strip_sd_prefix(LAST_SAVE_FILE_PATH), FA_READ) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
int lrp_size = f_size(&lrp_fil);
|
||||
|
||||
TCHAR lrp_path[lrp_size++];
|
||||
|
||||
if (f_read(&lrp_fil, lrp_path, lrp_size, &lrp_br) != FR_OK) {
|
||||
f_close(&lrp_fil);
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
if (f_close(&lrp_fil) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
// Now save the content back to the SD card!
|
||||
FIL fil;
|
||||
UINT br;
|
||||
UINT bw;
|
||||
uint8_t cartsave_data[KiB(128)];
|
||||
|
||||
// find the path to last save
|
||||
if (file_exists(strip_sd_prefix(lrp_path))) {
|
||||
if (file_exists(strip_sd_prefix(current_state.last_save_path))) {
|
||||
|
||||
int save_size = file_get_size(strip_sd_prefix(lrp_path));
|
||||
int save_size = file_get_size(strip_sd_prefix(current_state.last_save_path));
|
||||
|
||||
if ((f_open(&fil, strip_sd_prefix(lrp_path), FA_CREATE_ALWAYS | FA_READ | FA_WRITE)) != FR_OK) {
|
||||
if ((f_open(&fil, strip_sd_prefix(current_state.last_save_path), FA_CREATE_ALWAYS | FA_READ | FA_WRITE)) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
@ -92,7 +66,7 @@ static flashcart_err_t ed64_init (void) {
|
||||
ed64_ll_get_eeprom(cartsave_data, save_size);
|
||||
}
|
||||
|
||||
if (f_write(&fil, cartsave_data, save_size, &br) != FR_OK) {
|
||||
if (f_write(&fil, cartsave_data, save_size, &bw) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
@ -100,6 +74,10 @@ static flashcart_err_t ed64_init (void) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
}
|
||||
else {
|
||||
current_state.last_save_path = "";
|
||||
ed64_state_save(¤t_state);
|
||||
}
|
||||
}
|
||||
return FLASHCART_OK;
|
||||
}
|
||||
@ -258,21 +236,7 @@ static flashcart_err_t ed64_load_save (char *save_path) {
|
||||
}
|
||||
|
||||
|
||||
FIL lsp_fil;
|
||||
UINT lsp_bw;
|
||||
|
||||
if (f_open(&lsp_fil, strip_sd_prefix(LAST_SAVE_FILE_PATH), FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
if (f_write(&lsp_fil, strip_sd_prefix(save_path), strlen(save_path), &lsp_bw) != FR_OK) {
|
||||
f_close(&lsp_fil);
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
if (f_close(&lsp_fil) != FR_OK) {
|
||||
return FLASHCART_ERR_LOAD;
|
||||
}
|
||||
|
||||
current_state.last_save_path = save_path;
|
||||
current_state.is_warm_start = true;
|
||||
ed64_state_save(¤t_state);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
static ed64_pseudo_writeback_t init = {
|
||||
.is_warm_start = false,
|
||||
.is_fram_save_type = false,
|
||||
.last_rom_path = ""
|
||||
.last_save_path = ""
|
||||
};
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ void ed64_state_load (ed64_pseudo_writeback_t *state) {
|
||||
|
||||
state->is_warm_start = mini_get_bool(ini, "ed64", "is_warm_start", init.is_warm_start);
|
||||
state->is_fram_save_type = mini_get_bool(ini, "ed64", "is_fram_save_type", init.is_fram_save_type);
|
||||
state->last_rom_path = strdup(mini_get_string(ini, "ed64", "last_rom_path", init.last_rom_path));
|
||||
state->last_save_path = strdup(mini_get_string(ini, "ed64", "last_save_path", init.last_save_path));
|
||||
|
||||
mini_free(ini);
|
||||
}
|
||||
@ -34,7 +34,7 @@ void ed64_state_save (ed64_pseudo_writeback_t *state) {
|
||||
|
||||
mini_set_bool(ini, "ed64", "is_warm_start", state->is_warm_start);
|
||||
mini_set_bool(ini, "ed64", "is_fram_save_type", state->is_fram_save_type);
|
||||
mini_set_string(ini, "ed64", "last_rom_path", state->last_rom_path);
|
||||
mini_set_string(ini, "ed64", "last_save_path", state->last_save_path);
|
||||
|
||||
mini_save(ini);
|
||||
|
||||
|
@ -14,7 +14,7 @@ typedef struct {
|
||||
/** @brief The last save type was flash ram */
|
||||
bool is_fram_save_type;
|
||||
/** @brief The path to the last loaded ROM */
|
||||
char *last_rom_path;
|
||||
char *last_save_path;
|
||||
} ed64_pseudo_writeback_t;
|
||||
|
||||
void ed64_state_load (ed64_pseudo_writeback_t *state);
|
||||
|
Loading…
Reference in New Issue
Block a user