summaryrefslogtreecommitdiffstats
path: root/xbmc/filesystem/ResourceDirectory.cpp
blob: c3623d0ce040cfd523c4b079a415426b572f0b01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 *  Copyright (C) 2014-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "ResourceDirectory.h"

#include "FileItem.h"
#include "URL.h"
#include "filesystem/Directory.h"
#include "filesystem/ResourceFile.h"
#include "utils/URIUtils.h"

using namespace XFILE;

CResourceDirectory::CResourceDirectory() = default;

CResourceDirectory::~CResourceDirectory() = default;

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 (URIUtils::PathHasParent(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;
}