diff --git a/Plugins/PluginNowPlaying/Lyrics.cpp b/Plugins/PluginNowPlaying/Lyrics.cpp index a9f654e4..d15400fe 100644 --- a/Plugins/PluginNowPlaying/Lyrics.cpp +++ b/Plugins/PluginNowPlaying/Lyrics.cpp @@ -62,8 +62,8 @@ bool CLyrics::GetFromWikia(const std::wstring& artist, const std::wstring& title if (pos != std::wstring::npos) { data.erase(0, pos); - pos = data.find(L"'"); - url = data.substr(0, pos); + pos = data.find_first_of(L'\''); + url.assign(data, 0, pos); // Fetch the wiki page data = CInternet::DownloadUrl(url, CP_UTF8); @@ -148,8 +148,8 @@ bool CLyrics::GetFromLYRDB(const std::wstring& artist, const std::wstring& title if (pos != std::wstring::npos) { // Grab the first match - url = L"http://webservices.lyrdb.com/getlyr.php?q="; - url += data.substr(0, pos); + url.assign(data, 0, pos); + url.insert(0, L"http://webservices.lyrdb.com/getlyr.php?q="); data = CInternet::DownloadUrl(url, CP_ACP); if (!data.empty()) diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index 21a701de..cc6b96fb 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -445,7 +445,14 @@ void ExecuteBang(LPCTSTR bang, UINT id) ParentMeasure* parent = child->parent; CPlayer* player = parent->player; - if (_wcsicmp(bang, L"Pause") == 0) + if (!player->IsInitialized()) + { + if (_wcsicmp(bang, L"ClosePlayer") == 0 || _wcsicmp(bang, L"TogglePlayer") == 0) + { + player->OpenPlayer(parent->playerPath); + } + } + else if (_wcsicmp(bang, L"Pause") == 0) { player->Pause(); } @@ -469,13 +476,7 @@ void ExecuteBang(LPCTSTR bang, UINT id) { player->Previous(); } - else if (_wcsicmp(bang, L"OpenPlayer") == 0 || - (!player->IsInitialized() && _wcsicmp(bang, L"TogglePlayer") == 0)) - { - player->OpenPlayer(parent->playerPath); - } - else if (_wcsicmp(bang, L"ClosePlayer") == 0 || - (player->IsInitialized() && _wcsicmp(bang, L"TogglePlayer") == 0)) + else if (_wcsicmp(bang, L"OpenPlayer") == 0 || _wcsicmp(bang, L"TogglePlayer") == 0) { player->ClosePlayer(); } diff --git a/Plugins/PluginNowPlaying/PlayerCAD.cpp b/Plugins/PluginNowPlaying/PlayerCAD.cpp index bda83ab6..c23f4262 100644 --- a/Plugins/PluginNowPlaying/PlayerCAD.cpp +++ b/Plugins/PluginNowPlaying/PlayerCAD.cpp @@ -293,7 +293,8 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data.erase(0, ++len); len = data.find_first_of(L'\t'); - player->m_Duration = _wtoi(data.substr(0, len).c_str()); + std::wstring tmpStr(data, 0, len); + player->m_Duration = _wtoi(tmpStr.c_str()); data.erase(0, ++len); len = data.find_first_of(L'\t'); @@ -301,7 +302,8 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data.erase(0, ++len); len = data.find_first_of(L'\t'); - UINT rating = (_wtoi(data.substr(0, len).c_str()) + 1) / 2; // From 0 - 10 to 0 - 5 + tmpStr.assign(data, 0, len); + UINT rating = (_wtoi(tmpStr.c_str()) + 1) / 2; // From 0 - 10 to 0 - 5 player->m_Rating = rating; data.erase(0, ++len); @@ -322,11 +324,11 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM data.erase(0, 2); // Get rid of the 1\t at the beginning std::wstring::size_type len = data.find_first_of(L'\t'); - std::wstring className = data.substr(0, len); + std::wstring className(data, 0, len); data.erase(0, ++len); len = data.find_first_of(L'\t'); - std::wstring windowName = data.substr(0, len); + std::wstring windowName(data, 0, len); data.erase(0, ++len); len = data.find_first_of(L'\t'); diff --git a/Plugins/PluginNowPlaying/PlayerSpotify.cpp b/Plugins/PluginNowPlaying/PlayerSpotify.cpp index c33763c3..19efe895 100644 --- a/Plugins/PluginNowPlaying/PlayerSpotify.cpp +++ b/Plugins/PluginNowPlaying/PlayerSpotify.cpp @@ -99,18 +99,18 @@ void CPlayerSpotify::UpdateData() WCHAR buffer[256]; if (GetWindowText(m_Window, buffer, 256) > 10) { - std::wstring title = buffer; - title.erase(0, 10); // Get rid of "Spotify - " + std::wstring title = &buffer[10]; // Skip "Spotify - " std::wstring::size_type pos = title.find(L" – "); if (pos != std::wstring::npos) { - m_State = PLAYER_PLAYING; - std::wstring artist = title.substr(0, pos); - std::wstring track = title.substr(pos + 3); + std::wstring artist(title, 0, pos); + pos += 3; // Skip " - " + std::wstring track(title, pos); - if (track != m_Title && artist != m_Artist) + if (track != m_Title || artist != m_Artist) { + m_State = PLAYER_PLAYING; m_Title = track; m_Artist = artist; ++m_TrackCount; diff --git a/Plugins/PluginNowPlaying/PlayerWLM.cpp b/Plugins/PluginNowPlaying/PlayerWLM.cpp index 3a870421..592091c6 100644 --- a/Plugins/PluginNowPlaying/PlayerWLM.cpp +++ b/Plugins/PluginNowPlaying/PlayerWLM.cpp @@ -127,17 +127,17 @@ LRESULT CALLBACK CPlayerWLM::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM data.erase(0, len); // Get rid of the format len = data.find_first_of(L'\\'); - player->m_Title = data.substr(0, len); + player->m_Title.assign(data, 0, len); len += 2; data.erase(0, len); len = data.find_first_of(L'\\'); - player->m_Artist = data.substr(0, len); + player->m_Artist.assign(data, 0, len); len += 2; data.erase(0, len); len = data.find_first_of(L'\\'); - player->m_Album = data.substr(0, len); + player->m_Album.assign(data, 0, len); if (player->m_HasLyricsMeasure) { diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index d4cd5e41..528726fb 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -209,9 +209,9 @@ void CPlayerWinamp::UpdateData() pos = title.find(L" - "); if (pos != std::wstring::npos) { - m_Title = title.substr(0, pos); - pos += 3; // Skip " - " - m_Artist = title.substr(pos); + m_Title.assign(title, 0, pos); + pos += 3; // Skip " - " + m_Artist.assign(title, pos, title.length() - pos); m_Album.clear(); } else