diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-08-15 12:59:30 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-08-15 12:59:30 +0000 |
commit | 4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b (patch) | |
tree | 7ecdb7999066cfcf21acd7ed4ea02f5a51dd2943 /crawl-ref/source/database.cc | |
parent | 474793c7638ec859494caef26d03f6e1ce731f87 (diff) | |
download | crawl-ref-4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b.tar.gz crawl-ref-4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b.zip |
[1773753] Split and sort the description db input file (zelgadis).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2003 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r-- | crawl-ref/source/database.cc | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc index 66e7ad3a69..bf9c4fad14 100644 --- a/crawl-ref/source/database.cc +++ b/crawl-ref/source/database.cc @@ -26,9 +26,10 @@ db_list openDBList; DBM *descriptionDB; #define DESC_BASE_NAME "descript" -#define DESC_TXT (DESC_BASE_NAME ".txt") +#define DESC_TXT_DIR "descript" #define DESC_DB (DESC_BASE_NAME ".db") +static std::vector<std::string> description_txt_paths(); static void generate_description_db(); void databaseSystemInit() @@ -36,9 +37,17 @@ void databaseSystemInit() if (!descriptionDB) { std::string descriptionPath = get_savedir_path(DESC_DB); - check_newer(descriptionPath, - datafile_path(DESC_TXT), - generate_description_db); + std::vector<std::string> textPaths = description_txt_paths(); + + // If any of the description text files are newer then + // aggregated description db, then regenerate the whole db + for (int i = 0, size = textPaths.size(); i < size; i++) + if (is_newer(textPaths[i], descriptionPath)) + { + generate_description_db(); + break; + } + descriptionPath.erase(descriptionPath.length() - 3); if (!(descriptionDB = openDB(descriptionPath.c_str()))) end(1, true, "Failed to open DB: %s", descriptionPath.c_str()); @@ -103,16 +112,43 @@ std::string getLongDescription(const std::string &key) return std::string((const char *)result.dptr, result.dsize); } +static std::vector<std::string> description_txt_paths() +{ + std::vector<std::string> txt_file_names; + std::vector<std::string> paths; + + txt_file_names.push_back("features"); + txt_file_names.push_back("items"); + txt_file_names.push_back("monsters"); + txt_file_names.push_back("spells"); + + for (int i = 0, size = txt_file_names.size(); i < size; i++) + { + std::string name = DESC_TXT_DIR; + name += FILE_SEPARATOR; + name += txt_file_names[i]; + name += ".txt"; + + std::string txt_path = datafile_path(name); + paths.push_back(txt_path); + } + + return (paths); +} + static void store_descriptions(const std::string &in, const std::string &out); static void generate_description_db() { std::string db_path = get_savedir_path(DESC_BASE_NAME); std::string full_db_path = get_savedir_path(DESC_DB); - std::string txt_path = datafile_path(DESC_TXT); + + std::vector<std::string> txt_paths = description_txt_paths(); file_lock lock(get_savedir_path(DESC_BASE_NAME ".lk"), "wb"); unlink( full_db_path.c_str() ); - store_descriptions(txt_path, db_path); + + for (int i = 0, size = txt_paths.size(); i < size; i++) + store_descriptions(txt_paths[i], db_path); DO_CHMOD_PRIVATE(full_db_path.c_str()); } |