⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlistmgr.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 3 页
字号:

    if (!bResult) return bResult;

    //
    // If necessary rename the playlist in the MRU list
    //

    for (int i = 0; i < MAX_PLAYLIST_HISTORY; i++)
    {
        if (m_pszMRUPlaylist[i]
            && 0 == _tcscmp(m_pszMRUPlaylist[i], szOldPath))
        {
            MRURename(i, pCurr->pPlaylist->GetPath());
            break;
        }
    }

	// if the old name was a duplicate, fix up the duplicate
	// name list appropriately
	pCurr->RemoveDupName();

	// if the new name is a dup, add it to the list
	list_t * pIter = m_pPlaylists;
	ASSERT(pIter);
	while (pIter)
	{
		if (0 == _tcscmp(pszName, pIter->pPlaylist->GetName())
			&& 0 != _tcscmp(pCurr->pPlaylist->GetPath(),
							pIter->pPlaylist->GetPath()))
		{
			break;
		}

		pIter = pIter->pNext;
	}

	if (pIter)
		pCurr->AddDupName(pIter);

    return bResult;
}

bool CPlaylistMgr::IsValid(CPlaylist * pPlaylist)
{
    list_t * pCurr = m_pPlaylists;

    while (pCurr && pCurr->pPlaylist != pPlaylist)
    {
        pCurr = pCurr->pNext;
    }

    return pCurr ? true : false;
}

// This method returns the portion of the playlist
// path that is unique to this playlist.  If this
// playlist's name is unique among all playlists,
// NULL is returned.
LPTSTR CPlaylistMgr::GetDisplayName(int iIndex)
{
	int iPos;
	list_t* pIter;

	for (pIter = m_pPlaylists, iPos = 0; 
		 pIter && iPos < iIndex;
		 pIter = pIter->pNext, iPos++);

	if (!pIter)
	{
		ASSERT(FALSE);
		return NULL;
	}

	return GetDisplayNameHelper(pIter);
}

LPTSTR CPlaylistMgr::GetDisplayName(CPlaylist * pList)
{
	list_t* pIter;

	for (pIter = m_pPlaylists; 
		 pIter && pIter->pPlaylist != pList;
		 pIter = pIter->pNext);

	if (!pIter)
	{
		ASSERT(FALSE);
		return NULL;
	}

	return GetDisplayNameHelper(pIter);
}

LPTSTR CPlaylistMgr::GetDisplayNameHelper(list_t * pList)
{
	LPCTSTR szPath = NULL;
	int iWhack = 0;

	while (pList->pDupNames)
	{
		// figure out how many dups there are
		UINT cDups = 1;
		duplist_t* pDup = pList->pDupNames;
		while (pDup->pNext)
		{
			cDups++;
			pDup = pDup->pNext;
		}

		// get pointers to all playlist paths
		LPCTSTR* pszPaths = new LPCTSTR[cDups];
		if (!pszPaths)
		{
			ASSERT(FALSE);
			break;
		}

		UINT i = 0;

		pDup = pList->pDupNames;
		while (pDup)
		{
			pszPaths[i] = pDup->pList->pPlaylist->GetPath();
			if (pDup->pList == pList)
				szPath = pszPaths[i];
			i++;
			pDup = pDup->pNext;
		}

		ASSERT(szPath);

		// find the unique part
		bool fFound = false;
		TCHAR chCur = 0, chNext = 0;
		for (UINT iOuter = 0; ; iOuter++)
		{
			for (i = 0; i < cDups; i++)
			{
				if (!i)
				{
					chCur = pszPaths[i][iOuter];
					ASSERT(chCur);	// hit end of string???
				}
				else
				{
					if (chCur != (chNext = pszPaths[i][iOuter]))
					{
						fFound = true;
						ASSERT(chNext);	// hit end of string???
						break;
					}

					if (TEXT('\\') == chCur)
						iWhack = iOuter;

					chCur = chNext;
				}
			}

			if (fFound) break;
		}

		delete [] pszPaths;
		break;
	}

	LPCTSTR szName = pList->pPlaylist->GetName();

	UINT cReturn = _tcslen(szName) + 1;
	if (_tcsrchr(szName, TEXT('\\')))
	{
		cReturn--;
		szName++;
	}

	if (szPath)
	{
		cReturn += 4;	// 4 = 2 spaces + surrounding parens
		cReturn += _tcslen(szPath + iWhack);
		if (iWhack > 0) cReturn++;	// prepended ellipsis
	}

	LPTSTR szReturn = new TCHAR[cReturn];
	if (!szReturn)
	{
		ASSERT(FALSE);
		return NULL;
	}

	szReturn[cReturn - 1] = 0;

	// add playlist name
	_tcscpy(szReturn, szName);
	
	// remove extension from name before continuing
	TCHAR *pchPeriod = _tcsrchr(szReturn, TEXT('.'));
	if (pchPeriod) *pchPeriod = 0;

	// add path
	if (szPath)
	{
		_tcscat(szReturn, TEXT("  ("));

		if (iWhack > 0)
			_tcscat(szReturn, TEXT("\x2026"));

		_tcscat(szReturn, szPath + iWhack);

		// remove name from end of path
		LPTSTR szLast = _tcsrchr(szReturn, TEXT('\\'));
		if (szLast)
		{
			// handle case where playlist is in root dir
			if (0 == _tcscmp(szLast, szPath)
				|| TEXT('\x2026') == *(szLast-1))
				szLast++;

			*szLast = 0;
		}

		_tcscat(szReturn, TEXT(")"));
	}

	ASSERT(0 == szReturn[cReturn - 1]);
	szReturn[cReturn - 1] = 0;

	return szReturn;
}

bool CPlaylistMgr::CreateUniqueName(LPTSTR pszName, int iLength)
{
    LPCTSTR pszBase = TEXT("Playlist");
    LPCTSTR pszExt  = TEXT("asx");
    int     i       = 2;
    bool    bResult = false;

    _sntprintf(pszName, iLength, TEXT("%s\\%s.%s"), s_szBasePath, pszBase, pszExt);
    pszName[ iLength - 1] = 0;

    if (0xffffffff == GetFileAttributes(pszName))
    {
        bResult = true;
    }

    while (!bResult)
    {
        _sntprintf(pszName, iLength, TEXT("%s\\%s #%d.%s"), s_szBasePath, pszBase, i, pszExt);
	pszName[ iLength - 1 ] = 0;

        if (0xffffffff == GetFileAttributes(pszName))
        {
            bResult = true;
        }

        i++;
    }

    return bResult;
}

CPlaylistMgr * CPlaylistMgr::GetInstance()
{
    // Create only one instance of the Playlist Manager
    if (NULL == ms_pManager)
    {
        ms_pManager = new CPlaylistMgr;
    }

    return ms_pManager;
}

int CPlaylistMgr::GetPlaylistCount()
{
	int iCount;
	list_t* pIter;

    if (!m_bLoadedLocalPlaylists)
        LoadLocalPlaylists();

	for (pIter = m_pPlaylists, iCount = 0;
		 pIter;
		 pIter = pIter->pNext, iCount++);

	return iCount;
}

void CPlaylistMgr::GetMediaShare(LPTSTR szShare)
{
    if (m_pszMediaShare)
    {
        _tcscpy(szShare, m_pszMediaShare);
    }
    else
    {
        szShare[0] = TEXT('\0');
    }
}

void CPlaylistMgr::SetMediaShare(LPTSTR szShare)
{
    if (m_pszMediaShare)
    {
        delete [] m_pszMediaShare;
    }

    if (m_pszMediaShare = new TCHAR [_tcslen(szShare) + 1])
    {
        _tcscpy(m_pszMediaShare, szShare);
    }

    SaveRegState();
}

CPlaylistMgr::CPlaylistMgr()
{
    int i;

    m_pPlaylists    = NULL;
    m_iCurrent      = -1;
    m_pszMediaShare = NULL;

    //
    // Find all playlists in local store
    //

//    LoadLocalPlaylists();
    m_bLoadedLocalPlaylists = false;

    //
    // Figure out what the current playlist is from the registry.
    // (default it to 0)
    //

    for (i = 0; i < MAX_PLAYLIST_HISTORY; i++)
    {
        m_pszMRUPlaylist[i] = NULL;
    }

    m_iCurrent = -1;

    LoadRegState();

    //
    // Add Local Content
    //
    if (m_pLocalContent = new CPlaylist(TEXT("Local Content")))
    {
        m_pLocalContent->IsTransient(true);
    }

    //
    // Add Favorites
    //
    if (m_pFavorites = new CPlaylist(TEXT("\\My Documents\\Favorites.asx")))
    {
        m_pFavorites->IsHidden(true);

        if (false == m_pFavorites->Load())
        {
            m_pFavorites->IsCEPlaylist(true);
        }
    }
}

CPlaylistMgr::~CPlaylistMgr()
{
   while (m_pPlaylists)
   {
        list_t * pList = m_pPlaylists->pNext;

        delete m_pPlaylists;

        m_pPlaylists = pList;
    }
}

void CPlaylistMgr::UpdateMRUPlaylists()
{
    int         i;
    CPlaylist * pPlaylist;
    LPCTSTR     pszPath = NULL;
    bool        bInHistory = false;

    pPlaylist = CurrentPlaylist();

    if (NULL == pPlaylist)
    {
        return;
    }

    pszPath = pPlaylist->GetPath();

    for (i = 0; i < MAX_PLAYLIST_HISTORY; i++)
    {
        if (m_pszMRUPlaylist[i] &&
            0 == _tcscmp(m_pszMRUPlaylist[i], pszPath))
        {
            bInHistory = true;
            break;
        }
    }

    if (!bInHistory)
    {
        if (m_pszMRUPlaylist[MAX_PLAYLIST_HISTORY - 1])
        {
            delete [] m_pszMRUPlaylist[MAX_PLAYLIST_HISTORY - 1];
        }

        for (i = MAX_PLAYLIST_HISTORY - 1; i > 0; i--)
        {
            m_pszMRUPlaylist[i] = m_pszMRUPlaylist[i-1];
        }

        if (m_pszMRUPlaylist[0] = new TCHAR [_tcslen(pszPath) + 1])
        {
            _tcscpy(m_pszMRUPlaylist[0], pszPath);
        }
    }

    SaveRegState();
}

void CPlaylistMgr::SaveRegState()
{
    HKEY        hkResult  = NULL;
    CPlaylist * pPlaylist = NULL;
    TCHAR     * pszPath   = NULL;
    TCHAR     * pszShare  = NULL;

    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                      TEXT("SOFTWARE\\Microsoft\\CEPlayer"),
                                      0, 0, &hkResult))
    {
        TCHAR szRegKey[REGKEY_SIZE];

        for (int i = 0; i < MAX_PLAYLIST_HISTORY; i++)
        {
            LPCTSTR pszStr = TEXT("");

            if (NULL != m_pszMRUPlaylist[i])
            {
                pszStr = m_pszMRUPlaylist[i];
            }

            LoadString(g_hInst, ID_PLAYLIST1_REGKEY + i, szRegKey, REGKEY_SIZE);
            RegSetValueEx(hkResult, szRegKey, 0, REG_SZ,
                          (BYTE*)pszStr,
                          (_tcslen(pszStr) + 1) * sizeof (TCHAR));
        }

        pPlaylist = CurrentPlaylist();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -