diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index 7e2b9b98..a21aefea 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -303,7 +303,7 @@ std::wstring ConvertUTF8ToWide(LPCSTR str) return szWide; } -BOOL LogInternal(int nLevel, LPCTSTR pszModule, ULONGLONG elapsed, LPCTSTR pszMessage) +BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage) { // Add timestamp WCHAR buffer[128]; @@ -391,18 +391,17 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage) // Ignore LOG_DEBUG messages from plugins unless in debug mode if (nLevel != LOG_DEBUG || Rainmeter->GetDebug()) { - Log(nLevel, pszMessage, pszModule); + Log(nLevel, pszMessage); } return TRUE; } -void Log(int nLevel, const WCHAR* message, const WCHAR* module) +void Log(int nLevel, const WCHAR* message) { struct DELAYED_LOG_INFO { int level; - std::wstring module; ULONGLONG elapsed; std::wstring message; }; @@ -419,7 +418,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module) while (!c_LogDelay.empty()) { DELAYED_LOG_INFO& logInfo = c_LogDelay.front(); - LogInternal(logInfo.level, logInfo.module.c_str(), logInfo.elapsed, logInfo.message.c_str()); + LogInternal(logInfo.level, logInfo.elapsed, logInfo.message.c_str()); c_LogDelay.erase(c_LogDelay.begin()); } @@ -427,7 +426,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module) LeaveCriticalSection(&g_CsLogDelay); // Log the message - LogInternal(nLevel, module, elapsed, message); + LogInternal(nLevel, elapsed, message); LeaveCriticalSection(&g_CsLog); } @@ -436,7 +435,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module) // Queue the message EnterCriticalSection(&g_CsLogDelay); - DELAYED_LOG_INFO logInfo = {nLevel, module, elapsed, message}; + DELAYED_LOG_INFO logInfo = {nLevel, elapsed, message}; c_LogDelay.push_back(logInfo); LeaveCriticalSection(&g_CsLogDelay); diff --git a/Library/Litestep.h b/Library/Litestep.h index 74751332..fa2bd8c1 100644 --- a/Library/Litestep.h +++ b/Library/Litestep.h @@ -37,8 +37,8 @@ std::wstring ConvertToWide(LPCSTR str); std::string ConvertToUTF8(LPCWSTR str); std::wstring ConvertUTF8ToWide(LPCSTR str); -void Log(int nLevel, const WCHAR* message, const WCHAR* module = L"Rainmeter"); // Wrapper for LSLog(). -void LogWithArgs(int nLevel, const WCHAR* format, ... ); // Replacement for DebugLog(), has the same functionality but has the option to set teh Log Level. +void Log(int nLevel, const WCHAR* message); +void LogWithArgs(int nLevel, const WCHAR* format, ... ); void LogError(CError& error); void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = false); diff --git a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp index 69c3e218..150f3af0 100644 --- a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp +++ b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp @@ -334,7 +334,7 @@ void UpdateProcesses() values.found = false; newProcesses.push_back(values); -// LSLog(LOG_DEBUG, L"Rainmeter", name); // DEBUG +// LSLog(LOG_DEBUG, NULL, name); // DEBUG } delete pPerfCntr; diff --git a/Plugins/PluginCoreTemp/PluginCoreTemp.cpp b/Plugins/PluginCoreTemp/PluginCoreTemp.cpp index 1c51d09a..2b74cdf5 100644 --- a/Plugins/PluginCoreTemp/PluginCoreTemp.cpp +++ b/Plugins/PluginCoreTemp/PluginCoreTemp.cpp @@ -96,7 +96,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) else { g_Indexes[id] = 0; - LSLog(LOG_WARNING, L"Rainmeter", L"CoreTempPlugin: Selected CoreTempType requires CoreTempIndex, assuming 0."); + LSLog(LOG_WARNING, NULL, L"CoreTemp.dll: Selected CoreTempType requires CoreTempIndex, assuming 0"); } } } @@ -211,7 +211,7 @@ eMeasureType convertStringToMeasureType(LPCWSTR i_String) else { result = MeasureTemperature; - LSLog(LOG_WARNING, L"Rainmeter", L"CoreTempPlugin: Incorrect CoreTempType, assuming Temperature."); + LSLog(LOG_WARNING, NULL, L"CoreTemp.dll: Invalid CoreTempType"); } return result; diff --git a/Plugins/PluginMediaKey/PluginMediaKey.cpp b/Plugins/PluginMediaKey/PluginMediaKey.cpp index c1442e8a..ebb30717 100644 --- a/Plugins/PluginMediaKey/PluginMediaKey.cpp +++ b/Plugins/PluginMediaKey/PluginMediaKey.cpp @@ -90,7 +90,7 @@ void ExecuteBang(LPCTSTR args, UINT id) } else { - LSLog(LOG_WARNING, L"Rainmeter", L"MediaKeyPlugin: Unknown bang!"); + LSLog(LOG_WARNING, NULL, L"MediaKey.dll: Unknown bang"); } } diff --git a/Plugins/PluginNowPlaying/Internet.cpp b/Plugins/PluginNowPlaying/Internet.cpp index 17e2b767..e7bb2e21 100644 --- a/Plugins/PluginNowPlaying/Internet.cpp +++ b/Plugins/PluginNowPlaying/Internet.cpp @@ -37,7 +37,7 @@ void CInternet::Initialize() if (!c_NetHandle) { - LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: Unable to open net handle."); + LSLog(LOG_ERROR, NULL, L"NowPlaying.dll: Unable to open net handle"); } } @@ -67,7 +67,6 @@ std::wstring CInternet::DownloadUrl(const std::wstring& url, int codepage) if (!hUrlDump) { - LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlguin: Unable to open internet file."); return result; } @@ -86,7 +85,6 @@ std::wstring CInternet::DownloadUrl(const std::wstring& url, int codepage) // Read the data. if (!InternetReadFile(hUrlDump, (LPVOID)lpData, CHUNK_SIZE, &dwSize)) { - LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlguin: Unable to read internet file."); break; } else @@ -161,12 +159,12 @@ std::wstring CInternet::DownloadUrl(const std::wstring& url, int codepage) std::wstring CInternet::EncodeUrl(const std::wstring& url) { // Based on http://www.zedwood.com/article/111/cpp-urlencode-function - static const std::wstring url_chars = L" !*'();:@&=+$,/?#[]"; + const WCHAR* urlChars = L" !*'();:@&=+$,/?#[]"; std::wstring ret; for (size_t i = 0, max = url.length(); i < max; ++i) { - if (url_chars.find_first_of(url[i]) != std::string::npos) + if (wcschr(urlChars, url[i])) { // If reserved character ret.append(L"%"); diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index 71c165b8..de814854 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -61,7 +61,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: PluginBridge error"); + LSLog(LOG_ERROR, NULL, L"NowPlaying.dll: PluginBridge error"); } g_Instance = instance; @@ -100,12 +100,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) if (!child->parent) { // The referenced section doesn't exist - std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; + std::wstring error = L"NowPlaying.dll: Invalid PlayerName="; error += str; error += L" in ["; error += section; error += L"]"; - LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); + LSLog(LOG_WARNING, NULL, error.c_str()); delete child; return maxValue; } @@ -156,12 +156,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; + std::wstring error = L"NowPlaying.dll: Invalid PlayerName="; error += str; error += L" in ["; error += section; error += L"]"; - LSLog(LOG_ERROR, L"Rainmeter", error.c_str()); + LSLog(LOG_ERROR, NULL, error.c_str()); delete parent; delete child; return maxValue; @@ -250,7 +250,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else if (_wcsicmp(L"LYRICS", str) == 0) { - LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Using undocumented PlayerType=LYRICS!"); + LSLog(LOG_WARNING, NULL, L"NowPlaying.dll: Using undocumented PlayerType=LYRICS!"); child->type = MEASURE_LYRICS; } else if (_wcsicmp(L"FILE", str) == 0) @@ -259,12 +259,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"NowPlayingPlugin: Invalid PlayerType="; + std::wstring error = L"NowPlaying.dll: Invalid PlayerType="; error += str; error += L" in ["; error += section; error += L"]"; - LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); + LSLog(LOG_WARNING, NULL, error.c_str()); } child->parent->player->AddMeasure(child->type); @@ -580,9 +580,13 @@ void ExecuteBang(LPCTSTR bang, UINT id) } else { - LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Unknown bang!"); + LSLog(LOG_WARNING, NULL, L"NowPlaying.dll: Unknown bang"); } } + else + { + LSLog(LOG_WARNING, NULL, L"NowPlaying.dll: Unknown bang"); + } } } } diff --git a/Plugins/PluginNowPlaying/Player.cpp b/Plugins/PluginNowPlaying/Player.cpp index 2b3c984f..b38aa322 100644 --- a/Plugins/PluginNowPlaying/Player.cpp +++ b/Plugins/PluginNowPlaying/Player.cpp @@ -187,7 +187,7 @@ void CPlayer::FindLyrics() } else { - LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlugin: Failed to start lyrics thread."); + LSLog(LOG_DEBUG, NULL, L"NowPlaying.dll: Failed to start lyrics thread"); } } } diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.cpp b/Plugins/PluginNowPlaying/PlayerAIMP.cpp index 8d19026e..c8888bb0 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerAIMP.cpp @@ -32,6 +32,9 @@ CPlayer* CPlayerAIMP::c_Player = NULL; CPlayerAIMP::CPlayerAIMP() : CPlayer(), m_Window(), m_WinampWindow(), + m_LastCheckTime(0), + m_LastFileSize(0), + m_LastTitleSize(0), m_FileMap(), m_FileMapHandle() { @@ -74,13 +77,12 @@ CPlayer* CPlayerAIMP::Create() */ bool CPlayerAIMP::CheckWindow() { - static DWORD oldTime = 0; DWORD time = GetTickCount(); - + // Try to find AIMP every 5 seconds - if (time - oldTime > 5000) + if (time - m_LastCheckTime > 5000) { - oldTime = time; + m_LastCheckTime = time; m_Window = FindWindow(L"AIMP2_RemoteInfo", L"AIMP2_RemoteInfo"); if (m_Window) @@ -95,14 +97,6 @@ bool CPlayerAIMP::CheckWindow() { m_Initialized = true; } - else - { - LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: Unable to view AIMP file mapping."); - } - } - else - { - LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: AIMP - Unable to access AIMP file mapping."); } } } @@ -118,21 +112,15 @@ bool CPlayerAIMP::CheckWindow() */ void CPlayerAIMP::UpdateData() { - static INT64 oldFileSize = 0; - static long oldTitleLen = 0; - if (!m_Initialized) { - if (oldTitleLen != 0) + if (m_LastTitleSize != 0) { - oldFileSize = 0; - oldTitleLen = 0; + m_LastFileSize = 0; + m_LastTitleSize = 0; } - if (!CheckWindow()) - { - return; - } + if (!CheckWindow()) return; } // If initialized @@ -147,10 +135,10 @@ void CPlayerAIMP::UpdateData() if (m_FileMapHandle) CloseHandle(m_FileMapHandle); } - if (oldTitleLen != 0) + if (m_LastTitleSize != 0) { - oldFileSize = 0; - oldTitleLen = 0; + m_LastFileSize = 0; + m_LastTitleSize = 0; ClearData(); } @@ -163,11 +151,11 @@ void CPlayerAIMP::UpdateData() AIMP2FileInfo* info = (AIMP2FileInfo*)m_FileMap; if (info->cbSizeOf > 0 && - info->nFileSize != oldFileSize || // Avoid reading the same file - info->nTitleLen != oldTitleLen) + info->nFileSize != m_LastFileSize || // Avoid reading the same file + info->nTitleLen != m_LastTitleSize) { - oldFileSize = info->nFileSize; - oldTitleLen = info->nTitleLen; + m_LastFileSize = info->nFileSize; + m_LastTitleSize = info->nTitleLen; // 44 is sizeof(AIMP2FileInfo) / 2 (due to WCHAR being 16-bit). // Written explicitly due to size differences in 32bit/64bit. @@ -200,16 +188,9 @@ void CPlayerAIMP::UpdateData() m_FilePath = filepath; ++m_TrackCount; - // Find cover if needed - if (m_Measures & MEASURE_COVER) - { - FindCover(); - } + if (m_Measures & MEASURE_COVER) FindCover(); - if (m_Measures & MEASURE_LYRICS) - { - FindLyrics(); - } + if (m_Measures & MEASURE_LYRICS) FindLyrics(); } } } diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.h b/Plugins/PluginNowPlaying/PlayerAIMP.h index 92af5513..04f41a93 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.h +++ b/Plugins/PluginNowPlaying/PlayerAIMP.h @@ -54,6 +54,9 @@ private: HWND m_Window; // AIMP window HWND m_WinampWindow; // AIMP Winamp API window + DWORD m_LastCheckTime; + INT64 m_LastFileSize; + DWORD m_LastTitleSize; LPVOID m_FileMap; HANDLE m_FileMapHandle; }; diff --git a/Plugins/PluginNowPlaying/PlayerFoobar.cpp b/Plugins/PluginNowPlaying/PlayerFoobar.cpp index 8e5df7f2..cba7d690 100644 --- a/Plugins/PluginNowPlaying/PlayerFoobar.cpp +++ b/Plugins/PluginNowPlaying/PlayerFoobar.cpp @@ -98,8 +98,8 @@ void CPlayerFoobar::Initialize() int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION); if (version < 100) { - std::wstring error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\nDownload the latest version from foo-rainmeter.googlecode.com and try again."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST); + const WCHAR* error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\nDownload the latest version from foo-rainmeter.googlecode.com and try again."; + MessageBox(NULL, error, L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST); m_FooWindow = NULL; } else diff --git a/Plugins/PluginNowPlaying/PlayerITunes.cpp b/Plugins/PluginNowPlaying/PlayerITunes.cpp index 0b653b02..8db523f3 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.cpp +++ b/Plugins/PluginNowPlaying/PlayerITunes.cpp @@ -116,6 +116,7 @@ HRESULT STDMETHODCALLTYPE CPlayerITunes::CEventHandler::Invoke(DISPID dispidMemb */ CPlayerITunes::CPlayerITunes() : CPlayer(), m_CallbackWindow(), + m_LastCheckTime(0), m_iTunesActive(false), m_iTunes(), m_iTunesEvent() @@ -237,7 +238,6 @@ void CPlayerITunes::Initialize() else { m_Initialized = false; - LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: Failed to get hold of iTunes instance via COM."); } } @@ -308,12 +308,10 @@ LRESULT CALLBACK CPlayerITunes::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR */ bool CPlayerITunes::CheckWindow() { - static DWORD oldTime = 0; - DWORD time = GetTickCount(); - if (time - oldTime > 5000) + if (time - m_LastCheckTime > 5000) { - oldTime = time; + m_LastCheckTime = time; HWND wnd = FindWindow(L"ITWindow", L"iTunes"); if (wnd && !m_iTunesActive) diff --git a/Plugins/PluginNowPlaying/PlayerITunes.h b/Plugins/PluginNowPlaying/PlayerITunes.h index bec881fd..0aeaa31c 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.h +++ b/Plugins/PluginNowPlaying/PlayerITunes.h @@ -95,8 +95,9 @@ private: static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); static CPlayer* c_Player; - + HWND m_CallbackWindow; + DWORD m_LastCheckTime; bool m_iTunesActive; IiTunes* m_iTunes; CEventHandler* m_iTunesEvent; diff --git a/Plugins/PluginNowPlaying/PlayerSpotify.cpp b/Plugins/PluginNowPlaying/PlayerSpotify.cpp index 7e80f35d..c346346f 100644 --- a/Plugins/PluginNowPlaying/PlayerSpotify.cpp +++ b/Plugins/PluginNowPlaying/PlayerSpotify.cpp @@ -28,7 +28,8 @@ CPlayer* CPlayerSpotify::c_Player = NULL; ** */ CPlayerSpotify::CPlayerSpotify() : CPlayer(), - m_Window() + m_Window(), + m_LastCheckTime(0) { } @@ -67,13 +68,12 @@ CPlayer* CPlayerSpotify::Create() */ bool CPlayerSpotify::CheckWindow() { - static DWORD oldTime = 0; DWORD time = GetTickCount(); // Try to find Spotify window every 5 seconds - if (time - oldTime > 5000) + if (time - m_LastCheckTime > 5000) { - oldTime = time; + m_LastCheckTime = time; m_Window = FindWindow(L"SpotifyMainWindow", NULL); if (m_Window) diff --git a/Plugins/PluginNowPlaying/PlayerSpotify.h b/Plugins/PluginNowPlaying/PlayerSpotify.h index ded97a9a..38cd030d 100644 --- a/Plugins/PluginNowPlaying/PlayerSpotify.h +++ b/Plugins/PluginNowPlaying/PlayerSpotify.h @@ -57,6 +57,7 @@ private: static CPlayer* c_Player; HWND m_Window; + DWORD m_LastCheckTime; }; #endif diff --git a/Plugins/PluginNowPlaying/PlayerWMP.cpp b/Plugins/PluginNowPlaying/PlayerWMP.cpp index b3daa14c..d411c399 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerWMP.cpp @@ -153,6 +153,7 @@ void CPlayerWMP::CRemoteHost::SwitchedToControl() CPlayerWMP::CPlayerWMP() : CPlayer(), m_TrackChanged(false), m_Window(), + m_LastCheckTime(0), m_ComModule(), m_AxWindow(), m_IPlayer(), @@ -220,11 +221,7 @@ void CPlayerWMP::Initialize() g_Instance, NULL); - if (!m_Window) - { - LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlugin: Unable to create window (WMP)."); - return; - } + if (!m_Window) return; CComPtr spHostObject; CComPtr spHost; @@ -247,7 +244,6 @@ void CPlayerWMP::Initialize() } else { - LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlugin: Failed to initialize COM (WMP)."); return; } @@ -479,13 +475,12 @@ void CPlayerWMP::UpdateData() } else { - static DWORD oldTime = 0; DWORD time = GetTickCount(); // Try to find WMP window every 5 seconds - if (oldTime = 0 || time - oldTime > 5000) + if (m_LastCheckTime = 0 || time - m_LastCheckTime > 5000) { - oldTime = time; + m_LastCheckTime = time; if (FindWindow(L"WMPlayerApp", NULL)) { diff --git a/Plugins/PluginNowPlaying/PlayerWMP.h b/Plugins/PluginNowPlaying/PlayerWMP.h index 8b72f2b0..06b9277b 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.h +++ b/Plugins/PluginNowPlaying/PlayerWMP.h @@ -139,8 +139,10 @@ private: bool m_TrackChanged; HWND m_Window; - CAxWindow* m_AxWindow; + DWORD m_LastCheckTime; + CComModule m_ComModule; + CAxWindow* m_AxWindow; CComPtr m_IPlayer; CComPtr m_IControls; CComPtr m_ISettings; diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index a86b7a14..a8daecbe 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -77,13 +77,12 @@ CPlayer* CPlayerWinamp::Create(WINAMPTYPE type) */ bool CPlayerWinamp::CheckWindow() { - static DWORD oldTime = 0; DWORD time = GetTickCount(); - + // Try to find Winamp window every 5 seconds - if (time - oldTime > 5000) + if (time - m_LastCheckTime > 5000) { - oldTime = time; + m_LastCheckTime = time; m_Window = FindWindow(L"Winamp v1.x", NULL); if (m_Window) diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.h b/Plugins/PluginNowPlaying/PlayerWinamp.h index c27d63d4..5bae137e 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.h +++ b/Plugins/PluginNowPlaying/PlayerWinamp.h @@ -58,6 +58,7 @@ private: static CPlayer* c_Player; HWND m_Window; // Winamp window + DWORD m_LastCheckTime; bool m_UseUnicodeAPI; bool m_PlayingStream; WINAMPTYPE m_WinampType; diff --git a/Plugins/PluginPing/Ping.cpp b/Plugins/PluginPing/Ping.cpp index c846c098..8dd7e8fc 100644 --- a/Plugins/PluginPing/Ping.cpp +++ b/Plugins/PluginPing/Ping.cpp @@ -83,15 +83,12 @@ std::string ConvertToAscii(LPCTSTR str) if (str && *str) { - int strLen = (int)wcslen(str) + 1; + int strLen = (int)wcslen(str); 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; + szAscii.resize(bufLen); + WideCharToMultiByte(CP_ACP, 0, str, strLen, &szAscii[0], bufLen, NULL, NULL); } } return szAscii; @@ -154,14 +151,14 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Unable to get the host by name."); + LSLog(LOG_WARNING, NULL, L"PingPlugin.dll: Unable to get host by name"); } WSACleanup(); } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Unable to initialize Windows Sockets."); + LSLog(LOG_WARNING, NULL, L"PingPlugin.dll: Unable to start WSA"); } } valid = true; @@ -289,7 +286,6 @@ void Finalize(HMODULE instance, UINT id) if ((*i1).second->threadHandle) { // Should really wait until the thread finishes instead terminating it... - LSLog(LOG_NOTICE, L"Rainmeter", L"PingPlugin: Thread still running -> Terminate."); TerminateThread((*i1).second->threadHandle, 0); } LeaveCriticalSection(&g_CriticalSection); diff --git a/Plugins/PluginPower/PowerPlugin.cpp b/Plugins/PluginPower/PowerPlugin.cpp index 4994c5d9..a7ecfb84 100644 --- a/Plugins/PluginPower/PowerPlugin.cpp +++ b/Plugins/PluginPower/PowerPlugin.cpp @@ -67,6 +67,11 @@ HINSTANCE hDLL = NULL; int g_Instances, g_NumOfProcessors = 0; FPCALLNTPOWERINFORMATION fpCallNtPowerInformation = NULL; +void NullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) +{ + // Do nothing. +} + /* This function is called when the measure is initialized. The function must return the maximum value that can be measured. @@ -179,7 +184,7 @@ double Update2(UINT id) std::map::iterator i = g_States.find(id); if (i != g_States.end()) { - switch((*i).second) + switch ((*i).second) { case POWER_ACLINE: return status.ACLineStatus == 1 ? 1 : 0; @@ -220,7 +225,7 @@ double Update2(UINT id) case POWER_HZ: if (fpCallNtPowerInformation && g_NumOfProcessors > 0) { - PROCESSOR_POWER_INFORMATION* ppi = new PROCESSOR_POWER_INFORMATION [g_NumOfProcessors]; + PROCESSOR_POWER_INFORMATION* ppi = new PROCESSOR_POWER_INFORMATION[g_NumOfProcessors]; memset(ppi, 0, sizeof(PROCESSOR_POWER_INFORMATION) * g_NumOfProcessors); fpCallNtPowerInformation(ProcessorInformation, NULL, 0, ppi, sizeof(PROCESSOR_POWER_INFORMATION) * g_NumOfProcessors); double value = ((*i).second == POWER_MHZ) ? ppi[0].CurrentMhz : ppi[0].CurrentMhz * 1000000.0; @@ -233,14 +238,14 @@ double Update2(UINT id) return 0; } + /* This function is called when the value should be returned as a string. */ LPCTSTR GetString(UINT id, UINT flags) { - static WCHAR buffer[256]; - + static WCHAR buffer[128]; std::map::iterator i = g_States.find(id); if (i != g_States.end()) { @@ -259,13 +264,22 @@ LPCTSTR GetString(UINT id, UINT flags) std::map::iterator iter = g_Formats.find(id); if (iter != g_Formats.end()) { - tm time; - memset(&time, 0, sizeof(tm)); + tm time = {0}; time.tm_sec = status.BatteryLifeTime % 60; time.tm_min = (status.BatteryLifeTime / 60) % 60; time.tm_hour = status.BatteryLifeTime / 60 / 60; - wcsftime(buffer, 256, (*iter).second.c_str(), &time); + _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(NullCRTInvalidParameterHandler); + _CrtSetReportMode(_CRT_ASSERT, 0); + + errno = 0; + wcsftime(buffer, 128, (*iter).second.c_str(), &time); + if (errno == EINVAL) + { + buffer[0] = L'\0'; + } + + _set_invalid_parameter_handler(oldHandler); } else { diff --git a/Plugins/PluginRecycleManager/RecycleManager.cpp b/Plugins/PluginRecycleManager/RecycleManager.cpp index 560b3bd5..7d1e41ca 100644 --- a/Plugins/PluginRecycleManager/RecycleManager.cpp +++ b/Plugins/PluginRecycleManager/RecycleManager.cpp @@ -37,39 +37,31 @@ extern "C" __declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id); } -//const int NUMRECYCLE = 1; -//const int SIZERECYCLE = 2; - -//static std::map g_Values; - -// system resources that can be counted +// System resources that can be counted enum MEASURETYPE { NUMRECYCLE, SIZERECYCLE }; -// list of counter types corresponding to gauges static std::map g_Values; static std::map g_DriveList; - - /* -This function is called when the measure is initialized. -The function must return the maximum value that can be measured. -The return value can also be 0, which means that Rainmeter will -track the maximum value automatically. The parameters for this -function are: + This function is called when the measure is initialized. + The function must return the maximum value that can be measured. + The return value can also be 0, which means that Rainmeter will + track the maximum value automatically. The parameters for this + function are: -instance The instance of this DLL -iniFile The name of the ini-file (usually Rainmeter.ini) -section The name of the section in the ini-file for this measure -id The identifier for the measure. This is used to identify the measures that use the same plugin. + instance The instance of this DLL + iniFile The name of the ini-file (usually Rainmeter.ini) + section The name of the section in the ini-file for this measure + id The identifier for the measure. This is used to identify the measures that use the same plugin. */ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { - MEASURETYPE dataType = NUMRECYCLE; // 1 for numRecycled, 2 for sizeRecycled + MEASURETYPE dataType = NUMRECYCLE; /* Read our own settings from the ini-file */ LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT"); @@ -85,31 +77,23 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"RecycleType="; + std::wstring error = L"RecycleManager.dll: RecycleType="; error += type; - error += L" is not valid in measure ["; + error += L" is not valid in ["; error += section; - error += L"]."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + error += L"]"; + LSLog(LOG_ERROR, NULL, error.c_str()); } } g_Values[id] = dataType; - LPCTSTR drives = ReadConfigString(section, L"Drives", L"ALL"); - if (drives && wcslen(drives) > 0) - { - g_DriveList[id] = drives; - } - else - { - g_DriveList[id] = L"ALL"; - } + LPCTSTR drives = ReadConfigString(section, L"Drives", L""); + g_DriveList[id] = (drives && *drives) ? drives : L"ALL"; return 0; } - void Tokenize(const std::wstring& str, std::vector& tokens, const std::wstring& delimiters = L"|") { // Skip delimiters at beginning. @@ -129,64 +113,60 @@ void Tokenize(const std::wstring& str, std::vector& tokens, const } /* -This function is called when new value should be measured. -The function returns the new value. + This function is called when new value should be measured. + The function returns the new value. */ double Update2(UINT id) { + double retVal = 0; MEASURETYPE dataType = g_Values[id]; - std::wstring driveSet = g_DriveList[id]; + const std::wstring& driveSet = g_DriveList[id]; - SHQUERYRBINFO RecycleBinInfo = { 0 }; - RecycleBinInfo.cbSize = sizeof( RecycleBinInfo ); // Tell size of structure + SHQUERYRBINFO rbi = {0}; + rbi.cbSize = sizeof(SHQUERYRBINFO); if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) { - if (SHQueryRecycleBin( NULL, &RecycleBinInfo ) == S_OK) + if (SHQueryRecycleBin(NULL, &rbi) == S_OK) { if (dataType == SIZERECYCLE) { - return (double)RecycleBinInfo.i64Size; // size in bytes + retVal = (double)rbi.i64Size; // size in bytes } else if (dataType == NUMRECYCLE) { - return (double)RecycleBinInfo.i64NumItems; // number of items in bin + retVal = (double)rbi.i64NumItems; // number of items in bin } - return 0; - } - else - { - driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; } } - std::vector tokens; - std::wstring toSplit(driveSet.begin(), driveSet.end()); - double retVal = 0; - Tokenize(toSplit, tokens, L"|"); - - for (int i=0;i < tokens.size(); i++) + else { - double tempVal; - std::wstring strd = tokens.at(i); - SHQueryRecycleBin( strd.c_str(), &RecycleBinInfo ); // Get recycle bin info - if (dataType == SIZERECYCLE) + std::vector tokens; + Tokenize(driveSet, tokens); + + for (int i = 0, isize = (int)tokens.size(); i < isize; i++) { - tempVal = (double)RecycleBinInfo.i64Size; // size in bytes + if (SHQueryRecycleBin(tokens[i].c_str(), &rbi) == S_OK) + { + if (dataType == SIZERECYCLE) + { + retVal += (double)rbi.i64Size; // size in bytes + } + else if (dataType == NUMRECYCLE) + { + retVal += (double)rbi.i64NumItems; // number of items in bin + } + } } - else if (dataType == NUMRECYCLE) - { - tempVal = (double)RecycleBinInfo.i64NumItems; // number of items in bin - } - retVal += tempVal; } - return (retVal); + return retVal; } /* -If the measure needs to free resources before quitting. -The plugin can export Finalize function, which is called -when Rainmeter quits (or refreshes). + If the measure needs to free resources before quitting. + The plugin can export Finalize function, which is called + when Rainmeter quits (or refreshes). */ void Finalize(HMODULE instance, UINT id) { @@ -209,65 +189,50 @@ LPCTSTR GetPluginAuthor() void ExecuteBang(LPCTSTR args, UINT id) { - std::wstring bang = args; - std::wstring driveSet = g_DriveList[id]; - - if (_wcsicmp(bang.c_str(), L"EmptyBin") == 0) - { //Empty the Recycle Bin + const std::wstring& driveSet = g_DriveList[id]; + if (_wcsicmp(args, L"EmptyBin") == 0) + { + // Empty the Recycle Bin if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) { - if (SHEmptyRecycleBin( NULL, NULL, NULL ) == S_OK) - { - return; - } - else - { - driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; - } + SHEmptyRecycleBin( NULL, NULL, NULL ); } - std::vector tokens; - std::wstring toSplit(driveSet.begin(), driveSet.end()); - Tokenize(toSplit, tokens, L"|"); - - for (int i=0;i < tokens.size(); i++) + else { - std::wstring strd = tokens.at(i); - SHEmptyRecycleBin( NULL, strd.c_str(), NULL ); // empty bin + std::vector tokens; + Tokenize(driveSet, tokens); + + for (int i = 0, isize = (int)tokens.size(); i < isize; i++) + { + SHEmptyRecycleBin( NULL, tokens[i].c_str(), NULL ); // empty bin + } } return; } else { - if (_wcsicmp(bang.c_str(), L"EmptyBinSilent") == 0) - { //Empty the Recycle Bin (no prompt) + if (_wcsicmp(args, L"EmptyBinSilent") == 0) + { + // Empty the Recycle Bin (no prompt) if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) { - if (SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ) == S_OK) - { - return; - } - else - { - driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; - } + SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); } - std::vector tokens; - std::wstring toSplit(driveSet.begin(), driveSet.end()); - Tokenize(toSplit, tokens, L"|"); - - for (int i=0;i < tokens.size(); i++) + else { - std::wstring strd = tokens.at(i); - SHEmptyRecycleBin( NULL, strd.c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin + std::vector tokens; + Tokenize(driveSet, tokens); + + for (int i = 0, isize = (int)tokens.size(); i < isize; i++) + { + SHEmptyRecycleBin( NULL, tokens[i].c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin + } } - return; } - else if (_wcsicmp(bang.c_str(), L"OpenBin") == 0) - { //Open the Recycle Bin folder - //system("explorer.exe /N,::{645FF040-5081-101B-9F08-00AA002F954E}"); - std::wstring szCmd = L"explorer.exe"; - std::wstring szParm= L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}"; - ShellExecute(NULL,L"open",szCmd.c_str(),szParm.c_str(),NULL,SW_SHOW); + else if (_wcsicmp(args, L"OpenBin") == 0) + { + // Open the Recycle Bin folder + ShellExecute(NULL, L"open", L"explorer.exe", L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}", NULL, SW_SHOW); return; } } diff --git a/Plugins/PluginResMon/ResMon.cpp b/Plugins/PluginResMon/ResMon.cpp index 693e6ef7..5e7642aa 100644 --- a/Plugins/PluginResMon/ResMon.cpp +++ b/Plugins/PluginResMon/ResMon.cpp @@ -112,12 +112,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"GDICountType="; + std::wstring error = L"ResMon.dll: GDICountType="; error += type; - error += L" is not valid in measure ["; + error += L" is not valid in ["; error += section; - error += L"]."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + error += L"]"; + LSLog(LOG_ERROR, NULL, error.c_str()); } } diff --git a/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp b/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp index 82d04e0b..4676632a 100644 --- a/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp +++ b/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp @@ -110,12 +110,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"SpeedFanScale="; + std::wstring error = L"SpeedFanPlugin.dll: SpeedFanScale="; error += scale; - error += L" is not valid in measure ["; + error += L" is not valid in ["; error += section; - error += L"]."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + error += L"]"; + LSLog(LOG_ERROR, NULL, error.c_str()); } } } @@ -129,12 +129,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"SpeedFanType="; + std::wstring error = L"SpeedFanPlugin.dll: SpeedFanType="; error += type; - error += L" is not valid in measure ["; + error += L" is not valid in ["; error += section; - error += L"]."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + error += L"]"; + LSLog(LOG_ERROR, NULL, error.c_str()); } } @@ -267,7 +267,7 @@ bool ReadSharedData(SensorType type, TempScale scale, UINT number, double* value } else { - LSLog(LOG_WARNING, L"Rainmeter", L"SpeedFanPlugin: The shared memory has incorrect version."); + LSLog(LOG_ERROR, NULL, L"SpeedFanPlugin.dll: Incorrect shared memory version"); } UnmapViewOfFile(ptr); diff --git a/Plugins/PluginSysInfo/SysInfo.cpp b/Plugins/PluginSysInfo/SysInfo.cpp index fd11104f..c6f35905 100644 --- a/Plugins/PluginSysInfo/SysInfo.cpp +++ b/Plugins/PluginSysInfo/SysInfo.cpp @@ -159,7 +159,6 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { g_Types[id] = DNS_SERVER; } - else if (_wcsicmp(L"WORK_AREA_TOP", type) == 0) { g_Types[id] = WORK_AREA_TOP; @@ -206,12 +205,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"SysInfoType="; + std::wstring error = L"SysInfo.dll: SysInfoType="; error += type; - error += L" is not valid in measure ["; + error += L" is not valid in ["; error += section; - error += L"]."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + error += L"]"; + LSLog(LOG_ERROR, NULL, error.c_str()); } } @@ -230,15 +229,12 @@ std::wstring ConvertToWide(LPCSTR str) if (str && *str) { - int strLen = (int)strlen(str) + 1; + int strLen = (int)strlen(str); 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; + szWide.resize(bufLen); + MultiByteToWideChar(CP_ACP, 0, str, strLen, &szWide[0], bufLen); } } return szWide; @@ -435,11 +431,10 @@ double Update2(UINT id) if (data) //For speed purposes, only check if they specify a non-primary monitor. { - if (GetSystemMetrics(SM_CMONITORS)>32) + if (GetSystemMetrics(SM_CMONITORS) > 32) { - std::wstring error = L"That's alot of monitors! 32 is the max."; - MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONERROR); - exit(-1); + LSLog(LOG_ERROR, NULL, L"SysInfo.dll: Max amount of monitors supported is 32."); + return 0.0; } m_Monitors.count = 0; EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)(&m_Monitors)); diff --git a/Plugins/PluginWebParser/WebParser.cpp b/Plugins/PluginWebParser/WebParser.cpp index f9058429..4887eb66 100644 --- a/Plugins/PluginWebParser/WebParser.cpp +++ b/Plugins/PluginWebParser/WebParser.cpp @@ -724,7 +724,7 @@ double Update2(UINT id) } else // error { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Failed to begin download thread."; Log(LOG_ERROR, log.c_str()); @@ -768,7 +768,7 @@ double Update2(UINT id) } else // error { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Failed to begin thread."; Log(LOG_ERROR, log.c_str()); @@ -814,7 +814,7 @@ unsigned __stdcall NetworkThreadProc(void* pParam) } else { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Failed to dump debug data: "; log += urlData->debugFileLocation; @@ -894,7 +894,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) if (rc == 0) { // The output vector wasn't big enough - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Too many substrings!"; Log(LOG_ERROR, log.c_str()); @@ -915,7 +915,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) WCHAR buffer[32]; wsprintf(buffer, L"%2d", i); - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] (Index "; log += buffer; @@ -935,7 +935,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) } else { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Not enough substrings!"; Log(LOG_WARNING, log.c_str()); @@ -1006,7 +1006,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) } else // error { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += (*i).second->section; log += L"] Failed to begin download thread."; Log(LOG_ERROR, log.c_str()); @@ -1018,7 +1018,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) } else { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += (*i).second->section; log += L"] Not enough substrings!"; Log(LOG_WARNING, log.c_str()); @@ -1050,7 +1050,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) WCHAR buffer[32]; wsprintf(buffer, L"%d", rc); - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Matching error! ("; log += buffer; @@ -1084,7 +1084,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) WCHAR buffer[32]; wsprintf(buffer, L"%d", erroffset); - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] PCRE compilation failed at offset "; log += buffer; @@ -1105,7 +1105,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize) } else // error { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Failed to begin download thread."; Log(LOG_ERROR, log.c_str()); @@ -1266,7 +1266,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) { ready = false; - log = L"WebParser: ["; + log = L"WebParser.dll: ["; log += urlData->section; log += L"] Directory does not exist: "; log += directory; @@ -1276,7 +1276,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) { ready = false; - log = L"WebParser: ["; + log = L"WebParser.dll: ["; log += urlData->section; log += L"] Path is a directory, not a file: "; log += fullpath; @@ -1289,7 +1289,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) { ready = false; - log = L"WebParser: ["; + log = L"WebParser.dll: ["; log += urlData->section; log += L"] File is READ-ONLY: "; log += fullpath; @@ -1378,7 +1378,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) } // Write some log info - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Downloading url "; log += url; @@ -1446,7 +1446,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) wsprintf(buffer, L"result=0x%08X, COM=0x%08X", result, resultCoInitialize); - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Download failed ("; log += buffer; @@ -1462,7 +1462,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) } else { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] Download failed: "; log += url; @@ -1471,7 +1471,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam) } else { - std::wstring log = L"WebParser: ["; + std::wstring log = L"WebParser.dll: ["; log += urlData->section; log += L"] The url is empty.\n"; Log(LOG_ERROR, log.c_str()); @@ -1611,8 +1611,7 @@ BYTE* DownloadUrl(std::wstring& url, DWORD* dwDataSize, bool forceReload) int nBufferSize; const int CHUNK_SIZE = 8192; - std::wstring err = L"WebParser: Fetching URL: "; - err += url; + std::wstring err = L"WebParser.dll: Fetching: " + url; Log(LOG_DEBUG, err.c_str()); DWORD flags = INTERNET_FLAG_RESYNCHRONIZE; @@ -1704,10 +1703,6 @@ BYTE* DownloadUrl(std::wstring& url, DWORD* dwDataSize, bool forceReload) // Close the HINTERNET handle. InternetCloseHandle(hUrlDump); - err = L"WebParser: Finished URL: "; - err += url; - Log(LOG_DEBUG, err.c_str()); - // Delete the existing buffers. delete [] lpData; @@ -1725,7 +1720,7 @@ void ShowError(int lineNumber, WCHAR* errorMsg) WCHAR buffer[16]; wsprintf(buffer, L"%i", lineNumber); - std::wstring err = L"WebParser ("; + std::wstring err = L"WebParser.dll: ("; err += buffer; err += L") "; @@ -1793,11 +1788,11 @@ void ShowError(int lineNumber, WCHAR* errorMsg) } /* - Writes the log to a file (logging is thread safe (I think...)). + Writes the log to a file */ void Log(int level, const WCHAR* string) { - LSLog(level, L"Rainmeter", string); + LSLog(level, NULL, string); } UINT GetPluginVersion() diff --git a/Plugins/PluginWifiStatus/WifiStatus.cpp b/Plugins/PluginWifiStatus/WifiStatus.cpp index 1b07fe42..a33bb4c7 100644 --- a/Plugins/PluginWifiStatus/WifiStatus.cpp +++ b/Plugins/PluginWifiStatus/WifiStatus.cpp @@ -37,10 +37,9 @@ __declspec( dllexport ) UINT GetPluginVersion(); __declspec( dllexport ) LPCTSTR GetPluginAuthor(); } + //Function that translates DOT11 ENUMs to output strings LPCTSTR getDot11str(int,int); -//Wrapper function for writing to log file -void Log(const WCHAR* string); enum MEASURETYPE { @@ -95,7 +94,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) if ( ERROR_SUCCESS != dwErr ){ WCHAR buffer[256]; wsprintf(buffer, L"WifiStatus.dll: Unable to open WLAN API Handle. Error code (%d): %s",(int)dwErr,getDot11str(dwErr,5)); - Log(buffer); + LSLog(LOG_ERROR, NULL, buffer); return 0; } } @@ -105,20 +104,20 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) if (( ERROR_SUCCESS != dwErr) || (&pIntfList->dwNumberOfItems <= 0)){ WCHAR buffer[256]; wsprintf(buffer, L"WifiStatus.dll: Unable to find any WLAN interfaces/adapters. Error code %d",(int) dwErr); - Log(buffer); + LSLog(LOG_ERROR, NULL, buffer); return 0; } } //Select a WLAN interface, default 0. LPCTSTR data = ReadConfigString(section, L"WifiIntfID", L""); - if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ + if ((data != NULL) && *data){ if (_wtoi(data) < (int)pIntfList->dwNumberOfItems){ pInterface = &pIntfList->InterfaceInfo[_wtoi(data)]; } else { WCHAR buffer[256]; - wsprintf(buffer, L"WifiStatus.dll: Adapter is disabled or invalid (WifiIntfID=%s), fix INTF ID(default=0) or enable the adapter.",data); - Log(buffer); + wsprintf(buffer, L"WifiStatus.dll: Adapter (WifiIntfID=%s) not valid", data); + LSLog(LOG_ERROR, NULL, buffer); pInterface = &pIntfList->InterfaceInfo[0]; } } else { @@ -127,13 +126,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) //Select LIST style data = ReadConfigString(section, L"WifiListStyle", L""); - if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ + if ((data != NULL) && *data){ if ( (_wtoi(data) >= 0) && (_wtoi(data) <= 3)){ g_meas_data[id].listStyle = _wtoi(data); } else { WCHAR buffer[256]; - wsprintf(buffer, L"WifiStatus.dll: Invalid List Style given (WifiListStyle=%s), defaulting to 0.",data); - Log(buffer); + wsprintf(buffer, L"WifiStatus.dll: WifiListStyle=%s not valid",data); + LSLog(LOG_WARNING, NULL, buffer); g_meas_data[id].listStyle = 0; } } else { @@ -143,13 +142,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) //Set maxmimum number of list items data = ReadConfigString(section, L"WifiListLimit", L""); g_meas_data[id].listInit = false; - if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ + if ((data != NULL) && *data){ if (_wtoi(data) > 0){ g_meas_data[id].listMax = _wtoi(data); } else { WCHAR buffer[256]; - wsprintf(buffer, L"WifiStatus.dll: Invalid List Limit given (WifiListLimit=%s), defaulting to 5.",data); - Log(buffer); + wsprintf(buffer, L"WifiStatus.dll: WifiListLimit=%s not valid.",data); + LSLog(LOG_WARNING, NULL, buffer); g_meas_data[id].listMax = 5; } } else { @@ -178,8 +177,8 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) infoType=PHY; } else { WCHAR buffer[256]; - wsprintf(buffer, L"WifiStatus.dll: Invalid type given, WifiInfoType=%d.",type); - Log(buffer); + wsprintf(buffer, L"WifiStatus.dll: WifiInfoType=%d not valid",type); + LSLog(LOG_ERROR, NULL, buffer); } g_meas_data[id].type = infoType; } @@ -266,9 +265,7 @@ LPCTSTR GetString(UINT id, UINT flags) //Size of network name can be up to 64 chars, set to 80 to add room for delimiters g_meas_data[id].netlist = (WCHAR*)malloc( 80 * sizeof(WCHAR) * g_meas_data[id].listMax); if (g_meas_data[id].netlist == NULL){ - WCHAR debug[256]; - wsprintf(debug, L"WifiStatus.dll: Unable to allocate memory for network list."); - Log(buffer); + LSLog(LOG_ERROR, NULL, L"WifiStatus.dll: Unable to allocate network list memory"); g_meas_data[id].listInit = false; free(g_meas_data[id].netlist); return NULL; @@ -450,13 +447,13 @@ LPCTSTR getDot11str(int dot11enum,int type){ else{ switch(dot11enum){ case ERROR_INVALID_PARAMETER: - return L"Invalid parameters."; + return L"Invalid parameters"; case ERROR_NOT_ENOUGH_MEMORY: - return L"Not enough memory."; + return L"Not enough memory"; case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED: - return L"Too many handles already issued."; + return L"Too many handles already issued"; default: - return L"Unknown error code."; + return L"Unknown error code"; } } } @@ -486,15 +483,6 @@ void Finalize(HMODULE instance, UINT id) } } -/* - Wrapper function grabbed from the WebParser plugin -*/ -void Log(const WCHAR* string) -{ - // @TODO: put logging into critical section - LSLog(LOG_DEBUG, L"Rainmeter", string); -} - /* Returns the version number of the plugin. The value can be calculated like this: Major * 1000 + Minor. diff --git a/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp b/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp index 0d8cae72..a70d1666 100644 --- a/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp +++ b/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp @@ -84,7 +84,7 @@ bool InitCom() if (!com_initialized) com_initialized = SUCCEEDED(CoInitialize(0)); if (!com_initialized) { - LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: COM initialization failed!"); + LSLog(LOG_ERROR, NULL, L"Win7AudioPlugin.dll: COM initialization failed"); return false; } HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, 0, CLSCTX_ALL, @@ -92,7 +92,7 @@ bool InitCom() instance_created = (S_OK == hr && pEnumerator); if (!instance_created) { - std::wstring dbg_str = L"Win7AudioPlugin: COM instance creation failed!"; + std::wstring dbg_str = L"Win7AudioPlugin.dll: COM creation failed"; if (hr == REGDB_E_CLASSNOTREG) dbg_str += L" REGDB_E_CLASSNOTREG"; else if (hr == CLASS_E_NOAGGREGATION) dbg_str += L" CLASS_E_NOAGGREGATION"; else if (hr == E_NOINTERFACE) dbg_str += L" E_NOINTERFACE"; @@ -103,12 +103,12 @@ bool InitCom() dbg_str += e_code; } - LSLog(LOG_ERROR, L"Rainmeter", dbg_str.c_str()); + LSLog(LOG_ERROR, NULL, dbg_str.c_str()); return CleanUp() != 0; } if (S_OK != pEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pCollection) || !pCollection) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Could not enumerate AudioEndpoints!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Could not enumerate AudioEndpoints"); return CleanUp() != 0; } return true; @@ -144,7 +144,7 @@ HRESULT RegisterDevice(PCWSTR devID) } catch (...) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: RegisterDevice - Exception!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: RegisterDevice exception"); hr = S_FALSE; } UnInitCom(); @@ -169,7 +169,7 @@ std::wstring GetDefaultID() } catch (...) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: GetDefaultID - Exception!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: GetDefaultID exception"); id_default = L"Exception"; } SAFE_RELEASE(pEndpoint) @@ -206,7 +206,7 @@ bool GetWin7AudioState(const VolumeAction action) } catch (...) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Win7ToggleMute - Exception!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: ToggleMute exception"); } SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndpoint) @@ -265,7 +265,7 @@ bool SetWin7Volume(UINT volume, int offset = 0) } catch (...) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: SetWin7Volume - Exception!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: SetVolume exception"); } SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndpoint) @@ -394,8 +394,9 @@ LPCTSTR GetString(UINT id, UINT flags) SAFE_RELEASE(pEndpoint) wsprintf(result, L"ERROR - Getting Default Device"); } - } catch (...) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: GetString - Exception!"); + } catch (...) + { + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: GetString exception"); wsprintf(result, L"Exception"); } UnInitCom(); @@ -440,7 +441,7 @@ void ExecuteBang(LPCTSTR args, UINT id) { if (endpointIDs.size() <= 0) { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: No device found!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: No device found"); return; } // set to endpoint [index-1] @@ -450,7 +451,7 @@ void ExecuteBang(LPCTSTR args, UINT id) } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Incorrect number of arguments for the bang!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Incorrect number of arguments for bang"); } } else if (_wcsicmp(bang.c_str(), L"SetVolume") == 0) @@ -461,12 +462,12 @@ void ExecuteBang(LPCTSTR args, UINT id) { if (!SetWin7Volume(volume < 0 ? 0 : (volume > 100 ? 100 : (UINT)volume))) { - LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Error setting volume!"); + LSLog(LOG_ERROR, NULL, L"Win7AudioPlugin.dll: Error setting volume"); } } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Incorrect number of arguments for the bang!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Incorrect number of arguments for bang"); } } else if (_wcsicmp(bang.c_str(), L"ChangeVolume") == 0) @@ -477,59 +478,53 @@ void ExecuteBang(LPCTSTR args, UINT id) { if (!SetWin7Volume(0, offset)) { - LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Error changing volume!"); + LSLog(LOG_ERROR, NULL, L"Win7AudioPlugin.dll: Error changing volume"); } } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Incorrect number of arguments for the bang!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Incorrect number of arguments for bang"); } } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Unknown bang!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Unknown bang"); } } else if (_wcsicmp(wholeBang.c_str(), L"ToggleNext") == 0) { - //LSLog(LOG_NOTICE, L"Rainmeter", L"Win7AudioPlugin: Next device."); + //LSLog(LOG_NOTICE, NULL, L"Win7AudioPlugin.dll: Next device."); const UINT i = GetIndex(); if (i) RegisterDevice(endpointIDs[(i == endpointIDs.size()) ? 0 : i].c_str()); - else LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Update error - Try refresh!"); + else LSLog(LOG_ERROR, NULL, L"Win7AudioPlugin.dll: Update error"); } else if (_wcsicmp(wholeBang.c_str(), L"TogglePrevious") == 0) { const UINT i = GetIndex(); if (i) RegisterDevice(endpointIDs[(i == 1) ? endpointIDs.size() - 1 : i - 2].c_str()); - else LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Update error - Try refresh!"); + else LSLog(LOG_ERROR, NULL, L"Win7AudioPlugin.dll: Update error"); } else if (_wcsicmp(wholeBang.c_str(), L"ToggleMute") == 0) { - if (!GetWin7AudioState(TOGGLE_MUTE)) LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Mute Toggle Error!"); + GetWin7AudioState(TOGGLE_MUTE); } else if (_wcsicmp(wholeBang.c_str(), L"Mute") == 0) { if (!is_mute) { - if (!GetWin7AudioState(TOGGLE_MUTE)) - { - LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Mute Error!"); - } + GetWin7AudioState(TOGGLE_MUTE); } } else if (_wcsicmp(wholeBang.c_str(), L"Unmute") == 0) { if (is_mute) { - if (!GetWin7AudioState(TOGGLE_MUTE)) - { - LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Unmute Error!"); - } + GetWin7AudioState(TOGGLE_MUTE); } } else { - LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Unknown bang!"); + LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Unknown bang"); } } \ No newline at end of file diff --git a/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp b/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp index cb818458..ff523cd0 100644 --- a/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp +++ b/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp @@ -66,7 +66,6 @@ static std::map g_Values; UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { windowData wData; - wData.uMsg = 0; wData.wParam = 0; wData.lParam = 0; @@ -111,8 +110,8 @@ double Update2(UINT id) std::map::iterator i = g_Values.find(id); if (i != g_Values.end()) { - std::wstring& winName = (*i).second.windowName; - std::wstring& winClass = (*i).second.windowClass; + const std::wstring& winName = (*i).second.windowName; + const std::wstring& winClass = (*i).second.windowClass; HWND hwnd = FindWindow(winClass.empty() ? NULL : winClass.c_str(), winName.empty() ? NULL : winName.c_str()); if (hwnd) { @@ -136,7 +135,7 @@ double Update2(UINT id) LPCTSTR GetString(UINT id, UINT flags) { - static WCHAR buffer[256]; + static WCHAR buffer[64]; std::map::iterator i = g_Values.find(id); if (i != g_Values.end()) @@ -183,7 +182,7 @@ void ExecuteBang(LPCTSTR args, UINT id) { std::wstring wholeBang = args; - size_t pos = wholeBang.find(' '); + size_t pos = wholeBang.find(L' '); if (pos != -1) { std::wstring bang = wholeBang.substr(0, pos); @@ -207,26 +206,22 @@ void ExecuteBang(LPCTSTR args, UINT id) } else { - LSLog(LOG_ERROR, L"Rainmeter", L"WindowMessagePlugin: Unable to find the window!"); + LSLog(LOG_ERROR, NULL, L"WindowMessagePlugin.dll: Unable to find window"); } } else { - LSLog(LOG_ERROR, L"Rainmeter", L"WindowMessagePlugin: Unable to find the window data!"); + LSLog(LOG_ERROR, NULL, L"WindowMessagePlugin.dll: Unable to find window data"); } } else { - LSLog(LOG_WARNING, L"Rainmeter", L"WindowMessagePlugin: Incorrect number of arguments for the bang!"); + LSLog(LOG_WARNING, NULL, L"WindowMessagePlugin.dll: Incorrect number of arguments for bang"); } - } - else - { - LSLog(LOG_WARNING, L"Rainmeter", L"WindowMessagePlugin: Unknown bang!"); + + return; } } - else - { - LSLog(LOG_WARNING, L"Rainmeter", L"WindowMessagePlugin: Unable to parse the bang!"); - } + + LSLog(LOG_WARNING, NULL, L"WindowMessagePlugin.dll: Unknown bang"); } diff --git a/Plugins/PluginiTunes/iTunesPlugin.cpp b/Plugins/PluginiTunes/iTunesPlugin.cpp index 68256cce..498d7931 100644 --- a/Plugins/PluginiTunes/iTunesPlugin.cpp +++ b/Plugins/PluginiTunes/iTunesPlugin.cpp @@ -455,18 +455,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) { InstanceCreated = true; - LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully."); initEventHandler(); } else { - LSLog(LOG_WARNING, L"Rainmeter", L"iTunesPlugin: Unable to create the iTunesApp instance."); + LSLog(LOG_ERROR, NULL, L"iTunesPlugin.dll: Unable to create instance"); } } - else - { - LSLog(LOG_WARNING, L"Rainmeter", L"iTunesPlugin: Unable to find the iTunes window."); - } const wchar_t* type = ReadConfigString(section, L"Command", L""); for (int i = 0; i < COMMAND_COUNT; i++) @@ -500,12 +495,11 @@ UINT Update(UINT id) if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) { InstanceCreated = true; - LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully."); initEventHandler(); } else { - LSLog(LOG_WARNING, L"Rainmeter", L"iTunesPlugin: Unable to create the iTunesApp instance."); + LSLog(LOG_ERROR, NULL, L"iTunesPlugin.dll: Unable to create instance"); return 0; } } @@ -779,7 +773,7 @@ void ExecuteBang(LPCTSTR args, UINT id) } else { - LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: Invalid command."); + LSLog(LOG_NOTICE, NULL, L"iTunesPlugin.dll: Invalid Command"); return; } }