CMap<double,double,CString,LPCTSTR> lrcShow;
double key_time; //时间转换成以秒为单位,并将时间格式[00:00:00]歌词放于lrcShow映射中
CString strTemp,strtag,strFileName;
CFileDialog fileDlg(true);
fileDlg.m_ofn.lpstrFilter=L"Lrc Files(*.lrc)/0*.lrc/0 /
Mp3 Files(*.mp3)/0*.mp3/0"
L"Audio File(*.rmvb,*asf)/0*.rmvb,*.asf/0"
L"All Files(*.*)/0*.*/0/0";
if(IDOK==fileDlg.DoModal())
strFileName=fileDlg.GetFileName();
CStdioFile lrcFile;
CString strName=strFileName.Left(strFileName.GetLength()-4)+L".txt",strTitle,strAuthor; //歌曲名,歌手
CFile storeFile;
storeFile.Open(strName,CFile::modeCreate|CFile::modeWrite|CFile::modeRead);
CArchive ar(&storeFile,CArchive::store);
if(!lrcFile.Open(strFileName,CFile::modeRead|CFile::typeText)) //打开文件
return ;
while(lrcFile.ReadString(strLine)) //读一行
{
int length=strLine.GetLength(); //汉字解析
wchar_t *p=strLine.GetBuffer();
char *pp=new char[length+1];
for(int i=0;i<=length;++i)
pp[i]=(char)*(p+i);
strTemp=CString(pp);
// storeFile.Write(strTemp,strTemp.GetLength()); //写入到文件
// MessageBox(strTemp);
if(strTemp[1]>='0' && strTemp[1]<='5'strTemp[2]>='0' && strTemp[2]<='9'){ //判断[00:00:00]格式
CString strlrc=strTemp.Mid(strTemp.ReverseFind(L']')+1,strTemp.GetLength()); //获取一行最后的歌词[][]歌词
while((strTemp.Find(L"[")==0)&&(strTemp.Find(L"]")!=-1) && (strTemp.Find(L":")!=-1))
{//[00:00:00][00:00:00]
strtag=strTemp.Mid(strTemp.Find(L"[")+1,strTemp.Find(L"]")-1);
// MessageBox(strtag);
strTemp=strTemp.Mid(strTemp.Find(L"]")+1,strTemp.GetLength());
if(strTemp[0]=='['){
key_time=WcharToTime(strtag);
lrcShow.SetAt(key_time,strlrc); //调用转换函数,插入到map中
}else{
if(strTemp.ReverseFind(L'[')!=-1){ //[00:00:00]lrc[00:00:00]lrc格式
CString strlrc1=strTemp.Mid(0,strTemp.Find(L'['));
// MessageBox(strlrc1);
lrcShow.SetAt(WcharToTime(strtag),strlrc1);
strTemp=strTemp.Mid(strTemp.Find(L"["),strTemp.GetLength());
}
}
}
}else if(strTemp[1]==L't' && strTemp[2]==L'i'){
strTitle=strTemp.Right(strTemp.GetLength()-4); //音乐名
strTitle=strTitle.Left(strTitle.GetLength()-1);
}else if(strTemp[1]==L'a' && strTemp[2]==L'r'){
strAuthor=strTemp.Right(strTemp.GetLength()-4); //艺术家
strAuthor=strAuthor.Left(strAuthor.GetLength()-1);
}
}
lrcShow.SetAt(0,strTitle+strAuthor);
CMap<double,double,CString,LPCTSTR> mapLrc;
POSITION nPos=lrcShow.GetStartPosition();
size_t total=lrcShow.GetCount();
double *arrayTmp=new double[total];
int i=0;
while(nPos!=NULL){
lrcShow.GetNextAssoc(nPos,key_time,strTemp);
arrayTmp[i++]=key_time;
}
sort(arrayTmp,total);
for(unsigned int i=0;i<total;++i)
{
CString str;
nPos=lrcShow.GetStartPosition();
lrcShow.Lookup(arrayTmp[i],str);
mapLrc.SetAt(arrayTmp[i],str);
}
mapLrc.Serialize(ar); //序列化
ar.Close();
storeFile.Close();
lrcFile.Close();
delete arrayTmp;