diff --git a/xbmc/filesystem/DirectoryFactory.cpp b/xbmc/filesystem/DirectoryFactory.cpp
index 12fff33bd8f51..327d815524bca 100644
--- a/xbmc/filesystem/DirectoryFactory.cpp
+++ b/xbmc/filesystem/DirectoryFactory.cpp
@@ -118,6 +118,7 @@
#if defined(TARGET_ANDROID)
#include "AndroidAppDirectory.h"
#endif
+#include "ResourceDirectory.h"
using namespace XFILE;
@@ -242,6 +243,7 @@ IDirectory* CDirectoryFactory::Create(const CURL& url)
#ifdef HAVE_LIBBLURAY
if (url.IsProtocol("bluray")) return new CBlurayDirectory();
#endif
+ if (url.IsProtocol("resource")) return new CResourceDirectory();
}
CLog::Log(LOGWARNING, "%s - %sunsupported protocol(%s) in %s", __FUNCTION__, networkAvailable ? "" : "Network down or ", url.GetProtocol().c_str(), url.GetRedacted().c_str() );
diff --git a/xbmc/filesystem/FileFactory.cpp b/xbmc/filesystem/FileFactory.cpp
index f9df33a3cdb77..38c6814775870 100644
--- a/xbmc/filesystem/FileFactory.cpp
+++ b/xbmc/filesystem/FileFactory.cpp
@@ -98,6 +98,7 @@
#include "HDHomeRunFile.h"
#include "SlingboxFile.h"
#include "ImageFile.h"
+#include "ResourceFile.h"
#include "Application.h"
#include "URL.h"
#include "utils/log.h"
@@ -213,6 +214,7 @@ IFile* CFileFactory::CreateLoader(const CURL& url)
#ifdef HAVE_LIBBLURAY
else if (url.IsProtocol("bluray")) return new CBlurayFile();
#endif
+ else if (url.IsProtocol("resource")) return new CResourceFile();
}
CLog::Log(LOGWARNING, "%s - %sunsupported protocol(%s) in %s", __FUNCTION__, networkAvailable ? "" : "Network down or ", url.GetProtocol().c_str(), url.GetRedacted().c_str());
diff --git a/xbmc/filesystem/Makefile.in b/xbmc/filesystem/Makefile.in
index 72b51260216d5..7cb3de87f0b33 100644
--- a/xbmc/filesystem/Makefile.in
+++ b/xbmc/filesystem/Makefile.in
@@ -61,6 +61,8 @@ SRCS += posix/PosixDirectory.cpp
SRCS += posix/PosixFile.cpp
SRCS += PVRFile.cpp
SRCS += PVRDirectory.cpp
+SRCS += ResourceDirectory.cpp
+SRCS += ResourceFile.cpp
SRCS += RSSDirectory.cpp
SRCS += RTVDirectory.cpp
SRCS += RTVFile.cpp
diff --git a/xbmc/filesystem/ResourceDirectory.cpp b/xbmc/filesystem/ResourceDirectory.cpp
new file mode 100644
index 0000000000000..321d4d613c0d5
--- /dev/null
+++ b/xbmc/filesystem/ResourceDirectory.cpp
@@ -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
+ * .
+ *
+ */
+
+#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;
+}
diff --git a/xbmc/filesystem/ResourceDirectory.h b/xbmc/filesystem/ResourceDirectory.h
new file mode 100644
index 0000000000000..5f1e420a20fe8
--- /dev/null
+++ b/xbmc/filesystem/ResourceDirectory.h
@@ -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
+ * .
+ *
+ */
+
+#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);
+ };
+}
diff --git a/xbmc/filesystem/ResourceFile.cpp b/xbmc/filesystem/ResourceFile.cpp
new file mode 100644
index 0000000000000..dfdcc1e493c4d
--- /dev/null
+++ b/xbmc/filesystem/ResourceFile.cpp
@@ -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
+ * .
+ *
+ */
+
+#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
+
+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 resource = std::dynamic_pointer_cast(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;
+}
diff --git a/xbmc/filesystem/ResourceFile.h b/xbmc/filesystem/ResourceFile.h
new file mode 100644
index 0000000000000..3a6eb5bfd8ada
--- /dev/null
+++ b/xbmc/filesystem/ResourceFile.h
@@ -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
+ * .
+ *
+ */
+
+#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);
+};
+}