diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index a826b68d..2f9c741e 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -744,6 +744,13 @@ int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue) return (m_LastDefaultUsed) ? defValue : (int)ParseDouble(result, defValue, true); } +unsigned int CConfigParser::ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue) +{ + const std::wstring& result = ReadString(section, key, L""); + + return (m_LastDefaultUsed) ? defValue : (unsigned int)ParseDouble(result, defValue, true); +} + // Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) { @@ -1056,7 +1063,7 @@ void CConfigParser::ReadIniFile(const std::vector& iniFileMappings while (true) { items[0] = 0; - DWORD res = GetPrivateProfileString(NULL, NULL, NULL, items, itemsSize, iniRead.c_str()); + DWORD res = GetPrivateProfileSectionNames(items, itemsSize, iniRead.c_str()); if (res == 0) // File not found { delete [] items; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 2cecf6ca..770b5ceb 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -62,6 +62,7 @@ public: double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue); double ReadFormula(LPCTSTR section, LPCTSTR key, double defValue); int ReadInt(LPCTSTR section, LPCTSTR key, int defValue); + unsigned int ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue); Gdiplus::Color ReadColor(LPCTSTR section, LPCTSTR key, const Gdiplus::Color& defValue); Gdiplus::Rect ReadRect(LPCTSTR section, LPCTSTR key, const Gdiplus::Rect& defValue); RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue); diff --git a/Library/Measure.cpp b/Library/Measure.cpp index f70ef43c..665a0a09 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -161,7 +161,7 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section) m_IfEqualValue = parser.ReadFloat(section, L"IfEqualValue", 0.0); m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false); - m_AverageSize = parser.ReadInt(section, L"AverageSize", 0); + m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0); m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0); diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index 73ef08cb..8a89cc2d 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -584,7 +584,11 @@ void CMeasureNet::ResetStats() void CMeasureNet::ReadStats(const WCHAR* iniFile) { WCHAR buffer[64]; - int count = GetPrivateProfileInt(L"Statistics", L"NetStatsCount", 0, iniFile); + + CConfigParser parser; + parser.Initialize(iniFile, NULL, NULL, L"Statistics"); + + int count = parser.ReadInt(L"Statistics", L"NetStatsCount", 0); c_StatValues.clear(); @@ -593,18 +597,18 @@ void CMeasureNet::ReadStats(const WCHAR* iniFile) ULARGE_INTEGER value; _snwprintf_s(buffer, _TRUNCATE, L"NetStatsInHigh%i", i); - value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile); + value.HighPart = (DWORD)parser.ReadUInt(L"Statistics", buffer, 0); _snwprintf_s(buffer, _TRUNCATE, L"NetStatsInLow%i", i); - value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile); + value.LowPart = (DWORD)parser.ReadUInt(L"Statistics", buffer, 0); c_StatValues.push_back(value.QuadPart); _snwprintf_s(buffer, _TRUNCATE, L"NetStatsOutHigh%i", i); - value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile); + value.HighPart = (DWORD)parser.ReadUInt(L"Statistics", buffer, 0); _snwprintf_s(buffer, _TRUNCATE, L"NetStatsOutLow%i", i); - value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile); + value.LowPart = (DWORD)parser.ReadUInt(L"Statistics", buffer, 0); c_StatValues.push_back(value.QuadPart); }