forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filesystem: add support for resource:// paths
- Loading branch information
1 parent
d96e69c
commit afe4c91
Showing
7 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2014 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "ResourceDirectory.h" | ||
#include "FileItem.h" | ||
#include "URL.h" | ||
#include "filesystem/Directory.h" | ||
#include "filesystem/ResourceFile.h" | ||
#include "utils/StringUtils.h" | ||
#include "utils/URIUtils.h" | ||
|
||
using namespace XFILE; | ||
|
||
CResourceDirectory::CResourceDirectory() | ||
{ } | ||
|
||
CResourceDirectory::~CResourceDirectory() | ||
{ } | ||
|
||
bool CResourceDirectory::GetDirectory(const CURL& url, CFileItemList &items) | ||
{ | ||
const std::string pathToUrl(url.Get()); | ||
std::string translatedPath; | ||
if (!CResourceFile::TranslatePath(url, translatedPath)) | ||
return false; | ||
|
||
if (CDirectory::GetDirectory(translatedPath, items, m_strFileMask, m_flags | DIR_FLAG_GET_HIDDEN)) | ||
{ // replace our paths as necessary | ||
items.SetURL(url); | ||
for (int i = 0; i < items.Size(); i++) | ||
{ | ||
CFileItemPtr item = items[i]; | ||
if (StringUtils::StartsWith(item->GetPath(), translatedPath)) | ||
item->SetPath(URIUtils::AddFileToFolder(pathToUrl, item->GetPath().substr(translatedPath.size()))); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
std::string CResourceDirectory::TranslatePath(const CURL &url) | ||
{ | ||
std::string translatedPath; | ||
if (!CResourceFile::TranslatePath(url, translatedPath)) | ||
return ""; | ||
|
||
return translatedPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
/* | ||
* Copyright (C) 2014 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "filesystem/OverrideDirectory.h" | ||
|
||
namespace XFILE | ||
{ | ||
class CResourceDirectory : public COverrideDirectory | ||
{ | ||
public: | ||
CResourceDirectory(); | ||
virtual ~CResourceDirectory(); | ||
|
||
virtual bool GetDirectory(const CURL& url, CFileItemList &items); | ||
|
||
protected: | ||
virtual std::string TranslatePath(const CURL &url); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2014 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "ResourceFile.h" | ||
#include "URL.h" | ||
#include "Util.h" | ||
#include "addons/AddonManager.h" | ||
#include "addons/Resource.h" | ||
#include "utils/StringUtils.h" | ||
#include "utils/URIUtils.h" | ||
|
||
#include <sys/stat.h> | ||
|
||
using namespace ADDON; | ||
using namespace XFILE; | ||
|
||
CResourceFile::CResourceFile() | ||
: COverrideFile(false) | ||
{ } | ||
|
||
CResourceFile::~CResourceFile() | ||
{ } | ||
|
||
bool CResourceFile::TranslatePath(const std::string &path, std::string &translatedPath) | ||
{ | ||
return TranslatePath(CURL(path), translatedPath); | ||
} | ||
|
||
bool CResourceFile::TranslatePath(const CURL &url, std::string &translatedPath) | ||
{ | ||
translatedPath = url.Get(); | ||
|
||
// only handle resource:// paths | ||
if (!url.IsProtocol("resource")) | ||
return false; | ||
|
||
// the share name represents an identifier that can be mapped to an addon ID | ||
std::string addonId = url.GetHostName(); | ||
if (addonId.empty()) | ||
return false; | ||
|
||
AddonPtr addon; | ||
if (!CAddonMgr::Get().GetAddon(addonId, addon, ADDON_UNKNOWN, true) || addon == NULL) | ||
return false; | ||
|
||
std::shared_ptr<CResource> resource = std::dynamic_pointer_cast<ADDON::CResource>(addon); | ||
if (resource == NULL) | ||
return false; | ||
|
||
std::string filePath = url.GetFileName(); | ||
if (!resource->IsAllowed(filePath)) | ||
return false; | ||
|
||
translatedPath = CUtil::ValidatePath(URIUtils::AddFileToFolder(addon->Path(), "resources/" + filePath)); | ||
return true; | ||
} | ||
|
||
std::string CResourceFile::TranslatePath(const CURL &url) | ||
{ | ||
std::string translatedPath; | ||
if (!TranslatePath(url, translatedPath)) | ||
return ""; | ||
|
||
return translatedPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
/* | ||
* Copyright (C) 2014 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "filesystem/OverrideFile.h" | ||
|
||
namespace XFILE | ||
{ | ||
class CResourceFile : public COverrideFile | ||
{ | ||
public: | ||
CResourceFile(); | ||
virtual ~CResourceFile(); | ||
|
||
static bool TranslatePath(const std::string &path, std::string &translatedPath); | ||
static bool TranslatePath(const CURL &url, std::string &translatedPath); | ||
|
||
protected: | ||
virtual std::string TranslatePath(const CURL &url); | ||
}; | ||
} |