diff --git a/Application/Application.cpp b/Application/Application.cpp index 87f8255f..660dd4fa 100644 --- a/Application/Application.cpp +++ b/Application/Application.cpp @@ -58,7 +58,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd hWnd=InitInstance(hInstance, WinClass, WinName); if(!hWnd) return FALSE; - if (lpCmdLine[0] == '!') + if (lpCmdLine && lpCmdLine[0] == L'!') { // It's a !bang Bang(hWnd, lpCmdLine); @@ -158,8 +158,17 @@ HWND InitInstance(HINSTANCE hInstance, const WCHAR* WinClass, const WCHAR* WinNa */ void Bang(HWND hWnd, const WCHAR* command) { - // Check if Rainlendar is running + // Check if Rainmeter is running HWND wnd = FindWindow(L"RainmeterMeterWindow", NULL); + if (wnd == NULL) + { + // Check if all windows are "On Desktop" + HWND ProgmanHwnd = FindWindow(L"Progman", L"Program Manager"); + if (ProgmanHwnd) + { + wnd = FindWindowEx(ProgmanHwnd, NULL, L"RainmeterMeterWindow", NULL); + } + } if (wnd != NULL) { @@ -169,7 +178,7 @@ void Bang(HWND hWnd, const WCHAR* command) copyData.cbData = (DWORD)((wcslen(command) + 1) * sizeof(WCHAR)); copyData.lpData = (void*)command; - // Send the bang to the Rainlendar window + // Send the bang to the Rainmeter window SendMessage(wnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)©Data); } else diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index d6fe32c1..c870ecf8 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -22,7 +22,6 @@ #include "ConfigParser.h" #include "Litestep.h" #include "Rainmeter.h" -#include #include 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::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::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 >::iterator iter = m_Keys.begin(); for ( ; iter != m_Keys.end(); iter++) diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index 9a3e2d14..34c5a51c 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -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; } diff --git a/Library/Meter.h b/Library/Meter.h index 46705258..c7874714 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -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); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 08a7d624..39b91c0c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -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; diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index fe95500b..40e9ba3b 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -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; } diff --git a/Plugins/PluginPing/Ping.cpp b/Plugins/PluginPing/Ping.cpp index d48c58ca..b82e2f87 100644 --- a/Plugins/PluginPing/Ping.cpp +++ b/Plugins/PluginPing/Ping.cpp @@ -82,13 +82,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; } diff --git a/Plugins/PluginQuote/Quote.cpp b/Plugins/PluginQuote/Quote.cpp index 960d60c4..dc505082 100644 --- a/Plugins/PluginQuote/Quote.cpp +++ b/Plugins/PluginQuote/Quote.cpp @@ -57,13 +57,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; } @@ -72,13 +77,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; } diff --git a/Plugins/PluginSysInfo/SysInfo.cpp b/Plugins/PluginSysInfo/SysInfo.cpp index 67f5f8e8..e881868a 100644 --- a/Plugins/PluginSysInfo/SysInfo.cpp +++ b/Plugins/PluginSysInfo/SysInfo.cpp @@ -226,13 +226,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; } diff --git a/Plugins/PluginWebParser/WebParser.cpp b/Plugins/PluginWebParser/WebParser.cpp index c5729e18..d2fe6dbc 100644 --- a/Plugins/PluginWebParser/WebParser.cpp +++ b/Plugins/PluginWebParser/WebParser.cpp @@ -86,14 +86,18 @@ std::string ConvertToUTF8(LPCWSTR str) { std::string szAscii; - if (str) + if (str && *str) { - size_t len = (wcslen(str) + 1); - char* tmpSz = new char[len * 2]; - tmpSz[0] = 0; - WideCharToMultiByte(CP_UTF8, 0, str, -1, tmpSz, (int)len * 2, NULL, FALSE); - szAscii = tmpSz; - delete tmpSz; + int strLen = (int)wcslen(str) + 1; + int bufLen = WideCharToMultiByte(CP_UTF8, 0, str, strLen, NULL, 0, NULL, NULL); + if (bufLen > 0) + { + char* tmpSz = new char[bufLen]; + tmpSz[0] = 0; + WideCharToMultiByte(CP_UTF8, 0, str, strLen, tmpSz, bufLen, NULL, NULL); + szAscii = tmpSz; + delete [] tmpSz; + } } return szAscii; } @@ -102,14 +106,18 @@ std::string ConvertToUTF8(LPCSTR str, int codepage) { std::string szUTF8; - if (str) + if (str && *str) { - size_t len = strlen(str) + 1; - WCHAR* wideSz = new WCHAR[len * 2]; - wideSz[0] = 0; - MultiByteToWideChar(codepage, 0, str, (int)len, wideSz, (int)len * 2); - szUTF8 = ConvertToUTF8(wideSz); - delete wideSz; + int strLen = (int)strlen(str) + 1; + int bufLen = MultiByteToWideChar(codepage, 0, str, strLen, NULL, 0); + if (bufLen > 0) + { + WCHAR* wideSz = new WCHAR[bufLen]; + wideSz[0] = 0; + MultiByteToWideChar(codepage, 0, str, strLen, wideSz, bufLen); + szUTF8 = ConvertToUTF8(wideSz); + delete [] wideSz; + } } return szUTF8; } @@ -118,18 +126,37 @@ 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]; - wideSz[0] = 0; - MultiByteToWideChar(CP_UTF8, 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; } +HWND FindMeterWindow() +{ + HWND wnd = FindWindow(L"RainmeterMeterWindow", NULL); + if (wnd == NULL) + { + // Check if all windows are "On Desktop" + HWND ProgmanHwnd = FindWindow(L"Progman", L"Program Manager"); + if (ProgmanHwnd) + { + wnd = FindWindowEx(ProgmanHwnd, NULL, L"RainmeterMeterWindow", NULL); + } + } + return wnd; +} + /* This function is called when the measure is initialized. The function must return the maximum value that can be measured. @@ -540,7 +567,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData) { if (!urlData->finishAction.empty()) { - HWND wnd = FindWindow(L"RainmeterMeterWindow", NULL); + HWND wnd = FindMeterWindow(); if (wnd != NULL) { @@ -641,7 +668,7 @@ DWORD WINAPI NetworkDownloadThreadProc(LPVOID pParam) if (!urlData->finishAction.empty()) { - HWND wnd = FindWindow(L"RainmeterMeterWindow", NULL); + HWND wnd = FindMeterWindow(); if (wnd != NULL) {