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.
15 class CAdvancedSettings
;
21 static void RegisterAdvancedSettings(const CAdvancedSettings
& advancedSettings
);
22 static void UnregisterAdvancedSettings();
24 static std::string
GetDirectory(const std::string
&strFilePath
);
26 static std::string
GetFileName(const CURL
& url
);
27 static std::string
GetFileName(const std::string
& strFileNameAndPath
);
29 static std::string
GetExtension(const CURL
& url
);
30 static std::string
GetExtension(const std::string
& strFileName
);
33 /*! \brief Check if the CFileItem has a plugin path.
34 \param item The CFileItem.
35 \return true if there is a plugin path, false otherwise.
37 static bool HasPluginPath(const CFileItem
& item
);
40 \brief Check if there is a file extension
41 \param strFileName Path or URL to check
42 \return \e true if strFileName have an extension.
43 \note Returns false when strFileName is empty.
46 static bool HasExtension(const std::string
& strFileName
);
49 \brief Check if filename have any of the listed extensions
50 \param strFileName Path or URL to check
51 \param strExtensions List of '.' prefixed lowercase extensions separated with '|'
52 \return \e true if strFileName have any one of the extensions.
53 \note The check is case insensitive for strFileName, but requires
54 strExtensions to be lowercase. Returns false when strFileName or
55 strExtensions is empty.
58 static bool HasExtension(const std::string
& strFileName
, const std::string
& strExtensions
);
59 static bool HasExtension(const CURL
& url
, const std::string
& strExtensions
);
61 static void RemoveExtension(std::string
& strFileName
);
62 static std::string
ReplaceExtension(const std::string
& strFile
,
63 const std::string
& strNewExtension
);
64 static void Split(const std::string
& strFileNameAndPath
,
65 std::string
& strPath
, std::string
& strFileName
);
66 static std::vector
<std::string
> SplitPath(const std::string
& strPath
);
68 static void GetCommonPath(std::string
& strParent
, const std::string
& strPath
);
69 static std::string
GetParentPath(const std::string
& strPath
);
70 static bool GetParentPath(const std::string
& strPath
, std::string
& strParent
);
72 /*! \brief Retrieve the base path, accounting for stacks and files in rars.
74 \return the folder that contains the item.
76 static std::string
GetBasePath(const std::string
& strPath
);
78 /* \brief Change the base path of a URL: fromPath/fromFile -> toPath/toFile
79 Handles changes in path separator and filename URL encoding if necessary to derive toFile.
80 \param fromPath the base path of the original URL
81 \param fromFile the filename portion of the original URL
82 \param toPath the base path of the resulting URL
83 \return the full path.
85 static std::string
ChangeBasePath(const std::string
&fromPath
, const std::string
&fromFile
, const std::string
&toPath
, const bool &bAddPath
= true);
87 static CURL
SubstitutePath(const CURL
& url
, bool reverse
= false);
88 static std::string
SubstitutePath(const std::string
& strPath
, bool reverse
= false);
90 /*! \brief Check whether a URL is a given URL scheme.
91 Comparison is case-insensitive as per RFC1738
92 \param url a std::string path.
93 \param type a lower-case scheme name, e.g. "smb".
94 \return true if the url is of the given scheme, false otherwise.
95 \sa PathHasParent, PathEquals
97 static bool IsProtocol(const std::string
& url
, const std::string
& type
);
99 /*! \brief Check whether a path has a given parent.
100 Comparison is case-sensitive.
101 Use IsProtocol() to compare the protocol portion only.
102 \param path a std::string path.
103 \param parent the string the parent of the path should be compared against.
104 \param translate whether to translate any special paths into real paths
105 \return true if the path has the given parent string, false otherwise.
106 \sa IsProtocol, PathEquals
108 static bool PathHasParent(std::string path
, std::string parent
, bool translate
= false);
110 /*! \brief Check whether a path equals another path.
111 Comparison is case-sensitive.
112 \param path1 a std::string path.
113 \param path2 the second path the path should be compared against.
114 \param ignoreTrailingSlash ignore any trailing slashes in both paths
115 \return true if the paths are equal, false otherwise.
116 \sa IsProtocol, PathHasParent
118 static bool PathEquals(std::string path1
, std::string path2
, bool ignoreTrailingSlash
= false, bool ignoreURLOptions
= false);
120 static bool IsAddonsPath(const std::string
& strFile
);
121 static bool IsSourcesPath(const std::string
& strFile
);
122 static bool IsCDDA(const std::string
& strFile
);
123 static bool IsDAV(const std::string
& strFile
);
124 static bool IsDOSPath(const std::string
&path
);
125 static bool IsDVD(const std::string
& strFile
);
126 static bool IsFTP(const std::string
& strFile
);
127 static bool IsHTTP(const std::string
& strFile
, bool bTranslate
= false);
128 static bool IsUDP(const std::string
& strFile
);
129 static bool IsTCP(const std::string
& strFile
);
130 static bool IsHD(const std::string
& strFileName
);
131 static bool IsInArchive(const std::string
& strFile
);
132 static bool IsInRAR(const std::string
& strFile
);
133 static bool IsInternetStream(const std::string
& path
, bool bStrictCheck
= false);
134 static bool IsInternetStream(const CURL
& url
, bool bStrictCheck
= false);
135 static bool IsStreamedFilesystem(const std::string
& strPath
);
136 static bool IsNetworkFilesystem(const std::string
& strPath
);
137 static bool IsInAPK(const std::string
& strFile
);
138 static bool IsInZIP(const std::string
& strFile
);
139 static bool IsISO9660(const std::string
& strFile
);
140 static bool IsLiveTV(const std::string
& strFile
);
141 static bool IsPVRRecording(const std::string
& strFile
);
142 static bool IsPVRRecordingFileOrFolder(const std::string
& strFile
);
143 static bool IsPVRTVRecordingFileOrFolder(const std::string
& strFile
);
144 static bool IsPVRRadioRecordingFileOrFolder(const std::string
& strFile
);
145 static bool IsMultiPath(const std::string
& strPath
);
146 static bool IsMusicDb(const std::string
& strFile
);
147 static bool IsNfs(const std::string
& strFile
);
148 static bool IsOnDVD(const std::string
& strFile
);
149 static bool IsOnLAN(const std::string
& strFile
);
150 static bool IsHostOnLAN(const std::string
& hostName
, bool offLineCheck
= false);
151 static bool IsPlugin(const std::string
& strFile
);
152 static bool IsScript(const std::string
& strFile
);
153 static bool IsRAR(const std::string
& strFile
);
154 static bool IsRemote(const std::string
& strFile
);
155 static bool IsSmb(const std::string
& strFile
);
156 static bool IsSpecial(const std::string
& strFile
);
157 static bool IsStack(const std::string
& strFile
);
158 static bool IsFavourite(const std::string
& strFile
);
159 static bool IsUPnP(const std::string
& strFile
);
160 static bool IsURL(const std::string
& strFile
);
161 static bool IsVideoDb(const std::string
& strFile
);
162 static bool IsAPK(const std::string
& strFile
);
163 static bool IsZIP(const std::string
& strFile
);
164 static bool IsArchive(const std::string
& strFile
);
165 static bool IsBluray(const std::string
& strFile
);
166 static bool IsAndroidApp(const std::string
& strFile
);
167 static bool IsLibraryFolder(const std::string
& strFile
);
168 static bool IsLibraryContent(const std::string
& strFile
);
169 static bool IsPVR(const std::string
& strFile
);
170 static bool IsPVRChannel(const std::string
& strFile
);
171 static bool IsPVRChannelGroup(const std::string
& strFile
);
172 static bool IsPVRGuideItem(const std::string
& strFile
);
174 static std::string
AppendSlash(std::string strFolder
);
175 static void AddSlashAtEnd(std::string
& strFolder
);
176 static bool HasSlashAtEnd(const std::string
& strFile
, bool checkURL
= false);
177 static void RemoveSlashAtEnd(std::string
& strFolder
);
178 static bool CompareWithoutSlashAtEnd(const std::string
& strPath1
, const std::string
& strPath2
);
179 static std::string
FixSlashesAndDups(const std::string
& path
, const char slashCharacter
= '/', const size_t startFrom
= 0);
181 * Convert path to form without duplicated slashes and without relative directories
182 * Strip duplicated slashes
183 * Resolve and remove relative directories ("/../" and "/./")
184 * Will ignore slashes with other direction than specified
185 * Will not resolve path starting from relative directory
186 * @warning Don't use with "protocol://path"-style URLs
187 * @param path string to process
188 * @param slashCharacter character to use as directory delimiter
189 * @return transformed path
191 static std::string
CanonicalizePath(const std::string
& path
, const char slashCharacter
= '\\');
193 static CURL
CreateArchivePath(const std::string
& type
,
194 const CURL
& archiveUrl
,
195 const std::string
& pathInArchive
= "",
196 const std::string
& password
= "");
198 static std::string
AddFileToFolder(const std::string
& strFolder
, const std::string
& strFile
);
199 template <typename
... T
>
200 static std::string
AddFileToFolder(const std::string
& strFolder
, const std::string
& strFile
, T
... args
)
202 auto newPath
= AddFileToFolder(strFolder
, strFile
);
203 return AddFileToFolder(newPath
, args
...);
206 static bool HasParentInHostname(const CURL
& url
);
207 static bool HasEncodedHostname(const CURL
& url
);
208 static bool HasEncodedFilename(const CURL
& url
);
211 \brief Cleans up the given path by resolving "." and ".."
214 This methods goes through the given path and removes any "."
215 (as it states "this directory") and resolves any ".." by
216 removing the previous directory from the path. This is done
217 for file paths and host names (in case of VFS paths).
219 \param path Path to be cleaned up
220 \return Actual path without any "." or ".."
222 static std::string
GetRealPath(const std::string
&path
);
225 \brief Updates the URL encoded hostname of the given path
227 This method must only be used to update paths encoded with
228 the old (Eden) URL encoding implementation to the new (Frodo)
229 URL encoding implementation (which does not URL encode -_.!().
231 \param strFilename Path to update
232 \return True if the path has been updated/changed otherwise false
234 static bool UpdateUrlEncoding(std::string
&strFilename
);
237 static std::string
resolvePath(const std::string
&path
);
239 static const CAdvancedSettings
* m_advancedSettings
;