- NowPlaying.dll/iTunesPlugin.dll: Fixed incompatibility with iTunes controllers

- NowPlaying.dll: Removed support for caching cover art
This commit is contained in:
Birunthan Mohanathas 2011-11-05 17:52:53 +00:00
parent 2a166b520f
commit c8e4608b41
11 changed files with 109 additions and 156 deletions

View File

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

View File

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

View File

@ -30,7 +30,6 @@
#include "PlayerWMP.h"
static std::map<UINT, ChildMeasure*> 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();
}
}

View File

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

View File

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

View File

@ -34,6 +34,7 @@ enum PLAYSTATE
enum MEASURETYPE
{
MEASURE_NONE = 0x00000000,
MEASURE_ARTIST = 0x00000001,
MEASURE_TITLE = 0x00000002,
MEASURE_ALBUM = 0x00000004,
@ -66,7 +67,6 @@ 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;

View File

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

View File

@ -373,8 +373,6 @@ void CPlayerWMP::Uninitialize()
*/
void CPlayerWMP::UpdateData()
{
static bool clear = false;
if (m_Initialized)
{
// Get the volume

View File

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

View File

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

View File

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