mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Fixed: Multibang [] not assumed when [Measure] is replaced in CConfigParser::ReadString().
- Minor changes of ConvertToXXX(): Get an appropriate buffer size to convert the string. And using [] when deleting arrays. - Fixed a few memory leaks. - It's now possible to send the !BANG command when all windows are "On Desktop". (Rainmeter.exe and WebParser)
This commit is contained in:
@ -22,7 +22,6 @@
|
||||
#include "ConfigParser.h"
|
||||
#include "Litestep.h"
|
||||
#include "Rainmeter.h"
|
||||
#include <TCHAR.H>
|
||||
#include <algorithm>
|
||||
|
||||
extern CRainmeter* Rainmeter;
|
||||
@ -189,7 +188,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
|
||||
pos = result.find(L'#', start);
|
||||
if (pos != std::wstring::npos)
|
||||
{
|
||||
size_t end = result.find(L'#', pos + 1);
|
||||
end = result.find(L'#', pos + 1);
|
||||
if (end != std::wstring::npos)
|
||||
{
|
||||
std::wstring strTmp(result.begin() + pos + 1, result.begin() + end);
|
||||
@ -224,29 +223,38 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
|
||||
start = 0;
|
||||
end = std::wstring::npos;
|
||||
pos = std::wstring::npos;
|
||||
size_t pos2 = std::wstring::npos;
|
||||
loop = true;
|
||||
do
|
||||
{
|
||||
pos = result.find(L'[', start);
|
||||
if (pos != std::wstring::npos)
|
||||
{
|
||||
size_t end = result.find(L']', pos + 1);
|
||||
end = result.find(L']', pos + 1);
|
||||
if (end != std::wstring::npos)
|
||||
{
|
||||
std::wstring var(result.begin() + pos + 1, result.begin() + end);
|
||||
|
||||
std::map<std::wstring, CMeasure*>::iterator iter = m_Measures.find(var);
|
||||
if (iter != m_Measures.end())
|
||||
pos2 = result.find(L'[', pos + 1);
|
||||
if (pos2 == std::wstring::npos || end < pos2)
|
||||
{
|
||||
std::wstring value = (*iter).second->GetStringValue(true, 1, 5, false);
|
||||
|
||||
// Measure found, replace it with the value
|
||||
result.replace(result.begin() + pos, result.begin() + end + 1, value);
|
||||
start = pos + value.length();
|
||||
std::wstring var(result.begin() + pos + 1, result.begin() + end);
|
||||
|
||||
std::map<std::wstring, CMeasure*>::iterator iter = m_Measures.find(var);
|
||||
if (iter != m_Measures.end())
|
||||
{
|
||||
std::wstring value = (*iter).second->GetStringValue(true, 1, 5, false);
|
||||
|
||||
// Measure found, replace it with the value
|
||||
result.replace(result.begin() + pos, result.begin() + end + 1, value);
|
||||
start = pos + value.length();
|
||||
}
|
||||
else
|
||||
{
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
start = end;
|
||||
start = pos2;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -465,7 +473,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile)
|
||||
{
|
||||
items[0] = 0;
|
||||
int res = GetPrivateProfileString( NULL, NULL, NULL, items, size, iniFile.c_str());
|
||||
if (res == 0) return; // File not found
|
||||
if (res == 0) { delete [] items; return; } // File not found
|
||||
if (res < size - 2) break; // Fits in the buffer
|
||||
|
||||
delete [] items;
|
||||
@ -486,7 +494,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile)
|
||||
|
||||
// Read the keys and values
|
||||
int bufferSize = MAX_LINE_LENGTH;
|
||||
TCHAR* buffer = new TCHAR[bufferSize];
|
||||
WCHAR* buffer = new WCHAR[bufferSize];
|
||||
|
||||
stdext::hash_map<std::wstring, std::vector<std::wstring> >::iterator iter = m_Keys.begin();
|
||||
for ( ; iter != m_Keys.end(); iter++)
|
||||
|
@ -471,13 +471,18 @@ std::string ConvertToAscii(LPCTSTR str)
|
||||
{
|
||||
std::string szAscii;
|
||||
|
||||
if (str)
|
||||
if (str && *str)
|
||||
{
|
||||
size_t len = (wcslen(str) + 1);
|
||||
char* tmpSz = new char[len * 2];
|
||||
WideCharToMultiByte(CP_ACP, 0, str, -1, tmpSz, (int)len * 2, NULL, FALSE);
|
||||
szAscii = tmpSz;
|
||||
delete tmpSz;
|
||||
int strLen = (int)wcslen(str) + 1;
|
||||
int bufLen = WideCharToMultiByte(CP_ACP, 0, str, strLen, NULL, 0, NULL, NULL);
|
||||
if (bufLen > 0)
|
||||
{
|
||||
char* tmpSz = new char[bufLen];
|
||||
tmpSz[0] = 0;
|
||||
WideCharToMultiByte(CP_ACP, 0, str, strLen, tmpSz, bufLen, NULL, NULL);
|
||||
szAscii = tmpSz;
|
||||
delete [] tmpSz;
|
||||
}
|
||||
}
|
||||
return szAscii;
|
||||
}
|
||||
@ -486,13 +491,18 @@ std::wstring ConvertToWide(LPCSTR str)
|
||||
{
|
||||
std::wstring szWide;
|
||||
|
||||
if (str)
|
||||
if (str && *str)
|
||||
{
|
||||
size_t len = strlen(str) + 1;
|
||||
WCHAR* wideSz = new WCHAR[len * 2];
|
||||
MultiByteToWideChar(CP_ACP, 0, str, (int)len, wideSz, (int)len * 2);
|
||||
szWide = wideSz;
|
||||
delete wideSz;
|
||||
int strLen = (int)strlen(str) + 1;
|
||||
int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
|
||||
if (bufLen > 0)
|
||||
{
|
||||
WCHAR* wideSz = new WCHAR[bufLen];
|
||||
wideSz[0] = 0;
|
||||
MultiByteToWideChar(CP_ACP, 0, str, strLen, wideSz, bufLen);
|
||||
szWide = wideSz;
|
||||
delete [] wideSz;
|
||||
}
|
||||
}
|
||||
return szWide;
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ public:
|
||||
const WCHAR* GetName() { return m_Name.c_str(); };
|
||||
|
||||
static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow);
|
||||
static WCHAR* ConvertToWide(const char* string);
|
||||
|
||||
static void DrawBevel(Gdiplus::Graphics& graphics, Gdiplus::Rect& rect, Gdiplus::Pen& light, Gdiplus::Pen& dark);
|
||||
|
||||
|
@ -1514,7 +1514,7 @@ void CMeterWindow::ReadSkin()
|
||||
while(true)
|
||||
{
|
||||
int res = GetPrivateProfileString( NULL, NULL, NULL, items, size, iniFile.c_str());
|
||||
if (res == 0) return; // File not found
|
||||
if (res == 0) { delete [] items; return; } // File not found
|
||||
if (res < size - 2) break; // Fits in the buffer
|
||||
|
||||
delete [] items;
|
||||
|
@ -682,11 +682,11 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath)
|
||||
WCHAR* pos = wcsrchr(tmpName, L'\\');
|
||||
if(pos)
|
||||
{
|
||||
*(pos + 1)='\0';
|
||||
*(pos + 1) = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpName[0]='\0';
|
||||
tmpName[0] = L'\0';
|
||||
}
|
||||
|
||||
if(!c_DummyLitestep) InitalizeLitestep();
|
||||
@ -1770,7 +1770,7 @@ PLATFORM CRainmeter::IsNT()
|
||||
{
|
||||
// You got NT
|
||||
if(osvi.dwMajorVersion <= 4) return PLATFORM_NT4;
|
||||
if(osvi.dwMajorVersion == 5) return PLATFORM_2K;
|
||||
if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) return PLATFORM_2K;
|
||||
return PLATFORM_XP;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user