- PowerPlugin: Fixed crash when waking up from sleep/hibernation in some cases

- Code cleanup
This commit is contained in:
Birunthan Mohanathas 2011-10-12 13:34:04 +00:00
parent 7091b46689
commit 7790449f2a
30 changed files with 278 additions and 359 deletions

View File

@ -303,7 +303,7 @@ std::wstring ConvertUTF8ToWide(LPCSTR str)
return szWide; return szWide;
} }
BOOL LogInternal(int nLevel, LPCTSTR pszModule, ULONGLONG elapsed, LPCTSTR pszMessage) BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
{ {
// Add timestamp // Add timestamp
WCHAR buffer[128]; 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 // Ignore LOG_DEBUG messages from plugins unless in debug mode
if (nLevel != LOG_DEBUG || Rainmeter->GetDebug()) if (nLevel != LOG_DEBUG || Rainmeter->GetDebug())
{ {
Log(nLevel, pszMessage, pszModule); Log(nLevel, pszMessage);
} }
return TRUE; return TRUE;
} }
void Log(int nLevel, const WCHAR* message, const WCHAR* module) void Log(int nLevel, const WCHAR* message)
{ {
struct DELAYED_LOG_INFO struct DELAYED_LOG_INFO
{ {
int level; int level;
std::wstring module;
ULONGLONG elapsed; ULONGLONG elapsed;
std::wstring message; std::wstring message;
}; };
@ -419,7 +418,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module)
while (!c_LogDelay.empty()) while (!c_LogDelay.empty())
{ {
DELAYED_LOG_INFO& logInfo = c_LogDelay.front(); 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()); c_LogDelay.erase(c_LogDelay.begin());
} }
@ -427,7 +426,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module)
LeaveCriticalSection(&g_CsLogDelay); LeaveCriticalSection(&g_CsLogDelay);
// Log the message // Log the message
LogInternal(nLevel, module, elapsed, message); LogInternal(nLevel, elapsed, message);
LeaveCriticalSection(&g_CsLog); LeaveCriticalSection(&g_CsLog);
} }
@ -436,7 +435,7 @@ void Log(int nLevel, const WCHAR* message, const WCHAR* module)
// Queue the message // Queue the message
EnterCriticalSection(&g_CsLogDelay); EnterCriticalSection(&g_CsLogDelay);
DELAYED_LOG_INFO logInfo = {nLevel, module, elapsed, message}; DELAYED_LOG_INFO logInfo = {nLevel, elapsed, message};
c_LogDelay.push_back(logInfo); c_LogDelay.push_back(logInfo);
LeaveCriticalSection(&g_CsLogDelay); LeaveCriticalSection(&g_CsLogDelay);

View File

@ -37,8 +37,8 @@ std::wstring ConvertToWide(LPCSTR str);
std::string ConvertToUTF8(LPCWSTR str); std::string ConvertToUTF8(LPCWSTR str);
std::wstring ConvertUTF8ToWide(LPCSTR str); std::wstring ConvertUTF8ToWide(LPCSTR str);
void Log(int nLevel, const WCHAR* message, const WCHAR* module = L"Rainmeter"); // Wrapper for LSLog(). void Log(int nLevel, const WCHAR* message);
void LogWithArgs(int nLevel, const WCHAR* format, ... ); // Replacement for DebugLog(), has the same functionality but has the option to set teh Log Level. void LogWithArgs(int nLevel, const WCHAR* format, ... );
void LogError(CError& error); void LogError(CError& error);
void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = false); void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = false);

View File

@ -334,7 +334,7 @@ void UpdateProcesses()
values.found = false; values.found = false;
newProcesses.push_back(values); newProcesses.push_back(values);
// LSLog(LOG_DEBUG, L"Rainmeter", name); // DEBUG // LSLog(LOG_DEBUG, NULL, name); // DEBUG
} }
delete pPerfCntr; delete pPerfCntr;

View File

@ -96,7 +96,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
else else
{ {
g_Indexes[id] = 0; 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 else
{ {
result = MeasureTemperature; result = MeasureTemperature;
LSLog(LOG_WARNING, L"Rainmeter", L"CoreTempPlugin: Incorrect CoreTempType, assuming Temperature."); LSLog(LOG_WARNING, NULL, L"CoreTemp.dll: Invalid CoreTempType");
} }
return result; return result;

View File

@ -90,7 +90,7 @@ void ExecuteBang(LPCTSTR args, UINT id)
} }
else else
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"MediaKeyPlugin: Unknown bang!"); LSLog(LOG_WARNING, NULL, L"MediaKey.dll: Unknown bang");
} }
} }

View File

@ -37,7 +37,7 @@ void CInternet::Initialize()
if (!c_NetHandle) 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) if (!hUrlDump)
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlguin: Unable to open internet file.");
return result; return result;
} }
@ -86,7 +85,6 @@ std::wstring CInternet::DownloadUrl(const std::wstring& url, int codepage)
// Read the data. // Read the data.
if (!InternetReadFile(hUrlDump, (LPVOID)lpData, CHUNK_SIZE, &dwSize)) if (!InternetReadFile(hUrlDump, (LPVOID)lpData, CHUNK_SIZE, &dwSize))
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlguin: Unable to read internet file.");
break; break;
} }
else else
@ -161,12 +159,12 @@ std::wstring CInternet::DownloadUrl(const std::wstring& url, int codepage)
std::wstring CInternet::EncodeUrl(const std::wstring& url) std::wstring CInternet::EncodeUrl(const std::wstring& url)
{ {
// Based on http://www.zedwood.com/article/111/cpp-urlencode-function // 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; std::wstring ret;
for (size_t i = 0, max = url.length(); i < max; ++i) 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 // If reserved character
ret.append(L"%"); ret.append(L"%");

View File

@ -61,7 +61,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: PluginBridge error"); LSLog(LOG_ERROR, NULL, L"NowPlaying.dll: PluginBridge error");
} }
g_Instance = instance; g_Instance = instance;
@ -100,12 +100,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if (!child->parent) if (!child->parent)
{ {
// The referenced section doesn't exist // The referenced section doesn't exist
std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; std::wstring error = L"NowPlaying.dll: Invalid PlayerName=";
error += str; error += str;
error += L" in ["; error += L" in [";
error += section; error += section;
error += L"]"; error += L"]";
LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); LSLog(LOG_WARNING, NULL, error.c_str());
delete child; delete child;
return maxValue; return maxValue;
} }
@ -156,12 +156,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; std::wstring error = L"NowPlaying.dll: Invalid PlayerName=";
error += str; error += str;
error += L" in ["; error += L" in [";
error += section; error += section;
error += L"]"; error += L"]";
LSLog(LOG_ERROR, L"Rainmeter", error.c_str()); LSLog(LOG_ERROR, NULL, error.c_str());
delete parent; delete parent;
delete child; delete child;
return maxValue; return maxValue;
@ -250,7 +250,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else if (_wcsicmp(L"LYRICS", str) == 0) 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; child->type = MEASURE_LYRICS;
} }
else if (_wcsicmp(L"FILE", str) == 0) else if (_wcsicmp(L"FILE", str) == 0)
@ -259,12 +259,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"NowPlayingPlugin: Invalid PlayerType="; std::wstring error = L"NowPlaying.dll: Invalid PlayerType=";
error += str; error += str;
error += L" in ["; error += L" in [";
error += section; error += section;
error += L"]"; error += L"]";
LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); LSLog(LOG_WARNING, NULL, error.c_str());
} }
child->parent->player->AddMeasure(child->type); child->parent->player->AddMeasure(child->type);
@ -580,9 +580,13 @@ void ExecuteBang(LPCTSTR bang, UINT id)
} }
else 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");
}
} }
} }
} }

View File

@ -187,7 +187,7 @@ void CPlayer::FindLyrics()
} }
else 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");
} }
} }
} }

View File

@ -32,6 +32,9 @@ CPlayer* CPlayerAIMP::c_Player = NULL;
CPlayerAIMP::CPlayerAIMP() : CPlayer(), CPlayerAIMP::CPlayerAIMP() : CPlayer(),
m_Window(), m_Window(),
m_WinampWindow(), m_WinampWindow(),
m_LastCheckTime(0),
m_LastFileSize(0),
m_LastTitleSize(0),
m_FileMap(), m_FileMap(),
m_FileMapHandle() m_FileMapHandle()
{ {
@ -74,13 +77,12 @@ CPlayer* CPlayerAIMP::Create()
*/ */
bool CPlayerAIMP::CheckWindow() bool CPlayerAIMP::CheckWindow()
{ {
static DWORD oldTime = 0;
DWORD time = GetTickCount(); DWORD time = GetTickCount();
// Try to find AIMP every 5 seconds // 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"); m_Window = FindWindow(L"AIMP2_RemoteInfo", L"AIMP2_RemoteInfo");
if (m_Window) if (m_Window)
@ -95,14 +97,6 @@ bool CPlayerAIMP::CheckWindow()
{ {
m_Initialized = true; 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() void CPlayerAIMP::UpdateData()
{ {
static INT64 oldFileSize = 0;
static long oldTitleLen = 0;
if (!m_Initialized) if (!m_Initialized)
{ {
if (oldTitleLen != 0) if (m_LastTitleSize != 0)
{ {
oldFileSize = 0; m_LastFileSize = 0;
oldTitleLen = 0; m_LastTitleSize = 0;
} }
if (!CheckWindow()) if (!CheckWindow()) return;
{
return;
}
} }
// If initialized // If initialized
@ -147,10 +135,10 @@ void CPlayerAIMP::UpdateData()
if (m_FileMapHandle) CloseHandle(m_FileMapHandle); if (m_FileMapHandle) CloseHandle(m_FileMapHandle);
} }
if (oldTitleLen != 0) if (m_LastTitleSize != 0)
{ {
oldFileSize = 0; m_LastFileSize = 0;
oldTitleLen = 0; m_LastTitleSize = 0;
ClearData(); ClearData();
} }
@ -163,11 +151,11 @@ void CPlayerAIMP::UpdateData()
AIMP2FileInfo* info = (AIMP2FileInfo*)m_FileMap; AIMP2FileInfo* info = (AIMP2FileInfo*)m_FileMap;
if (info->cbSizeOf > 0 && if (info->cbSizeOf > 0 &&
info->nFileSize != oldFileSize || // Avoid reading the same file info->nFileSize != m_LastFileSize || // Avoid reading the same file
info->nTitleLen != oldTitleLen) info->nTitleLen != m_LastTitleSize)
{ {
oldFileSize = info->nFileSize; m_LastFileSize = info->nFileSize;
oldTitleLen = info->nTitleLen; m_LastTitleSize = info->nTitleLen;
// 44 is sizeof(AIMP2FileInfo) / 2 (due to WCHAR being 16-bit). // 44 is sizeof(AIMP2FileInfo) / 2 (due to WCHAR being 16-bit).
// Written explicitly due to size differences in 32bit/64bit. // Written explicitly due to size differences in 32bit/64bit.
@ -200,16 +188,9 @@ void CPlayerAIMP::UpdateData()
m_FilePath = filepath; m_FilePath = filepath;
++m_TrackCount; ++m_TrackCount;
// Find cover if needed if (m_Measures & MEASURE_COVER) FindCover();
if (m_Measures & MEASURE_COVER)
{
FindCover();
}
if (m_Measures & MEASURE_LYRICS) if (m_Measures & MEASURE_LYRICS) FindLyrics();
{
FindLyrics();
}
} }
} }
} }

View File

@ -54,6 +54,9 @@ private:
HWND m_Window; // AIMP window HWND m_Window; // AIMP window
HWND m_WinampWindow; // AIMP Winamp API window HWND m_WinampWindow; // AIMP Winamp API window
DWORD m_LastCheckTime;
INT64 m_LastFileSize;
DWORD m_LastTitleSize;
LPVOID m_FileMap; LPVOID m_FileMap;
HANDLE m_FileMapHandle; HANDLE m_FileMapHandle;
}; };

View File

@ -98,8 +98,8 @@ void CPlayerFoobar::Initialize()
int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION); int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION);
if (version < 100) 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."; 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.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST); MessageBox(NULL, error, L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST);
m_FooWindow = NULL; m_FooWindow = NULL;
} }
else else

View File

@ -116,6 +116,7 @@ HRESULT STDMETHODCALLTYPE CPlayerITunes::CEventHandler::Invoke(DISPID dispidMemb
*/ */
CPlayerITunes::CPlayerITunes() : CPlayer(), CPlayerITunes::CPlayerITunes() : CPlayer(),
m_CallbackWindow(), m_CallbackWindow(),
m_LastCheckTime(0),
m_iTunesActive(false), m_iTunesActive(false),
m_iTunes(), m_iTunes(),
m_iTunesEvent() m_iTunesEvent()
@ -237,7 +238,6 @@ void CPlayerITunes::Initialize()
else else
{ {
m_Initialized = false; 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() bool CPlayerITunes::CheckWindow()
{ {
static DWORD oldTime = 0;
DWORD time = GetTickCount(); DWORD time = GetTickCount();
if (time - oldTime > 5000) if (time - m_LastCheckTime > 5000)
{ {
oldTime = time; m_LastCheckTime = time;
HWND wnd = FindWindow(L"ITWindow", L"iTunes"); HWND wnd = FindWindow(L"ITWindow", L"iTunes");
if (wnd && !m_iTunesActive) if (wnd && !m_iTunesActive)

View File

@ -97,6 +97,7 @@ private:
static CPlayer* c_Player; static CPlayer* c_Player;
HWND m_CallbackWindow; HWND m_CallbackWindow;
DWORD m_LastCheckTime;
bool m_iTunesActive; bool m_iTunesActive;
IiTunes* m_iTunes; IiTunes* m_iTunes;
CEventHandler* m_iTunesEvent; CEventHandler* m_iTunesEvent;

View File

@ -28,7 +28,8 @@ CPlayer* CPlayerSpotify::c_Player = NULL;
** **
*/ */
CPlayerSpotify::CPlayerSpotify() : CPlayer(), CPlayerSpotify::CPlayerSpotify() : CPlayer(),
m_Window() m_Window(),
m_LastCheckTime(0)
{ {
} }
@ -67,13 +68,12 @@ CPlayer* CPlayerSpotify::Create()
*/ */
bool CPlayerSpotify::CheckWindow() bool CPlayerSpotify::CheckWindow()
{ {
static DWORD oldTime = 0;
DWORD time = GetTickCount(); DWORD time = GetTickCount();
// Try to find Spotify window every 5 seconds // 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); m_Window = FindWindow(L"SpotifyMainWindow", NULL);
if (m_Window) if (m_Window)

View File

@ -57,6 +57,7 @@ private:
static CPlayer* c_Player; static CPlayer* c_Player;
HWND m_Window; HWND m_Window;
DWORD m_LastCheckTime;
}; };
#endif #endif

View File

@ -153,6 +153,7 @@ void CPlayerWMP::CRemoteHost::SwitchedToControl()
CPlayerWMP::CPlayerWMP() : CPlayer(), CPlayerWMP::CPlayerWMP() : CPlayer(),
m_TrackChanged(false), m_TrackChanged(false),
m_Window(), m_Window(),
m_LastCheckTime(0),
m_ComModule(), m_ComModule(),
m_AxWindow(), m_AxWindow(),
m_IPlayer(), m_IPlayer(),
@ -220,11 +221,7 @@ void CPlayerWMP::Initialize()
g_Instance, g_Instance,
NULL); NULL);
if (!m_Window) if (!m_Window) return;
{
LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlugin: Unable to create window (WMP).");
return;
}
CComPtr<IObjectWithSite> spHostObject; CComPtr<IObjectWithSite> spHostObject;
CComPtr<IAxWinHostWindow> spHost; CComPtr<IAxWinHostWindow> spHost;
@ -247,7 +244,6 @@ void CPlayerWMP::Initialize()
} }
else else
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"NowPlayingPlugin: Failed to initialize COM (WMP).");
return; return;
} }
@ -479,13 +475,12 @@ void CPlayerWMP::UpdateData()
} }
else else
{ {
static DWORD oldTime = 0;
DWORD time = GetTickCount(); DWORD time = GetTickCount();
// Try to find WMP window every 5 seconds // 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)) if (FindWindow(L"WMPlayerApp", NULL))
{ {

View File

@ -139,8 +139,10 @@ private:
bool m_TrackChanged; bool m_TrackChanged;
HWND m_Window; HWND m_Window;
CAxWindow* m_AxWindow; DWORD m_LastCheckTime;
CComModule m_ComModule; CComModule m_ComModule;
CAxWindow* m_AxWindow;
CComPtr<IWMPPlayer4> m_IPlayer; CComPtr<IWMPPlayer4> m_IPlayer;
CComPtr<IWMPControls> m_IControls; CComPtr<IWMPControls> m_IControls;
CComPtr<IWMPSettings> m_ISettings; CComPtr<IWMPSettings> m_ISettings;

View File

@ -77,13 +77,12 @@ CPlayer* CPlayerWinamp::Create(WINAMPTYPE type)
*/ */
bool CPlayerWinamp::CheckWindow() bool CPlayerWinamp::CheckWindow()
{ {
static DWORD oldTime = 0;
DWORD time = GetTickCount(); DWORD time = GetTickCount();
// Try to find Winamp window every 5 seconds // 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); m_Window = FindWindow(L"Winamp v1.x", NULL);
if (m_Window) if (m_Window)

View File

@ -58,6 +58,7 @@ private:
static CPlayer* c_Player; static CPlayer* c_Player;
HWND m_Window; // Winamp window HWND m_Window; // Winamp window
DWORD m_LastCheckTime;
bool m_UseUnicodeAPI; bool m_UseUnicodeAPI;
bool m_PlayingStream; bool m_PlayingStream;
WINAMPTYPE m_WinampType; WINAMPTYPE m_WinampType;

View File

@ -83,15 +83,12 @@ std::string ConvertToAscii(LPCTSTR str)
if (str && *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); int bufLen = WideCharToMultiByte(CP_ACP, 0, str, strLen, NULL, 0, NULL, NULL);
if (bufLen > 0) if (bufLen > 0)
{ {
char* tmpSz = new char[bufLen]; szAscii.resize(bufLen);
tmpSz[0] = 0; WideCharToMultiByte(CP_ACP, 0, str, strLen, &szAscii[0], bufLen, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str, strLen, tmpSz, bufLen, NULL, NULL);
szAscii = tmpSz;
delete [] tmpSz;
} }
} }
return szAscii; return szAscii;
@ -154,14 +151,14 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else 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(); WSACleanup();
} }
else 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; valid = true;
@ -289,7 +286,6 @@ void Finalize(HMODULE instance, UINT id)
if ((*i1).second->threadHandle) if ((*i1).second->threadHandle)
{ {
// Should really wait until the thread finishes instead terminating it... // 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); TerminateThread((*i1).second->threadHandle, 0);
} }
LeaveCriticalSection(&g_CriticalSection); LeaveCriticalSection(&g_CriticalSection);

View File

@ -67,6 +67,11 @@ HINSTANCE hDLL = NULL;
int g_Instances, g_NumOfProcessors = 0; int g_Instances, g_NumOfProcessors = 0;
FPCALLNTPOWERINFORMATION fpCallNtPowerInformation = NULL; 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. This function is called when the measure is initialized.
The function must return the maximum value that can be measured. The function must return the maximum value that can be measured.
@ -179,7 +184,7 @@ double Update2(UINT id)
std::map<UINT, POWER_STATE>::iterator i = g_States.find(id); std::map<UINT, POWER_STATE>::iterator i = g_States.find(id);
if (i != g_States.end()) if (i != g_States.end())
{ {
switch((*i).second) switch ((*i).second)
{ {
case POWER_ACLINE: case POWER_ACLINE:
return status.ACLineStatus == 1 ? 1 : 0; return status.ACLineStatus == 1 ? 1 : 0;
@ -220,7 +225,7 @@ double Update2(UINT id)
case POWER_HZ: case POWER_HZ:
if (fpCallNtPowerInformation && g_NumOfProcessors > 0) 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); memset(ppi, 0, sizeof(PROCESSOR_POWER_INFORMATION) * g_NumOfProcessors);
fpCallNtPowerInformation(ProcessorInformation, NULL, 0, ppi, 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; double value = ((*i).second == POWER_MHZ) ? ppi[0].CurrentMhz : ppi[0].CurrentMhz * 1000000.0;
@ -233,14 +238,14 @@ double Update2(UINT id)
return 0; return 0;
} }
/* /*
This function is called when the value should be This function is called when the value should be
returned as a string. returned as a string.
*/ */
LPCTSTR GetString(UINT id, UINT flags) LPCTSTR GetString(UINT id, UINT flags)
{ {
static WCHAR buffer[256]; static WCHAR buffer[128];
std::map<UINT, POWER_STATE>::iterator i = g_States.find(id); std::map<UINT, POWER_STATE>::iterator i = g_States.find(id);
if (i != g_States.end()) if (i != g_States.end())
{ {
@ -259,13 +264,22 @@ LPCTSTR GetString(UINT id, UINT flags)
std::map<UINT, std::wstring>::iterator iter = g_Formats.find(id); std::map<UINT, std::wstring>::iterator iter = g_Formats.find(id);
if (iter != g_Formats.end()) if (iter != g_Formats.end())
{ {
tm time; tm time = {0};
memset(&time, 0, sizeof(tm));
time.tm_sec = status.BatteryLifeTime % 60; time.tm_sec = status.BatteryLifeTime % 60;
time.tm_min = (status.BatteryLifeTime / 60) % 60; time.tm_min = (status.BatteryLifeTime / 60) % 60;
time.tm_hour = 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 else
{ {

View File

@ -37,39 +37,31 @@ extern "C"
__declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id); __declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id);
} }
//const int NUMRECYCLE = 1; // System resources that can be counted
//const int SIZERECYCLE = 2;
//static std::map<UINT, int> g_Values;
// system resources that can be counted
enum MEASURETYPE enum MEASURETYPE
{ {
NUMRECYCLE, NUMRECYCLE,
SIZERECYCLE SIZERECYCLE
}; };
// list of counter types corresponding to gauges
static std::map<UINT, MEASURETYPE> g_Values; static std::map<UINT, MEASURETYPE> g_Values;
static std::map<UINT, std::wstring> g_DriveList; static std::map<UINT, std::wstring> g_DriveList;
/* /*
This function is called when the measure is initialized. This function is called when the measure is initialized.
The function must return the maximum value that can be measured. The function must return the maximum value that can be measured.
The return value can also be 0, which means that Rainmeter will The return value can also be 0, which means that Rainmeter will
track the maximum value automatically. The parameters for this track the maximum value automatically. The parameters for this
function are: function are:
instance The instance of this DLL instance The instance of this DLL
iniFile The name of the ini-file (usually Rainmeter.ini) iniFile The name of the ini-file (usually Rainmeter.ini)
section The name of the section in the ini-file for this measure 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. 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) 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 */ /* Read our own settings from the ini-file */
LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT"); LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT");
@ -85,31 +77,23 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"RecycleType="; std::wstring error = L"RecycleManager.dll: RecycleType=";
error += type; error += type;
error += L" is not valid in measure ["; error += L" is not valid in [";
error += section; error += section;
error += L"]."; error += L"]";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); LSLog(LOG_ERROR, NULL, error.c_str());
} }
} }
g_Values[id] = dataType; g_Values[id] = dataType;
LPCTSTR drives = ReadConfigString(section, L"Drives", L"ALL"); LPCTSTR drives = ReadConfigString(section, L"Drives", L"");
if (drives && wcslen(drives) > 0) g_DriveList[id] = (drives && *drives) ? drives : L"ALL";
{
g_DriveList[id] = drives;
}
else
{
g_DriveList[id] = L"ALL";
}
return 0; return 0;
} }
void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters = L"|") void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters = L"|")
{ {
// Skip delimiters at beginning. // Skip delimiters at beginning.
@ -129,64 +113,60 @@ void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const
} }
/* /*
This function is called when new value should be measured. This function is called when new value should be measured.
The function returns the new value. The function returns the new value.
*/ */
double Update2(UINT id) double Update2(UINT id)
{ {
double retVal = 0;
MEASURETYPE dataType = g_Values[id]; MEASURETYPE dataType = g_Values[id];
std::wstring driveSet = g_DriveList[id]; const std::wstring& driveSet = g_DriveList[id];
SHQUERYRBINFO RecycleBinInfo = { 0 }; SHQUERYRBINFO rbi = {0};
RecycleBinInfo.cbSize = sizeof( RecycleBinInfo ); // Tell size of structure rbi.cbSize = sizeof(SHQUERYRBINFO);
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
if (SHQueryRecycleBin( NULL, &RecycleBinInfo ) == S_OK) if (SHQueryRecycleBin(NULL, &rbi) == S_OK)
{ {
if (dataType == SIZERECYCLE) if (dataType == SIZERECYCLE)
{ {
return (double)RecycleBinInfo.i64Size; // size in bytes retVal = (double)rbi.i64Size; // size in bytes
} }
else if (dataType == NUMRECYCLE) 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 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<std::wstring> tokens; std::vector<std::wstring> tokens;
std::wstring toSplit(driveSet.begin(), driveSet.end()); Tokenize(driveSet, tokens);
double retVal = 0;
Tokenize(toSplit, tokens, L"|");
for (int i=0;i < tokens.size(); i++) for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
{
if (SHQueryRecycleBin(tokens[i].c_str(), &rbi) == S_OK)
{ {
double tempVal;
std::wstring strd = tokens.at(i);
SHQueryRecycleBin( strd.c_str(), &RecycleBinInfo ); // Get recycle bin info
if (dataType == SIZERECYCLE) if (dataType == SIZERECYCLE)
{ {
tempVal = (double)RecycleBinInfo.i64Size; // size in bytes retVal += (double)rbi.i64Size; // size in bytes
} }
else if (dataType == NUMRECYCLE) else if (dataType == NUMRECYCLE)
{ {
tempVal = (double)RecycleBinInfo.i64NumItems; // number of items in bin retVal += (double)rbi.i64NumItems; // number of items in bin
}
}
} }
retVal += tempVal;
} }
return (retVal); return retVal;
} }
/* /*
If the measure needs to free resources before quitting. If the measure needs to free resources before quitting.
The plugin can export Finalize function, which is called The plugin can export Finalize function, which is called
when Rainmeter quits (or refreshes). when Rainmeter quits (or refreshes).
*/ */
void Finalize(HMODULE instance, UINT id) void Finalize(HMODULE instance, UINT id)
{ {
@ -209,65 +189,50 @@ LPCTSTR GetPluginAuthor()
void ExecuteBang(LPCTSTR args, UINT id) void ExecuteBang(LPCTSTR args, UINT id)
{ {
std::wstring bang = args; const std::wstring& driveSet = g_DriveList[id];
std::wstring driveSet = g_DriveList[id]; if (_wcsicmp(args, L"EmptyBin") == 0)
{
if (_wcsicmp(bang.c_str(), L"EmptyBin") == 0) // Empty the Recycle Bin
{ //Empty the Recycle Bin
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
if (SHEmptyRecycleBin( NULL, NULL, NULL ) == S_OK) SHEmptyRecycleBin( NULL, NULL, NULL );
{
return;
} }
else 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<std::wstring> tokens; std::vector<std::wstring> tokens;
std::wstring toSplit(driveSet.begin(), driveSet.end()); Tokenize(driveSet, tokens);
Tokenize(toSplit, tokens, L"|");
for (int i=0;i < tokens.size(); i++) for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
{ {
std::wstring strd = tokens.at(i); SHEmptyRecycleBin( NULL, tokens[i].c_str(), NULL ); // empty bin
SHEmptyRecycleBin( NULL, strd.c_str(), NULL ); // empty bin }
} }
return; return;
} }
else else
{ {
if (_wcsicmp(bang.c_str(), L"EmptyBinSilent") == 0) if (_wcsicmp(args, L"EmptyBinSilent") == 0)
{ //Empty the Recycle Bin (no prompt) {
// Empty the Recycle Bin (no prompt)
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0) if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
if (SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ) == S_OK) SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND );
{
return;
} }
else 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<std::wstring> tokens; std::vector<std::wstring> tokens;
std::wstring toSplit(driveSet.begin(), driveSet.end()); Tokenize(driveSet, tokens);
Tokenize(toSplit, tokens, L"|");
for (int i=0;i < tokens.size(); i++) for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
{ {
std::wstring strd = tokens.at(i); SHEmptyRecycleBin( NULL, tokens[i].c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin
SHEmptyRecycleBin( NULL, strd.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 else if (_wcsicmp(args, L"OpenBin") == 0)
//system("explorer.exe /N,::{645FF040-5081-101B-9F08-00AA002F954E}"); {
std::wstring szCmd = L"explorer.exe"; // Open the Recycle Bin folder
std::wstring szParm= L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}"; ShellExecute(NULL, L"open", L"explorer.exe", L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}", NULL, SW_SHOW);
ShellExecute(NULL,L"open",szCmd.c_str(),szParm.c_str(),NULL,SW_SHOW);
return; return;
} }
} }

View File

@ -112,12 +112,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"GDICountType="; std::wstring error = L"ResMon.dll: GDICountType=";
error += type; error += type;
error += L" is not valid in measure ["; error += L" is not valid in [";
error += section; error += section;
error += L"]."; error += L"]";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); LSLog(LOG_ERROR, NULL, error.c_str());
} }
} }

View File

@ -110,12 +110,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"SpeedFanScale="; std::wstring error = L"SpeedFanPlugin.dll: SpeedFanScale=";
error += scale; error += scale;
error += L" is not valid in measure ["; error += L" is not valid in [";
error += section; error += section;
error += L"]."; error += L"]";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); LSLog(LOG_ERROR, NULL, error.c_str());
} }
} }
} }
@ -129,12 +129,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"SpeedFanType="; std::wstring error = L"SpeedFanPlugin.dll: SpeedFanType=";
error += type; error += type;
error += L" is not valid in measure ["; error += L" is not valid in [";
error += section; error += section;
error += L"]."; error += L"]";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); LSLog(LOG_ERROR, NULL, error.c_str());
} }
} }
@ -267,7 +267,7 @@ bool ReadSharedData(SensorType type, TempScale scale, UINT number, double* value
} }
else 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); UnmapViewOfFile(ptr);

View File

@ -159,7 +159,6 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
g_Types[id] = DNS_SERVER; g_Types[id] = DNS_SERVER;
} }
else if (_wcsicmp(L"WORK_AREA_TOP", type) == 0) else if (_wcsicmp(L"WORK_AREA_TOP", type) == 0)
{ {
g_Types[id] = WORK_AREA_TOP; g_Types[id] = WORK_AREA_TOP;
@ -206,12 +205,12 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"SysInfoType="; std::wstring error = L"SysInfo.dll: SysInfoType=";
error += type; error += type;
error += L" is not valid in measure ["; error += L" is not valid in [";
error += section; error += section;
error += L"]."; error += L"]";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); LSLog(LOG_ERROR, NULL, error.c_str());
} }
} }
@ -230,15 +229,12 @@ std::wstring ConvertToWide(LPCSTR str)
if (str && *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); int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
if (bufLen > 0) if (bufLen > 0)
{ {
WCHAR* wideSz = new WCHAR[bufLen]; szWide.resize(bufLen);
wideSz[0] = 0; MultiByteToWideChar(CP_ACP, 0, str, strLen, &szWide[0], bufLen);
MultiByteToWideChar(CP_ACP, 0, str, strLen, wideSz, bufLen);
szWide = wideSz;
delete [] wideSz;
} }
} }
return szWide; 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 (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."; LSLog(LOG_ERROR, NULL, L"SysInfo.dll: Max amount of monitors supported is 32.");
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONERROR); return 0.0;
exit(-1);
} }
m_Monitors.count = 0; m_Monitors.count = 0;
EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)(&m_Monitors)); EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)(&m_Monitors));

View File

@ -724,7 +724,7 @@ double Update2(UINT id)
} }
else // error else // error
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Failed to begin download thread."; log += L"] Failed to begin download thread.";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -768,7 +768,7 @@ double Update2(UINT id)
} }
else // error else // error
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Failed to begin thread."; log += L"] Failed to begin thread.";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -814,7 +814,7 @@ unsigned __stdcall NetworkThreadProc(void* pParam)
} }
else else
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Failed to dump debug data: "; log += L"] Failed to dump debug data: ";
log += urlData->debugFileLocation; log += urlData->debugFileLocation;
@ -894,7 +894,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
if (rc == 0) if (rc == 0)
{ {
// The output vector wasn't big enough // The output vector wasn't big enough
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Too many substrings!"; log += L"] Too many substrings!";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -915,7 +915,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
WCHAR buffer[32]; WCHAR buffer[32];
wsprintf(buffer, L"%2d", i); wsprintf(buffer, L"%2d", i);
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] (Index "; log += L"] (Index ";
log += buffer; log += buffer;
@ -935,7 +935,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
} }
else else
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Not enough substrings!"; log += L"] Not enough substrings!";
Log(LOG_WARNING, log.c_str()); Log(LOG_WARNING, log.c_str());
@ -1006,7 +1006,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
} }
else // error else // error
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += (*i).second->section; log += (*i).second->section;
log += L"] Failed to begin download thread."; log += L"] Failed to begin download thread.";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -1018,7 +1018,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
} }
else else
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += (*i).second->section; log += (*i).second->section;
log += L"] Not enough substrings!"; log += L"] Not enough substrings!";
Log(LOG_WARNING, log.c_str()); Log(LOG_WARNING, log.c_str());
@ -1050,7 +1050,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
WCHAR buffer[32]; WCHAR buffer[32];
wsprintf(buffer, L"%d", rc); wsprintf(buffer, L"%d", rc);
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Matching error! ("; log += L"] Matching error! (";
log += buffer; log += buffer;
@ -1084,7 +1084,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
WCHAR buffer[32]; WCHAR buffer[32];
wsprintf(buffer, L"%d", erroffset); wsprintf(buffer, L"%d", erroffset);
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] PCRE compilation failed at offset "; log += L"] PCRE compilation failed at offset ";
log += buffer; log += buffer;
@ -1105,7 +1105,7 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
} }
else // error else // error
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Failed to begin download thread."; log += L"] Failed to begin download thread.";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -1266,7 +1266,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
{ {
ready = false; ready = false;
log = L"WebParser: ["; log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Directory does not exist: "; log += L"] Directory does not exist: ";
log += directory; log += directory;
@ -1276,7 +1276,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
{ {
ready = false; ready = false;
log = L"WebParser: ["; log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Path is a directory, not a file: "; log += L"] Path is a directory, not a file: ";
log += fullpath; log += fullpath;
@ -1289,7 +1289,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
{ {
ready = false; ready = false;
log = L"WebParser: ["; log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] File is READ-ONLY: "; log += L"] File is READ-ONLY: ";
log += fullpath; log += fullpath;
@ -1378,7 +1378,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
} }
// Write some log info // Write some log info
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Downloading url "; log += L"] Downloading url ";
log += url; log += url;
@ -1446,7 +1446,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
wsprintf(buffer, L"result=0x%08X, COM=0x%08X", result, resultCoInitialize); 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 += urlData->section;
log += L"] Download failed ("; log += L"] Download failed (";
log += buffer; log += buffer;
@ -1462,7 +1462,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
} }
else else
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] Download failed: "; log += L"] Download failed: ";
log += url; log += url;
@ -1471,7 +1471,7 @@ unsigned __stdcall NetworkDownloadThreadProc(void* pParam)
} }
else else
{ {
std::wstring log = L"WebParser: ["; std::wstring log = L"WebParser.dll: [";
log += urlData->section; log += urlData->section;
log += L"] The url is empty.\n"; log += L"] The url is empty.\n";
Log(LOG_ERROR, log.c_str()); Log(LOG_ERROR, log.c_str());
@ -1611,8 +1611,7 @@ BYTE* DownloadUrl(std::wstring& url, DWORD* dwDataSize, bool forceReload)
int nBufferSize; int nBufferSize;
const int CHUNK_SIZE = 8192; const int CHUNK_SIZE = 8192;
std::wstring err = L"WebParser: Fetching URL: "; std::wstring err = L"WebParser.dll: Fetching: " + url;
err += url;
Log(LOG_DEBUG, err.c_str()); Log(LOG_DEBUG, err.c_str());
DWORD flags = INTERNET_FLAG_RESYNCHRONIZE; DWORD flags = INTERNET_FLAG_RESYNCHRONIZE;
@ -1704,10 +1703,6 @@ BYTE* DownloadUrl(std::wstring& url, DWORD* dwDataSize, bool forceReload)
// Close the HINTERNET handle. // Close the HINTERNET handle.
InternetCloseHandle(hUrlDump); InternetCloseHandle(hUrlDump);
err = L"WebParser: Finished URL: ";
err += url;
Log(LOG_DEBUG, err.c_str());
// Delete the existing buffers. // Delete the existing buffers.
delete [] lpData; delete [] lpData;
@ -1725,7 +1720,7 @@ void ShowError(int lineNumber, WCHAR* errorMsg)
WCHAR buffer[16]; WCHAR buffer[16];
wsprintf(buffer, L"%i", lineNumber); wsprintf(buffer, L"%i", lineNumber);
std::wstring err = L"WebParser ("; std::wstring err = L"WebParser.dll: (";
err += buffer; err += buffer;
err += L") "; 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) void Log(int level, const WCHAR* string)
{ {
LSLog(level, L"Rainmeter", string); LSLog(level, NULL, string);
} }
UINT GetPluginVersion() UINT GetPluginVersion()

View File

@ -37,10 +37,9 @@ __declspec( dllexport ) UINT GetPluginVersion();
__declspec( dllexport ) LPCTSTR GetPluginAuthor(); __declspec( dllexport ) LPCTSTR GetPluginAuthor();
} }
//Function that translates DOT11 ENUMs to output strings //Function that translates DOT11 ENUMs to output strings
LPCTSTR getDot11str(int,int); LPCTSTR getDot11str(int,int);
//Wrapper function for writing to log file
void Log(const WCHAR* string);
enum MEASURETYPE enum MEASURETYPE
{ {
@ -95,7 +94,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if ( ERROR_SUCCESS != dwErr ){ if ( ERROR_SUCCESS != dwErr ){
WCHAR buffer[256]; WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Unable to open WLAN API Handle. Error code (%d): %s",(int)dwErr,getDot11str(dwErr,5)); 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; return 0;
} }
} }
@ -105,20 +104,20 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if (( ERROR_SUCCESS != dwErr) || (&pIntfList->dwNumberOfItems <= 0)){ if (( ERROR_SUCCESS != dwErr) || (&pIntfList->dwNumberOfItems <= 0)){
WCHAR buffer[256]; WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Unable to find any WLAN interfaces/adapters. Error code %d",(int) dwErr); 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; return 0;
} }
} }
//Select a WLAN interface, default 0. //Select a WLAN interface, default 0.
LPCTSTR data = ReadConfigString(section, L"WifiIntfID", L""); LPCTSTR data = ReadConfigString(section, L"WifiIntfID", L"");
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ if ((data != NULL) && *data){
if (_wtoi(data) < (int)pIntfList->dwNumberOfItems){ if (_wtoi(data) < (int)pIntfList->dwNumberOfItems){
pInterface = &pIntfList->InterfaceInfo[_wtoi(data)]; pInterface = &pIntfList->InterfaceInfo[_wtoi(data)];
} else { } else {
WCHAR buffer[256]; 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); wsprintf(buffer, L"WifiStatus.dll: Adapter (WifiIntfID=%s) not valid", data);
Log(buffer); LSLog(LOG_ERROR, NULL, buffer);
pInterface = &pIntfList->InterfaceInfo[0]; pInterface = &pIntfList->InterfaceInfo[0];
} }
} else { } else {
@ -127,13 +126,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
//Select LIST style //Select LIST style
data = ReadConfigString(section, L"WifiListStyle", L""); data = ReadConfigString(section, L"WifiListStyle", L"");
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ if ((data != NULL) && *data){
if ( (_wtoi(data) >= 0) && (_wtoi(data) <= 3)){ if ( (_wtoi(data) >= 0) && (_wtoi(data) <= 3)){
g_meas_data[id].listStyle = _wtoi(data); g_meas_data[id].listStyle = _wtoi(data);
} else { } else {
WCHAR buffer[256]; WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Invalid List Style given (WifiListStyle=%s), defaulting to 0.",data); wsprintf(buffer, L"WifiStatus.dll: WifiListStyle=%s not valid",data);
Log(buffer); LSLog(LOG_WARNING, NULL, buffer);
g_meas_data[id].listStyle = 0; g_meas_data[id].listStyle = 0;
} }
} else { } else {
@ -143,13 +142,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
//Set maxmimum number of list items //Set maxmimum number of list items
data = ReadConfigString(section, L"WifiListLimit", L""); data = ReadConfigString(section, L"WifiListLimit", L"");
g_meas_data[id].listInit = false; g_meas_data[id].listInit = false;
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){ if ((data != NULL) && *data){
if (_wtoi(data) > 0){ if (_wtoi(data) > 0){
g_meas_data[id].listMax = _wtoi(data); g_meas_data[id].listMax = _wtoi(data);
} else { } else {
WCHAR buffer[256]; WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Invalid List Limit given (WifiListLimit=%s), defaulting to 5.",data); wsprintf(buffer, L"WifiStatus.dll: WifiListLimit=%s not valid.",data);
Log(buffer); LSLog(LOG_WARNING, NULL, buffer);
g_meas_data[id].listMax = 5; g_meas_data[id].listMax = 5;
} }
} else { } else {
@ -178,8 +177,8 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
infoType=PHY; infoType=PHY;
} else { } else {
WCHAR buffer[256]; WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Invalid type given, WifiInfoType=%d.",type); wsprintf(buffer, L"WifiStatus.dll: WifiInfoType=%d not valid",type);
Log(buffer); LSLog(LOG_ERROR, NULL, buffer);
} }
g_meas_data[id].type = infoType; 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 //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); g_meas_data[id].netlist = (WCHAR*)malloc( 80 * sizeof(WCHAR) * g_meas_data[id].listMax);
if (g_meas_data[id].netlist == NULL){ if (g_meas_data[id].netlist == NULL){
WCHAR debug[256]; LSLog(LOG_ERROR, NULL, L"WifiStatus.dll: Unable to allocate network list memory");
wsprintf(debug, L"WifiStatus.dll: Unable to allocate memory for network list.");
Log(buffer);
g_meas_data[id].listInit = false; g_meas_data[id].listInit = false;
free(g_meas_data[id].netlist); free(g_meas_data[id].netlist);
return NULL; return NULL;
@ -450,13 +447,13 @@ LPCTSTR getDot11str(int dot11enum,int type){
else{ else{
switch(dot11enum){ switch(dot11enum){
case ERROR_INVALID_PARAMETER: case ERROR_INVALID_PARAMETER:
return L"Invalid parameters."; return L"Invalid parameters";
case ERROR_NOT_ENOUGH_MEMORY: case ERROR_NOT_ENOUGH_MEMORY:
return L"Not enough memory."; return L"Not enough memory";
case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED: case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED:
return L"Too many handles already issued."; return L"Too many handles already issued";
default: 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 Returns the version number of the plugin. The value
can be calculated like this: Major * 1000 + Minor. can be calculated like this: Major * 1000 + Minor.

View File

@ -84,7 +84,7 @@ bool InitCom()
if (!com_initialized) com_initialized = SUCCEEDED(CoInitialize(0)); if (!com_initialized) com_initialized = SUCCEEDED(CoInitialize(0));
if (!com_initialized) 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; return false;
} }
HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, 0, CLSCTX_ALL, HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, 0, CLSCTX_ALL,
@ -92,7 +92,7 @@ bool InitCom()
instance_created = (S_OK == hr && pEnumerator); instance_created = (S_OK == hr && pEnumerator);
if (!instance_created) 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"; 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 == CLASS_E_NOAGGREGATION) dbg_str += L" CLASS_E_NOAGGREGATION";
else if (hr == E_NOINTERFACE) dbg_str += L" E_NOINTERFACE"; else if (hr == E_NOINTERFACE) dbg_str += L" E_NOINTERFACE";
@ -103,12 +103,12 @@ bool InitCom()
dbg_str += e_code; dbg_str += e_code;
} }
LSLog(LOG_ERROR, L"Rainmeter", dbg_str.c_str()); LSLog(LOG_ERROR, NULL, dbg_str.c_str());
return CleanUp() != 0; return CleanUp() != 0;
} }
if (S_OK != pEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pCollection) || !pCollection) 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 CleanUp() != 0;
} }
return true; return true;
@ -144,7 +144,7 @@ HRESULT RegisterDevice(PCWSTR devID)
} }
catch (...) catch (...)
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: RegisterDevice - Exception!"); LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: RegisterDevice exception");
hr = S_FALSE; hr = S_FALSE;
} }
UnInitCom(); UnInitCom();
@ -169,7 +169,7 @@ std::wstring GetDefaultID()
} }
catch (...) catch (...)
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: GetDefaultID - Exception!"); LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: GetDefaultID exception");
id_default = L"Exception"; id_default = L"Exception";
} }
SAFE_RELEASE(pEndpoint) SAFE_RELEASE(pEndpoint)
@ -206,7 +206,7 @@ bool GetWin7AudioState(const VolumeAction action)
} }
catch (...) catch (...)
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Win7ToggleMute - Exception!"); LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: ToggleMute exception");
} }
SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndptVol)
SAFE_RELEASE(pEndpoint) SAFE_RELEASE(pEndpoint)
@ -265,7 +265,7 @@ bool SetWin7Volume(UINT volume, int offset = 0)
} }
catch (...) catch (...)
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: SetWin7Volume - Exception!"); LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: SetVolume exception");
} }
SAFE_RELEASE(pEndptVol) SAFE_RELEASE(pEndptVol)
SAFE_RELEASE(pEndpoint) SAFE_RELEASE(pEndpoint)
@ -394,8 +394,9 @@ LPCTSTR GetString(UINT id, UINT flags)
SAFE_RELEASE(pEndpoint) SAFE_RELEASE(pEndpoint)
wsprintf(result, L"ERROR - Getting Default Device"); wsprintf(result, L"ERROR - Getting Default Device");
} }
} catch (...) { } catch (...)
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: GetString - Exception!"); {
LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: GetString exception");
wsprintf(result, L"Exception"); wsprintf(result, L"Exception");
} }
UnInitCom(); UnInitCom();
@ -440,7 +441,7 @@ void ExecuteBang(LPCTSTR args, UINT id)
{ {
if (endpointIDs.size() <= 0) 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; return;
} }
// set to endpoint [index-1] // set to endpoint [index-1]
@ -450,7 +451,7 @@ void ExecuteBang(LPCTSTR args, UINT id)
} }
else 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) 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))) 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 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) else if (_wcsicmp(bang.c_str(), L"ChangeVolume") == 0)
@ -477,59 +478,53 @@ void ExecuteBang(LPCTSTR args, UINT id)
{ {
if (!SetWin7Volume(0, offset)) 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 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 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) 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(); const UINT i = GetIndex();
if (i) RegisterDevice(endpointIDs[(i == endpointIDs.size()) ? 0 : i].c_str()); 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) else if (_wcsicmp(wholeBang.c_str(), L"TogglePrevious") == 0)
{ {
const UINT i = GetIndex(); const UINT i = GetIndex();
if (i) RegisterDevice(endpointIDs[(i == 1) ? endpointIDs.size() - 1 : i - 2].c_str()); 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) 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) else if (_wcsicmp(wholeBang.c_str(), L"Mute") == 0)
{ {
if (!is_mute) if (!is_mute)
{ {
if (!GetWin7AudioState(TOGGLE_MUTE)) GetWin7AudioState(TOGGLE_MUTE);
{
LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Mute Error!");
}
} }
} }
else if (_wcsicmp(wholeBang.c_str(), L"Unmute") == 0) else if (_wcsicmp(wholeBang.c_str(), L"Unmute") == 0)
{ {
if (is_mute) if (is_mute)
{ {
if (!GetWin7AudioState(TOGGLE_MUTE)) GetWin7AudioState(TOGGLE_MUTE);
{
LSLog(LOG_ERROR, L"Rainmeter", L"Win7AudioPlugin: Unmute Error!");
}
} }
} }
else else
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"Win7AudioPlugin: Unknown bang!"); LSLog(LOG_WARNING, NULL, L"Win7AudioPlugin.dll: Unknown bang");
} }
} }

View File

@ -66,7 +66,6 @@ static std::map<UINT, windowData> g_Values;
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
windowData wData; windowData wData;
wData.uMsg = 0; wData.uMsg = 0;
wData.wParam = 0; wData.wParam = 0;
wData.lParam = 0; wData.lParam = 0;
@ -111,8 +110,8 @@ double Update2(UINT id)
std::map<UINT, windowData>::iterator i = g_Values.find(id); std::map<UINT, windowData>::iterator i = g_Values.find(id);
if (i != g_Values.end()) if (i != g_Values.end())
{ {
std::wstring& winName = (*i).second.windowName; const std::wstring& winName = (*i).second.windowName;
std::wstring& winClass = (*i).second.windowClass; const std::wstring& winClass = (*i).second.windowClass;
HWND hwnd = FindWindow(winClass.empty() ? NULL : winClass.c_str(), winName.empty() ? NULL : winName.c_str()); HWND hwnd = FindWindow(winClass.empty() ? NULL : winClass.c_str(), winName.empty() ? NULL : winName.c_str());
if (hwnd) if (hwnd)
{ {
@ -136,7 +135,7 @@ double Update2(UINT id)
LPCTSTR GetString(UINT id, UINT flags) LPCTSTR GetString(UINT id, UINT flags)
{ {
static WCHAR buffer[256]; static WCHAR buffer[64];
std::map<UINT, windowData>::iterator i = g_Values.find(id); std::map<UINT, windowData>::iterator i = g_Values.find(id);
if (i != g_Values.end()) if (i != g_Values.end())
@ -183,7 +182,7 @@ void ExecuteBang(LPCTSTR args, UINT id)
{ {
std::wstring wholeBang = args; std::wstring wholeBang = args;
size_t pos = wholeBang.find(' '); size_t pos = wholeBang.find(L' ');
if (pos != -1) if (pos != -1)
{ {
std::wstring bang = wholeBang.substr(0, pos); std::wstring bang = wholeBang.substr(0, pos);
@ -207,26 +206,22 @@ void ExecuteBang(LPCTSTR args, UINT id)
} }
else 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 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 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");
}
return;
} }
} }
else
{ LSLog(LOG_WARNING, NULL, L"WindowMessagePlugin.dll: Unknown bang");
LSLog(LOG_WARNING, L"Rainmeter", L"WindowMessagePlugin: Unknown bang!");
}
}
else
{
LSLog(LOG_WARNING, L"Rainmeter", L"WindowMessagePlugin: Unable to parse the bang!");
}
} }

View File

@ -455,18 +455,13 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER)))
{ {
InstanceCreated = true; InstanceCreated = true;
LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully.");
initEventHandler(); initEventHandler();
} }
else 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""); const wchar_t* type = ReadConfigString(section, L"Command", L"");
for (int i = 0; i < COMMAND_COUNT; i++) 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))) if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER)))
{ {
InstanceCreated = true; InstanceCreated = true;
LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully.");
initEventHandler(); initEventHandler();
} }
else 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; return 0;
} }
} }
@ -779,7 +773,7 @@ void ExecuteBang(LPCTSTR args, UINT id)
} }
else else
{ {
LSLog(LOG_NOTICE, L"Rainmeter", L"iTunesPlugin: Invalid command."); LSLog(LOG_NOTICE, NULL, L"iTunesPlugin.dll: Invalid Command");
return; return;
} }
} }