Esempio n. 1
0
int CAPETag::GetFieldString(const str_utf16 * pFieldName, str_utf16 * pBuffer, int * pBufferCharacters)
{
    if (m_bAnalyzed == FALSE) { Analyze(); }

    int nRetVal = ERROR_UNDEFINED;

    if (*pBufferCharacters > 0)
    {
        CAPETagField * pAPETagField = GetTagField(pFieldName);
        if (pAPETagField == NULL)
        {
            // the field doesn't exist -- return an empty string
            memset(pBuffer, 0, *pBufferCharacters * sizeof(str_utf16));
            *pBufferCharacters = 0;
        }
        else if (pAPETagField->GetIsUTF8Text() || (m_nAPETagVersion < 2000))
        {
            // get the value in UTF-16 format
            CSmartPtr<str_utf16> spUTF16;
            if (m_nAPETagVersion >= 2000)
                spUTF16.Assign(GetUTF16FromUTF8((str_utf8 *) pAPETagField->GetFieldValue()), TRUE);
            else
                spUTF16.Assign(GetUTF16FromANSI(pAPETagField->GetFieldValue()), TRUE);

            // get the number of characters
            int nCharacters = (wcslen(spUTF16) + 1);
            if (nCharacters > *pBufferCharacters)
            {
                // we'll fail here, because it's not clear what would get returned (null termination, size, etc.)
                // and we really don't want to cause buffer overruns on the client side
                *pBufferCharacters = nCharacters;
            }
            else
            {
                // just copy in
                *pBufferCharacters = nCharacters;
                memcpy(pBuffer, spUTF16.GetPtr(), *pBufferCharacters * sizeof(str_utf16));
                nRetVal = ERROR_SUCCESS;
            }
        }
        else
        {
            // memset the whole buffer to NULL (so everything left over is NULL terminated)
            memset(pBuffer, 0, *pBufferCharacters * sizeof(str_utf16));

            // do a binary dump (need to convert from wchar's to bytes)
            int nBufferBytes = (*pBufferCharacters - 1) * sizeof(str_utf16);
            nRetVal = GetFieldBinary(pFieldName, pBuffer, &nBufferBytes);
            *pBufferCharacters = (nBufferBytes / sizeof(str_utf16)) + 1;
        }
    }

    return nRetVal;
}
Esempio n. 2
0
bool CMyAPEInfo::GetFieldAsUtf8(wchar_t *pFieldName,CAPETag &tag, CSongMetaData::StringData &s)
{
	CAPETagField * pAPETagField = tag.GetTagField(pFieldName);
	if (pAPETagField == NULL)
	{
		return false;
	}
	else if (pAPETagField->GetIsUTF8Text() || (tag.GetAPETagVersion() < 2000))
	{
		if (tag.GetAPETagVersion() >= 2000)
			s = pAPETagField->GetFieldValue();
		else
			s = ConvFromISO8859_1ToUTF8(pAPETagField->GetFieldValue());

	}
	else
	{
		wxASSERT(false);
		return false;
	}
	return true;
}
Esempio n. 3
0
HRESULT ApeDecoder::Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags )
{
	//char ex[2048] = "ape";
	//if(!isFile_ex(strFileName,ex))
	//{
	//	return M_FILE_EXTENSION_NOT_EXPECTED;//E_FAIL;
	//}
	if(WAVEFILE_READ != dwFlags)
	{
		return M_INVALID_PARAMETERS;//E_FAIL;
	}
	int nRetVal = 0;
	m_pAPEDecompress = CreateIAPEDecompress(strFileName,&nRetVal);
	if(NULL == m_pAPEDecompress)
	{
		return M_APE_FAIL_CREATE_DECODER;//E_FAIL;
	}
	m_block_algin = m_pAPEDecompress->GetInfo(APE_INFO_BLOCK_ALIGN);
	m_nWaveDataAllocSize = APE_BLOCKS_NUM * m_block_algin;
	m_pWaveDataAlloc = (BYTE*) malloc(m_nWaveDataAllocSize);
	m_pWaveDataBuffer = m_pWaveDataAlloc;
	m_total_blocks = m_pAPEDecompress->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS);
	m_id3.bitrate = m_pAPEDecompress->GetInfo(APE_DECOMPRESS_AVERAGE_BITRATE);
	// get and set wave header
	nRetVal = m_pAPEDecompress->GetInfo(APE_INFO_WAVEFORMATEX,(int) m_pwfx,0);
	if(0 != nRetVal)
	{
		return M_APE_FAIL_GET_WAVE_INFO;//E_FAIL;
	}
	m_dwSize = m_pAPEDecompress->GetInfo(APE_INFO_WAV_DATA_BYTES);
	if(m_dwSize <= 0)
	{
		return M_APE_FAIL_GET_INFO;//E_FAIL;
	}
	m_id3.duration_times = (float)m_dwSize / (float)m_pwfx->nAvgBytesPerSec; 

	m_id3.EmptyTags();
	CAPETag * pAPETag = (CAPETag *) m_pAPEDecompress->GetInfo(APE_INFO_TAG);
	BOOL bHasID3Tag = pAPETag->GetHasID3Tag();
	BOOL bHasAPETag = pAPETag->GetHasAPETag();

	if (bHasID3Tag || bHasAPETag)
	{
		// iterate through all the tag fields
		
		CAPETagField * pTagField = pAPETag->GetTagField(APE_TAG_FIELD_TITLE);
		if(pTagField)
		{
			/*printf("%X\n",pTagField->GetFieldValue()[0]);
			printf("%X\n",pTagField->GetFieldValue()[1]);
			printf("%X\n",pTagField->GetFieldValue()[2]);*/
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.title.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.title.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_ARTIST);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.artist.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.artist.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_ALBUM);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.album.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.album.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_YEAR);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.year.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.year.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_COMMENT);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.comment.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.comment.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_GENRE);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.genre.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.genre.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}

		
	}
	return S_OK;
}