Merge pull request #213 from ClaudiuHKS/CLang_mTime

Replace CLang file hashing with .st_mtime
This commit is contained in:
Vincent Herbet 2015-02-19 21:11:10 +01:00
commit 62413f6277
2 changed files with 13 additions and 56 deletions

View File

@ -318,48 +318,22 @@ void reparse_color(String* def)
// -- BAILOPAN // -- BAILOPAN
int CLangMngr::MergeDefinitionFile(const char *file) int CLangMngr::MergeDefinitionFile(const char *file)
{ {
const char* md5buffer = hashFile(file, Hash_Md5); /** Tries to open the file. */
if (!md5buffer) struct stat fileStat;
if (stat(file, &fileStat))
{ {
CVector<md5Pair *>::iterator iter; FileList.remove(file);
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
{
char buf[33] = {0};
(*iter)->val.assign(buf);
break;
}
}
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file); AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
return 0; return 0;
} }
bool foundFlag = false; /** Checks if there is an existing entry with same time stamp. */
time_t timeStamp;
CVector<md5Pair *>::iterator iter; if (FileList.retrieve(file, &timeStamp) && fileStat.st_mtime == timeStamp)
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
{
if ((*iter)->val.compare(md5buffer) == 0)
{
return -1; return -1;
} else {
(*iter)->val.assign(md5buffer);
break;
}
foundFlag = true;
}
}
if (!foundFlag) /** 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);
md5Pair *p = new md5Pair;
p->file.assign(file);
p->val.assign(md5buffer);
FileList.push_back(p);
}
FILE* fp = fopen(file, "rt"); FILE* fp = fopen(file, "rt");
if (!fp) if (!fp)
@ -532,12 +506,6 @@ const char *CLangMngr::GetDef(const char *langName, const char *key, int &status
void CLangMngr::InvalidateCache() void CLangMngr::InvalidateCache()
{ {
for (size_t i = 0; i < FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
FileList.clear(); FileList.clear();
} }
@ -558,12 +526,6 @@ void CLangMngr::Clear()
delete m_Languages[i]; delete m_Languages[i];
} }
for (i = 0; i < FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
for (i = 0; i < KeyList.size(); i++) for (i = 0; i < KeyList.size(); i++)
{ {
if (KeyList[i]) if (KeyList[i])

View File

@ -11,6 +11,7 @@
#define _INCLUDE_CLANG_H #define _INCLUDE_CLANG_H
#include "sh_tinyhash.h" #include "sh_tinyhash.h"
#include "sm_stringhashmap.h"
#define LANG_SERVER 0 #define LANG_SERVER 0
#define LANG_PLAYER -1 #define LANG_PLAYER -1
@ -18,12 +19,6 @@
#define ERR_BADKEY 1 // Lang key not found #define ERR_BADKEY 1 // Lang key not found
#define ERR_BADLANG 2 // Invalid lang #define ERR_BADLANG 2 // Invalid lang
struct md5Pair
{
String file;
String val;
};
struct sKeyDef struct sKeyDef
{ {
String *definition; String *definition;
@ -118,7 +113,7 @@ private:
LangVec m_Languages; LangVec m_Languages;
CVector<md5Pair *> FileList; StringHashMap<time_t> FileList;
CVector<String *> KeyList; CVector<String *> KeyList;
THash<String, keytbl_val> KeyTable; THash<String, keytbl_val> KeyTable;