Skip to content

Commit

Permalink
fixed: Path substitution didn't work for files (only library items)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnova committed Nov 5, 2013
1 parent ecdb733 commit d88e5dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
21 changes: 16 additions & 5 deletions xbmc/filesystem/Directory.cpp
Expand Up @@ -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;
};

Expand All @@ -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;
Expand All @@ -76,8 +77,8 @@ class CGetDirectory

public:

CGetDirectory(boost::shared_ptr<IDirectory>& imp, const CStdString& dir)
: m_result(new CResult(dir))
CGetDirectory(boost::shared_ptr<IDirectory>& imp, const CStdString& dir, const CStdString& listDir)
: m_result(new CResult(dir, listDir))
{
m_id = CJobManager::GetInstance().AddJob(new CGetJob(imp, m_result)
, NULL
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions xbmc/utils/URIUtils.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/utils/URIUtils.h
Expand Up @@ -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);
Expand Down

0 comments on commit d88e5dd

Please sign in to comment.