diff --git a/src/menu/rom_info.c b/src/menu/rom_info.c index 14026ee9..a2f50cf1 100644 --- a/src/menu/rom_info.c +++ b/src/menu/rom_info.c @@ -1,3 +1,4 @@ +#include #include #include @@ -832,13 +833,21 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def mini_t *ini = mini_try_load(path_get(overrides_path)); if (!ini) { - return ROM_ERR_IO; + return ROM_ERR_SAVE_IO; } + int mini_err; + if (value == default_value) { - mini_delete_value(ini, NULL, id); + mini_err = mini_delete_value(ini, NULL, id); } else { - mini_set_int(ini, NULL, id, value); + mini_err = mini_set_int(ini, NULL, id, value); + } + + if ((mini_err != MINI_OK) && (mini_err != MINI_VALUE_NOT_FOUND)) { + path_free(overrides_path); + mini_free(ini); + return ROM_ERR_SAVE_IO; } bool empty = mini_empty(ini); @@ -847,16 +856,16 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def if (mini_save(ini, MINI_FLAGS_NONE) != MINI_OK) { path_free(overrides_path); mini_free(ini); - return ROM_ERR_IO; + return ROM_ERR_SAVE_IO; } } mini_free(ini); if (empty) { - if (remove(path_get(overrides_path))) { + if (remove(path_get(overrides_path)) && (errno != ENOENT)) { path_free(overrides_path); - return ROM_ERR_IO; + return ROM_ERR_SAVE_IO; } } @@ -946,10 +955,10 @@ rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info) { setbuf(f, NULL); if (fread(&rom_header, sizeof(rom_header), 1, f) != 1) { fclose(f); - return ROM_ERR_IO; + return ROM_ERR_LOAD_IO; } if (fclose(f)) { - return ROM_ERR_IO; + return ROM_ERR_LOAD_IO; } fix_rom_header_endianness(&rom_header, rom_info); diff --git a/src/menu/rom_info.h b/src/menu/rom_info.h index cb241a2e..0308cfc9 100644 --- a/src/menu/rom_info.h +++ b/src/menu/rom_info.h @@ -18,7 +18,8 @@ /** @brief ROM error enumeration. */ typedef enum { ROM_OK, - ROM_ERR_IO, + ROM_ERR_LOAD_IO, + ROM_ERR_SAVE_IO, ROM_ERR_NO_FILE, } rom_err_t; diff --git a/src/menu/views/browser.c b/src/menu/views/browser.c index bb514b1b..75c45a15 100644 --- a/src/menu/views/browser.c +++ b/src/menu/views/browser.c @@ -1,6 +1,6 @@ +#include #include #include -#include #include #include "../fonts.h" diff --git a/src/menu/views/load_rom.c b/src/menu/views/load_rom.c index e6d8e531..9695bbc4 100644 --- a/src/menu/views/load_rom.c +++ b/src/menu/views/load_rom.c @@ -10,7 +10,8 @@ static component_boxart_t *boxart; static char *convert_error_message (rom_err_t err) { switch (err) { - case ROM_ERR_IO: return "I/O error during loading/storing ROM information"; + case ROM_ERR_LOAD_IO: return "I/O error during loading ROM information and/or options"; + case ROM_ERR_SAVE_IO: return "I/O error during storing ROM options"; case ROM_ERR_NO_FILE: return "Couldn't open ROM file"; default: return "Unknown ROM info load error"; } diff --git a/src/utils/fs.c b/src/utils/fs.c index 41b69c48..b02b2e2c 100644 --- a/src/utils/fs.c +++ b/src/utils/fs.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include #include "fs.h"