Skip to content

Commit

Permalink
Merge pull request #25 from BensonLaur/optimizing-ncm-id
Browse files Browse the repository at this point in the history
优化启动、优化NCM文件ID匹配操作
  • Loading branch information
BensonLaur authored May 27, 2018
2 parents 5f35a9e + a210a64 commit a7f5b5a
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 140 deletions.
Binary file modified BesLyric/BesLyric.aps
Binary file not shown.
Binary file modified BesLyric/BesLyric.rc
Binary file not shown.
2 changes: 2 additions & 0 deletions BesLyric/BesLyric.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<ClCompile Include="entity\AutoUpdateThread.cpp" />
<ClCompile Include="entity\CheckIntegrityThread.cpp" />
<ClCompile Include="entity\GuessLyricInfoThread.cpp" />
<ClCompile Include="entity\LoadAndCheckNcmIDThread.cpp" />
<ClCompile Include="entity\LrcHandler.cpp" />
<ClCompile Include="entity\LyricMaker.cpp" />
<ClCompile Include="entity\LyricPlayer.cpp" />
Expand Down Expand Up @@ -184,6 +185,7 @@
<ClInclude Include="entity\FileDroper.h" />
<ClInclude Include="entity\GuessLyricInfoThread.h" />
<ClInclude Include="entity\ISearcher.h" />
<ClInclude Include="entity\LoadAndCheckNcmIDThread.h" />
<ClInclude Include="entity\LrcHandler.h" />
<ClInclude Include="entity\LyricMaker.h" />
<ClInclude Include="entity\LyricPlayer.h" />
Expand Down
6 changes: 6 additions & 0 deletions BesLyric/BesLyric.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
<ClCompile Include="lib\md5\md5.cpp">
<Filter>Header Files\lib\md5</Filter>
</ClCompile>
<ClCompile Include="entity\LoadAndCheckNcmIDThread.cpp">
<Filter>Source Files\entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BesLyric.rc">
Expand Down Expand Up @@ -374,6 +377,9 @@
<ClInclude Include="lib\md5\md5.h">
<Filter>Header Files\lib\md5</Filter>
</ClInclude>
<ClInclude Include="entity\LoadAndCheckNcmIDThread.h">
<Filter>Header Files\entity</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="uires\uires.idx">
Expand Down
2 changes: 1 addition & 1 deletion BesLyric/Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct UpdateItem
Y表示次版本,较大修改时更新
Z表示修改号,小问题时更新
*/
static const wstring VERSION_NUMBER = L"2.2.3"; //版本号(注意每次更改版本号时需要更改2处,1处是这里,1处是 BesLyric.rc 中的Version)
static const wstring VERSION_NUMBER = L"2.2.4"; //版本号(注意每次更改版本号时需要更改2处,1处是这里,1处是 BesLyric.rc 中的Version)

// v 2.1.10 以及以前的版本使用的链接
static const wstring LINK_VERSION_LOG= L"http://files.cnblogs.com/files/BensonLaur/versionLog.zip"; //链接,指向版本日志文件
Expand Down
37 changes: 17 additions & 20 deletions BesLyric/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void CMainDlg::test()
//CDownloader::DownloadFile( L"http://music.163.com/song/media/outer/url?id=1111.mp3",
// L"C:\\Users\\BensonLaur\\Desktop\\NetEase\\test.mp3");

string md5;
CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\imgdecoder-gdip.dll", md5);
CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\render-gdi.dll", md5);
CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\soui.dll", md5);
CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\soui-sys-resource.dll", md5);
CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\utilities.dll", md5);
//string md5;
//CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\imgdecoder-gdip.dll", md5);
//CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\render-gdi.dll", md5);
//CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\soui.dll", md5);
//CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\soui-sys-resource.dll", md5);
//CCheckIntegrityThread::GetFileMd5(L"E:\\git\\BesLyric\\Debug\\utilities.dll", md5);

}

Expand All @@ -78,19 +78,6 @@ CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND"))
m_pageResult = NULL;
m_pageSearchLyric = NULL;
m_pageSearchNcmID = NULL;

//初始化etc文件并清理相关文件
initFloderAndFile();


//启动自动更新线程
AutoUpdateThread::getSingleton().Start();

//检测程序的完整性
CCheckIntegrityThread::getSingleton().Start(false);

//test
test();
}

CMainDlg::~CMainDlg()
Expand Down Expand Up @@ -134,7 +121,17 @@ BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
//初始化记录页面播放足迹,详看变量的说明
FootPrintPage = -1;

test();
//test();
//初始化页面之后再执行耗时的操作

//初始化etc文件并清理相关文件
initFloderAndFile();

//启动自动更新线程
AutoUpdateThread::getSingleton().Start();

//检测程序的完整性
CCheckIntegrityThread::getSingleton().Start(false);
return 0;
}

Expand Down
116 changes: 5 additions & 111 deletions BesLyric/PageSearchNcmID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
#include "entity\NcmIDManager.h"
#include "utility\Downloader.h"

#include "entity\LoadAndCheckNcmIDThread.h"

CPageSearchNcmID::CPageSearchNcmID()
{
if(!CNcmIDManager::GetInstance()->LoadDataPairs())
_MessageBox(NULL, L"加载ncm与id映射文件失败", L"提示", MB_OK|MB_ICONINFORMATION);

m_pMainWnd = NULL; /* 主窗口指针 */

m_window_search_ncm_id_tip = NULL;
Expand Down Expand Up @@ -72,6 +70,9 @@ void CPageSearchNcmID::Init(SHostWnd *pMainWnd)
pMcListView->SetAdapter(pAdapter);
pAdapter->Release();
}

//用线程加载和检测NCMID ,之所以使用线程,是因为该操作联网耗时
CLoadAndCheckNcmIDThread::getSingleton().Start();
}

//获得主窗口对象
Expand Down Expand Up @@ -137,7 +138,7 @@ void CPageSearchNcmID::OnBtnSelectID()
{
if(!bValid)
{
_MessageBox(M()->m_hWnd, L"当前填写ID为无效ID,匹配ID失败", L"提示", MB_OK|MB_ICONINFORMATION);
_MessageBox(M()->m_hWnd, L"当前填写ID为无效ID 或 其对应歌曲网易没有版权,匹配ID失败", L"提示", MB_OK|MB_ICONINFORMATION);
return;
}
}
Expand Down Expand Up @@ -233,113 +234,6 @@ void CPageSearchNcmID::ShowIDResult(IDSearchResult* pResult)

}

////选择原歌词保存路径
//void CPageSearchNcmID::OnBtnSelectOriginLyricPath(LPCWSTR pFilePath)
//{
// BOOL bRet = TRUE;
// LPCWSTR pPath = NULL;
//
// if(pFilePath == NULL)
// {
// SStringW pathBefore = m_editOriginLyricPath->GetWindowTextW();
// CBrowseDlg Browser;
// BOOL bRet = Browser.DoDirBrowse(::GetActiveWindow(),_T("选择 【原歌词】 保存路径"), TRUE, pathBefore);
//
// if(bRet == TRUE)
// pPath = Browser.GetDirPath();
// }
// else
// pPath = pFilePath;
//
// if(bRet == TRUE)
// {
// m_editOriginLyricPath->SetWindowTextW(pPath);
// }
//}
//
////选择Lrc歌词保存路径
//void CPageSearchNcmID::OnBtnSelectLrcLyricPath(LPCWSTR pFilePath)
//{
// BOOL bRet = TRUE;
// LPCWSTR pPath = NULL;
//
// if(pFilePath == NULL)
// {
// SStringW pathBefore = m_editLrcLyricPath->GetWindowTextW();
// CBrowseDlg Browser;
// BOOL bRet = Browser.DoDirBrowse(::GetActiveWindow(),_T("选择 【LRC歌词】 保存路径"), TRUE, pathBefore);
//
// if(bRet == TRUE)
// pPath = Browser.GetDirPath();
// }
// else
// pPath = pFilePath;
//
// if(bRet == TRUE)
// {
// m_editLrcLyricPath->SetWindowTextW(pPath);
// }
//}
//
////保存原歌词
//void CPageSearchNcmID::OnBtnSaveOriginLyricPath()
//{
// SStringW strContent = CStringHelper::Trim(m_editOriginLyricContent->GetWindowTextW(),L" \t\r\n");
//
// if(strContent.GetLength() == 0)
// {
// _MessageBox(M()->m_hWnd, L"歌词内容为空,无法保存!", L"提示", MB_OK|MB_ICONINFORMATION);
// return;
// }
//
// SStringW strPath = m_editOriginLyricPath->GetWindowTextW();
// SStringW strSong = CStringHelper::Trim(m_editOriginLyricName->GetWindowTextW());
// SStringW strArtist = CStringHelper::Trim(m_editOriginLyricArtist->GetWindowTextW());
// SStringW strConnector = (strSong.GetLength()!=0 && strArtist.GetLength() != 0)? L"-":L"";
//
// CFileDialogEx saveDlg(FALSE, strArtist+ strConnector+ strSong ,strPath.GetBuffer(1),L"txt",L"原歌词文件(txt)\0*.txt;\0\0",OFN_OVERWRITEPROMPT, M()->m_hWnd);
// int ret = saveDlg.DoModal();
// if(ret == TRUE)
// {
// //将文本内容保存到文件中
// SStringW savePath = saveDlg.m_szFileName;
// if(FileOperator::WriteToUtf8File(wstring(savePath.GetBuffer(1)), wstring(strContent.GetBuffer(1))))
// _MessageBox(M()->m_hWnd, (L"原歌词已保存!\\n\\n保存路径:\\n"+savePath).GetBuffer(1), L"提示", MB_OK|MB_ICONINFORMATION);
// else
// _MessageBox(M()->m_hWnd, (L"保存操作失败!\\n\\n路径:\\n"+savePath).GetBuffer(1), L"提示", MB_OK|MB_ICONWARNING);
// }
//}
//
////保存Lrc歌词
//void CPageSearchNcmID::OnBtnSaveLrcLyricPath()
//{
// SStringW strContent = CStringHelper::Trim(m_editLrcLyricContent->GetWindowTextW(),L" \t\r\n");
//
// if(strContent.GetLength() == 0)
// {
// _MessageBox(M()->m_hWnd, L"歌词内容为空,无法保存!", L"提示", MB_OK|MB_ICONINFORMATION);
// return;
// }
//
// SStringW strPath = m_editLrcLyricPath->GetWindowTextW();
// SStringW strSong = CStringHelper::Trim(m_editLrcLyricName->GetWindowTextW());
// SStringW strArtist = CStringHelper::Trim(m_editLrcLyricArtist->GetWindowTextW());
// SStringW strConnector = (strSong.GetLength()!=0 && strArtist.GetLength() != 0)? L"-":L"";
//
// CFileDialogEx saveDlg(FALSE, strSong+ strConnector+ strArtist ,strPath.GetBuffer(1),L"lrc",L"LRC歌词文件(lrc)\0*.lrc;\0\0",OFN_OVERWRITEPROMPT, M()->m_hWnd);
// int ret = saveDlg.DoModal();
// if(ret == TRUE)
// {
// //将文本内容保存到文件中
// SStringW savePath = saveDlg.m_szFileName;
// if(FileOperator::WriteToUtf8File(wstring(savePath.GetBuffer(1)), wstring(strContent.GetBuffer(1))))
// _MessageBox(M()->m_hWnd, (L"LRC歌词已保存!\\n\\n保存路径:\\n"+savePath).GetBuffer(1), L"提示", MB_OK|MB_ICONINFORMATION);
// else
// _MessageBox(M()->m_hWnd, (L"保存操作失败!\\n\\n路径:\\n"+savePath).GetBuffer(1), L"提示", MB_OK|MB_ICONWARNING);
// }
//}
//

//根据猜测结果自动填充搜索关键词并开始搜索
void CPageSearchNcmID::OnSearchWithGuess(SongInfoGuessResult* pGuessRes)
{
Expand Down
28 changes: 28 additions & 0 deletions BesLyric/PageSearchNcmID.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,39 @@ class CSongIDMcAdapterFix : public SMcAdapterBase
pItem->FindChildByName(L"txt_mclv_music_artist")->SetWindowText(SStringW().Format(L"%s",pli->strMusicArtist.c_str()));
pItem->FindChildByName(L"txt_mclv_ncm_id")->SetWindowText(SStringW().Format(L"%s",pli->strSongID.c_str()));

SButton *pBtnView = pItem->FindChildByName2<SButton>(L"btn_mclv_view");
pBtnView->SetUserData(position);
SButton *pBtnListen = pItem->FindChildByName2<SButton>(L"btn_mclv_listen");
pBtnListen->SetUserData(position);
SButton *pBtnSelect = pItem->FindChildByName2<SButton>(L"btn_mclv_select");
pBtnSelect->SetUserData(position);

pBtnView->GetEventSet()->subscribeEvent(EVT_CMD,Subscriber(&CSongIDMcAdapterFix::OnButtonViewClick,this));
pBtnListen->GetEventSet()->subscribeEvent(EVT_CMD,Subscriber(&CSongIDMcAdapterFix::OnButtonListenClick,this));
pBtnSelect->GetEventSet()->subscribeEvent(EVT_CMD,Subscriber(&CSongIDMcAdapterFix::OnButtonSelectClick,this));

}

bool OnButtonViewClick(EventArgs *pEvt)
{
SButton *pBtn = sobj_cast<SButton>(pEvt->sender);
int iItem = pBtn->GetUserData();
SONG_ID_INFO *pli =m_IDInfo.GetData()+iItem;

wstring strLink = L"http://music.163.com/#/song?id=" + pli->strSongID;
ShellExecute(NULL,L"open",strLink.c_str() ,NULL, NULL,SW_SHOWNORMAL);
return true;
}

bool OnButtonListenClick(EventArgs *pEvt)
{
SButton *pBtn = sobj_cast<SButton>(pEvt->sender);
int iItem = pBtn->GetUserData();
SONG_ID_INFO *pli =m_IDInfo.GetData()+iItem;

ShellExecute(NULL,L"open",(L"http://music.163.com/song/media/outer/url?id=" + pli->strSongID).c_str() ,NULL, NULL,SW_SHOWNORMAL);
return true;
}

bool OnButtonSelectClick(EventArgs *pEvt)
{
Expand Down
12 changes: 8 additions & 4 deletions BesLyric/entity/CheckIntegrityThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ bool CCheckIntegrityThread::Start(bool bShowPassTip)
//启动检测线程
m_handleThreadCheking = ::CreateThread(NULL, 0, ProcChecking, this, 0 ,NULL);

::WaitForSingleObject(m_EventUpdateDownloadDone, INFINITE); //等待update 文件下载完毕,才弹出窗口

//启动UI线程
m_handleThreadUI = ::CreateThread(NULL, 0, ProcUI, this, 0 ,NULL);

return (m_handleThreadCheking != NULL && m_handleThreadUI!=NULL);
return (m_handleThreadCheking != NULL);
}


Expand Down Expand Up @@ -114,6 +113,10 @@ DWORD WINAPI CCheckIntegrityThread::ProcUI(LPVOID pParam)

dlg.SetEventHandleForWndHandle(pThread->m_EventWndInitDone, &pThread->m_hCheckWnd, pThread);


::WaitForSingleObject(pThread->m_EventUpdateDownloadDone, INFINITE); //等待update 文件下载完毕,才弹出窗口


int ret = dlg.DoModal(NULL);

return 0;
Expand Down Expand Up @@ -348,7 +351,8 @@ bool CCheckIntegrityThread::DownloadUpdateFileAndMark()
wstring strTempUpdate = m_wstrEtcFloder + L"tempDir\\update.xml" ;
if(!CDownloader::DownloadFile(LINK_UPDATE_ITEM_FILE, strTempUpdate))
{
_MessageBox(NULL, L"无法下载update.xml文件,检测更新失败", L"提示", MB_OK|MB_ICONWARNING);
//不提示失败,不然每次不联网启动都提示这一句
//_MessageBox(NULL, L"无法下载update.xml文件,检测更新失败", L"提示", MB_OK|MB_ICONWARNING);
return false;
}

Expand Down
23 changes: 23 additions & 0 deletions BesLyric/entity/LoadAndCheckNcmIDThread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "stdafx.h"
#include "LoadAndCheckNcmIDThread.h"
#include "NcmIDManager.h"

//开始线程
bool CLoadAndCheckNcmIDThread::Start()
{
//启动线程
m_handleThread = ::CreateThread(NULL, 0, ProcLoadAndCheckNcmID, this, 0 ,NULL);

return (m_handleThread != NULL);
}

//结束线程
void CLoadAndCheckNcmIDThread::Stop(){}

//检测(与下载) 线程执行地址
DWORD WINAPI CLoadAndCheckNcmIDThread::ProcLoadAndCheckNcmID(LPVOID pParam)
{
CNcmIDManager::GetInstance()->LoadAndCheckDataPairs();

return 0;
}
Loading

0 comments on commit a7f5b5a

Please sign in to comment.