diff --git a/MusicPlayer2/Common.cpp b/MusicPlayer2/Common.cpp index d0da1593..247ea8eb 100644 --- a/MusicPlayer2/Common.cpp +++ b/MusicPlayer2/Common.cpp @@ -485,6 +485,36 @@ int CCommon::DeleteAFile(HWND hwnd, _tstring file) return SHFileOperation(&FileOp); //删除文件 } +int CCommon::CopyAFile(HWND hwnd, _tstring file_from, _tstring file_to) +{ + file_from.push_back(_T('\0')); //pFrom必须以两个\0结尾 + file_to.push_back(_T('\0')); //pTo必须以两个\0结尾 + SHFILEOPSTRUCT FileOp{}; + FileOp.hwnd = hwnd; + FileOp.wFunc = FO_COPY; + FileOp.pFrom = file_from.c_str(); + FileOp.pTo = file_to.c_str(); + FileOp.fFlags = FOF_ALLOWUNDO; + FileOp.hNameMappings = NULL; + FileOp.lpszProgressTitle = _T("复制"); + return SHFileOperation(&FileOp); +} + +int CCommon::MoveAFile(HWND hwnd, _tstring file_from, _tstring file_to) +{ + file_from.push_back(_T('\0')); //pFrom必须以两个\0结尾 + file_to.push_back(_T('\0')); //pTo必须以两个\0结尾 + SHFILEOPSTRUCT FileOp{}; + FileOp.hwnd = hwnd; + FileOp.wFunc = FO_MOVE; + FileOp.pFrom = file_from.c_str(); + FileOp.pTo = file_to.c_str(); + FileOp.fFlags = FOF_ALLOWUNDO; + FileOp.hNameMappings = NULL; + FileOp.lpszProgressTitle = _T("移动"); + return SHFileOperation(&FileOp); +} + bool CCommon::CopyStringToClipboard(const wstring & str) { if (OpenClipboard(NULL)) diff --git a/MusicPlayer2/Common.h b/MusicPlayer2/Common.h index d9f0f530..23f823b4 100644 --- a/MusicPlayer2/Common.h +++ b/MusicPlayer2/Common.h @@ -113,6 +113,12 @@ public: //删除一个文件 static int DeleteAFile(HWND hwnd, _tstring file); + //复制一个文件 + static int CopyAFile(HWND hwnd, _tstring file_from, _tstring file_to); + + //移动一个文件 + static int MoveAFile(HWND hwnd, _tstring file_from, _tstring file_to); + //将一个字符串保存到剪贴板 static bool CopyStringToClipboard(const wstring& str); diff --git a/MusicPlayer2/CoverDownloadDlg.cpp b/MusicPlayer2/CoverDownloadDlg.cpp index 1436fd26..ace921f4 100644 Binary files a/MusicPlayer2/CoverDownloadDlg.cpp and b/MusicPlayer2/CoverDownloadDlg.cpp differ diff --git a/MusicPlayer2/DataSettingsDlg.cpp b/MusicPlayer2/DataSettingsDlg.cpp index 3294c9f8..0e0c2313 100644 --- a/MusicPlayer2/DataSettingsDlg.cpp +++ b/MusicPlayer2/DataSettingsDlg.cpp @@ -75,7 +75,7 @@ void CDataSettingsDlg::ShowDataSizeInfo() { CString info; if (m_data_size < 1024) - info.Format(_T("当前数据文件大小:% 个字节"), m_data_size); + info.Format(_T("当前数据文件大小:%d 个字节"), m_data_size); else if (m_data_size < 1024 * 1024) info.Format(_T("当前数据文件大小:%.2f KB (%d 字节)"), static_cast(m_data_size) / 1024.0f, m_data_size); else diff --git a/MusicPlayer2/FindDlg.cpp b/MusicPlayer2/FindDlg.cpp index 953497f8..7c26a71a 100644 --- a/MusicPlayer2/FindDlg.cpp +++ b/MusicPlayer2/FindDlg.cpp @@ -45,7 +45,7 @@ void CFindDlg::ShowFindResult() m_find_result_list.SetItemText(i, 2, m_playlist[m_find_result[i]].title.c_str()); m_find_result_list.SetItemText(i, 3, m_playlist[m_find_result[i]].artist.c_str()); m_find_result_list.SetItemText(i, 4, m_playlist[m_find_result[i]].album.c_str()); - m_find_result_list.SetItemText(i, 5, (theApp.m_player.GetCurrentPath() + m_playlist[m_find_result[i]].file_name).c_str()); + m_find_result_list.SetItemText(i, 5, (theApp.m_player.GetCurrentDir() + m_playlist[m_find_result[i]].file_name).c_str()); } } else @@ -461,7 +461,7 @@ void CFindDlg::OnFdOpenFileLocation() if (m_find_current_playlist) { if (m_item_selected >= 0 && m_item_selected < m_find_result.size()) - file = theApp.m_player.GetCurrentPath() + m_playlist[m_find_result[m_item_selected]].file_name; + file = theApp.m_player.GetCurrentDir() + m_playlist[m_find_result[m_item_selected]].file_name; else return; } diff --git a/MusicPlayer2/LyricBatchDownloadDlg.cpp b/MusicPlayer2/LyricBatchDownloadDlg.cpp index 49761999..83512eca 100644 --- a/MusicPlayer2/LyricBatchDownloadDlg.cpp +++ b/MusicPlayer2/LyricBatchDownloadDlg.cpp @@ -234,7 +234,7 @@ UINT CLyricBatchDownloadDlg::ThreadFunc(LPVOID lpParam) //设置要保存的歌词的路径 wstring lyric_path; if (pInfo->save_to_song_folder) - lyric_path = theApp.m_player.GetCurrentPath() + pInfo->playlist->at(i).file_name; + lyric_path = theApp.m_player.GetCurrentDir() + pInfo->playlist->at(i).file_name; else lyric_path = theApp.m_play_setting_data.lyric_path + pInfo->playlist->at(i).file_name; size_t index = lyric_path.rfind(L'.'); //查找文件名最后一个点 diff --git a/MusicPlayer2/LyricDownloadDlg.cpp b/MusicPlayer2/LyricDownloadDlg.cpp index bd607ed4..bb3927bb 100644 --- a/MusicPlayer2/LyricDownloadDlg.cpp +++ b/MusicPlayer2/LyricDownloadDlg.cpp @@ -132,7 +132,7 @@ BOOL CLyricDownloadDlg::OnInitDialog() } m_file_name = theApp.m_player.GetFileName(); - m_file_path = theApp.m_player.GetCurrentPath() + m_file_name; + m_file_path = theApp.m_player.GetCurrentDir() + m_file_name; size_t index = m_file_path.rfind(L'.'); //查找文件名最后一个点 m_file_path = m_file_path.substr(0, index + 1) + L"lrc"; //将文件名的扩展名改为lrc diff --git a/MusicPlayer2/LyricEditDlg.cpp b/MusicPlayer2/LyricEditDlg.cpp index 2456b13d..ed2ee1ed 100644 --- a/MusicPlayer2/LyricEditDlg.cpp +++ b/MusicPlayer2/LyricEditDlg.cpp @@ -86,7 +86,7 @@ bool CLyricEditDlg::SaveLyric(const wchar_t * path, CodeType code_type) { if (path[0] == L'\0') //如果保存时传递的路径的空字符串,则将保存路径设置为当前歌曲所在路径 { - m_lyric_path = theApp.m_player.GetCurrentPath() + theApp.m_player.GetFileName(); + m_lyric_path = theApp.m_player.GetCurrentDir() + theApp.m_player.GetFileName(); int index = m_lyric_path.rfind(L'.'); m_lyric_path = m_lyric_path.substr(0, index); m_lyric_path += L".lrc"; diff --git a/MusicPlayer2/MiniModeDlg.cpp b/MusicPlayer2/MiniModeDlg.cpp index b17cafd3..c0ca3a8e 100644 --- a/MusicPlayer2/MiniModeDlg.cpp +++ b/MusicPlayer2/MiniModeDlg.cpp @@ -625,7 +625,7 @@ void CMiniModeDlg::OnMiniModeExit() //{ // // TODO: 在此添加命令处理程序代码 // CPropertyDlg propertyDlg(theApp.m_player.GetPlayList()); -// propertyDlg.m_path = theApp.m_player.GetCurrentPath(); +// propertyDlg.m_path = theApp.m_player.GetCurrentDir(); // propertyDlg.m_index = theApp.m_player.GetIndex(); // propertyDlg.m_song_num = theApp.m_player.GetSongNum(); // propertyDlg.DoModal(); diff --git a/MusicPlayer2/MusicPlayer2.rc b/MusicPlayer2/MusicPlayer2.rc index 1cedb366..567729a6 100644 Binary files a/MusicPlayer2/MusicPlayer2.rc and b/MusicPlayer2/MusicPlayer2.rc differ diff --git a/MusicPlayer2/MusicPlayerDlg.cpp b/MusicPlayer2/MusicPlayerDlg.cpp index 68cf7d4c..43adb171 100644 --- a/MusicPlayer2/MusicPlayerDlg.cpp +++ b/MusicPlayer2/MusicPlayerDlg.cpp @@ -270,6 +270,8 @@ BEGIN_MESSAGE_MAP(CMusicPlayerDlg, CDialog) ON_MESSAGE(WM_MUSIC_STREAM_OPENED, &CMusicPlayerDlg::OnMusicStreamOpened) ON_COMMAND(ID_CURRENT_EXPLORE_ONLINE, &CMusicPlayerDlg::OnCurrentExploreOnline) ON_COMMAND(ID_DELETE_ALBUM_COVER, &CMusicPlayerDlg::OnDeleteAlbumCover) + ON_COMMAND(ID_COPY_FILE_TO, &CMusicPlayerDlg::OnCopyFileTo) + ON_COMMAND(ID_MOVE_FILE_TO, &CMusicPlayerDlg::OnMoveFileTo) END_MESSAGE_MAP() @@ -340,7 +342,7 @@ void CMusicPlayerDlg::LoadConfig() theApp.m_play_setting_data.cortana_lyric_double_line = (GetPrivateProfileInt(_T("config"), _T("cortana_lyric_double_line"), 0, theApp.m_config_path.c_str()) != 0); theApp.m_app_setting_data.show_spectrum = (GetPrivateProfileInt(_T("config"), _T("show_spectrum"), 1, theApp.m_config_path.c_str()) != 0); theApp.m_app_setting_data.show_album_cover = (GetPrivateProfileInt(_T("config"), _T("show_album_cover"), 1, theApp.m_config_path.c_str()) != 0); - theApp.m_app_setting_data.album_cover_fit = static_cast(GetPrivateProfileInt(_T("config"), _T("album_cover_fit"), 2, theApp.m_config_path.c_str())); + theApp.m_app_setting_data.album_cover_fit = static_cast(GetPrivateProfileInt(_T("config"), _T("album_cover_fit"), 1, theApp.m_config_path.c_str())); theApp.m_app_setting_data.album_cover_as_background = (GetPrivateProfileInt(_T("config"), _T("album_cover_as_background"), 0, theApp.m_config_path.c_str()) != 0); theApp.m_play_setting_data.cortana_show_album_cover = (GetPrivateProfileInt(_T("config"), _T("cortana_show_album_cover"), 1, theApp.m_config_path.c_str()) != 0); theApp.m_play_setting_data.cortana_icon_beat = (GetPrivateProfileInt(_T("config"), _T("cortana_icon_beat"), 0, theApp.m_config_path.c_str()) != 0); @@ -898,7 +900,7 @@ void CMusicPlayerDlg::ShowPlayList() //设置播放列表中突出显示的项目 SetPlayListColor(); //显示当前路径 - m_path_edit.SetWindowTextW(theApp.m_player.GetCurrentPath().c_str()); + m_path_edit.SetWindowTextW(theApp.m_player.GetCurrentDir().c_str()); m_progress_bar.SetSongLength(theApp.m_player.GetSongLength()); @@ -1657,7 +1659,7 @@ void CMusicPlayerDlg::OnSetPath() delete m_pSetPathDlg; m_pSetPathDlg = nullptr; } - m_pSetPathDlg = new CSetPathDlg(theApp.m_player.GetRecentPath(), theApp.m_player.GetCurrentPath()); + m_pSetPathDlg = new CSetPathDlg(theApp.m_player.GetRecentPath(), theApp.m_player.GetCurrentDir()); m_pSetPathDlg->Create(IDD_SET_PATH_DIALOG); m_pSetPathDlg->ShowWindow(SW_SHOW); } @@ -1962,7 +1964,7 @@ void CMusicPlayerDlg::OnFileOpenFolder() CFolderBrowserDlg folderPickerDlg(this->GetSafeHwnd()); folderPickerDlg.SetInfo(_T("请选择一个文件夹,文件夹里的所有音频文件都将添加到播放列表。")); #else - CFilePathHelper current_path(theApp.m_player.GetCurrentPath()); + CFilePathHelper current_path(theApp.m_player.GetCurrentDir()); CFolderPickerDialog folderPickerDlg(current_path.GetParentDir().c_str()); #endif if (folderPickerDlg.DoModal() == IDOK) @@ -2324,7 +2326,7 @@ void CMusicPlayerDlg::OnItemProperty() { // TODO: 在此添加命令处理程序代码 CPropertyDlg propertyDlg(theApp.m_player.GetPlayList()); - propertyDlg.m_path = theApp.m_player.GetCurrentPath(); + propertyDlg.m_path = theApp.m_player.GetCurrentDir(); propertyDlg.m_index = m_item_selected; propertyDlg.m_song_num = theApp.m_player.GetSongNum(); //propertyDlg.m_playing_index = theApp.m_player.GetIndex(); @@ -2469,7 +2471,7 @@ void CMusicPlayerDlg::OnDeleteFromDisk() { if (m_item_selected == theApp.m_player.GetIndex()) //如果删除的文件是正在播放的文件,则删除前必须先关闭文件 theApp.m_player.MusicControl(Command::CLOSE); - wstring file_name{ theApp.m_player.GetCurrentPath() + theApp.m_player.GetPlayList()[m_item_selected].file_name }; + wstring file_name{ theApp.m_player.GetCurrentDir() + theApp.m_player.GetPlayList()[m_item_selected].file_name }; int rtn; rtn = CCommon::DeleteAFile(m_hWnd, file_name); if (rtn == 0) @@ -2630,7 +2632,7 @@ void CMusicPlayerDlg::OnSongInfo() { // TODO: 在此添加命令处理程序代码 CPropertyDlg propertyDlg(theApp.m_player.GetPlayList()); - propertyDlg.m_path = theApp.m_player.GetCurrentPath(); + propertyDlg.m_path = theApp.m_player.GetCurrentDir(); propertyDlg.m_index = theApp.m_player.GetIndex(); propertyDlg.m_song_num = theApp.m_player.GetSongNum(); propertyDlg.DoModal(); @@ -3012,11 +3014,11 @@ UINT CMusicPlayerDlg::DownloadLyricAndCoverThreadFunc(LPVOID lpParam) { wstring album_name{ match_item.album }; CCommon::FileNameNormalize(album_name); - cover_file_path.SetFilePath(theApp.m_player.GetCurrentPath() + album_name); + cover_file_path.SetFilePath(theApp.m_player.GetCurrentDir() + album_name); } else //否则以歌曲文件名为文件名保存 { - cover_file_path.SetFilePath(theApp.m_player.GetCurrentPath() + theApp.m_player.GetCurrentSongInfo().file_name); + cover_file_path.SetFilePath(theApp.m_player.GetCurrentDir() + theApp.m_player.GetCurrentSongInfo().file_name); } CFilePathHelper url_path(cover_url); cover_file_path.ReplaceFileExtension(url_path.GetFileExtension().c_str()); @@ -3048,7 +3050,7 @@ UINT CMusicPlayerDlg::DownloadLyricAndCoverThreadFunc(LPVOID lpParam) } else { - lyric_path.SetFilePath(theApp.m_player.GetCurrentPath() + theApp.m_player.GetCurrentSongInfo().file_name); + lyric_path.SetFilePath(theApp.m_player.GetCurrentDir() + theApp.m_player.GetCurrentSongInfo().file_name); } lyric_path.ReplaceFileExtension(L"lrc"); string _lyric_str = CCommon::UnicodeToStr(lyric_str, CodeType::UTF8); @@ -3205,3 +3207,60 @@ void CMusicPlayerDlg::OnDeleteAlbumCover() // TODO: 在此添加命令处理程序代码 theApp.m_player.DeleteAlbumCover(); } + + +void CMusicPlayerDlg::OnCopyFileTo() +{ + // TODO: 在此添加命令处理程序代码 + LPCTSTR title{ _T("选择复制的目标文件夹") }; +#ifdef COMPILE_IN_WIN_XP + CFolderBrowserDlg folderPickerDlg(this->GetSafeHwnd()); + folderPickerDlg.SetInfo(title); +#else + CFilePathHelper current_path(theApp.m_player.GetCurrentDir()); + CFolderPickerDialog folderPickerDlg(current_path.GetParentDir().c_str()); + folderPickerDlg.m_ofn.lpstrTitle = title; +#endif + if (folderPickerDlg.DoModal() == IDOK) + { + if (m_item_selected >= 0 && m_item_selected < theApp.m_player.GetSongNum()) + { + wstring source_file{ theApp.m_player.GetCurrentDir() + theApp.m_player.GetPlayList()[m_item_selected].file_name }; + CCommon::CopyAFile(this->GetSafeHwnd(), theApp.m_player.GetCurrentFilePath(), wstring(folderPickerDlg.GetPathName())); + } + } +} + + +void CMusicPlayerDlg::OnMoveFileTo() +{ + // TODO: 在此添加命令处理程序代码 + LPCTSTR title{ _T("选择移动的目标文件夹") }; +#ifdef COMPILE_IN_WIN_XP + CFolderBrowserDlg folderPickerDlg(this->GetSafeHwnd()); + folderPickerDlg.SetInfo(title); +#else + CFilePathHelper current_path(theApp.m_player.GetCurrentDir()); + CFolderPickerDialog folderPickerDlg(current_path.GetParentDir().c_str()); + folderPickerDlg.m_ofn.lpstrTitle = title; +#endif + if (folderPickerDlg.DoModal() == IDOK) + { + if (m_item_selected >= 0 && m_item_selected < theApp.m_player.GetSongNum()) + { + if (m_item_selected == theApp.m_player.GetIndex()) //如果移动的文件是正在播放的文件,则移动前必须先关闭文件 + theApp.m_player.MusicControl(Command::CLOSE); + wstring source_file{ theApp.m_player.GetCurrentDir() + theApp.m_player.GetPlayList()[m_item_selected].file_name }; + int rtn; + rtn = CCommon::MoveAFile(m_hWnd, source_file, wstring(folderPickerDlg.GetPathName())); + if (rtn == 0) + { + //如果文件移动成功,同时从播放列表中移除 + theApp.m_player.RemoveSong(m_item_selected); + ShowPlayList(); + UpdatePlayPauseButton(); + DrawInfo(true); + } + } + } +} diff --git a/MusicPlayer2/MusicPlayerDlg.h b/MusicPlayer2/MusicPlayerDlg.h index c6369ae8..d48d281d 100644 --- a/MusicPlayer2/MusicPlayerDlg.h +++ b/MusicPlayer2/MusicPlayerDlg.h @@ -291,4 +291,6 @@ protected: public: afx_msg void OnCurrentExploreOnline(); afx_msg void OnDeleteAlbumCover(); + afx_msg void OnCopyFileTo(); + afx_msg void OnMoveFileTo(); }; diff --git a/MusicPlayer2/Player.cpp b/MusicPlayer2/Player.cpp index 6a219e50..8ff7a277 100644 --- a/MusicPlayer2/Player.cpp +++ b/MusicPlayer2/Player.cpp @@ -1018,7 +1018,7 @@ void CPlayer::LoadConfig() theApp.m_play_setting_data.lyric_karaoke_disp = (GetPrivateProfileIntW(L"config", L"lyric_karaoke_disp", 1, theApp.m_config_path.c_str()) != 0); m_sort_mode = static_cast(GetPrivateProfileIntW(L"config", L"sort_mode", 0, theApp.m_config_path.c_str())); theApp.m_play_setting_data.lyric_fuzzy_match = (GetPrivateProfileIntW(L"config", L"lyric_fuzzy_match", 1, theApp.m_config_path.c_str()) != 0); - GetPrivateProfileStringW(L"config", L"default_album_file_name", L"Folder", buff, 255, theApp.m_config_path.c_str()); + GetPrivateProfileStringW(L"config", L"default_album_file_name", L"cover", buff, 255, theApp.m_config_path.c_str()); //theApp.m_app_setting_data.default_album_name = buff; CCommon::StringSplit(buff, L',', theApp.m_app_setting_data.default_album_name); diff --git a/MusicPlayer2/Player.h b/MusicPlayer2/Player.h index 03b24395..cb2d41c2 100644 --- a/MusicPlayer2/Player.h +++ b/MusicPlayer2/Player.h @@ -192,7 +192,8 @@ public: vector& GetPlayList() { return m_playlist; } //获取播放列表的引用 Time GetAllSongLength(int track) const; //获取指定序号的歌曲的长度 int GetSongNum() const { return m_song_num; } //获取歌曲总数 - const wstring& GetCurrentPath() const { return m_path; } //获取当前路径 + const wstring& GetCurrentDir() const { return m_path; } //获取当前目录 + wstring GetCurrentFilePath() const { return m_path + m_current_file_name; } //获取正在播放文件的路径 int GetIndex() const { return m_index; } //获取当前播放的曲目序号 wstring GetFileName() const { return (m_current_file_name.empty() ? wstring(L"没有找到文件") : m_current_file_name); } wstring GetLyricName() const { return m_Lyrics.GetPathName(); } diff --git a/MusicPlayer2/PropertyDlg.cpp b/MusicPlayer2/PropertyDlg.cpp index c16032a9..48fe011c 100644 --- a/MusicPlayer2/PropertyDlg.cpp +++ b/MusicPlayer2/PropertyDlg.cpp @@ -398,7 +398,7 @@ void CPropertyDlg::OnBnClickedSaveToFileButton() bool text_cut_off; wstring file_path; - file_path = theApp.m_player.GetCurrentPath() + m_all_song_info[m_index].file_name; + file_path = theApp.m_player.GetCurrentDir() + m_all_song_info[m_index].file_name; if (!CAudioTag::WriteMp3Tag(file_path.c_str(), song_info, text_cut_off)) { MessageBox(_T("无法写入文件!"), NULL, MB_ICONWARNING | MB_OK); @@ -408,11 +408,11 @@ void CPropertyDlg::OnBnClickedSaveToFileButton() //重新从文件读取该歌曲的标签 HSTREAM hStream; hStream = BASS_StreamCreateFile(FALSE, file_path.c_str(), 0, 0, BASS_SAMPLE_FLOAT); - //CAudioCommon::GetAudioTags(hStream, AudioType::AU_MP3, theApp.m_player.GetCurrentPath(), m_all_song_info[m_index]); - CAudioTag audio_tag(hStream, theApp.m_player.GetCurrentPath(), m_all_song_info[m_index]); + //CAudioCommon::GetAudioTags(hStream, AudioType::AU_MP3, theApp.m_player.GetCurrentDir(), m_all_song_info[m_index]); + CAudioTag audio_tag(hStream, theApp.m_player.GetCurrentDir(), m_all_song_info[m_index]); audio_tag.GetAudioTag(true); BASS_StreamFree(hStream); - theApp.m_song_data[theApp.m_player.GetCurrentPath() + m_all_song_info[m_index].file_name] = m_all_song_info[m_index]; + theApp.m_song_data[theApp.m_player.GetCurrentDir() + m_all_song_info[m_index].file_name] = m_all_song_info[m_index]; m_modified = false; m_save_button.EnableWindow(m_write_enable && m_modified); @@ -437,7 +437,7 @@ void CPropertyDlg::OnCbnSelchangeGenreCombo() // // //重新从文件读取该歌曲的标签 // wstring file_path; -// file_path = theApp.m_player.GetCurrentPath() + m_all_song_info[m_index].file_name; +// file_path = theApp.m_player.GetCurrentDir() + m_all_song_info[m_index].file_name; // HSTREAM hStream; // hStream = BASS_StreamCreateFile(FALSE, file_path.c_str(), 0, 0, BASS_SAMPLE_FLOAT); // CAudioCommon::GetAudioTags(hStream, AudioType::AU_MP3, m_all_song_info[m_index]); diff --git a/MusicPlayer2/resource.h b/MusicPlayer2/resource.h index 93249403..11ac9468 100644 Binary files a/MusicPlayer2/resource.h and b/MusicPlayer2/resource.h differ