Merge pull request #25808 from CastagnaIT/fix_url_parse
[xbmc.git] / xbmc / filesystem / Directory.h
blob08067ac1d54fed0e223ffedcf8336f05a2af9971
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "IDirectory.h"
13 #include <functional>
14 #include <memory>
15 #include <string>
17 class CFileItem;
19 namespace XFILE
21 /*!
22 \ingroup filesystem
23 \brief Wrappers for \e IDirectory
25 class CDirectory
27 public:
28 CDirectory(void);
29 virtual ~CDirectory(void);
31 class CHints
33 public:
34 std::string mask;
35 int flags = DIR_FLAG_DEFAULTS;
38 static bool GetDirectory(const CURL& url
39 , CFileItemList &items
40 , const std::string &strMask
41 , int flags);
43 static bool GetDirectory(const CURL& url,
44 const std::shared_ptr<IDirectory>& pDirectory,
45 CFileItemList& items,
46 const CHints& hints);
48 static bool GetDirectory(const CURL& url
49 , CFileItemList &items
50 , const CHints &hints);
52 static bool Create(const CURL& url);
53 static bool Exists(const CURL& url, bool bUseCache = true);
54 static bool Remove(const CURL& url);
55 static bool RemoveRecursive(const CURL& url);
57 static bool GetDirectory(const std::string& strPath
58 , CFileItemList &items
59 , const std::string &strMask
60 , int flags);
62 static bool GetDirectory(const std::string& strPath,
63 const std::shared_ptr<IDirectory>& pDirectory,
64 CFileItemList& items,
65 const std::string& strMask,
66 int flags);
68 static bool GetDirectory(const std::string& strPath
69 , CFileItemList &items
70 , const CHints &hints);
72 using DirectoryEnumerationCallback = std::function<void(const std::shared_ptr<CFileItem>& item)>;
73 using DirectoryFilter = std::function<bool(const std::shared_ptr<CFileItem>& folder)>;
75 /*!
76 * \brief Enumerates files and folders in and below a directory. Every applicable gets passed to the callback.
78 * \param path Directory to enumerate
79 * \param callback Files and folders matching the criteria are passed to this function
80 * \param filter Only folders are passed to this function. If it return false the folder and everything below it will skipped from the enumeration
81 * \param fileOnly If true only files are passed to \p callback. Doesn't affect \p filter
82 * \param mask Only files matching this mask are passed to \p callback
83 * \param flags See \ref DIR_FLAG enum
85 static bool EnumerateDirectory(
86 const std::string& path,
87 const DirectoryEnumerationCallback& callback,
88 const DirectoryFilter& filter = [](const std::shared_ptr<CFileItem>&) { return true; },
89 bool fileOnly = false,
90 const std::string& mask = "",
91 int flags = DIR_FLAG_DEFAULTS);
93 static bool Create(const std::string& strPath);
94 static bool Exists(const std::string& strPath, bool bUseCache = true);
95 static bool Remove(const std::string& strPath);
96 static bool RemoveRecursive(const std::string& strPath);
98 /*! \brief Filter files that act like directories from the list, replacing them with their directory counterparts
99 \param items The item list to filter
100 \param mask The mask to apply when filtering files
101 \param expandImages True to include disc images in file directory expansion
103 static void FilterFileDirectories(CFileItemList &items, const std::string &mask,
104 bool expandImages=false);