- 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

@ -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"%");

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}

View File

@ -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();
}
}
}

View File

@ -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;
};

View File

@ -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

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

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

View File

@ -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<IObjectWithSite> spHostObject;
CComPtr<IAxWinHostWindow> 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))
{

View File

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

View File

@ -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)

View File

@ -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;