frontend: simplify config handling
[picodrive.git] / platform / common / emu.c
index d0cc988..e7a9912 100644 (file)
@@ -581,33 +581,29 @@ int emu_read_config(const char *rom_fname, int no_defaults)
        }\r
        else\r
        {\r
-               char *sect = emu_make_rom_id(rom_fname);\r
+               char ext[16];\r
+               int vol;\r
 \r
                if (config_slot != 0)\r
-                    sprintf(cfg, "game.%i.cfg", config_slot);\r
-               else strcpy(cfg,  "game.cfg");\r
-\r
-               ret = -1;\r
-               if (config_havesect(cfg, sect))\r
-               {\r
-                       // read user's config\r
-                       int vol = currentConfig.volume;\r
-                       emu_set_defconfig();\r
-                       ret = config_readsect(cfg, sect);\r
-                       currentConfig.volume = vol; // make vol global (bah)\r
-               }\r
+                       snprintf(ext, sizeof(ext), ".%i.cfg", config_slot);\r
                else\r
+                       strcpy(ext, ".cfg");\r
+\r
+               fname_ext(cfg, sizeof(cfg), "cfg"PATH_SEP, ext, rom_fname);\r
+\r
+               // read user's config\r
+               vol = currentConfig.volume;\r
+               ret = config_readsect(cfg, NULL);\r
+               currentConfig.volume = vol; // make vol global (bah)\r
+\r
+               if (ret != 0)\r
                {\r
                        // read global config, and apply game_def.cfg on top\r
                        make_config_cfg(cfg);\r
                        config_readsect(cfg, NULL);\r
-                       emu_make_path(cfg, "game_def.cfg", sizeof(cfg));\r
-                       ret = config_readsect(cfg, sect);\r
-               }\r
 \r
-               if (ret == 0)\r
-               {\r
-                       lprintf("loaded cfg from sect \"%s\"\n", sect);\r
+                       emu_make_path(cfg, "game_def.cfg", sizeof(cfg));\r
+                       ret = config_readsect(cfg, emu_make_rom_id(rom_fname));\r
                }\r
        }\r
 \r
@@ -632,7 +628,7 @@ int emu_read_config(const char *rom_fname, int no_defaults)
 \r
 int emu_write_config(int is_game)\r
 {\r
-       char cfg[512], *game_sect = NULL;\r
+       char cfg[512];\r
        int ret, write_lrom = 0;\r
 \r
        if (!is_game)\r
@@ -640,15 +636,18 @@ int emu_write_config(int is_game)
                make_config_cfg(cfg);\r
                write_lrom = 1;\r
        } else {\r
+               char ext[16];\r
+\r
                if (config_slot != 0)\r
-                    sprintf(cfg, "game.%i.cfg", config_slot);\r
-               else strcpy(cfg,  "game.cfg");\r
-               game_sect = emu_make_rom_id(rom_fname_loaded);\r
-               lprintf("emu_write_config: sect \"%s\"\n", game_sect);\r
+                       snprintf(ext, sizeof(ext), ".%i.cfg", config_slot);\r
+               else\r
+                       strcpy(ext, ".cfg");\r
+\r
+               romfname_ext(cfg, sizeof(cfg), "cfg"PATH_SEP, ext);\r
        }\r
 \r
        lprintf("emu_write_config: %s ", cfg);\r
-       ret = config_writesect(cfg, game_sect);\r
+       ret = config_write(cfg);\r
        if (write_lrom) config_writelrom(cfg);\r
 #ifndef NO_SYNC\r
        sync();\r
@@ -1172,6 +1171,7 @@ void emu_init(void)
        mkdir_path(path, pos, "mds");\r
        mkdir_path(path, pos, "srm");\r
        mkdir_path(path, pos, "brm");\r
+       mkdir_path(path, pos, "cfg");\r
 \r
        pprof_init();\r
 \r