mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
Prevented keys from overwriting each other
This commit is contained in:
parent
11952467e1
commit
d4ad09619e
@ -189,6 +189,16 @@ uint32_t CLangMngr::CLang::LangEntry::GetDefHash()
|
|||||||
return m_DefHash;
|
return m_DefHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLangMngr::CLang::LangEntry::SetCache(bool c)
|
||||||
|
{
|
||||||
|
m_isCache = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CLangMngr::CLang::LangEntry::GetCache()
|
||||||
|
{
|
||||||
|
return m_isCache;
|
||||||
|
}
|
||||||
|
|
||||||
const char *CLangMngr::CLang::LangEntry::GetDef()
|
const char *CLangMngr::CLang::LangEntry::GetDef()
|
||||||
{
|
{
|
||||||
return m_pDef.c_str();
|
return m_pDef.c_str();
|
||||||
@ -268,10 +278,12 @@ CLangMngr::CLang::CLang(const char *lang)
|
|||||||
m_LanguageName[2]=0;
|
m_LanguageName[2]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLangMngr::CLang::LangEntry *CLangMngr::CLang::AddEntry(int pKey, uint32_t defHash, const char *def)
|
CLangMngr::CLang::LangEntry *CLangMngr::CLang::AddEntry(int pKey, uint32_t defHash, const char *def, bool cache)
|
||||||
{
|
{
|
||||||
LangEntry *p = new LangEntry(pKey, defHash, def);
|
LangEntry *p = new LangEntry(pKey, defHash, def);
|
||||||
|
|
||||||
|
p->SetCache(cache);
|
||||||
|
|
||||||
m_LookUpTable.push_back(p);
|
m_LookUpTable.push_back(p);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -306,6 +318,7 @@ CLangMngr::CLang::LangEntry * CLangMngr::CLang::GetEntry(int pkey)
|
|||||||
|
|
||||||
LangEntry *e = new LangEntry(pkey);
|
LangEntry *e = new LangEntry(pkey);
|
||||||
e->SetKey(pkey);
|
e->SetKey(pkey);
|
||||||
|
e->SetCache(true);
|
||||||
m_LookUpTable.push_back(e);
|
m_LookUpTable.push_back(e);
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
@ -321,9 +334,15 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
|
|||||||
def = vec.front()->def->c_str();
|
def = vec.front()->def->c_str();
|
||||||
LangEntry *entry = GetEntry(key);
|
LangEntry *entry = GetEntry(key);
|
||||||
if (entry->GetDefHash() != MakeHash(def))
|
if (entry->GetDefHash() != MakeHash(def))
|
||||||
|
{
|
||||||
|
if (entry->GetCache())
|
||||||
{
|
{
|
||||||
entry->SetDef(def);
|
entry->SetDef(def);
|
||||||
entry->SetKey(key);
|
entry->SetKey(key);
|
||||||
|
entry->SetCache(false);
|
||||||
|
} else {
|
||||||
|
AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete vec.front();
|
delete vec.front();
|
||||||
vec.pop();
|
vec.pop();
|
||||||
@ -1184,7 +1203,7 @@ bool CLangMngr::Load(const char *filename)
|
|||||||
char *data = new char[deflen+1];
|
char *data = new char[deflen+1];
|
||||||
fread(data, sizeof(char), deflen, fp);
|
fread(data, sizeof(char), deflen, fp);
|
||||||
data[deflen] = 0;
|
data[deflen] = 0;
|
||||||
m_Languages[i]->AddEntry(keynum, defhash, data);
|
m_Languages[i]->AddEntry(keynum, defhash, data, true);
|
||||||
delete [] data;
|
delete [] data;
|
||||||
fseek(fp, save, SEEK_SET); //bring back to next entry
|
fseek(fp, save, SEEK_SET); //bring back to next entry
|
||||||
}
|
}
|
||||||
|
@ -102,15 +102,19 @@ class CLangMngr
|
|||||||
int key;
|
int key;
|
||||||
// the definition
|
// the definition
|
||||||
String m_pDef;
|
String m_pDef;
|
||||||
|
// is this from the cache or not?
|
||||||
|
bool m_isCache;
|
||||||
public:
|
public:
|
||||||
// Set
|
// Set
|
||||||
void SetKey(int key);
|
void SetKey(int key);
|
||||||
void SetDef(const char *pDef);
|
void SetDef(const char *pDef);
|
||||||
|
void SetCache(bool c);
|
||||||
// Get
|
// Get
|
||||||
uint32_t GetDefHash();
|
uint32_t GetDefHash();
|
||||||
int GetKey();
|
int GetKey();
|
||||||
const char *GetDef();
|
const char *GetDef();
|
||||||
int GetDefLength();
|
int GetDefLength();
|
||||||
|
bool GetCache();
|
||||||
|
|
||||||
// Constructors / destructors
|
// Constructors / destructors
|
||||||
LangEntry();
|
LangEntry();
|
||||||
@ -135,7 +139,7 @@ class CLangMngr
|
|||||||
LookUpVec m_LookUpTable;
|
LookUpVec m_LookUpTable;
|
||||||
CLangMngr *m_LMan;
|
CLangMngr *m_LMan;
|
||||||
public:
|
public:
|
||||||
LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def);
|
LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def, bool cache);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Merge definitions into a language
|
// Merge definitions into a language
|
||||||
|
Loading…
Reference in New Issue
Block a user