summaryrefslogtreecommitdiff
path: root/plugins/ListeningTo/src/players
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-11 14:47:34 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-11 14:47:34 +0000
commiteb031473db62a4fac910f7cb2d13765a753df92d (patch)
treefe35fc5ba40891644ede85b58cf7ef4b6e87f9c1 /plugins/ListeningTo/src/players
parenta15cd68f0412e1b211e746a2e4d5682e96f5a113 (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14912 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/ListeningTo/src/players')
-rw-r--r--plugins/ListeningTo/src/players/foobar.cpp10
-rw-r--r--plugins/ListeningTo/src/players/generic.cpp328
-rw-r--r--plugins/ListeningTo/src/players/itunes.cpp55
-rw-r--r--plugins/ListeningTo/src/players/mradio.cpp14
-rw-r--r--plugins/ListeningTo/src/players/player.cpp65
-rw-r--r--plugins/ListeningTo/src/players/player.h10
-rw-r--r--plugins/ListeningTo/src/players/watrack.cpp54
-rw-r--r--plugins/ListeningTo/src/players/winamp.cpp4
-rw-r--r--plugins/ListeningTo/src/players/wmp.cpp147
9 files changed, 245 insertions, 442 deletions
diff --git a/plugins/ListeningTo/src/players/foobar.cpp b/plugins/ListeningTo/src/players/foobar.cpp
index 2b27f8d7a7..a0198f18fa 100644
--- a/plugins/ListeningTo/src/players/foobar.cpp
+++ b/plugins/ListeningTo/src/players/foobar.cpp
@@ -20,14 +20,14 @@ Boston, MA 02111-1307, USA.
#include "..\stdafx.h"
static TCHAR *wcs[] = {
- _T("{DA7CD0DE-1602-45e6-89A1-C2CA151E008E}/1"), // Foobar 0.9.1
- _T("{DA7CD0DE-1602-45e6-89A1-C2CA151E008E}"),
- _T("{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}"), // Foobar 0.9.5.3
- _T("{E7076D1C-A7BF-4f39-B771-BCBE88F2A2A8}"), // Foobar Columns UI
+ _T("{DA7CD0DE-1602-45e6-89A1-C2CA151E008E}/1"), // Foobar 0.9.1
+ _T("{DA7CD0DE-1602-45e6-89A1-C2CA151E008E}"),
+ _T("{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}"), // Foobar 0.9.5.3
+ _T("{E7076D1C-A7BF-4f39-B771-BCBE88F2A2A8}"), // Foobar Columns UI
};
Foobar::Foobar()
-{
+{
name = _T("foobar2000");
window_classes = wcs;
num_window_classes = _countof(wcs);
diff --git a/plugins/ListeningTo/src/players/generic.cpp b/plugins/ListeningTo/src/players/generic.cpp
index cc0ecae708..dcf7ba02df 100644
--- a/plugins/ListeningTo/src/players/generic.cpp
+++ b/plugins/ListeningTo/src/players/generic.cpp
@@ -19,51 +19,52 @@ Boston, MA 02111-1307, USA.
#include "..\stdafx.h"
-static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
-
static UINT hTimer = NULL;
+static HANDLE hLog = NULL;
GenericPlayer *singleton = NULL;
-int m_log(const TCHAR *function, const TCHAR *fmt, ...)
+void m_log(const TCHAR *function, const TCHAR *fmt, ...)
{
-#if 0
- va_list va;
- TCHAR text[1024];
- size_t len;
-
- len = mir_sntprintf(text, _T("[%08u - %08u] [%s] "),
- GetCurrentThreadId(), GetTickCount(), function);
+ if (hLog == NULL) {
+ hLog = mir_createLog(MODULE_NAME, _T("ListeningTo log"), _T("c:\\temp\\listeningto.txt"), 0);
+ if (hLog == NULL)
+ return;
+ }
- va_start(va, fmt);
- mir_vsntprintf(&text[len], _countof(text) - len, fmt, va);
- va_end(va);
+ mir_writeLogT(hLog, _T("%s: "), function);
- BOOL writeBOM = (GetFileAttributes(_T("c:\\miranda_listeningto.log.txt")) == INVALID_FILE_ATTRIBUTES);
+ va_list args;
+ va_start(args, fmt);
+ mir_writeLogVT(hLog, fmt, args);
+}
- FILE *fp = _tfopen(_T("c:\\miranda_listeningto.log.txt"), _T("ab"));
+static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message) {
+ case WM_COPYDATA:
+ if (loaded) {
+ COPYDATASTRUCT *pData = (PCOPYDATASTRUCT)lParam;
+ if (pData == NULL || pData->dwData != MIRANDA_DW_PROTECTION || pData->cbData == 0 || pData->lpData == NULL)
+ return FALSE;
- if (fp != NULL)
- {
+ if (singleton != NULL)
+ singleton->NewData((WCHAR *)pData->lpData, pData->cbData / 2);
- if (writeBOM)
- fwprintf(fp, L"\xFEFF");
+ return TRUE;
+ }
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
- _ftprintf(fp, _T("%s\r\n"), text);
- fclose(fp);
- return 0;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
}
- else
- {
- return -1;
- }
-#else
return 0;
-#endif
}
-
GenericPlayer::GenericPlayer()
{
name = _T("GenericPlayer");
@@ -72,23 +73,22 @@ GenericPlayer::GenericPlayer()
received[0] = L'\0';
singleton = this;
- WNDCLASS wc = {0};
- wc.lpfnWndProc = ReceiverWndProc;
- wc.hInstance = hInst;
- wc.lpszClassName = MIRANDA_WINDOWCLASS;
+ WNDCLASS wc = { 0 };
+ wc.lpfnWndProc = ReceiverWndProc;
+ wc.hInstance = hInst;
+ wc.lpszClassName = MIRANDA_WINDOWCLASS;
RegisterClass(&wc);
- hWnd = CreateWindow(MIRANDA_WINDOWCLASS, LPGENT("Miranda ListeningTo receiver"),
- 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
+ hWnd = CreateWindow(MIRANDA_WINDOWCLASS, LPGENT("Miranda ListeningTo receiver"),
+ 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
}
GenericPlayer::~GenericPlayer()
{
- if (hTimer != NULL)
- {
+ if (hTimer != NULL) {
KillTimer(NULL, hTimer);
hTimer = NULL;
}
@@ -104,133 +104,101 @@ GenericPlayer::~GenericPlayer()
void GenericPlayer::ProcessReceived()
{
- EnterCriticalSection(&cs);
-
- // Do the processing
- // L"<Status 0-stoped 1-playing>\\0<Player>\\0<Type>\\0<Title>\\0<Artist>\\0<Album>\\0<Track>\\0<Year>\\0<Genre>\\0<Length (secs)>\\0\\0"
-
- WCHAR *p1 = wcsstr(received, L"\\0");
-
- if (IsEmpty(received) || p1 == NULL)
{
-// if (received[0] == L'\0')
-// m_log(_T("ProcessReceived"), _T("ERROR: Empty text"));
-// else
-// m_log(_T("ProcessReceived"), _T("ERROR: No \\0 found"));
-
- // Ignore
- LeaveCriticalSection(&cs);
- return;
- }
-
- // Process string
- WCHAR *parts[11] = {0};
- int pCount = 0;
- WCHAR *p = received;
- do {
- *p1 = _T('\0');
+ mir_cslock lck(cs);
+
+ // Do the processing
+ // L"<Status 0-stoped 1-playing>\\0<Player>\\0<Type>\\0<Title>\\0<Artist>\\0<Album>\\0<Track>\\0<Year>\\0<Genre>\\0<Length (secs)>\\0\\0"
+
+ WCHAR *p1 = wcsstr(received, L"\\0");
+ if (IsEmpty(received) || p1 == NULL)
+ return;
+
+ // Process string
+ WCHAR *parts[11] = { 0 };
+ int pCount = 0;
+ WCHAR *p = received;
+ do {
+ *p1 = _T('\0');
+ parts[pCount] = p;
+ pCount++;
+ p = p1 + 2;
+ p1 = wcsstr(p, _T("\\0"));
+ } while (p1 != NULL && pCount < 10);
+ if (p1 != NULL)
+ *p1 = _T('\0');
parts[pCount] = p;
- pCount ++;
- p = p1 + 2;
- p1 = wcsstr(p, _T("\\0"));
- } while( p1 != NULL && pCount < 10 );
- if (p1 != NULL)
- *p1 = _T('\0');
- parts[pCount] = p;
-
- if (pCount < 5)
- {
-// m_log(_T("ProcessReceived"), _T("ERROR: Too little pieces"));
- // Ignore
- LeaveCriticalSection(&cs);
- return;
- }
+ if (pCount < 5)
+ return;
- // See if player is enabled
- Player *player = this;
- for (int i = FIRST_PLAYER; i < NUM_PLAYERS; i++)
- {
+ // See if player is enabled
+ Player *player = this;
+ for (int i = FIRST_PLAYER; i < NUM_PLAYERS; i++) {
- WCHAR *player_name = players[i]->name;
+ WCHAR *player_name = players[i]->name;
- if (_wcsicmp(parts[1], player_name) == 0)
- {
- player = players[i];
- break;
+ if (_wcsicmp(parts[1], player_name) == 0) {
+ player = players[i];
+ break;
+ }
}
- }
-
-
- player->FreeData();
-
- if (wcscmp(L"1", parts[0]) != 0 || IsEmpty(parts[1]) || (IsEmpty(parts[3]) && IsEmpty(parts[4])))
- {
- // Stoped playing or not enought info
+ player->FreeData();
-// if (wcscmp(L"1", parts[0]) != 0)
-// m_log(_T("ProcessReceived"), _T("END: Stoped playing"));
-// else
-// m_log(_T("ProcessReceived"), _T("ERROR: not enought info"));
- }
- else
- {
- LISTENINGTOINFO *li = player->LockListeningInfo();
-
- li->cbSize = sizeof(listening_info);
- li->dwFlags = LTI_TCHAR;
- li->ptszType = U2TD(parts[2], _T("Music"));
- li->ptszTitle = U2T(parts[3]);
- li->ptszArtist = U2T(parts[4]);
- li->ptszAlbum = U2T(parts[5]);
- li->ptszTrack = U2T(parts[6]);
- li->ptszYear = U2T(parts[7]);
- li->ptszGenre = U2T(parts[8]);
-
- if (player == this)
- li->ptszPlayer = mir_u2t(parts[1]);
- else
- li->ptszPlayer = mir_tstrdup(player->name);
-
- if (parts[9] != NULL)
- {
- long length = _wtoi(parts[9]);
- if (length > 0)
- {
- li->ptszLength = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
-
- int s = length % 60;
- int m = (length / 60) % 60;
- int h = (length / 60) / 60;
-
- if (h > 0)
- mir_sntprintf(li->ptszLength, 9, _T("%d:%02d:%02d"), h, m, s);
- else
- mir_sntprintf(li->ptszLength, 9, _T("%d:%02d"), m, s);
+ if (wcscmp(L"1", parts[0]) != 0 || IsEmpty(parts[1]) || (IsEmpty(parts[3]) && IsEmpty(parts[4]))) {
+ // Stoped playing or not enought info
+ }
+ else {
+ mir_cslock lck(player->GetLock());
+ LISTENINGTOINFO *li = player->GetInfo();
+
+ li->cbSize = sizeof(listening_info);
+ li->dwFlags = LTI_TCHAR;
+ li->ptszType = U2TD(parts[2], _T("Music"));
+ li->ptszTitle = U2T(parts[3]);
+ li->ptszArtist = U2T(parts[4]);
+ li->ptszAlbum = U2T(parts[5]);
+ li->ptszTrack = U2T(parts[6]);
+ li->ptszYear = U2T(parts[7]);
+ li->ptszGenre = U2T(parts[8]);
+
+ if (player == this)
+ li->ptszPlayer = mir_u2t(parts[1]);
+ else
+ li->ptszPlayer = mir_tstrdup(player->name);
+
+ if (parts[9] != NULL) {
+ long length = _wtoi(parts[9]);
+ if (length > 0) {
+ li->ptszLength = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
+
+ int s = length % 60;
+ int m = (length / 60) % 60;
+ int h = (length / 60) / 60;
+
+ if (h > 0)
+ mir_sntprintf(li->ptszLength, 9, _T("%d:%02d:%02d"), h, m, s);
+ else
+ mir_sntprintf(li->ptszLength, 9, _T("%d:%02d"), m, s);
+ }
}
}
- player->ReleaseListeningInfo();
- }
-
- // Put back the '\\'s
- for(int i = 1; i <= pCount; i++)
- *(parts[i] - 2) = L'\\';
- if (p1 != NULL)
- *p1 = L'\\';
-
- wcscpy(last_received, received);
+ // Put back the '\\'s
+ for (int i = 1; i <= pCount; i++)
+ *(parts[i] - 2) = L'\\';
+ if (p1 != NULL)
+ *p1 = L'\\';
- LeaveCriticalSection(&cs);
+ wcscpy(last_received, received);
+ }
NotifyInfoChanged();
-
-// m_log(_T("ProcessReceived"), _T("END: Success"));
}
-static VOID CALLBACK SendTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+static VOID CALLBACK SendTimerProc(HWND, UINT, UINT_PTR, DWORD)
{
KillTimer(NULL, hTimer);
hTimer = NULL;
@@ -238,8 +206,6 @@ static VOID CALLBACK SendTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
if (!loaded)
return;
-// m_log(_T("SendTimerProc"), _T("It's time to process"));
-
if (singleton != NULL)
singleton->ProcessReceived();
}
@@ -247,80 +213,18 @@ static VOID CALLBACK SendTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
void GenericPlayer::NewData(const WCHAR *data, size_t len)
{
-// m_log(_T("NewData"), _T("Processing"));
-
if (data[0] == _T('\0'))
- {
-// m_log(_T("NewData"), _T("ERROR: Text is empty"));
return;
- }
- EnterCriticalSection(&cs);
+ mir_cslock lck(cs);
len = min(len, 1023);
- if (wcsncmp(received, data, len) != 0)
- {
-// m_log(_T("NewData"), _T("Got new text, scheduling update"));
-
+ if (wcsncmp(received, data, len) != 0) {
wcsncpy(received, data, len);
received[len] = L'\0';
-
-// m_log(_T("NewData"), _T("Text: %s"), received);
-
-
if (hTimer)
KillTimer(NULL, hTimer);
hTimer = SetTimer(NULL, NULL, 300, SendTimerProc); // Do the processing after we return true
}
-// else
-// {
-// m_log(_T("NewData"), _T("END: Text is the same as last time"));
-// }
-
- LeaveCriticalSection(&cs);
-}
-
-
-static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message)
- {
- case WM_COPYDATA:
- {
- if (!loaded)
- return FALSE;
-
-// m_log(_T("ReceiverWndProc"), _T("START: Received message"));
-
- COPYDATASTRUCT* pData = (PCOPYDATASTRUCT) lParam;
- if (pData == NULL || pData->dwData != MIRANDA_DW_PROTECTION
- || pData->cbData == 0 || pData->lpData == NULL)
- {
-/* if (pData == NULL)
- m_log(_T("ReceiverWndProc"), _T("ERROR: COPYDATASTRUCT* is NULL"));
- else if (pData->dwData != MIRANDA_DW_PROTECTION)
- m_log(_T("ReceiverWndProc"), _T("ERROR: pData->dwData is incorrect"));
- else if (pData->cbData == 0)
- m_log(_T("ReceiverWndProc"), _T("ERROR: pData->cbData is 0"));
- else if (pData->lpData == NULL)
- m_log(_T("ReceiverWndProc"), _T("ERROR: pData->lpData is NULL"));
-*/
- return FALSE;
- }
-
-// m_log(_T("ReceiverWndProc"), _T("Going to process"));
- if (singleton != NULL)
- singleton->NewData((WCHAR *) pData->lpData, pData->cbData / 2);
-
- return TRUE;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- default :
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
}
diff --git a/plugins/ListeningTo/src/players/itunes.cpp b/plugins/ListeningTo/src/players/itunes.cpp
index af479f22c8..fa444bc10d 100644
--- a/plugins/ListeningTo/src/players/itunes.cpp
+++ b/plugins/ListeningTo/src/players/itunes.cpp
@@ -38,13 +38,11 @@ ITunes::ITunes()
ret = NULL;
}
-
void ITunes::FindWindow()
{
hwnd = ::FindWindow(_T("iTunes"), _T("iTunes"));
}
-
void ITunes::FreeTempData()
{
#define RELEASE(_x_) if (_x_ != NULL) { _x_->Release(); _x_ = NULL; }
@@ -53,14 +51,12 @@ void ITunes::FreeTempData()
RELEASE(track);
RELEASE(iTunesApp);
- if (ret != NULL)
- {
+ if (ret != NULL) {
SysFreeString(ret);
ret = NULL;
}
}
-
#define CALL(_F_) hr = _F_; if (FAILED(hr)) return FALSE
// Init data and put filename playing in ret and ->fi.filename
@@ -73,60 +69,56 @@ BOOL ITunes::InitAndGetFilename()
if (hwnd == NULL)
return FALSE;
- CALL( CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, __uuidof(iTunesApp), (void **)&iTunesApp));
+ CALL(CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, __uuidof(iTunesApp), (void **)&iTunesApp));
ITPlayerState state;
- CALL( iTunesApp->get_PlayerState(&state));
+ CALL(iTunesApp->get_PlayerState(&state));
if (state == ITPlayerStateStopped)
return FALSE;
- CALL( iTunesApp->get_CurrentTrack(&track));
+ CALL(iTunesApp->get_CurrentTrack(&track));
if (track == NULL)
return FALSE;
- CALL( track->QueryInterface(__uuidof(file), (void **)&file));
+ CALL(track->QueryInterface(__uuidof(file), (void **)&file));
- CALL( file->get_Location(&ret));
+ CALL(file->get_Location(&ret));
return !IsEmpty(ret);
}
-
BOOL ITunes::FillCache()
{
HRESULT hr;
long lret;
- CALL( track->get_Album(&ret));
+ CALL(track->get_Album(&ret));
listening_info.ptszAlbum = U2T(ret);
- CALL( track->get_Artist(&ret));
+ CALL(track->get_Artist(&ret));
listening_info.ptszArtist = U2T(ret);
- CALL( track->get_Name(&ret));
+ CALL(track->get_Name(&ret));
listening_info.ptszTitle = U2T(ret);
- CALL( track->get_Year(&lret));
- if (lret > 0)
- {
- listening_info.ptszYear = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
+ CALL(track->get_Year(&lret));
+ if (lret > 0) {
+ listening_info.ptszYear = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
_itot(lret, listening_info.ptszYear, 10);
}
- CALL( track->get_TrackNumber(&lret));
- if (lret > 0)
- {
- listening_info.ptszTrack = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
+ CALL(track->get_TrackNumber(&lret));
+ if (lret > 0) {
+ listening_info.ptszTrack = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
_itot(lret, listening_info.ptszTrack, 10);
}
- CALL( track->get_Genre(&ret));
+ CALL(track->get_Genre(&ret));
listening_info.ptszGenre = U2T(ret);
- CALL( track->get_Duration(&lret));
- if (lret > 0)
- {
- listening_info.ptszLength = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
+ CALL(track->get_Duration(&lret));
+ if (lret > 0) {
+ listening_info.ptszLength = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
int s = lret % 60;
int m = (lret / 60) % 60;
@@ -140,15 +132,14 @@ BOOL ITunes::FillCache()
listening_info.ptszType = mir_tstrdup(_T("Music"));
- if (listening_info.ptszTitle == NULL)
- {
+ if (listening_info.ptszTitle == NULL) {
// Get from filename
WCHAR *p = wcsrchr(filename, '\\');
if (p != NULL)
p++;
else
p = filename;
-
+
listening_info.ptszTitle = mir_u2t(p);
TCHAR *pt = _tcsrchr(listening_info.ptszTitle, '.');
@@ -164,13 +155,11 @@ BOOL ITunes::FillCache()
return TRUE;
}
-
BOOL ITunes::GetListeningInfo(LISTENINGTOINFO *lti)
{
FreeData();
- if (InitAndGetFilename() && lstrcmp(filename, ret) != 0)
- {
+ if (InitAndGetFilename() && lstrcmp(filename, ret) != 0) {
// Fill the data cache
wcscpy(filename, ret);
diff --git a/plugins/ListeningTo/src/players/mradio.cpp b/plugins/ListeningTo/src/players/mradio.cpp
index 54dd45a8d1..1b99945902 100644
--- a/plugins/ListeningTo/src/players/mradio.cpp
+++ b/plugins/ListeningTo/src/players/mradio.cpp
@@ -35,12 +35,12 @@ void MRadio::EnableDisable()
int MRadio::GetData()
{
for (MCONTACT hContact = db_find_first("mRadio"); hContact; hContact = db_find_next(hContact, "mRadio")) {
- WORD status = db_get_w(hContact, "mRadio", "Status", ID_STATUS_OFFLINE);
+ WORD status = db_get_w(hContact, "mRadio", "Status", ID_STATUS_OFFLINE);
if (status != ID_STATUS_ONLINE)
continue;
DBVARIANT dbv;
- if (!db_get_s(hContact, "mRadio", "Nick", &dbv)) {
+ if (!db_get_s(hContact, "mRadio", "Nick", &dbv)) {
listening_info.cbSize = sizeof(listening_info);
listening_info.dwFlags = LTI_TCHAR;
listening_info.ptszArtist = mir_tstrdup(_T("Radio"));
@@ -58,16 +58,14 @@ int MRadio::GetData()
BOOL MRadio::GetListeningInfo(LISTENINGTOINFO *lti)
{
- FreeData();
+ FreeData();
- if (enabled)
- {
- if (CallService(MS_RADIO_COMMAND, MRC_STATUS, RD_STATUS_GET) == RD_STATUS_PLAYING)
- {
+ if (enabled) {
+ if (CallService(MS_RADIO_COMMAND, MRC_STATUS, RD_STATUS_GET) == RD_STATUS_PLAYING) {
if (!GetData())
FreeData();
}
}
return Player::GetListeningInfo(lti);
-} \ No newline at end of file
+}
diff --git a/plugins/ListeningTo/src/players/player.cpp b/plugins/ListeningTo/src/players/player.cpp
index f87818a90b..d7834f3e83 100644
--- a/plugins/ListeningTo/src/players/player.cpp
+++ b/plugins/ListeningTo/src/players/player.cpp
@@ -24,13 +24,11 @@ extern void HasNewListeningInfo();
Player::Player() : name(_T("Player")), enabled(FALSE), needPoll(FALSE)
{
memset(&listening_info, 0, sizeof(listening_info));
- InitializeCriticalSection(&cs);
}
Player::~Player()
{
FreeData();
- DeleteCriticalSection(&cs);
}
void Player::NotifyInfoChanged()
@@ -41,49 +39,24 @@ void Player::NotifyInfoChanged()
BOOL Player::GetListeningInfo(LISTENINGTOINFO *lti)
{
- EnterCriticalSection(&cs);
+ mir_cslock lck(cs);
- BOOL ret;
if (listening_info.cbSize == 0)
- {
- ret = FALSE;
- }
- else
- {
- if (lti != NULL)
- CopyListeningInfo(lti, &listening_info);
- ret = TRUE;
- }
+ return false;
- LeaveCriticalSection(&cs);
-
- return ret;
+ if (lti != NULL)
+ CopyListeningInfo(lti, &listening_info);
+ return true;
}
void Player::FreeData()
{
- EnterCriticalSection(&cs);
+ mir_cslock lck(cs);
if (listening_info.cbSize != 0)
FreeListeningInfo(&listening_info);
-
- LeaveCriticalSection(&cs);
}
-LISTENINGTOINFO * Player::LockListeningInfo()
-{
- EnterCriticalSection(&cs);
-
- return &listening_info;
-}
-
-void Player::ReleaseListeningInfo()
-{
- LeaveCriticalSection(&cs);
-}
-
-
-
ExternalPlayer::ExternalPlayer()
{
name = _T("ExternalPlayer");
@@ -101,8 +74,7 @@ ExternalPlayer::~ExternalPlayer()
HWND ExternalPlayer::FindWindow()
{
HWND hwnd = NULL;
- for(int i = 0; i < num_window_classes; i++)
- {
+ for (int i = 0; i < num_window_classes; i++) {
hwnd = ::FindWindow(window_classes[i], NULL);
if (hwnd != NULL)
break;
@@ -154,7 +126,7 @@ void CodeInjectionPlayer::InjectCode()
// Get the dll path
- char dll_path[1024] = {0};
+ char dll_path[1024] = { 0 };
if (!GetModuleFileNameA(hInst, dll_path, _countof(dll_path)))
return;
@@ -179,33 +151,30 @@ void CodeInjectionPlayer::InjectCode()
// Do the code injection
unsigned long pid;
GetWindowThreadProcessId(hwnd, &pid);
- HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION
- | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, pid);
+ HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION
+ | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, pid);
if (hProcess == NULL)
return;
- char *_dll = (char *) VirtualAllocEx(hProcess, NULL, len+1, MEM_COMMIT, PAGE_READWRITE );
- if (_dll == NULL)
- {
+ char *_dll = (char *)VirtualAllocEx(hProcess, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE);
+ if (_dll == NULL) {
CloseHandle(hProcess);
return;
}
- WriteProcessMemory(hProcess, _dll, dll_path, len+1, NULL);
+ WriteProcessMemory(hProcess, _dll, dll_path, len + 1, NULL);
HMODULE hKernel32 = GetModuleHandleA("kernel32");
HANDLE hLoadLibraryA = GetProcAddress(hKernel32, "LoadLibraryA");
DWORD threadId;
- HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) hLoadLibraryA,
- _dll, 0, &threadId);
- if (hThread == NULL)
- {
- VirtualFreeEx(hProcess, _dll, len+1, MEM_RELEASE);
+ HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)hLoadLibraryA, _dll, 0, &threadId);
+ if (hThread == NULL) {
+ VirtualFreeEx(hProcess, _dll, len + 1, MEM_RELEASE);
CloseHandle(hProcess);
return;
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
- VirtualFreeEx(hProcess, _dll, len+1, MEM_RELEASE);
+ VirtualFreeEx(hProcess, _dll, len + 1, MEM_RELEASE);
CloseHandle(hProcess);
}
diff --git a/plugins/ListeningTo/src/players/player.h b/plugins/ListeningTo/src/players/player.h
index 45396ad261..83a14e3a69 100644
--- a/plugins/ListeningTo/src/players/player.h
+++ b/plugins/ListeningTo/src/players/player.h
@@ -22,7 +22,7 @@ class Player
{
protected:
LISTENINGTOINFO listening_info;
- CRITICAL_SECTION cs;
+ mir_cs cs;
void NotifyInfoChanged();
@@ -34,14 +34,12 @@ public:
Player();
virtual ~Player();
- virtual BOOL GetListeningInfo(LISTENINGTOINFO *lti);
+ __forceinline mir_cs& GetLock() { return cs; }
+ __forceinline LISTENINGTOINFO* GetInfo() { return &listening_info; }
+ virtual BOOL GetListeningInfo(LISTENINGTOINFO *lti);
virtual void FreeData();
- // Helpers to write to this object's listening info
- virtual LISTENINGTOINFO * LockListeningInfo();
- virtual void ReleaseListeningInfo();
-
// Called everytime options change
virtual void EnableDisable() {}
};
diff --git a/plugins/ListeningTo/src/players/watrack.cpp b/plugins/ListeningTo/src/players/watrack.cpp
index 4af891b39a..7f3a6a68cc 100644
--- a/plugins/ListeningTo/src/players/watrack.cpp
+++ b/plugins/ListeningTo/src/players/watrack.cpp
@@ -21,7 +21,7 @@ Boston, MA 02111-1307, USA.
static WATrack *instance = NULL;
-int NewStatusCallback(WPARAM wParam, LPARAM lParam)
+int NewStatusCallback(WPARAM wParam, LPARAM lParam)
{
if (!loaded)
return 0;
@@ -30,7 +30,6 @@ int NewStatusCallback(WPARAM wParam, LPARAM lParam)
return 0;
}
-
WATrack::WATrack()
{
name = _T("WATrack");
@@ -38,23 +37,18 @@ WATrack::WATrack()
hNewStatusHook = NULL;
}
-
-
WATrack::~WATrack()
{
- if (hNewStatusHook != NULL)
- {
+ if (hNewStatusHook != NULL) {
UnhookEvent(hNewStatusHook);
hNewStatusHook = NULL;
}
instance = NULL;
}
-
void WATrack::EnableDisable()
{
- if (!ServiceExists(MS_WAT_GETMUSICINFO))
- {
+ if (!ServiceExists(MS_WAT_GETMUSICINFO)) {
enabled = FALSE;
return;
}
@@ -63,65 +57,45 @@ void WATrack::EnableDisable()
hNewStatusHook = HookEvent(ME_WAT_NEWSTATUS, NewStatusCallback);
}
-
void WATrack::NewStatus(int event, int value)
{
- EnterCriticalSection(&cs);
-
- if (event == WAT_EVENT_PLUGINSTATUS && value != 0)
- {
- FreeData();
- }
- else
{
- GetData();
+ mir_cslock lck(cs);
+ if (event == WAT_EVENT_PLUGINSTATUS && value != 0)
+ FreeData();
+ else
+ GetData();
}
- LeaveCriticalSection(&cs);
-
NotifyInfoChanged();
}
-
void WATrack::GetData()
{
-
-
SONGINFO *si = NULL;
-
- int playing = CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM) &si);
-
-
+ int playing = CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM)&si);
FreeData();
// See if something is playing
- if (playing == WAT_RES_NOTFOUND
- || si == NULL
- || si->status != 1
- || ( IsEmpty(si->artist) && IsEmpty(si->title)) )
- {
+ if (playing == WAT_RES_NOTFOUND || si == NULL || si->status != 1 || (IsEmpty(si->artist) && IsEmpty(si->title)))
return;
- }
// Copy new data
-
listening_info.ptszAlbum = DUP(si->album);
listening_info.ptszArtist = DUP(si->artist);
listening_info.ptszTitle = DUP(si->title);
listening_info.ptszYear = DUP(si->year);
- if (si->track > 0)
- {
- listening_info.ptszTrack = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
+ if (si->track > 0) {
+ listening_info.ptszTrack = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
_itot(si->track, listening_info.ptszTrack, 10);
}
listening_info.ptszGenre = DUP(si->genre);
- if (si->total > 0)
- {
- listening_info.ptszLength = (TCHAR*) mir_alloc(10 * sizeof(TCHAR));
+ if (si->total > 0) {
+ listening_info.ptszLength = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
int s = si->total % 60;
int m = (si->total / 60) % 60;
diff --git a/plugins/ListeningTo/src/players/winamp.cpp b/plugins/ListeningTo/src/players/winamp.cpp
index c3e08a02af..1dcaea4e98 100644
--- a/plugins/ListeningTo/src/players/winamp.cpp
+++ b/plugins/ListeningTo/src/players/winamp.cpp
@@ -20,11 +20,11 @@ Boston, MA 02111-1307, USA.
#include "..\stdafx.h"
static TCHAR *wcs[] = {
- _T("Winamp v1.x")
+ _T("Winamp v1.x")
};
Winamp::Winamp()
-{
+{
name = _T("Winamp");
window_classes = wcs;
num_window_classes = _countof(wcs);
diff --git a/plugins/ListeningTo/src/players/wmp.cpp b/plugins/ListeningTo/src/players/wmp.cpp
index 7dc2c6fff0..2b46ba6195 100644
--- a/plugins/ListeningTo/src/players/wmp.cpp
+++ b/plugins/ListeningTo/src/players/wmp.cpp
@@ -23,37 +23,30 @@ Boston, MA 02111-1307, USA.
static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
-
static UINT hTimer = NULL;
-
WindowsMediaPlayer *singleton = NULL;
-
-
WindowsMediaPlayer::WindowsMediaPlayer()
{
name = _T("WindowsMediaPlayer");
received[0] = _T('\0');
singleton = this;
- WNDCLASS wc = {0};
- wc.lpfnWndProc = ReceiverWndProc;
- wc.hInstance = hInst;
- wc.lpszClassName = WMP_WINDOWCLASS;
+ WNDCLASS wc = { 0 };
+ wc.lpfnWndProc = ReceiverWndProc;
+ wc.hInstance = hInst;
+ wc.lpszClassName = WMP_WINDOWCLASS;
RegisterClass(&wc);
- hWnd = CreateWindow(WMP_WINDOWCLASS, LPGENT("Miranda ListeningTo WMP receiver"),
- 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
+ hWnd = CreateWindow(WMP_WINDOWCLASS, LPGENT("Miranda ListeningTo WMP receiver"),
+ 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
}
-
-
WindowsMediaPlayer::~WindowsMediaPlayer()
{
- if (hTimer != NULL)
- {
+ if (hTimer != NULL) {
KillTimer(NULL, hTimer);
hTimer = NULL;
}
@@ -65,70 +58,62 @@ WindowsMediaPlayer::~WindowsMediaPlayer()
singleton = NULL;
}
-
-
void WindowsMediaPlayer::ProcessReceived()
{
- EnterCriticalSection(&cs);
-
- FreeData();
+ {
+ mir_cslock lck(cs);
+ FreeData();
- // Do the processing
- // MSNMusicString = L"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0"
- // MSNMusicString, msn->msncommand, strMSNFormat, msn->title, msn->artist, msn->album, msn->wmcontentid);
+ // Do the processing
+ // MSNMusicString = L"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0"
+ // MSNMusicString, msn->msncommand, strMSNFormat, msn->title, msn->artist, msn->album, msn->wmcontentid);
- WCHAR *p1 = wcsstr(received, L"\\0");
+ WCHAR *p1 = wcsstr(received, L"\\0");
- if (received[0] == L'\0' || p1 == NULL)
- {
- LeaveCriticalSection(&cs);
- NotifyInfoChanged();
- return;
- }
+ if (received[0] == L'\0' || p1 == NULL) {
+ NotifyInfoChanged();
+ return;
+ }
- // Process string
- WCHAR *parts[8] = {0};
- int pCount = 0;
- WCHAR *p = received;
- do {
- *p1 = L'\0';
+ // Process string
+ WCHAR *parts[8] = { 0 };
+ int pCount = 0;
+ WCHAR *p = received;
+ do {
+ *p1 = L'\0';
+ parts[pCount] = p;
+ pCount++;
+ p = p1 + 2;
+ p1 = wcsstr(p, L"\\0");
+ } while (p1 != NULL && pCount < 7);
+ if (p1 != NULL)
+ *p1 = L'\0';
parts[pCount] = p;
- pCount ++;
- p = p1 + 2;
- p1 = wcsstr(p, L"\\0");
- } while( p1 != NULL && pCount < 7 );
- if (p1 != NULL)
- *p1 = L'\0';
- parts[pCount] = p;
-
- // Fill cache
- if (pCount > 4 && !IsEmpty(parts[1]) && (!IsEmpty(parts[4]) || !IsEmpty(parts[5])))
- {
- listening_info.cbSize = sizeof(listening_info);
- listening_info.dwFlags = LTI_TCHAR;
- listening_info.ptszType = U2T(parts[1]);
- listening_info.ptszTitle = U2T(parts[4]);
- listening_info.ptszArtist = U2T(parts[5]);
- listening_info.ptszAlbum = U2T(parts[6]);
+ // Fill cache
+ if (pCount > 4 && !IsEmpty(parts[1]) && (!IsEmpty(parts[4]) || !IsEmpty(parts[5]))) {
+ listening_info.cbSize = sizeof(listening_info);
+ listening_info.dwFlags = LTI_TCHAR;
- listening_info.ptszPlayer = mir_tstrdup(name);
- }
+ listening_info.ptszType = U2T(parts[1]);
+ listening_info.ptszTitle = U2T(parts[4]);
+ listening_info.ptszArtist = U2T(parts[5]);
+ listening_info.ptszAlbum = U2T(parts[6]);
- // Put back the '\\'s
- for(int i = 1; i <= pCount; i++)
- *(parts[i] - 2) = L'\\';
- if (p1 != NULL)
- *p1 = L'\\';
+ listening_info.ptszPlayer = mir_tstrdup(name);
+ }
- LeaveCriticalSection(&cs);
+ // Put back the '\\'s
+ for (int i = 1; i <= pCount; i++)
+ *(parts[i] - 2) = L'\\';
+ if (p1 != NULL)
+ *p1 = L'\\';
+ }
NotifyInfoChanged();
}
-
-
-static VOID CALLBACK SendTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+static VOID CALLBACK SendTimerProc(HWND, UINT, UINT_PTR, DWORD)
{
KillTimer(NULL, hTimer);
hTimer = NULL;
@@ -140,40 +125,25 @@ static VOID CALLBACK SendTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
singleton->ProcessReceived();
}
-
void WindowsMediaPlayer::NewData(const WCHAR *data, size_t len)
{
- EnterCriticalSection(&cs);
+ mir_cslock lck(cs);
len = min(len, 1023);
- if (wcsncmp(received, data, len) != 0)
- {
+ if (wcsncmp(received, data, len) != 0) {
wcsncpy(received, data, len);
received[len] = _T('\0');
-/*
- m_log(_T("ReceiverWndProc"), _T("WMP : New data: [%d] %s"), len, received);
-
-*/
if (hTimer)
KillTimer(NULL, hTimer);
hTimer = SetTimer(NULL, NULL, 300, SendTimerProc); // Do the processing after we return true
}
-/* else
- {
- m_log(_T("NewData"), _T("END: Text is the same as last time"));
- }
-*/
- LeaveCriticalSection(&cs);
}
-
-
static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
- case WM_COPYDATA :
+ switch (message) {
+ case WM_COPYDATA:
{
if (!loaded)
return FALSE;
@@ -181,19 +151,20 @@ static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam,
if (singleton == NULL || !singleton->enabled)
return FALSE;
- COPYDATASTRUCT* pData = (PCOPYDATASTRUCT) lParam;
+ COPYDATASTRUCT* pData = (PCOPYDATASTRUCT)lParam;
if (pData->dwData != 0x547 || pData->cbData == 0 || pData->lpData == NULL)
return FALSE;
if (singleton != NULL)
- singleton->NewData((WCHAR *) pData->lpData, pData->cbData / 2);
+ singleton->NewData((WCHAR *)pData->lpData, pData->cbData / 2);
return TRUE;
}
- case WM_DESTROY :
- PostQuitMessage(0);
- break;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
-} \ No newline at end of file
+}