Skip to content

Commit

Permalink
Избавляемся от CPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Sep 13, 2024
1 parent 003ccdc commit 0dfec89
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 57 deletions.
4 changes: 1 addition & 3 deletions src/apps/mplayerc/Content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ namespace Content {
}

if (fn2.Find(':') < 0 && fn2.Find(L"\\\\") != 0 && fn2.Find(L"//") != 0) {
CPath p;
p.Combine(dir, fn2);
fn2 = (LPCWSTR)p;
fn2 = GetCombineFilePath(dir, fn2);
}

if (!fn2.CompareNoCase(fn)) {
Expand Down
41 changes: 20 additions & 21 deletions src/apps/mplayerc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ WCHAR LastChar(const CStringW& str)
return len > 0 ? str.GetAt(len - 1) : 0;
}

static CString MakePath(CString path)
static CStringW MakePath(CStringW path)
{
if (::PathIsURLW(path) || Youtube::CheckURL(path)) { // skip URLs
if (path.Left(8).MakeLower() == L"file:///") {
Expand All @@ -66,9 +66,9 @@ static CString MakePath(CString path)

path.Replace('/', '\\');

CPath c(path);
c.Canonicalize();
return CString(c);
CStringW c = GetCanonicalizeFilePath(path);

return c;
}

struct CUETrack {
Expand Down Expand Up @@ -338,9 +338,8 @@ static void StringToPaths(const CStringW& curentdir, const CStringW& str, std::v
if (hFind == INVALID_HANDLE_VALUE) {
continue;
} else {
CPath parentdir(path + L"\\..");
parentdir.Canonicalize();
parentdir.AddBackslash();
CStringW parentdir = GetCanonicalizeFilePath(path + L"\\..");
AddSlash(parentdir);

do {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && wcscmp(fd.cFileName, L".") && wcscmp(fd.cFileName, L"..")) {
Expand Down Expand Up @@ -1447,7 +1446,7 @@ void CPlayerPlaylistBar::ParsePlayList(std::list<CString>& fns, CSubtitleItemLis
AddItem(fns, subs);
}

static CString CombinePath(CPath base, const CString& relative)
static CString CombinePath(CStringW base, const CStringW& relative)
{
if (StartsWith(relative, L":\\", 1) || StartsWith(relative, L"\\")) {
return relative;
Expand All @@ -1462,7 +1461,7 @@ static CString CombinePath(CPath base, const CString& relative)
return CUrlParser::CombineUrl(base, relative);
}

base.Append(relative);
CombineFilePath(base, relative);
return base;
}

Expand All @@ -1486,8 +1485,7 @@ bool CPlayerPlaylistBar::ParseMPCPlayList(const CString& fn)
return false;
}

CPath base(fn);
base.RemoveFileSpec();
CStringW base = GetFolderPath(fn);

PlayList.m_nSelectedAudioTrack = PlayList.m_nSelectedSubtitleTrack = -1;

Expand Down Expand Up @@ -1715,17 +1713,18 @@ bool CPlayerPlaylistBar::ParseM3UPlayList(CString fn)
return false;
}

CPath base(fn);
if (!f.GetRedirectURL().IsEmpty()) {
base = (CPath)f.GetRedirectURL();
CStringW base;
if (f.GetRedirectURL().GetLength()) {
base = f.GetRedirectURL();
}
else {
base = fn;
}

if (fn.Find(L"://") > 0) {
CString tmp(base);
tmp.Truncate(tmp.ReverseFind('/'));
base = (CPath)tmp;
base.Truncate(base.ReverseFind('/'));
} else {
base.RemoveFileSpec();
RemoveFileSpec(base);
}

std::map<CString, CAudioItemList> audio_fns;
Expand Down Expand Up @@ -1891,13 +1890,13 @@ bool CPlayerPlaylistBar::ParseCUEPlayList(CString fn)
}
}

CPath base(fn);
base.RemoveFileSpec();
CStringW base = GetFolderPath(fn);
AddSlash(base);

INT_PTR c = curPlayList.GetCount();

for (const auto& fName : fileNames){
CString fullPath = MakePath(CombinePath(base, fName));
CString fullPath = MakePath(base + fName);
BOOL bExists = TRUE;
if (!::PathFileExistsW(fullPath)) {
CString ext = GetFileExt(fullPath);
Expand Down
18 changes: 7 additions & 11 deletions src/apps/mplayerc/WebClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,9 @@ bool CWebClientSocket::OnBrowser(CStringA& hdr, CStringA& body, CStringA& mime)
}

if (CFileGetStatus(path, fs) && (fs.m_attribute&CFile::directory) || path.Find(L"\\") == 0) {
CPath p(path);
p.Canonicalize();
p.MakePretty();
p.AddBackslash();
path = (LPCWSTR)p;
path = GetCanonicalizeFilePath(path);
::PathMakePrettyW(path.GetBuffer());
AddSlash(path);
}

CStringA files;
Expand All @@ -492,13 +490,11 @@ bool CWebClientSocket::OnBrowser(CStringA& hdr, CStringA& body, CStringA& mime)

path = "Root";
} else {
CString parent;
CStringW parent;

if (path.GetLength() > 3) {
CPath p(path + "..");
p.Canonicalize();
p.AddBackslash();
parent = (LPCWSTR)p;
parent = GetCanonicalizeFilePath(path + "..");
AddSlash(parent);
}

files += "<tr class=\"dir\">\r\n";
Expand Down Expand Up @@ -780,7 +776,7 @@ bool CWebClientSocket::OnStatus(CStringA& hdr, CStringA& body, CStringA& mime)
CString title;
m_pMainFrame->GetWindowTextW(title);

CPath file(m_pMainFrame->m_wndPlaylistBar.GetCurFileName());
CStringW file(m_pMainFrame->m_wndPlaylistBar.GetCurFileName());

CString status;
OAFilterState fs = m_pMainFrame->GetMediaState();
Expand Down
34 changes: 14 additions & 20 deletions src/apps/mplayerc/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,18 @@ CWebServer::CWebServer(CMainFrame* pMainFrame, int nPort)
m_mimes[".png"] = "image/png";
m_mimes[".js"] = "text/javascript";

m_webroot = CPath(GetProgramDir());

CString WebRoot = AfxGetAppSettings().strWebRoot;
WebRoot.Replace('/', '\\');
WebRoot.Trim();
CPath p(WebRoot);
if (WebRoot.Find(L":\\") < 0 && WebRoot.Find(L"\\\\") < 0) {
m_webroot.Append(WebRoot);
m_webroot = GetCombineFilePath(GetProgramDir(), WebRoot);
} else {
m_webroot = p;
m_webroot = GetCanonicalizeFilePath(WebRoot);
}
m_webroot.Canonicalize();
m_webroot.MakePretty();
if (!m_webroot.IsDirectory()) {
m_webroot = CPath();
::PathMakePrettyW(m_webroot.GetBuffer());

if (!::PathIsDirectoryW(m_webroot)) {
m_webroot.Empty();
}

std::list<CString> sl;
Expand Down Expand Up @@ -235,22 +232,19 @@ void CWebServer::Deploy(CString dir)

bool CWebServer::ToLocalPath(CString& path, CString& redir)
{
if (!path.IsEmpty() && m_webroot.IsDirectory()) {
if (!path.IsEmpty() && ::PathIsDirectoryW(m_webroot)) {
CString tmp = path;
tmp.Replace('/', '\\');
tmp.TrimLeft('\\');

CPath p;
p.Combine(m_webroot, tmp);
p.Canonicalize();
CStringW p = GetCombineFilePath(m_webroot, tmp); // Combine and Canonicalize

if (p.IsDirectory()) {
if (PathIsDirectoryW(p)) {
std::list<CString> sl;
Explode(AfxGetAppSettings().strWebDefIndex, sl, L';');
for (const auto& str : sl) {
CPath p2 = p;
p2.Append(str);
if (p2.FileExists()) {
CStringW p2 = GetCombineFilePath(p, str);
if (::PathFileExistsW(p2)) {
p = p2;
redir = path;
if (redir.GetAt(redir.GetLength()-1) != L'/') {
Expand All @@ -262,7 +256,7 @@ bool CWebServer::ToLocalPath(CString& path, CString& redir)
}
}

if (wcslen(p) > wcslen(m_webroot) && p.FileExists()) {
if (wcslen(p) > wcslen(m_webroot) && ::PathFileExistsW(p)) {
path = (LPCWSTR)p;
return true;
}
Expand Down Expand Up @@ -331,7 +325,7 @@ void CWebServer::OnRequest(CWebClientSocket* pClient, CStringA& hdr, CStringA& b

bool fHandled = false, fCGI = false;

if (m_webroot.IsDirectory()) {
if (::PathIsDirectoryW(m_webroot)) {
CStringA tmphdr;
fHandled = fCGI = CallCGI(pClient, tmphdr, body, mime);

Expand Down Expand Up @@ -383,7 +377,7 @@ void CWebServer::OnRequest(CWebClientSocket* pClient, CStringA& hdr, CStringA& b
}
}

if (!fHandled && m_webroot.IsDirectory()) {
if (!fHandled && ::PathIsDirectoryW(m_webroot)) {
fHandled = LoadPage(0, body, pClient->m_path);
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/mplayerc/WebServer.h
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 @@ -63,7 +63,7 @@ class CWebServer
static const std::map<CString, CWebServer::RequestHandler> m_internalpages;
static const std::map<CString, UINT> m_downloads;
static std::map<CStringA, CStringA> m_mimes;
CPath m_webroot;
CStringW m_webroot;

std::map<CString, CString> m_cgi;
bool CallCGI(CWebClientSocket* pClient, CStringA& hdr, CStringA& body, CStringA& mime);
Expand Down

0 comments on commit 0dfec89

Please sign in to comment.