Skip to content

Commit

Permalink
Классы COpenFileDialog и CSaveFileDialog упрощены.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Sep 15, 2024
1 parent d53d46b commit ef765d2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 37 deletions.
14 changes: 7 additions & 7 deletions src/apps/mplayerc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5807,7 +5807,7 @@ void CMainFrame::OnFileOpenIso()
return;
}

m_wndPlaylistBar.Open(fd.GetFilePath());
m_wndPlaylistBar.Open(fd.GetPathName());
OpenCurPlaylistItem();
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -6843,7 +6843,7 @@ void CMainFrame::OnFileSaveSubtitle()

if (fd.DoModal() == IDOK) {
CAutoLock cAutoLock(&m_csSubLock);
pVSF->Save(fd.GetFilePath());
pVSF->Save(fd.GetPathName());
}

return;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mplayerc/PPageFileInfoRes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mplayerc/PPageFileInfoSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mplayerc/PlayerCaptureDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mplayerc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 6 additions & 16 deletions src/apps/mplayerc/SaveFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
16 changes: 6 additions & 10 deletions src/apps/mplayerc/SaveFileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<WCHAR[]> m_pstrInitialDir;
CStringW m_strInitialDir;

public:
COpenFileDialog(
Expand All @@ -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<CStringW> GetFilePaths();
};

Expand All @@ -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<WCHAR[]> m_pstrInitialDir;
CStringW m_strInitialDir;

public:
CSaveFileDialog(
Expand All @@ -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();
};

0 comments on commit ef765d2

Please sign in to comment.