Revert "Add a horrible mutex to make ConfigFile thread-safe"
This reverts commit 3eb8e2d41fc99dba8765e301adf3758df5e0f314. Fixes a number of isses with ConfigFile, and prevents the hotkey thread from potentially corrupting the config file.
This commit is contained in:
parent
ba7a078694
commit
521a90585a
@ -65,8 +65,6 @@ BOOL ConfigFile::LoadFile(DWORD dwOpenMode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
|
|
||||||
if(bOpen)
|
if(bOpen)
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
@ -95,14 +93,11 @@ BOOL ConfigFile::LoadFile(DWORD dwOpenMode)
|
|||||||
|
|
||||||
bOpen = 1;
|
bOpen = 1;
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::LoadData()
|
void ConfigFile::LoadData()
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
TSTR lpCurLine = lpFileData, lpNextLine;
|
TSTR lpCurLine = lpFileData, lpNextLine;
|
||||||
ConfigSection *lpCurSection=NULL;
|
ConfigSection *lpCurSection=NULL;
|
||||||
DWORD i;
|
DWORD i;
|
||||||
@ -161,13 +156,10 @@ void ConfigFile::LoadData()
|
|||||||
|
|
||||||
*lpNextLine = '\r';
|
*lpNextLine = '\r';
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::Close()
|
void ConfigFile::Close()
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
DWORD i,j,k;
|
DWORD i,j,k;
|
||||||
|
|
||||||
for(i=0; i<Sections.Num(); i++)
|
for(i=0; i<Sections.Num(); i++)
|
||||||
@ -196,13 +188,10 @@ void ConfigFile::Close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bOpen = 0;
|
bOpen = 0;
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ConfigFile::SaveAs(CTSTR lpPath)
|
BOOL ConfigFile::SaveAs(CTSTR lpPath)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
XFile newFile;
|
XFile newFile;
|
||||||
|
|
||||||
String tmpPath = lpPath;
|
String tmpPath = lpPath;
|
||||||
@ -211,28 +200,18 @@ BOOL ConfigFile::SaveAs(CTSTR lpPath)
|
|||||||
if (newFile.Open(tmpPath, XFILE_WRITE, XFILE_CREATEALWAYS))
|
if (newFile.Open(tmpPath, XFILE_WRITE, XFILE_CREATEALWAYS))
|
||||||
{
|
{
|
||||||
if (newFile.Write("\xEF\xBB\xBF", 3) != 3)
|
if (newFile.Write("\xEF\xBB\xBF", 3) != 3)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
if (!newFile.WriteAsUTF8(lpFileData))
|
if (!newFile.WriteAsUTF8(lpFileData))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
newFile.Close();
|
newFile.Close();
|
||||||
if (!OSRenameFile(tmpPath, lpPath))
|
if (!OSRenameFile(tmpPath, lpPath))
|
||||||
Log(TEXT("ConfigFile::SaveAs: Unable to move new config file %s to %s"), tmpPath.Array(), lpPath);
|
Log(TEXT("ConfigFile::SaveAs: Unable to move new config file %s to %s"), tmpPath.Array(), lpPath);
|
||||||
|
|
||||||
strFileName = lpPath;
|
strFileName = lpPath;
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +222,6 @@ void ConfigFile::SetFilePath(CTSTR lpPath)
|
|||||||
|
|
||||||
String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -258,16 +236,11 @@ String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
|||||||
{
|
{
|
||||||
ConfigKey &key = section.Keys[j];
|
ConfigKey &key = section.Keys[j];
|
||||||
if(scmpi(lpKey, key.name) == 0)
|
if(scmpi(lpKey, key.name) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return String(key.ValueList[0]);
|
return String(key.ValueList[0]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
|
|
||||||
if(def)
|
if(def)
|
||||||
return String(def);
|
return String(def);
|
||||||
else
|
else
|
||||||
@ -276,7 +249,6 @@ String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
|||||||
|
|
||||||
CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -291,16 +263,11 @@ CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
|||||||
{
|
{
|
||||||
ConfigKey &key = section.Keys[j];
|
ConfigKey &key = section.Keys[j];
|
||||||
if(scmpi(lpKey, key.name) == 0)
|
if(scmpi(lpKey, key.name) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return key.ValueList[0];
|
return key.ValueList[0];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
|
|
||||||
if(def)
|
if(def)
|
||||||
return def;
|
return def;
|
||||||
else
|
else
|
||||||
@ -309,7 +276,6 @@ CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def)
|
|||||||
|
|
||||||
int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def)
|
int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -326,35 +292,24 @@ int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def)
|
|||||||
if(scmpi(lpKey, key.name) == 0)
|
if(scmpi(lpKey, key.name) == 0)
|
||||||
{
|
{
|
||||||
if(scmpi(key.ValueList[0], TEXT("true")) == 0)
|
if(scmpi(key.ValueList[0], TEXT("true")) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
else if(scmpi(key.ValueList[0], TEXT("false")) == 0)
|
else if(scmpi(key.ValueList[0], TEXT("false")) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(ValidIntString(key.ValueList[0]))
|
if(ValidIntString(key.ValueList[0]))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return tstring_base_to_int(key.ValueList[0], NULL, 0);
|
return tstring_base_to_int(key.ValueList[0], NULL, 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def)
|
DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -369,21 +324,16 @@ DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def)
|
|||||||
{
|
{
|
||||||
ConfigKey &key = section.Keys[j];
|
ConfigKey &key = section.Keys[j];
|
||||||
if(scmpi(lpKey, key.name) == 0)
|
if(scmpi(lpKey, key.name) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return tstring_base_to_int(key.ValueList[0], NULL, 0);
|
return tstring_base_to_int(key.ValueList[0], NULL, 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def)
|
float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -398,21 +348,16 @@ float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def)
|
|||||||
{
|
{
|
||||||
ConfigKey &key = section.Keys[j];
|
ConfigKey &key = section.Keys[j];
|
||||||
if(scmpi(lpKey, key.name) == 0)
|
if(scmpi(lpKey, key.name) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return (float)tstof(key.ValueList[0]);
|
return (float)tstof(key.ValueList[0]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
|
Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -446,12 +391,10 @@ Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
|
|||||||
if(!(strValue = schr(strValue, ',')))
|
if(!(strValue = schr(strValue, ',')))
|
||||||
{
|
{
|
||||||
ret.w = 1.0f;
|
ret.w = 1.0f;
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret.w = float(tstof(++strValue));
|
ret.w = float(tstof(++strValue));
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else if(*strValue == '[')
|
else if(*strValue == '[')
|
||||||
@ -471,18 +414,15 @@ Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
|
|||||||
if(!(strValue = schr(strValue, ',')))
|
if(!(strValue = schr(strValue, ',')))
|
||||||
{
|
{
|
||||||
ret.w = 1.0f;
|
ret.w = 1.0f;
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret.w = (float(tstoi(++strValue))/255.0f)+0.001f;
|
ret.w = (float(tstoi(++strValue))/255.0f)+0.001f;
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else if( (*LPWORD(strValue) == 'x0') ||
|
else if( (*LPWORD(strValue) == 'x0') ||
|
||||||
(*LPWORD(strValue) == 'X0') )
|
(*LPWORD(strValue) == 'X0') )
|
||||||
{
|
{
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return RGBA_to_Vect4(tstring_base_to_int(strValue+2, NULL, 16));
|
return RGBA_to_Vect4(tstring_base_to_int(strValue+2, NULL, 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,13 +430,11 @@ Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return Color4(0.0f, 0.0f, 0.0f, 0.0f);
|
return Color4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList)
|
BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -523,13 +461,11 @@ BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return bFoundKey;
|
return bFoundKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList)
|
BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -565,13 +501,11 @@ BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return bFoundKey;
|
return bFoundKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatList)
|
BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatList)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -597,13 +531,11 @@ BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return bFoundKey;
|
return bFoundKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ConfigFile::GetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorList)
|
BOOL ConfigFile::GetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorList)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
|
|
||||||
@ -677,7 +609,6 @@ BOOL ConfigFile::GetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return bFoundKey;
|
return bFoundKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +751,6 @@ void ConfigFile::SetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorL
|
|||||||
|
|
||||||
BOOL ConfigFile::HasKey(CTSTR lpSection, CTSTR lpKey)
|
BOOL ConfigFile::HasKey(CTSTR lpSection, CTSTR lpKey)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
for(unsigned int i=0; i<Sections.Num(); i++)
|
for(unsigned int i=0; i<Sections.Num(); i++)
|
||||||
{
|
{
|
||||||
ConfigSection §ion = Sections[i];
|
ConfigSection §ion = Sections[i];
|
||||||
@ -829,15 +759,11 @@ BOOL ConfigFile::HasKey(CTSTR lpSection, CTSTR lpKey)
|
|||||||
for(unsigned int j=0; j<section.Keys.Num(); j++)
|
for(unsigned int j=0; j<section.Keys.Num(); j++)
|
||||||
{
|
{
|
||||||
if(scmpi(section.Keys[j].name, lpKey) == 0)
|
if(scmpi(section.Keys[j].name, lpKey) == 0)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,7 +771,6 @@ BOOL ConfigFile::HasKey(CTSTR lpSection, CTSTR lpKey)
|
|||||||
|
|
||||||
void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
TSTR lpTemp = lpFileData, lpEnd = &lpFileData[dwLength], lpSectionStart;
|
TSTR lpTemp = lpFileData, lpEnd = &lpFileData[dwLength], lpSectionStart;
|
||||||
@ -885,8 +810,6 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -906,8 +829,6 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(*(LPWORD)lpTemp == '//')
|
else if(*(LPWORD)lpTemp == '//')
|
||||||
@ -925,10 +846,7 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
int newlen = slen(newvalue);
|
int newlen = slen(newvalue);
|
||||||
|
|
||||||
if ((*lpTemp == '\r' && *newvalue == '\0') || (lpNextLine - lpTemp == newlen && !scmp_n(lpTemp, newvalue, newlen)))
|
if ((*lpTemp == '\r' && *newvalue == '\0') || (lpNextLine - lpTemp == newlen && !scmp_n(lpTemp, newvalue, newlen)))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
String tmpFileName = strFileName;
|
String tmpFileName = strFileName;
|
||||||
tmpFileName += TEXT(".tmp");
|
tmpFileName += TEXT(".tmp");
|
||||||
@ -937,25 +855,13 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
if (file.Open(tmpFileName, XFILE_WRITE, XFILE_CREATEALWAYS))
|
if (file.Open(tmpFileName, XFILE_WRITE, XFILE_CREATEALWAYS))
|
||||||
{
|
{
|
||||||
if (file.Write("\xEF\xBB\xBF", 3) != 3)
|
if (file.Write("\xEF\xBB\xBF", 3) != 3)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!file.WriteAsUTF8(&lpFileData[2], DWORD(lpTemp - lpFileData - 2)))
|
if (!file.WriteAsUTF8(&lpFileData[2], DWORD(lpTemp - lpFileData - 2)))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!file.WriteAsUTF8(newvalue, slen(newvalue)))
|
if (!file.WriteAsUTF8(newvalue, slen(newvalue)))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!file.WriteAsUTF8(lpNextLine, slen(lpNextLine) - 2))
|
if (!file.WriteAsUTF8(lpNextLine, slen(lpNextLine) - 2))
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
file.Close();
|
file.Close();
|
||||||
if (!OSRenameFile(tmpFileName, strFileName))
|
if (!OSRenameFile(tmpFileName, strFileName))
|
||||||
@ -964,8 +870,6 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -985,13 +889,10 @@ void ConfigFile::SetKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::Remove(CTSTR lpSection, CTSTR lpKey)
|
void ConfigFile::Remove(CTSTR lpSection, CTSTR lpKey)
|
||||||
{
|
{
|
||||||
OSEnterMutex(hHorribleThreadSafetyMutex);
|
|
||||||
assert(lpSection);
|
assert(lpSection);
|
||||||
assert(lpKey);
|
assert(lpKey);
|
||||||
TSTR lpTemp = lpFileData, lpEnd = &lpFileData[dwLength], lpSectionStart;
|
TSTR lpTemp = lpFileData, lpEnd = &lpFileData[dwLength], lpSectionStart;
|
||||||
@ -1014,18 +915,12 @@ void ConfigFile::Remove(CTSTR lpSection, CTSTR lpKey)
|
|||||||
}while(lpTemp < lpEnd);
|
}while(lpTemp < lpEnd);
|
||||||
|
|
||||||
if(!bInSection)
|
if(!bInSection)
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return; //not possible, usually.
|
return; //not possible, usually.
|
||||||
}
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(*lpTemp == '[')
|
if(*lpTemp == '[')
|
||||||
{
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
else if(bInSection && (*(LPWORD)lpTemp != '//'))
|
else if(bInSection && (*(LPWORD)lpTemp != '//'))
|
||||||
{
|
{
|
||||||
if((scmpi_n(lpTemp, lpKey, dwKeyNameSize) == 0) && (lpTemp[dwKeyNameSize] == '='))
|
if((scmpi_n(lpTemp, lpKey, dwKeyNameSize) == 0) && (lpTemp[dwKeyNameSize] == '='))
|
||||||
@ -1039,16 +934,12 @@ void ConfigFile::Remove(CTSTR lpSection, CTSTR lpKey)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lpTemp = schr(lpTemp, '\n')+1;
|
lpTemp = schr(lpTemp, '\n')+1;
|
||||||
}while(lpTemp < lpEnd);
|
}while(lpTemp < lpEnd);
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
||||||
@ -1090,8 +981,6 @@ void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,8 +1002,6 @@ void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(*(LPWORD)lpTemp == '//')
|
else if(*(LPWORD)lpTemp == '//')
|
||||||
@ -1143,8 +1030,6 @@ void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1164,6 +1049,4 @@ void ConfigFile::AddKey(CTSTR lpSection, CTSTR lpKey, CTSTR newvalue)
|
|||||||
|
|
||||||
if(LoadFile(XFILE_OPENEXISTING))
|
if(LoadFile(XFILE_OPENEXISTING))
|
||||||
LoadData();
|
LoadData();
|
||||||
|
|
||||||
OSLeaveMutex(hHorribleThreadSafetyMutex);
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ struct ConfigSection
|
|||||||
class BASE_EXPORT ConfigFile
|
class BASE_EXPORT ConfigFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConfigFile() : bOpen(0), strFileName(), lpFileData(NULL), dwLength(0) { hHorribleThreadSafetyMutex = OSCreateMutex(); }
|
ConfigFile() : bOpen(0), strFileName(), lpFileData(NULL), dwLength(0) {}
|
||||||
~ConfigFile() {Close();}
|
~ConfigFile() {Close();}
|
||||||
|
|
||||||
BOOL Create(CTSTR lpConfigFile);
|
BOOL Create(CTSTR lpConfigFile);
|
||||||
@ -105,5 +105,4 @@ private:
|
|||||||
String strFileName;
|
String strFileName;
|
||||||
TSTR lpFileData;
|
TSTR lpFileData;
|
||||||
DWORD dwLength;
|
DWORD dwLength;
|
||||||
HANDLE hHorribleThreadSafetyMutex;
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user