From 7d25827001493a82a8f75cfc6a0b956164b44f05 Mon Sep 17 00:00:00 2001 From: Guilherme Menaldo Date: Tue, 1 Oct 2019 22:57:09 -0300 Subject: Dehardcodes db files base path so the db folder can be easily moved --- src/map/achievement.c | 6 ++++-- src/map/clif.c | 9 ++++++--- src/map/guild.c | 3 ++- src/map/itemdb.c | 24 ++++++++---------------- src/map/map.c | 10 ++++------ src/map/mob.c | 4 +--- src/map/pc.c | 9 +++------ src/map/script.c | 3 ++- src/map/skill.c | 2 +- src/map/status.c | 6 ++++-- src/map/stylist.c | 3 ++- 11 files changed, 37 insertions(+), 42 deletions(-) (limited to 'src/map') diff --git a/src/map/achievement.c b/src/map/achievement.c index 7ab80e183..c2ebb5fdd 100644 --- a/src/map/achievement.c +++ b/src/map/achievement.c @@ -1099,7 +1099,8 @@ static bool achievement_get_rewards(struct map_session_data *sd, const struct ac */ static void achievement_readdb_ranks(void) { - const char *filename = "db/achievement_rank_db.conf"; + char filename[256]; + libconfig->format_db_path("achievement_rank_db.conf", filename, sizeof(filename)); struct config_t ar_conf = { 0 }; struct config_setting_t *ardb = NULL, *conf = NULL; int entry = 0; @@ -1777,7 +1778,8 @@ static void achievement_readdb_additional_fields(const struct config_setting_t * */ static void achievement_readb(void) { - const char *filename = "db/"DBPATH"achievement_db.conf"; + char filename[256]; + libconfig->format_db_path(DBPATH"achievement_db.conf", filename, sizeof(filename)); struct config_t ach_conf = { 0 }; struct config_setting_t *achdb = NULL, *conf = NULL; int entry = 0, count = 0; diff --git a/src/map/clif.c b/src/map/clif.c index f6caa502e..f8e2b63a2 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -19784,7 +19784,8 @@ static void clif_cashshop_db(void) { struct config_t cashshop_conf; struct config_setting_t *cashshop = NULL, *cats = NULL; - const char *config_filename = "db/cashshop_db.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("cashshop_db.conf", config_filename, sizeof(config_filename)); int i, item_count_t = 0; for( i = 0; i < CASHSHOP_TAB_MAX; i++ ) { CREATE(clif->cs.data[i], struct hCSData *, 1); @@ -21055,7 +21056,8 @@ static bool clif_parse_roulette_db(void) { struct config_t roulette_conf; struct config_setting_t *roulette = NULL, *levels = NULL; - const char *config_filename = "db/roulette_db.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("roulette_db.conf", config_filename, sizeof(config_filename)); int i, j, item_count_t = 0; for( i = 0; i < MAX_ROULETTE_LEVEL; i++ ) { @@ -22539,7 +22541,8 @@ static bool clif_parse_attendance_db(void) { struct config_t attendance_conf; struct config_setting_t *attendance = NULL, *it = NULL; - const char *config_filename = "db/attendance_db.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("attendance_db.conf", config_filename, sizeof(config_filename)); int i = 0; if (!libconfig->load_file(&attendance_conf, config_filename)) diff --git a/src/map/guild.c b/src/map/guild.c index 2faf60e2b..edd74a776 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -152,7 +152,8 @@ static bool guild_read_castledb_libconfig(void) { struct config_t castle_conf; struct config_setting_t *castle_db = NULL, *it = NULL; - const char *config_filename = "db/castle_db.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("castle_db.conf", config_filename, sizeof(config_filename)); int i = 0; if (libconfig->load_file(&castle_conf, config_filename) == 0) diff --git a/src/map/itemdb.c b/src/map/itemdb.c index a97325e57..5dc3d9317 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -846,11 +846,8 @@ static void itemdb_read_groups(void) { struct config_t item_group_conf; struct config_setting_t *itg = NULL, *it = NULL; -#ifdef RENEWAL - const char *config_filename = "db/re/item_group.conf"; // FIXME hardcoded name -#else - const char *config_filename = "db/pre-re/item_group.conf"; // FIXME hardcoded name -#endif + char config_filename[256]; + libconfig->format_db_path(DBPATH"item_group.conf", config_filename, sizeof(config_filename)); const char *itname; int i = 0, count = 0, c; unsigned int *gsize = NULL; @@ -1144,11 +1141,8 @@ static void itemdb_read_packages(void) { struct config_t item_packages_conf; struct config_setting_t *itg = NULL, *it = NULL, *t = NULL; -#ifdef RENEWAL - const char *config_filename = "db/re/item_packages.conf"; // FIXME hardcoded name -#else - const char *config_filename = "db/pre-re/item_packages.conf"; // FIXME hardcoded name -#endif + char config_filename[256]; + libconfig->format_db_path(DBPATH"item_packages.conf", config_filename, sizeof(config_filename)); const char *itname; int i = 0, count = 0, c = 0, highest_gcount = 0; unsigned int *must = NULL, *random = NULL, *rgroup = NULL, **rgroups = NULL; @@ -1393,7 +1387,8 @@ static void itemdb_read_options(void) struct config_t item_options_db; struct config_setting_t *ito = NULL, *conf = NULL; int index = 0, count = 0; - const char *filepath = "db/item_options.conf"; + char filepath[256]; + libconfig->format_db_path("item_options.conf", filepath, sizeof(filepath)); VECTOR_DECL(int) duplicate_id; if (!libconfig->load_file(&item_options_db, filepath)) @@ -1494,11 +1489,8 @@ static void itemdb_read_chains(void) { struct config_t item_chain_conf; struct config_setting_t *itc = NULL; -#ifdef RENEWAL - const char *config_filename = "db/re/item_chain.conf"; // FIXME hardcoded name -#else - const char *config_filename = "db/pre-re/item_chain.conf"; // FIXME hardcoded name -#endif + char config_filename[256]; + libconfig->format_db_path(DBPATH"item_chain.conf", config_filename, sizeof(config_filename)); int i = 0, count = 0; if (!libconfig->load_file(&item_chain_conf, config_filename)) diff --git a/src/map/map.c b/src/map/map.c index 332bbe75f..ebd5b068c 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4055,6 +4055,7 @@ static bool map_config_read_database(const char *filename, struct config_t *conf return false; } libconfig->setting_lookup_mutable_string(setting, "db_path", map->db_path, sizeof(map->db_path)); + libconfig->set_db_path(map->db_path); libconfig->setting_lookup_int(setting, "save_settings", &map->save_settings); if (libconfig->setting_lookup_int(setting, "autosave_time", &map->autosave_interval) == CONFIG_TRUE) { @@ -5574,12 +5575,8 @@ static void read_map_zone_db(void) { struct config_t map_zone_db; struct config_setting_t *zones = NULL; - /* TODO: #ifndef required for re/pre-re */ -#ifdef RENEWAL - const char *config_filename = "db/re/map_zone_db.conf"; // FIXME hardcoded name -#else - const char *config_filename = "db/pre-re/map_zone_db.conf"; // FIXME hardcoded name -#endif + char config_filename[256]; + libconfig->format_db_path(DBPATH"map_zone_db.conf", config_filename, sizeof(config_filename)); if (!libconfig->load_file(&map_zone_db, config_filename)) return; @@ -6774,6 +6771,7 @@ void map_defaults(void) map->extra_scripts_count = 0; sprintf(map->db_path ,"db"); + libconfig->set_db_path(map->db_path); sprintf(map->help_txt ,"conf/help.txt"); sprintf(map->charhelp_txt ,"conf/charhelp.txt"); diff --git a/src/map/mob.c b/src/map/mob.c index e04d6944e..a9d6c8a51 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -4078,10 +4078,8 @@ static bool mob_read_optdrops_group(struct config_setting_t *group, int n) */ static bool mob_read_optdrops_db(void) { - const char *filename = "option_drop_groups.conf"; // FIXME hardcoded name - char filepath[256]; - safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, filename); + libconfig->format_db_path("option_drop_groups.conf", filepath, sizeof(filepath)); struct config_t option_groups; if (libconfig->load_file(&option_groups, filepath) == CONFIG_FALSE) { diff --git a/src/map/pc.c b/src/map/pc.c index 2cefa7674..3192690eb 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -11533,12 +11533,9 @@ static bool pc_read_exp_db(void) struct config_t exp_db_conf; struct config_setting_t *edb = NULL; int entry_count = 0; - -#ifdef RENEWAL - const char *config_filename = "db/re/exp_group_db.conf"; -#else - const char *config_filename = "db/pre-re/exp_group_db.conf"; -#endif + char config_filename[256]; + + libconfig->format_db_path(DBPATH"exp_group_db.conf", config_filename, sizeof(config_filename)); if (!libconfig->load_file(&exp_db_conf, config_filename)) return false; diff --git a/src/map/script.c b/src/map/script.c index 0fe97574c..557fada9f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5150,7 +5150,8 @@ static uint8 script_add_language(const char *name) static void script_load_translations(void) { struct config_t translations_conf; - const char *config_filename = "db/translations.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("translations.conf", config_filename, sizeof(config_filename)); struct config_setting_t *translations = NULL; int i, size; int total = 0; diff --git a/src/map/skill.c b/src/map/skill.c index ad27ef0e3..dc710eadf 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -21105,7 +21105,7 @@ static bool skill_read_skilldb(const char *filename) nullpo_retr(false, filename); - sprintf(filepath,"db/%s",filename); + libconfig->format_db_path(filename, filepath, sizeof(filepath)); if (!libconfig->load_file(&skilldb, filepath)) { return false; // Libconfig error report. diff --git a/src/map/status.c b/src/map/status.c index 71cce28c5..83b94b955 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -13339,10 +13339,12 @@ static void status_read_job_db(void) int i = 0; struct config_t job_db_conf; struct config_setting_t *jdb = NULL; + char config_filename[256]; + #ifdef RENEWAL_ASPD - const char *config_filename = "db/re/job_db.conf"; + libconfig->format_db_path(DBPATH_RE"job_db.conf", config_filename, sizeof(config_filename)); #else - const char *config_filename = "db/pre-re/job_db.conf"; + libconfig->format_db_path(DBPATH_PRE"job_db.conf", config_filename, sizeof(config_filename)); #endif if (!libconfig->load_file(&job_db_conf, config_filename)) diff --git a/src/map/stylist.c b/src/map/stylist.c index 7e7c13bf7..438302214 100644 --- a/src/map/stylist.c +++ b/src/map/stylist.c @@ -40,7 +40,8 @@ static bool stylist_read_db_libconfig(void) { struct config_t stylist_conf; struct config_setting_t *stylist_db = NULL, *it = NULL; - const char *config_filename = "db/stylist_db.conf"; // FIXME hardcoded name + char config_filename[256]; + libconfig->format_db_path("stylist_db.conf", config_filename, sizeof(config_filename)); int i = 0; if (!libconfig->load_file(&stylist_conf, config_filename)) -- cgit v1.2.3-70-g09d2