From c8e4608b419513a1b08f4ec24729539b18c6fcd4 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 5 Nov 2011 17:52:53 +0000 Subject: [PATCH] - NowPlaying.dll/iTunesPlugin.dll: Fixed incompatibility with iTunes controllers - NowPlaying.dll: Removed support for caching cover art --- Plugins/PluginNowPlaying/Cover.cpp | 2 +- Plugins/PluginNowPlaying/Cover.h | 2 +- Plugins/PluginNowPlaying/NowPlaying.cpp | 16 +--- Plugins/PluginNowPlaying/NowPlaying.h | 16 +++- Plugins/PluginNowPlaying/Player.cpp | 61 ++++-------- Plugins/PluginNowPlaying/Player.h | 5 +- Plugins/PluginNowPlaying/PlayerITunes.cpp | 55 +++++------ Plugins/PluginNowPlaying/PlayerWMP.cpp | 2 - Plugins/PluginNowPlaying/PlayerWinamp.cpp | 98 ++++++++++---------- Plugins/PluginNowPlaying/PluginNowPlaying.rc | 4 +- Plugins/PluginiTunes/iTunesPlugin.cpp | 4 +- 11 files changed, 109 insertions(+), 156 deletions(-) diff --git a/Plugins/PluginNowPlaying/Cover.cpp b/Plugins/PluginNowPlaying/Cover.cpp index e8adb8e4..b9b1fa83 100644 --- a/Plugins/PluginNowPlaying/Cover.cpp +++ b/Plugins/PluginNowPlaying/Cover.cpp @@ -70,7 +70,7 @@ bool CCover::GetLocal(std::wstring filename, const std::wstring& folder, std::ws ** Attempts to extract cover art from audio files. ** */ -bool CCover::GetEmbedded(const TagLib::FileRef& fr, std::wstring& target) +bool CCover::GetEmbedded(const TagLib::FileRef& fr, const std::wstring& target) { bool found = false; diff --git a/Plugins/PluginNowPlaying/Cover.h b/Plugins/PluginNowPlaying/Cover.h index 554d8a4c..10bd2a90 100644 --- a/Plugins/PluginNowPlaying/Cover.h +++ b/Plugins/PluginNowPlaying/Cover.h @@ -44,7 +44,7 @@ class CCover public: static bool GetCached(std::wstring& path); static bool GetLocal(std::wstring filename, const std::wstring& folder, std::wstring& target); - static bool GetEmbedded(const TagLib::FileRef& fr, std::wstring& target); + static bool GetEmbedded(const TagLib::FileRef& fr, const std::wstring& target); static std::wstring GetFileFolder(const std::wstring& file); private: diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index de814854..00ce8423 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -30,7 +30,6 @@ #include "PlayerWMP.h" static std::map g_Measures; -std::wstring g_CachePath; std::wstring g_SettingsFile; HINSTANCE g_Instance = NULL; @@ -42,15 +41,8 @@ HINSTANCE g_Instance = NULL; */ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { - if (g_Measures.empty()) + if (!g_Instance) { - // Get path to temporary folder (for cover art cache) - WCHAR buffer[MAX_PATH]; - GetTempPath(MAX_PATH, buffer); - wcscat(buffer, L"Rainmeter-Cache\\"); - CreateDirectory(buffer, NULL); - g_CachePath = buffer; - // Get path to Plugins.ini (usually %APPDATA%\Rainmeter\Plugins.ini) std::wstring str = PluginBridge(L"getconfig", iniFile); if (!str.empty()) @@ -59,10 +51,6 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) g_SettingsFile = PluginBridge(L"getvariable", str.c_str()); g_SettingsFile += L"Plugins.ini"; } - else - { - LSLog(LOG_ERROR, NULL, L"NowPlaying.dll: PluginBridge error"); - } g_Instance = instance; CInternet::Initialize(); @@ -168,7 +156,6 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } parent->id = id; - parent->childCount = 1; parent->player->AddInstance(); parent->playerPath = ReadConfigString(section, L"PlayerPath", L""); parent->trackChangeAction = ReadConfigString(section, L"TrackChangeAction", L""); @@ -300,6 +287,7 @@ void Finalize(HMODULE instance, UINT id) if (g_Measures.empty()) { + g_Instance = NULL; CInternet::Finalize(); } } diff --git a/Plugins/PluginNowPlaying/NowPlaying.h b/Plugins/PluginNowPlaying/NowPlaying.h index b3576504..0e7d198e 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.h +++ b/Plugins/PluginNowPlaying/NowPlaying.h @@ -23,6 +23,13 @@ struct ParentMeasure { + ParentMeasure() : + player(NULL), + childCount(1), + trackCount(0), + disableLeadingZero(false) + {} + UINT id; UINT childCount; UINT trackCount; @@ -33,16 +40,17 @@ struct ParentMeasure std::wstring trackChangeAction; std::wstring playerPath; bool disableLeadingZero; - - ParentMeasure() : player(NULL) {} }; struct ChildMeasure { + ChildMeasure() : + type(MEASURE_NONE), + parent(NULL) + {} + MEASURETYPE type; ParentMeasure* parent; - - ChildMeasure() : parent(NULL) {} }; void SecondsToTime(UINT seconds, bool leadingZero, WCHAR* buffer); diff --git a/Plugins/PluginNowPlaying/Player.cpp b/Plugins/PluginNowPlaying/Player.cpp index b38aa322..67bffef7 100644 --- a/Plugins/PluginNowPlaying/Player.cpp +++ b/Plugins/PluginNowPlaying/Player.cpp @@ -19,8 +19,6 @@ #include "StdAfx.h" #include "Player.h" -extern std::wstring g_CachePath; - /* ** CPlayer ** @@ -42,6 +40,11 @@ CPlayer::CPlayer() : m_Volume(), m_InternetThread() { + // Get temporary file for cover art + WCHAR buffer[MAX_PATH]; + GetTempPath(MAX_PATH, buffer); + GetTempFileName(buffer, L"cvr", 0, buffer); + m_TempCoverPath = buffer; } /* @@ -111,35 +114,6 @@ void CPlayer::UpdateMeasure() } } -/* -** GetCacheFile -** -** Creates escaped path to cache file (without extension) -** -*/ -std::wstring CPlayer::GetCacheFile() -{ - std::wstring path = g_CachePath; - - if (m_Artist.empty() || m_Title.empty()) - { - path += L"temp"; - } - else - { - std::wstring name = m_Artist + L" - "; - name += m_Title; - - // Replace reserved chars with _ - std::wstring::size_type pos = 0; - while ((pos = name.find_first_of(L"\\/:*?\"<>|", pos)) != std::wstring::npos) name[pos] = L'_'; - - path += name; - } - - return path; -} - /* ** FindCover ** @@ -148,21 +122,20 @@ std::wstring CPlayer::GetCacheFile() */ void CPlayer::FindCover() { - m_CoverPath = GetCacheFile(); - - if (!CCover::GetCached(m_CoverPath)) + TagLib::FileRef fr(m_FilePath.c_str()); + if (!fr.isNull() && CCover::GetEmbedded(fr, m_TempCoverPath)) { - TagLib::FileRef fr(m_FilePath.c_str()); - if (fr.isNull() || !CCover::GetEmbedded(fr, m_CoverPath)) - { - std::wstring trackFolder = CCover::GetFileFolder(m_FilePath); + m_CoverPath = m_TempCoverPath; + } + else + { + std::wstring trackFolder = CCover::GetFileFolder(m_FilePath); - if (!CCover::GetLocal(L"cover", trackFolder, m_CoverPath) && - !CCover::GetLocal(L"folder", trackFolder, m_CoverPath)) - { - // Nothing found - m_CoverPath.clear(); - } + if (!CCover::GetLocal(L"cover", trackFolder, m_CoverPath) && + !CCover::GetLocal(L"folder", trackFolder, m_CoverPath)) + { + // Nothing found + m_CoverPath.clear(); } } } diff --git a/Plugins/PluginNowPlaying/Player.h b/Plugins/PluginNowPlaying/Player.h index 9106ecba..2d91cd84 100644 --- a/Plugins/PluginNowPlaying/Player.h +++ b/Plugins/PluginNowPlaying/Player.h @@ -34,6 +34,7 @@ enum PLAYSTATE enum MEASURETYPE { + MEASURE_NONE = 0x00000000, MEASURE_ARTIST = 0x00000001, MEASURE_TITLE = 0x00000002, MEASURE_ALBUM = 0x00000004, @@ -65,8 +66,7 @@ public: bool IsInitialized() { return m_Initialized; } UINT GetTrackCount() { return m_TrackCount; } - - std::wstring GetCacheFile(); + void FindCover(); void FindLyrics(); @@ -104,6 +104,7 @@ protected: UINT m_InstanceCount; UINT m_UpdateCount; UINT m_TrackCount; + std::wstring m_TempCoverPath; INT m_Measures; PLAYSTATE m_State; diff --git a/Plugins/PluginNowPlaying/PlayerITunes.cpp b/Plugins/PluginNowPlaying/PlayerITunes.cpp index 8db523f3..db9f4a18 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.cpp +++ b/Plugins/PluginNowPlaying/PlayerITunes.cpp @@ -287,7 +287,7 @@ LRESULT CALLBACK CPlayerITunes::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR case WM_TIMER: if (wParam == TIMER_CHECKACTIVE) { - if (!FindWindow(L"iTunes", L"iTunes")) + if (!FindWindow(L"iTunesApp", L"iTunes") && !FindWindow(L"iTunes", L"iTunes")) { player->m_iTunesActive = false; KillTimer(hwnd, TIMER_CHECKACTIVE); @@ -313,8 +313,7 @@ bool CPlayerITunes::CheckWindow() { m_LastCheckTime = time; - HWND wnd = FindWindow(L"ITWindow", L"iTunes"); - if (wnd && !m_iTunesActive) + if ((FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes")) && !m_iTunesActive) { m_iTunesActive = true; Initialize(); @@ -387,46 +386,36 @@ void CPlayerITunes::OnTrackChange() if (m_Measures & MEASURE_COVER) { - m_CoverPath = GetCacheFile(); - if (!CCover::GetCached(m_CoverPath)) + m_CoverPath.clear(); + + // Check for embedded art through iTunes interface + IITArtworkCollection* artworkCollection; + hr = track->get_Artwork(&artworkCollection); + + if (SUCCEEDED(hr)) { - // Art not in cache, check for embedded art through iTunes interface - IITArtworkCollection* artworkCollection; - hr = track->get_Artwork(&artworkCollection); + long count; + artworkCollection->get_Count(&count); - if (SUCCEEDED(hr)) + if (count > 0) { - long count; - artworkCollection->get_Count(&count); + IITArtwork* artwork; + hr = artworkCollection->get_Item(1, &artwork); - if (count > 0) + if (SUCCEEDED(hr)) { - IITArtwork* artwork; - hr = artworkCollection->get_Item(1, &artwork); - + tmpStr = m_TempCoverPath.c_str(); + hr = artwork->SaveArtworkToFile(tmpStr); if (SUCCEEDED(hr)) { - tmpStr = m_CoverPath.c_str(); - hr = artwork->SaveArtworkToFile(tmpStr); - if (FAILED(hr)) - { - m_CoverPath.clear(); - } - - artwork->Release(); + m_CoverPath = m_TempCoverPath; } - } - else - { - m_CoverPath.clear(); - } - artworkCollection->Release(); - } - else - { - m_CoverPath.clear(); + artwork->Release(); + } } + + artworkCollection->Release(); } } diff --git a/Plugins/PluginNowPlaying/PlayerWMP.cpp b/Plugins/PluginNowPlaying/PlayerWMP.cpp index d411c399..5c8aa28b 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerWMP.cpp @@ -373,8 +373,6 @@ void CPlayerWMP::Uninitialize() */ void CPlayerWMP::UpdateData() { - static bool clear = false; - if (m_Initialized) { // Get the volume diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index a8daecbe..b9c77220 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -33,6 +33,7 @@ CPlayer* CPlayerWinamp::c_Player = NULL; */ CPlayerWinamp::CPlayerWinamp(WINAMPTYPE type) : CPlayer(), m_Window(), + m_LastCheckTime(0), m_UseUnicodeAPI(false), m_PlayingStream(false), m_WinampType(type), @@ -123,7 +124,7 @@ void CPlayerWinamp::UpdateData() if (m_WinampHandle) CloseHandle(m_WinampHandle); } - if (!m_FilePath.empty()) + if (m_State != PLAYER_STOPPED) { ClearData(); } @@ -198,67 +199,66 @@ void CPlayerWinamp::UpdateData() // Find cover if needed if (m_Measures & MEASURE_COVER) { - m_CoverPath = GetCacheFile(); - if (!CCover::GetCached(m_CoverPath) && - (tag && !CCover::GetEmbedded(fr, m_CoverPath))) + if (tag && CCover::GetEmbedded(fr, m_TempCoverPath)) { - std::wstring trackFolder = CCover::GetFileFolder(m_FilePath); + // Got everything, return + m_CoverPath = m_TempCoverPath; + return; + } - if (!m_Album.empty()) + std::wstring trackFolder = CCover::GetFileFolder(m_FilePath); + if (!m_Album.empty()) + { + // Winamp stores covers usually as %album%.jpg + std::wstring file = m_Album; + std::wstring::size_type end = file.length(); + for (std::wstring::size_type pos = 0; pos < end; ++pos) { - // Winamp stores covers usually as %album%.jpg - std::wstring file = m_Album; - std::wstring::size_type end = file.length(); - for (std::wstring::size_type pos = 0; pos < end; ++pos) + // Replace reserved chars according to Winamp specs + switch (file[pos]) { - // Replace reserved chars according to Winamp specs - switch (file[pos]) - { - case L'?': - case L'*': - case L'|': - file[pos] = L'_'; - break; + case L'?': + case L'*': + case L'|': + file[pos] = L'_'; + break; - case L'/': - case L'\\': - case L':': - file[pos] = L'-'; - break; + case L'/': + case L'\\': + case L':': + file[pos] = L'-'; + break; - case L'\"': - file[pos] = L'\''; - break; + case L'\"': + file[pos] = L'\''; + break; - case L'<': - file[pos] = L'('; - break; + case L'<': + file[pos] = L'('; + break; - case L'>': - file[pos] = L')'; - break; - } - } - - if (CCover::GetLocal(file, trackFolder, m_CoverPath)) - { - // %album% art file found - return; + case L'>': + file[pos] = L')'; + break; } } - if (!CCover::GetLocal(L"cover", trackFolder, m_CoverPath) && - !CCover::GetLocal(L"folder", trackFolder, m_CoverPath)) + if (CCover::GetLocal(file, trackFolder, m_CoverPath)) { - // Nothing found - m_CoverPath.clear(); + // %album% art file found + return; } } - } - if (tag) + if (!CCover::GetLocal(L"cover", trackFolder, m_CoverPath) && + !CCover::GetLocal(L"folder", trackFolder, m_CoverPath)) + { + // Nothing found + m_CoverPath.clear(); + } + } + else if (tag) { - // Got metadata, return return; } } @@ -266,11 +266,7 @@ void CPlayerWinamp::UpdateData() { m_Rating = 0; m_Duration = 0; - - if (m_Measures & MEASURE_COVER) - { - m_CoverPath.clear(); - } + m_CoverPath.clear(); } } else if (!m_PlayingStream) diff --git a/Plugins/PluginNowPlaying/PluginNowPlaying.rc b/Plugins/PluginNowPlaying/PluginNowPlaying.rc index 89f749a1..f14bf88d 100644 --- a/Plugins/PluginNowPlaying/PluginNowPlaying.rc +++ b/Plugins/PluginNowPlaying/PluginNowPlaying.rc @@ -12,7 +12,7 @@ // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,3,5 + FILEVERSION 1,1,3,6 PRODUCTVERSION PRODUCTVER FILEFLAGSMASK 0x17L #ifdef _DEBUG @@ -29,7 +29,7 @@ BEGIN BLOCK "040904E4" BEGIN VALUE "FileDescription", "NowPlaying Plugin for Rainmeter" - VALUE "FileVersion", "1.1.3.5" + VALUE "FileVersion", "1.1.3.6" VALUE "InternalName", "NowPlaying" VALUE "LegalCopyright", "Copyright (C) 2011 - Birunthan Mohanathas" VALUE "OriginalFilename", "NowPlaying.dll" diff --git a/Plugins/PluginiTunes/iTunesPlugin.cpp b/Plugins/PluginiTunes/iTunesPlugin.cpp index 498d7931..b5a305d9 100644 --- a/Plugins/PluginiTunes/iTunesPlugin.cpp +++ b/Plugins/PluginiTunes/iTunesPlugin.cpp @@ -450,7 +450,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) CoInitialized = true; } - if (CoInitialized && !InstanceCreated && ::FindWindow(L"ITWindow", L"iTunes")) + if (CoInitialized && !InstanceCreated && (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes"))) { if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) { @@ -490,7 +490,7 @@ UINT Update(UINT id) if (!CoInitialized || !InstanceCreated) { // Check if the iTunes window has appeared - if (::FindWindow(L"ITWindow", L"iTunes")) + if (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes")) { if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) {