Skip to content

Commit

Permalink
Улучшена поддержка открытия File URI - формат file://...
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksoid1978 committed Nov 19, 2024
1 parent 060842f commit 21f6959
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/DSUtil/FileHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ CStringW GetFullCannonFilePath(LPCWSTR path)
return newPath;
}

bool ConvertFileUriToPath(CStringW& uri)
{
if (StartsWith(uri, L"file://")) {
DWORD size = uri.GetLength();
CStringW path;
if (S_OK == UrlUnescapeW(uri.GetBuffer(), path.GetBuffer(size), &size, URL_ESCAPE_URI_COMPONENT)) {
path.ReleaseBuffer(size);
if (S_OK == PathCreateFromUrlW(path.GetString(), path.GetBuffer(), &size, 0)) {
path.ReleaseBuffer(size);
uri = path;
return true;
}
}
}

return false;
}

void StripToRoot(CStringW& path)
{
BOOL ret = ::PathStripToRootW(path.GetBuffer());
Expand Down
2 changes: 2 additions & 0 deletions src/DSUtil/FileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ CStringW GetCombineFilePath(LPCWSTR dir, LPCWSTR file);
// creates a full and canonical path
CStringW GetFullCannonFilePath(LPCWSTR path);

bool ConvertFileUriToPath(CStringW& uri);

void StripToRoot(CStringW& path);
CStringW GetStripToRoot(LPCWSTR path);

Expand Down
10 changes: 4 additions & 6 deletions src/apps/mplayerc/Content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,8 @@ namespace Content {
CString url = CString(match[k].first, match[k].length());
url.Trim();

if (playlist_type == PLAYLIST_RAM && StartsWith(url, L"file://")) {
url.Delete(0, 7);
url.Replace('/', '\\');
if (playlist_type == PLAYLIST_RAM) {
ConvertFileUriToPath(url);
}

CUrlParser dst;
Expand Down Expand Up @@ -345,9 +344,8 @@ namespace Content {
CString fn2 = CString(match[k].first, match[k].length());
fn2.Trim();

if (playlist_type == PLAYLIST_RAM && StartsWith(fn2, L"file://")) {
fn2.Delete(0, 7);
fn2.Replace('/', '\\');
if (playlist_type == PLAYLIST_RAM) {
ConvertFileUriToPath(fn2);
}

if (fn2.Find(':') < 0 && fn2.Find(L"\\\\") != 0 && fn2.Find(L"//") != 0) {
Expand Down
19 changes: 10 additions & 9 deletions src/apps/mplayerc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@
#define ID_PLSMENU_POSITION_BOTTOM 2008
#define ID_PLSMENU_POSITION_FLOAT 2009

WCHAR LastChar(const CStringW& str)
static WCHAR LastChar(const CStringW& str)
{
int len = str.GetLength();
return len > 0 ? str.GetAt(len - 1) : 0;
}

static CStringW MakePath(CStringW path)
{
if (::PathIsURLW(path) || Youtube::CheckURL(path)) { // skip URLs
if (path.Left(8).MakeLower() == L"file:///") {
path.Delete(0, 8);
path.Replace('/', '\\');
}
if (ConvertFileUriToPath(path)) {
return path;
}

if (::PathIsURLW(path) || Youtube::CheckURL(path)) { // skip URLs
return path;
}

Expand Down Expand Up @@ -1450,7 +1449,7 @@ void CPlayerPlaylistBar::ParsePlayList(std::list<CString>& fns, CSubtitleItemLis

static CString CombinePath(CStringW base, const CStringW& relative)
{
if (StartsWith(relative, L":\\", 1) || StartsWith(relative, L"\\")) {
if (StartsWith(relative, L":\\", 1) || StartsWith(relative, L"\\") || StartsWith(relative, L"file://")) {
return relative;
}

Expand Down Expand Up @@ -2145,8 +2144,10 @@ void CPlayerPlaylistBar::Append(std::list<CString>& fns, const bool bMulti, CSub
}

for (auto& fn : fns) {
if (::PathIsURLW(fn)) {
fn = UrlDecode(fn);
if (!ConvertFileUriToPath(fn)) {
if (::PathIsURLW(fn)) {
fn = UrlDecode(fn);
}
}
}

Expand Down

0 comments on commit 21f6959

Please sign in to comment.