Skip to content

Commit

Permalink
DSUtil:Добавлена функция GetCurrentDir.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Sep 13, 2024
1 parent 3178c65 commit d565a77
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
19 changes: 16 additions & 3 deletions src/DSUtil/FileHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@ CStringW GetCombineFilePath(LPCWSTR dir, LPCWSTR file)
CStringW GetCanonicalizeFilePath(LPCWSTR path)
{
CStringW newPath;
DWORD buflen = ::GetFullPathNameW(path, 0, nullptr, nullptr);
const DWORD buflen = ::GetFullPathNameW(path, 0, nullptr, nullptr);
if (buflen > 0) {
DWORD len = ::GetFullPathNameW(path, buflen, newPath.GetBuffer(buflen - 1), nullptr);
if (len > buflen) {
if (len >= buflen) {
len = 0;
}
newPath.ReleaseBufferSetLength(len);
}

return newPath;
}

Expand All @@ -186,6 +185,20 @@ CStringW GetStripToRoot(LPCWSTR path)
return newPath;
}

CStringW GetCurrentDir()
{
CStringW curDir;
const DWORD buflen = ::GetCurrentDirectoryW(0, nullptr);
if (buflen > 0) {
DWORD len = ::GetCurrentDirectoryW(buflen, curDir.GetBuffer(buflen - 1));
if (len >= buflen) {
len = 0;
}
curDir.ReleaseBufferSetLength(len);
}
return curDir;
}

//
// Generate temporary files with any extension
//
Expand Down
2 changes: 2 additions & 0 deletions src/DSUtil/FileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ CStringW GetCanonicalizeFilePath(LPCWSTR path);
void StripToRoot(CStringW& path);
CStringW GetStripToRoot(LPCWSTR path);

CStringW GetCurrentDir();

BOOL GetTemporaryFilePath(CStringW strExtension, CStringW& strFileName);
CStringW CompactPath(LPCWSTR Path, UINT cchMax);

Expand Down
29 changes: 17 additions & 12 deletions src/apps/mplayerc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5534,8 +5534,7 @@ LRESULT CMainFrame::HandleCmdLine(WPARAM wParam, LPARAM lParam)
if (!s.slFiles.empty()) {
GetCDROMType(s.slFiles.front()[0], sl);
} else {
CString dir;
dir.ReleaseBufferSetLength(GetCurrentDirectoryW(MAX_PATH, dir.GetBuffer(MAX_PATH)));
CString dir = GetCurrentDir();

GetCDROMType(dir[0], sl);
for (WCHAR drive = 'C'; sl.empty() && drive <= 'Z'; drive++) {
Expand Down Expand Up @@ -12397,16 +12396,19 @@ CString CMainFrame::OpenFile(OpenFileData* pOFD)
CorrectAceStream(fn);

if (SUCCEEDED(hr)) {
WCHAR path[MAX_PATH] = { 0 };
BOOL bIsDirSet = FALSE;
if (!::PathIsURLW(fn) && ::GetCurrentDirectoryW(MAX_PATH, path)) {
bIsDirSet = ::SetCurrentDirectoryW(GetFolderPath(fn));
CStringW oldcurdir;
BOOL bIsDirSet = FALSE;
if (!::PathIsURLW(fn)) {
oldcurdir = GetCurrentDir();
if (oldcurdir.GetLength()) {
bIsDirSet = ::SetCurrentDirectoryW(GetFolderPath(fn));
}
}

hr = m_pGB->RenderFile(fn, nullptr);

if (bIsDirSet) {
::SetCurrentDirectoryW(path);
::SetCurrentDirectoryW(oldcurdir);
}
}

Expand Down Expand Up @@ -12540,18 +12542,21 @@ CString CMainFrame::OpenFile(OpenFileData* pOFD)
CorrectAceStream(fn);

if (SUCCEEDED(hr)) {
WCHAR path[MAX_PATH] = { 0 };
BOOL bIsDirSet = FALSE;
if (!::PathIsURLW(fn) && ::GetCurrentDirectoryW(MAX_PATH, path)) {
bIsDirSet = ::SetCurrentDirectoryW(GetFolderPath(fn));
CStringW oldcurdir;
BOOL bIsDirSet = FALSE;
if (!::PathIsURLW(fn)) {
oldcurdir = GetCurrentDir();
if (oldcurdir.GetLength()) {
bIsDirSet = ::SetCurrentDirectoryW(GetFolderPath(fn));
}
}

if (CComQIPtr<IGraphBuilderAudio> pGBA = m_pGB.p) {
hr = pGBA->RenderAudioFile(fn);
}

if (bIsDirSet) {
::SetCurrentDirectoryW(path);
::SetCurrentDirectoryW(oldcurdir);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/mplayerc/PlayerCaptureDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
* (C) 2006-2023 see Authors.txt
* (C) 2006-2024 see Authors.txt
*
* This file is part of MPC-BE.
*
Expand Down Expand Up @@ -649,7 +649,7 @@ void CPlayerCaptureDialog::InitControls()
}
} else {
// Use current directory
m_file.ReleaseBufferSetLength(GetCurrentDirectoryW(MAX_PATH, dir.GetBuffer(MAX_PATH)));
m_file = GetCurrentDir();
}
CoTaskMemFree(pathVideos);

Expand Down

0 comments on commit d565a77

Please sign in to comment.