From 2d05df47cd49da2f683ec43171a435db261f412a Mon Sep 17 00:00:00 2001 From: spx Date: Thu, 1 Dec 2011 08:40:37 +0000 Subject: [PATCH] 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 --- Library/Rainmeter.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index e8845d5e..b11b6ae0 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -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); } }