Fixed unnecessary error message when resulting ROM override config file was already empty

This commit is contained in:
Mateusz Faderewski 2024-06-02 19:24:36 +02:00
parent 3ffe7087b1
commit 7fa60f4253
5 changed files with 23 additions and 12 deletions

View File

@ -1,3 +1,4 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
@ -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);

View File

@ -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;

View File

@ -1,6 +1,6 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <time.h>
#include "../fonts.h"

View File

@ -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";
}

View File

@ -1,7 +1,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include "fs.h"