diff options
-rw-r--r-- | xbmc/FileSystem/Directory.cpp | 34 | ||||
-rw-r--r-- | xbmc/FileSystem/Directory.h | 6 | ||||
-rw-r--r-- | xbmc/FileSystem/File.cpp | 22 |
3 files changed, 44 insertions, 18 deletions
diff --git a/xbmc/FileSystem/Directory.cpp b/xbmc/FileSystem/Directory.cpp index 592c0141c5..bb09cb6990 100644 --- a/xbmc/FileSystem/Directory.cpp +++ b/xbmc/FileSystem/Directory.cpp @@ -36,6 +36,7 @@ #include "GUIDialogBusy.h" #include "SingleLock.h" #include "Util.h" +#include "AdvancedSettings.h" using namespace std; using namespace XFILE; @@ -124,7 +125,8 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C { try { - auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(strPath)); + CStdString realPath = Translate(strPath); + auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(realPath)); if (!pDirectory.get()) return false; @@ -150,7 +152,7 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C { CSingleExit ex(g_graphicsContext); - CGetDirectory get(*pDirectory, strPath); + CGetDirectory get(*pDirectory, realPath); if(!get.Wait(TIME_TO_BUSY_DIALOG)) { CGUIDialogBusy* dialog = NULL; @@ -186,7 +188,7 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C else { items.m_strPath = strPath; - result = pDirectory->GetDirectory(strPath, items); + result = pDirectory->GetDirectory(realPath, items); } if (!result) @@ -243,9 +245,10 @@ bool CDirectory::Create(const CStdString& strPath) { try { - auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(strPath)); + CStdString realPath = Translate(strPath); + auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(realPath)); if (pDirectory.get()) - if(pDirectory->Create(strPath.c_str())) + if(pDirectory->Create(realPath.c_str())) return true; } #ifndef _LINUX @@ -266,9 +269,10 @@ bool CDirectory::Exists(const CStdString& strPath) { try { - auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(strPath)); + CStdString realPath = Translate(strPath); + auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(realPath)); if (pDirectory.get()) - return pDirectory->Exists(strPath.c_str()); + return pDirectory->Exists(realPath.c_str()); } #ifndef _LINUX catch (const win32_exception &e) @@ -288,9 +292,10 @@ bool CDirectory::Remove(const CStdString& strPath) { try { - auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(strPath)); + CStdString realPath = Translate(strPath); + auto_ptr<IDirectory> pDirectory(CFactoryDirectory::Create(realPath)); if (pDirectory.get()) - if(pDirectory->Remove(strPath.c_str())) + if(pDirectory->Remove(realPath.c_str())) return true; } #ifndef _LINUX @@ -326,3 +331,14 @@ void CDirectory::FilterFileDirectories(CFileItemList &items, const CStdString &m } } } + +CStdString CDirectory::Translate(const CStdString &path) +{ + for (CAdvancedSettings::StringMapping::iterator i = g_advancedSettings.m_pathSubstitutions.begin(); + i != g_advancedSettings.m_pathSubstitutions.end(); i++) + { + if (strncmp(path.c_str(), i->first.c_str(), i->first.size()) == 0) + return CUtil::AddFileToFolder(i->second, path.Mid(i->first.size())); + } + return path; +} diff --git a/xbmc/FileSystem/Directory.h b/xbmc/FileSystem/Directory.h index 7ad728a011..84c4a73db9 100644 --- a/xbmc/FileSystem/Directory.h +++ b/xbmc/FileSystem/Directory.h @@ -52,5 +52,11 @@ public: \param items The item list to filter \param mask The mask to apply when filtering files */ static void FilterFileDirectories(CFileItemList &items, const CStdString &mask); + + /*! \brief Apply users path translation to a path, returning the translated path + \param path the path to fetch + \return translated path based on user path<->path translation table. + */ + static CStdString Translate(const CStdString &path); }; } diff --git a/xbmc/FileSystem/File.cpp b/xbmc/FileSystem/File.cpp index dedeecfde7..38b44128d9 100644 --- a/xbmc/FileSystem/File.cpp +++ b/xbmc/FileSystem/File.cpp @@ -23,6 +23,7 @@ #include "Application.h" #include "Util.h" #include "DirectoryCache.h" +#include "Directory.h" #include "FileCache.h" #include "utils/log.h" @@ -220,7 +221,7 @@ bool CFile::Open(const CStdString& strFileName, unsigned int flags) return false; } - CURL url(strFileName); + CURL url(CDirectory::Translate(strFileName)); if ( (flags & READ_NO_CACHE) == 0 && CUtil::IsInternetStream(url) && !CUtil::IsPicture(strFileName) ) m_flags |= READ_CACHED; @@ -300,7 +301,7 @@ bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite) { try { - CURL url(strFileName); + CURL url(CDirectory::Translate(strFileName)); m_pFile = CFileFactory::CreateLoader(url); if (m_pFile && m_pFile->OpenForWrite(url, bOverWrite)) @@ -341,7 +342,7 @@ bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */) return false; } - CURL url(strFileName); + CURL url(CDirectory::Translate(strFileName)); auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) @@ -372,7 +373,7 @@ int CFile::Stat(const CStdString& strFileName, struct __stat64* buffer) { try { - CURL url(strFileName); + CURL url(CDirectory::Translate(strFileName)); auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) @@ -683,7 +684,7 @@ bool CFile::Delete(const CStdString& strFileName) { try { - CURL url(strFileName); + CURL url(CDirectory::Translate(strFileName)); auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) @@ -718,8 +719,8 @@ bool CFile::Rename(const CStdString& strFileName, const CStdString& strNewFileNa { try { - CURL url(strFileName); - CURL urlnew(strNewFileName); + CURL url(CDirectory::Translate(strFileName)); + CURL urlnew(CDirectory::Translate(strNewFileName)); auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) @@ -750,7 +751,7 @@ bool CFile::SetHidden(const CStdString& fileName, bool hidden) { try { - CURL url(fileName); + CURL url(CDirectory::Translate(fileName)); auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) @@ -927,6 +928,9 @@ bool CFileStream::Open(const CURL& filename) { Close(); + // NOTE: This is currently not translated - reason is that all entry points into CFileStream::Open currently + // go from the CStdString version below. We may have to change this in future, but I prefer not decoding + // the URL and re-encoding, or applying the translation twice. m_file = CFileFactory::CreateLoader(filename); if(m_file && m_file->Open(filename)) { @@ -954,7 +958,7 @@ void CFileStream::Close() bool CFileStream::Open(const CStdString& filename) { - return Open(CURL(filename)); + return Open(CURL(CDirectory::Translate(filename))); } #ifdef _ARMEL |