From ef765d2fc5a2fdb608156a9618928797eee7be51 Mon Sep 17 00:00:00 2001 From: v0lt Date: Sun, 15 Sep 2024 07:33:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20COpenFil?= =?UTF-8?q?eDialog=20=D0=B8=20CSaveFileDialog=20=D1=83=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/mplayerc/MainFrm.cpp | 14 +++++++------- src/apps/mplayerc/PPageFileInfoRes.cpp | 2 +- src/apps/mplayerc/PPageFileInfoSheet.cpp | 2 +- src/apps/mplayerc/PlayerCaptureDialog.cpp | 2 +- src/apps/mplayerc/PlayerPlaylistBar.cpp | 2 +- src/apps/mplayerc/SaveFileDialog.cpp | 22 ++++++---------------- src/apps/mplayerc/SaveFileDialog.h | 16 ++++++---------- 7 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/apps/mplayerc/MainFrm.cpp b/src/apps/mplayerc/MainFrm.cpp index 7a9bcbe375..fd50f1440b 100644 --- a/src/apps/mplayerc/MainFrm.cpp +++ b/src/apps/mplayerc/MainFrm.cpp @@ -5807,7 +5807,7 @@ void CMainFrame::OnFileOpenIso() return; } - m_wndPlaylistBar.Open(fd.GetFilePath()); + m_wndPlaylistBar.Open(fd.GetPathName()); OpenCurPlaylistItem(); } } @@ -6045,8 +6045,8 @@ void CMainFrame::OnFileSaveAs() if (fd.DoModal() != IDOK) { return; } - CStringW savedFileName(fd.GetFilePath()); - if (in.CompareNoCase(fd.GetFilePath()) == 0) { + CStringW savedFileName(fd.GetPathName()); + if (in.CompareNoCase(savedFileName) == 0) { return; } @@ -6573,7 +6573,7 @@ void CMainFrame::OnFileSaveImage() s.iThumbLevelPNG = std::clamp(fd.m_PngCompression, 1, 9); s.bSnapShotSubtitles = fd.m_bDrawSubtitles; - CStringW pdst = fd.GetFilePath(); + CStringW pdst = fd.GetPathName(); if (GetFileExt(pdst).MakeLower() != s.strSnapShotExt) { RenameFileExt(pdst, s.strSnapShotExt); } @@ -6668,7 +6668,7 @@ void CMainFrame::OnFileSaveThumbnails() s.iThumbLevelPNG = std::clamp(fd.m_PngCompression, 1, 9); s.bSnapShotSubtitles = fd.m_bDrawSubtitles; - CStringW pdst = fd.GetFilePath(); + CStringW pdst = fd.GetPathName(); if (GetFileExt(pdst).MakeLower() != s.strSnapShotExt) { RenameFileExt(pdst, s.strSnapShotExt); } @@ -6843,7 +6843,7 @@ void CMainFrame::OnFileSaveSubtitle() if (fd.DoModal() == IDOK) { CAutoLock cAutoLock(&m_csSubLock); - pVSF->Save(fd.GetFilePath()); + pVSF->Save(fd.GetPathName()); } return; @@ -6877,7 +6877,7 @@ void CMainFrame::OnFileSaveSubtitle() s.bSubSaveExternalStyleFile = !!fd.GetSaveExternalStyleFile(); CAutoLock cAutoLock(&m_csSubLock); - pRTS->SaveAs(fd.GetFilePath(), types[fd.m_ofn.nFilterIndex - 1], m_pCAP->GetFPS(), m_pCAP->GetSubtitleDelay(), fd.GetEncoding(), s.bSubSaveExternalStyleFile); + pRTS->SaveAs(fd.GetPathName(), types[fd.m_ofn.nFilterIndex - 1], m_pCAP->GetFPS(), m_pCAP->GetSubtitleDelay(), fd.GetEncoding(), s.bSubSaveExternalStyleFile); } return; diff --git a/src/apps/mplayerc/PPageFileInfoRes.cpp b/src/apps/mplayerc/PPageFileInfoRes.cpp index bae2a2b7bb..ce14a2ea5a 100644 --- a/src/apps/mplayerc/PPageFileInfoRes.cpp +++ b/src/apps/mplayerc/PPageFileInfoRes.cpp @@ -159,7 +159,7 @@ void CPPageFileInfoRes::OnSaveAs() ext_list, this); if (fd.DoModal() == IDOK) { FILE* f = nullptr; - if (_wfopen_s(&f, fd.GetFilePath(), L"wb") == 0) { + if (_wfopen_s(&f, fd.GetPathName(), L"wb") == 0) { fwrite((*it).data.data(), 1, (*it).data.size(), f); fclose(f); } diff --git a/src/apps/mplayerc/PPageFileInfoSheet.cpp b/src/apps/mplayerc/PPageFileInfoSheet.cpp index 28eade4ad8..4323c89fa6 100644 --- a/src/apps/mplayerc/PPageFileInfoSheet.cpp +++ b/src/apps/mplayerc/PPageFileInfoSheet.cpp @@ -154,7 +154,7 @@ void CPPageFileInfoSheet::OnSaveAs() if (filedlg.DoModal() == IDOK) { CFile mFile; - if (mFile.Open(filedlg.GetFilePath(), CFile::modeCreate | CFile::modeWrite)) { + if (mFile.Open(filedlg.GetPathName(), CFile::modeCreate | CFile::modeWrite)) { const WCHAR bom = 0xFEFF; mFile.Write(&bom, sizeof(WCHAR)); mFile.Write(LPCWSTR(m_mi.MI_Text), m_mi.MI_Text.GetLength() * sizeof(WCHAR)); diff --git a/src/apps/mplayerc/PlayerCaptureDialog.cpp b/src/apps/mplayerc/PlayerCaptureDialog.cpp index 37800ecc0d..cea736cc73 100644 --- a/src/apps/mplayerc/PlayerCaptureDialog.cpp +++ b/src/apps/mplayerc/PlayerCaptureDialog.cpp @@ -1560,7 +1560,7 @@ void CPlayerCaptureDialog::OnOpenFile() L"Media files (*.avi,*.mkv,*.dsm)|*.avi;*.mkv;*.dsm|", this); if (fd.DoModal() == IDOK) { - CString str = fd.GetFilePath(); + CString str = fd.GetPathName(); CString ext = str.Mid(str.ReverseFind('.')+1).MakeLower(); if (ext == L"avi") { diff --git a/src/apps/mplayerc/PlayerPlaylistBar.cpp b/src/apps/mplayerc/PlayerPlaylistBar.cpp index e3a22c0ec2..9ddaab28f9 100644 --- a/src/apps/mplayerc/PlayerPlaylistBar.cpp +++ b/src/apps/mplayerc/PlayerPlaylistBar.cpp @@ -3682,7 +3682,7 @@ void CPlayerPlaylistBar::OnContextMenu(CWnd* /*pWnd*/, CPoint p) int idx = fd.m_pOFN->nFilterIndex; - CStringW path(fd.GetFilePath()); + CStringW path(fd.GetPathName()); CStringW base = GetFolderPath(path); s.strLastSavedPlaylistDir = GetAddSlash(base); diff --git a/src/apps/mplayerc/SaveFileDialog.cpp b/src/apps/mplayerc/SaveFileDialog.cpp index 4bcb8d6088..89f2c4df4d 100644 --- a/src/apps/mplayerc/SaveFileDialog.cpp +++ b/src/apps/mplayerc/SaveFileDialog.cpp @@ -35,17 +35,12 @@ COpenFileDialog::COpenFileDialog( CWnd* pParentWnd) : CFileDialog(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd) { - CStringW dir = ::GetFolderPath(lpszFileName); - size_t size = dir.GetLength() + 1; + m_strInitialDir = ::GetFolderPath(lpszFileName); - m_pstrInitialDir.reset(new WCHAR[size]); - memset(m_pstrInitialDir.get(), 0, size * sizeof(WCHAR)); - wcscpy_s(m_pstrInitialDir.get(), size, dir.GetString()); - - m_pOFN->lpstrInitialDir = m_pstrInitialDir.get(); + m_pOFN->lpstrInitialDir = m_strInitialDir.GetString(); } -CStringW COpenFileDialog::GetFilePath() +CStringW COpenFileDialog::GetPathName() { CStringW filepath; @@ -112,17 +107,12 @@ CSaveFileDialog::CSaveFileDialog( CWnd* pParentWnd) : CFileDialog(FALSE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd) { - CStringW dir = ::GetFolderPath(lpszFileName); - size_t size = dir.GetLength() + 1; - - m_pstrInitialDir.reset(new WCHAR[size]); - memset(m_pstrInitialDir.get(), 0, size * sizeof(WCHAR)); - wcscpy_s(m_pstrInitialDir.get(), size, dir.GetString()); + m_strInitialDir = ::GetFolderPath(lpszFileName); - m_pOFN->lpstrInitialDir = m_pstrInitialDir.get(); + m_pOFN->lpstrInitialDir = m_strInitialDir.GetString(); } -CStringW CSaveFileDialog::GetFilePath() +CStringW CSaveFileDialog::GetPathName() { CStringW filepath; diff --git a/src/apps/mplayerc/SaveFileDialog.h b/src/apps/mplayerc/SaveFileDialog.h index fb747a37b6..4c9cd2a21d 100644 --- a/src/apps/mplayerc/SaveFileDialog.h +++ b/src/apps/mplayerc/SaveFileDialog.h @@ -31,10 +31,7 @@ class COpenFileDialog : public CFileDialog DECLARE_DYNAMIC(COpenFileDialog) private: - // CFileDialog::GetPathName does not work for long paths, use GetFilePath instead. - CFileDialog::GetPathName; - - std::unique_ptr m_pstrInitialDir; + CStringW m_strInitialDir; public: COpenFileDialog( @@ -46,7 +43,8 @@ class COpenFileDialog : public CFileDialog virtual ~COpenFileDialog() = default; // Returns the file path selected for opening. Long paths are supported. - CStringW GetFilePath(); + // PS: parent CFileDialog::GetPathName does not work for long paths. + CStringW GetPathName(); //std::vector GetFilePaths(); }; @@ -59,10 +57,7 @@ class CSaveFileDialog : public CFileDialog DECLARE_DYNAMIC(CSaveFileDialog) private: - // CFileDialog::GetPathName does not work for long paths, use GetFilePath instead. - CFileDialog::GetPathName; - - std::unique_ptr m_pstrInitialDir; + CStringW m_strInitialDir; public: CSaveFileDialog( @@ -74,5 +69,6 @@ class CSaveFileDialog : public CFileDialog virtual ~CSaveFileDialog() = default; // Returns the file path selected for saving. Long paths are supported. - CStringW GetFilePath(); + // PS: parent CFileDialog::GetPathName does not work for long paths. + CStringW GetPathName(); };