diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 1a4ff965..e01cf76c 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -318,48 +318,22 @@ void reparse_color(String* def) // -- BAILOPAN int CLangMngr::MergeDefinitionFile(const char *file) { - const char* md5buffer = hashFile(file, Hash_Md5); - if (!md5buffer) + /** Tries to open the file. */ + struct stat fileStat; + if (stat(file, &fileStat)) { - CVector::iterator iter; - for (iter = FileList.begin(); iter != FileList.end(); ++iter) - { - if ((*iter)->file.compare(file) == 0) - { - char buf[33] = {0}; - (*iter)->val.assign(buf); - break; - } - } + FileList.remove(file); AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file); return 0; } - - bool foundFlag = false; - - CVector::iterator iter; - for (iter = FileList.begin(); iter != FileList.end(); ++iter) - { - if ((*iter)->file.compare(file) == 0) - { - if ((*iter)->val.compare(md5buffer) == 0) - { - return -1; - } else { - (*iter)->val.assign(md5buffer); - break; - } - foundFlag = true; - } - } - if (!foundFlag) - { - md5Pair *p = new md5Pair; - p->file.assign(file); - p->val.assign(md5buffer); - FileList.push_back(p); - } + /** Checks if there is an existing entry with same time stamp. */ + time_t timeStamp; + if (FileList.retrieve(file, &timeStamp) && fileStat.st_mtime == timeStamp) + return -1; + + /** If yes, it either means that the entry doesn't exist or the existing entry needs to be updated. */ + FileList.replace(file, fileStat.st_mtime); FILE* fp = fopen(file, "rt"); if (!fp) @@ -532,12 +506,6 @@ const char *CLangMngr::GetDef(const char *langName, const char *key, int &status void CLangMngr::InvalidateCache() { - for (size_t i = 0; i < FileList.size(); i++) - { - if (FileList[i]) - delete FileList[i]; - } - FileList.clear(); } @@ -558,12 +526,6 @@ void CLangMngr::Clear() delete m_Languages[i]; } - for (i = 0; i < FileList.size(); i++) - { - if (FileList[i]) - delete FileList[i]; - } - for (i = 0; i < KeyList.size(); i++) { if (KeyList[i]) diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index 98863af6..cbeda037 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -11,6 +11,7 @@ #define _INCLUDE_CLANG_H #include "sh_tinyhash.h" +#include "sm_stringhashmap.h" #define LANG_SERVER 0 #define LANG_PLAYER -1 @@ -18,12 +19,6 @@ #define ERR_BADKEY 1 // Lang key not found #define ERR_BADLANG 2 // Invalid lang -struct md5Pair -{ - String file; - String val; -}; - struct sKeyDef { String *definition; @@ -118,7 +113,7 @@ private: LangVec m_Languages; - CVector FileList; + StringHashMap FileList; CVector KeyList; THash KeyTable;