Fixed issue that Rainmeter.stats is not created and generates error on startup if Rainmeter.ini doesn't contain [Statistics]-section.

http://rainmeter.net/forum/viewtopic.php?f=14&t=10418
This commit is contained in:
spx 2011-12-01 08:40:37 +00:00
parent f28ecf6e83
commit 2d05df47cd

View File

@ -2511,22 +2511,29 @@ void CRainmeter::UpdateDesktopWorkArea(bool reset)
*/
void CRainmeter::ReadStats()
{
const WCHAR* statsFile = m_StatsFile.c_str();
// If m_StatsFile doesn't exist, create it and copy the stats section from m_IniFile
if (_waccess(m_StatsFile.c_str(), 0) == -1)
if (_waccess(statsFile, 0) == -1)
{
const WCHAR* iniFile = m_IniFile.c_str();
WCHAR* tmpSz = new WCHAR[SHRT_MAX]; // Max size returned by GetPrivateProfileSection()
if (GetPrivateProfileSection(L"Statistics", tmpSz, SHRT_MAX, m_IniFile.c_str()) > 0)
if (GetPrivateProfileSection(L"Statistics", tmpSz, SHRT_MAX, iniFile) > 0)
{
WritePrivateProfileSection(L"Statistics", tmpSz, m_StatsFile.c_str());
WritePrivateProfileString(L"Statistics", NULL, NULL, m_IniFile.c_str());
WritePrivateProfileString(L"Statistics", NULL, NULL, iniFile);
}
else
{
tmpSz[0] = tmpSz[1] = L'\0';
}
WritePrivateProfileSection(L"Statistics", tmpSz, statsFile);
delete [] tmpSz;
}
// Only Net measure has stats at the moment
CMeasureNet::ReadStats(m_StatsFile.c_str(), m_StatsDate);
CMeasureNet::ReadStats(statsFile, m_StatsDate);
}
/*
@ -2546,9 +2553,10 @@ void CRainmeter::WriteStats(bool bForce)
lastWrite = ticks;
// Only Net measure has stats at the moment
CMeasureNet::WriteStats(m_StatsFile.c_str(), m_StatsDate.c_str());
const WCHAR* statsFile = m_StatsFile.c_str();
CMeasureNet::WriteStats(statsFile, m_StatsDate.c_str());
WritePrivateProfileString(NULL, NULL, NULL, m_StatsFile.c_str());
WritePrivateProfileString(NULL, NULL, NULL, statsFile);
}
}