From d88e5dd040cb089a288e2ac07d51c2cf44b5543f Mon Sep 17 00:00:00 2001 From: arnova Date: Sun, 3 Nov 2013 16:18:25 +0100 Subject: [PATCH] fixed: Path substitution didn't work for files (only library items) --- xbmc/filesystem/Directory.cpp | 21 ++++++++++++++++----- xbmc/utils/URIUtils.cpp | 25 +++++++++++++++++++------ xbmc/utils/URIUtils.h | 2 +- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/xbmc/filesystem/Directory.cpp b/xbmc/filesystem/Directory.cpp index 3a2b5c79432ec..de98f21b67180 100644 --- a/xbmc/filesystem/Directory.cpp +++ b/xbmc/filesystem/Directory.cpp @@ -46,10 +46,11 @@ class CGetDirectory struct CResult { - CResult(const CStdString& dir) : m_event(true), m_dir(dir), m_result(false) {} + CResult(const CStdString& dir, const CStdString& listDir) : m_event(true), m_dir(dir), m_listDir(listDir), m_result(false) {} CEvent m_event; CFileItemList m_list; CStdString m_dir; + CStdString m_listDir; bool m_result; }; @@ -64,7 +65,7 @@ class CGetDirectory public: virtual bool DoWork() { - m_result->m_list.SetPath(m_result->m_dir); + m_result->m_list.SetPath(m_result->m_listDir); m_result->m_result = m_imp->GetDirectory(m_result->m_dir, m_result->m_list); m_result->m_event.Set(); return m_result->m_result; @@ -76,8 +77,8 @@ class CGetDirectory public: - CGetDirectory(boost::shared_ptr& imp, const CStdString& dir) - : m_result(new CResult(dir)) + CGetDirectory(boost::shared_ptr& imp, const CStdString& dir, const CStdString& listDir) + : m_result(new CResult(dir, listDir)) { m_id = CJobManager::GetInstance().AddJob(new CGetJob(imp, m_result) , NULL @@ -152,7 +153,7 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, c { CSingleExit ex(g_graphicsContext); - CGetDirectory get(pDirectory, realPath); + CGetDirectory get(pDirectory, realPath, strPath); if(!get.Wait(TIME_TO_BUSY_DIALOG)) { CGUIDialogBusy* dialog = (CGUIDialogBusy*)g_windowManager.GetWindow(WINDOW_DIALOG_BUSY); @@ -222,6 +223,16 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, c if (!(hints.flags & DIR_FLAG_NO_FILE_DIRS) && !items.IsMusicDb() && !items.IsVideoDb() && !items.IsSmartPlayList()) FilterFileDirectories(items, hints.mask); + // Correct items for path substitution + if (strPath != realPath) + { + for (int i = 0; i < items.Size(); ++i) + { + CFileItemPtr item = items[i]; + item->SetPath(URIUtils::SubstitutePath(item->GetPath(), true)); + } + } + return true; } XBMCCOMMONS_HANDLE_UNCHECKED diff --git a/xbmc/utils/URIUtils.cpp b/xbmc/utils/URIUtils.cpp index 3d9e914f39c50..bda6246b0d120 100644 --- a/xbmc/utils/URIUtils.cpp +++ b/xbmc/utils/URIUtils.cpp @@ -405,17 +405,30 @@ bool URIUtils::GetParentPath(const CStdString& strPath, CStdString& strParent) return true; } -CStdString URIUtils::SubstitutePath(const CStdString& strPath) +CStdString URIUtils::SubstitutePath(const CStdString& strPath, bool reverse /* = false */) { for (CAdvancedSettings::StringMapping::iterator i = g_advancedSettings.m_pathSubstitutions.begin(); i != g_advancedSettings.m_pathSubstitutions.end(); i++) { - if (strncmp(strPath.c_str(), i->first.c_str(), HasSlashAtEnd(i->first.c_str()) ? i->first.size()-1 : i->first.size()) == 0) + if (!reverse) { - if (strPath.size() > i->first.size()) - return URIUtils::AddFileToFolder(i->second, strPath.Mid(i->first.size())); - else - return i->second; + if (strncmp(strPath.c_str(), i->first.c_str(), HasSlashAtEnd(i->first.c_str()) ? i->first.size()-1 : i->first.size()) == 0) + { + if (strPath.size() > i->first.size()) + return URIUtils::AddFileToFolder(i->second, strPath.Mid(i->first.size())); + else + return i->second; + } + } + else + { + if (strncmp(strPath.c_str(), i->second.c_str(), HasSlashAtEnd(i->second.c_str()) ? i->second.size()-1 : i->second.size()) == 0) + { + if (strPath.size() > i->second.size()) + return URIUtils::AddFileToFolder(i->first, strPath.Mid(i->second.size())); + else + return i->second; + } } } return strPath; diff --git a/xbmc/utils/URIUtils.h b/xbmc/utils/URIUtils.h index 7844509b1d3e5..146bf5cd019e0 100644 --- a/xbmc/utils/URIUtils.h +++ b/xbmc/utils/URIUtils.h @@ -68,7 +68,7 @@ class URIUtils static void GetCommonPath(CStdString& strPath, const CStdString& strPath2); static CStdString GetParentPath(const CStdString& strPath); static bool GetParentPath(const CStdString& strPath, CStdString& strParent); - static CStdString SubstitutePath(const CStdString& strPath); + static CStdString SubstitutePath(const CStdString& strPath, bool reverse = false); static bool IsAddonsPath(const CStdString& strFile); static bool IsSourcesPath(const CStdString& strFile);