diff --git a/OBSApi/Utility/ConfigFile.cpp b/OBSApi/Utility/ConfigFile.cpp index 16dbcd834..37fc5334d 100644 --- a/OBSApi/Utility/ConfigFile.cpp +++ b/OBSApi/Utility/ConfigFile.cpp @@ -109,6 +109,9 @@ BOOL ConfigFile::LoadFile(DWORD dwOpenMode) lpTempFileData[dwLength+4] = 0; file.Close(); + if (!lpFileData) + lpFileData = (TSTR)new InternalUselessStuff; + lpActualFileData = utf8_createTstr(lpTempFileData); dwLength = slen(lpActualFileData); Free(lpTempFileData); @@ -231,6 +234,9 @@ void ConfigFile::Close() BOOL ConfigFile::SaveAs(CTSTR lpPath) { + if (!bOpen || !lpFileData) + return false; + OSEnterMutex(hHorribleThreadSafetyMutex); XFile newFile; @@ -272,6 +278,9 @@ void ConfigFile::SetFilePath(CTSTR lpPath) String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def) { + if (!bOpen || !lpFileData) + return String(def); + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -305,6 +314,9 @@ String ConfigFile::GetString(CTSTR lpSection, CTSTR lpKey, CTSTR def) CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def) { + if (!bOpen || !lpFileData) + return def; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -338,6 +350,9 @@ CTSTR ConfigFile::GetStringPtr(CTSTR lpSection, CTSTR lpKey, CTSTR def) int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def) { + if (!bOpen || !lpFileData) + return def; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -383,6 +398,9 @@ int ConfigFile::GetInt(CTSTR lpSection, CTSTR lpKey, int def) DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def) { + if (!bOpen || !lpFileData) + return def; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -412,6 +430,9 @@ DWORD ConfigFile::GetHex(CTSTR lpSection, CTSTR lpKey, DWORD def) float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def) { + if (!bOpen || !lpFileData) + return def; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -441,6 +462,9 @@ float ConfigFile::GetFloat(CTSTR lpSection, CTSTR lpKey, float def) Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey) { + if (!bOpen || !lpFileData) + return Color4(0.0f, 0.0f, 0.0f, 0.0f); + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -525,6 +549,9 @@ Color4 ConfigFile::GetColor(CTSTR lpSection, CTSTR lpKey) BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList) { + if (!bOpen || !lpFileData) + return false; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -558,6 +585,9 @@ BOOL ConfigFile::GetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List &IntList) { + if (!bOpen || !lpFileData) + return false; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -600,6 +630,9 @@ BOOL ConfigFile::GetIntList(CTSTR lpSection, CTSTR lpKey, List &IntList) BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List &FloatList) { + if (!bOpen || !lpFileData) + return false; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey); @@ -632,6 +665,9 @@ BOOL ConfigFile::GetFloatList(CTSTR lpSection, CTSTR lpKey, List &FloatLi BOOL ConfigFile::GetColorList(CTSTR lpSection, CTSTR lpKey, List &ColorList) { + if (!bOpen || !lpFileData) + return false; + OSEnterMutex(hHorribleThreadSafetyMutex); assert(lpSection); assert(lpKey);