Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Filesystem.h
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "AddonBase.h"
12#include "c-api/filesystem.h"
13
14#ifdef __cplusplus
15
16#include <cstring>
17#include <map>
18#include <vector>
19
20namespace kodi
21{
22namespace vfs
23{
24
25//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
26// Main page text for filesystem group by Doxygen.
27//{{{
28
29//==============================================================================
48//------------------------------------------------------------------------------
49
50//==============================================================================
56//------------------------------------------------------------------------------
57
58//==============================================================================
64//------------------------------------------------------------------------------
65
66//==============================================================================
72//------------------------------------------------------------------------------
73
74//==============================================================================
80//------------------------------------------------------------------------------
81
82//}}}
83
84//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
85// "C++" related filesystem definitions
86//{{{
87
88//==============================================================================
95class ATTR_DLL_LOCAL FileStatus : public kodi::addon::CStructHdl<FileStatus, STAT_STRUCTURE>
96{
97public:
99 FileStatus() { memset(m_cStructure, 0, sizeof(STAT_STRUCTURE)); }
100 FileStatus(const FileStatus& channel) : CStructHdl(channel) {}
101 FileStatus(const STAT_STRUCTURE* channel) : CStructHdl(channel) {}
102 FileStatus(STAT_STRUCTURE* channel) : CStructHdl(channel) {}
126
130
132 void SetDeviceId(uint32_t deviceId) { m_cStructure->deviceId = deviceId; }
133
135 uint32_t GetDeviceId() const { return m_cStructure->deviceId; }
136
138 void SetFileSerialNumber(uint64_t fileSerialNumber)
139 {
140 m_cStructure->fileSerialNumber = fileSerialNumber;
141 }
142
144 uint64_t GetFileSerialNumber() const { return m_cStructure->fileSerialNumber; }
145
147 void SetSize(uint64_t size) { m_cStructure->size = size; }
148
150 uint64_t GetSize() const { return m_cStructure->size; }
151
153 void SetAccessTime(time_t accessTime) { m_cStructure->accessTime = accessTime; }
154
156 time_t GetAccessTime() const { return m_cStructure->accessTime; }
157
159 void SetModificationTime(time_t modificationTime)
160 {
161 m_cStructure->modificationTime = modificationTime;
162 }
163
165 time_t GetModificationTime() const { return m_cStructure->modificationTime; }
166
168 void SetStatusTime(time_t statusTime) { m_cStructure->statusTime = statusTime; }
169
171 time_t GetStatusTime() const { return m_cStructure->statusTime; }
172
174 void SetIsDirectory(bool isDirectory) { m_cStructure->isDirectory = isDirectory; }
175
177 bool GetIsDirectory() const { return m_cStructure->isDirectory; }
178
180 void SetIsSymLink(bool isSymLink) { m_cStructure->isSymLink = isSymLink; }
181
183 bool GetIsSymLink() const { return m_cStructure->isSymLink; }
184
186 void SetIsBlock(bool isBlock) { m_cStructure->isBlock = isBlock; }
187
189 bool GetIsBlock() const { return m_cStructure->isBlock; }
190
192 void SetIsCharacter(bool isCharacter) { m_cStructure->isCharacter = isCharacter; }
193
195 bool GetIsCharacter() const { return m_cStructure->isCharacter; }
196
198 void SetIsFifo(bool isFifo) { m_cStructure->isFifo = isFifo; }
199
201 bool GetIsFifo() const { return m_cStructure->isFifo; }
202
204 void SetIsRegular(bool isRegular) { m_cStructure->isRegular = isRegular; }
205
207 bool GetIsRegular() const { return m_cStructure->isRegular; }
208
210 void SetIsSocket(bool isSocket) { m_cStructure->isSocket = isSocket; }
211
213 bool GetIsSocket() const { return m_cStructure->isSocket; }
215};
217//------------------------------------------------------------------------------
218
219//==============================================================================
227class ATTR_DLL_LOCAL CacheStatus
228 : public kodi::addon::CStructHdl<CacheStatus, VFS_CACHE_STATUS_DATA>
229{
230public:
232 CacheStatus() { memset(m_cStructure, 0, sizeof(VFS_CACHE_STATUS_DATA)); }
233 CacheStatus(const CacheStatus& channel) : CStructHdl(channel) {}
234 CacheStatus(const VFS_CACHE_STATUS_DATA* channel) : CStructHdl(channel) {}
235 CacheStatus(VFS_CACHE_STATUS_DATA* channel) : CStructHdl(channel) {}
250
254
256 void SetForward(uint64_t forward) { m_cStructure->forward = forward; }
257
259 uint64_t GetForward() { return m_cStructure->forward; }
260
262 void SetMaxRate(uint32_t maxrate) { m_cStructure->maxrate = maxrate; }
263
265 uint32_t GetMaxRate() { return m_cStructure->maxrate; }
266
268 void SetCurrentRate(uint32_t currate) { m_cStructure->currate = currate; }
269
271 uint32_t GetCurrentRate() { return m_cStructure->currate; }
272
274 void SetLowRate(uint32_t lowrate) { m_cStructure->lowrate = lowrate; }
275
277 uint32_t GetLowRate() { return m_cStructure->lowrate; }
278
280};
282//------------------------------------------------------------------------------
283
284//==============================================================================
297class ATTR_DLL_LOCAL HttpHeader
298{
299public:
300 //==========================================================================
304 {
305 using namespace ::kodi::addon;
306
307 CPrivateBase::m_interface->toKodi->kodi_filesystem->http_header_create(
308 CPrivateBase::m_interface->toKodi->kodiBase, &m_handle);
309 }
310 //--------------------------------------------------------------------------
311
312 //==========================================================================
316 {
317 using namespace ::kodi::addon;
318
319 CPrivateBase::m_interface->toKodi->kodi_filesystem->http_header_free(
320 CPrivateBase::m_interface->toKodi->kodiBase, &m_handle);
321 }
322 //--------------------------------------------------------------------------
323
337
340
341 //==========================================================================
348 std::string GetValue(const std::string& param) const
349 {
350 using namespace ::kodi::addon;
351
352 if (!m_handle.handle)
353 return "";
354
355 std::string protoLine;
356 char* string = m_handle.get_value(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle,
357 param.c_str());
358 if (string != nullptr)
359 {
360 protoLine = string;
361 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
362 string);
363 }
364 return protoLine;
365 }
366 //--------------------------------------------------------------------------
367
368 //==========================================================================
375 std::vector<std::string> GetValues(const std::string& param) const
376 {
377 using namespace kodi::addon;
378
379 if (!m_handle.handle)
380 return std::vector<std::string>();
381
382 int numValues = 0;
383 char** res(m_handle.get_values(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle,
384 param.c_str(), &numValues));
385 if (res)
386 {
387 std::vector<std::string> vecReturn;
388 vecReturn.reserve(numValues);
389 for (int i = 0; i < numValues; ++i)
390 {
391 vecReturn.emplace_back(res[i]);
392 }
393 CPrivateBase::m_interface->toKodi->free_string_array(
394 CPrivateBase::m_interface->toKodi->kodiBase, res, numValues);
395 return vecReturn;
396 }
397 return std::vector<std::string>();
398 }
399 //--------------------------------------------------------------------------
400
401 //==========================================================================
406 std::string GetHeader() const
407 {
408 using namespace ::kodi::addon;
409
410 if (!m_handle.handle)
411 return "";
412
413 std::string header;
414 char* string =
415 m_handle.get_header(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle);
416 if (string != nullptr)
417 {
418 header = string;
419 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
420 string);
421 }
422 return header;
423 }
424 //--------------------------------------------------------------------------
425
426 //==========================================================================
431 std::string GetMimeType() const
432 {
433 using namespace ::kodi::addon;
434
435 if (!m_handle.handle)
436 return "";
437
438 std::string protoLine;
439 char* string =
440 m_handle.get_mime_type(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle);
441 if (string != nullptr)
442 {
443 protoLine = string;
444 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
445 string);
446 }
447 return protoLine;
448 }
449 //--------------------------------------------------------------------------
450
451 //==========================================================================
456 std::string GetCharset() const
457 {
458 using namespace ::kodi::addon;
459
460 if (!m_handle.handle)
461 return "";
462
463 std::string protoLine;
464 char* string =
465 m_handle.get_charset(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle);
466 if (string != nullptr)
467 {
468 protoLine = string;
469 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
470 string);
471 }
472 return protoLine;
473 }
474 //--------------------------------------------------------------------------
475
476 //==========================================================================
481 std::string GetProtoLine() const
482 {
483 using namespace ::kodi::addon;
484
485 if (!m_handle.handle)
486 return "";
487
488 std::string protoLine;
489 char* string =
490 m_handle.get_proto_line(CPrivateBase::m_interface->toKodi->kodiBase, m_handle.handle);
491 if (string != nullptr)
492 {
493 protoLine = string;
494 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
495 string);
496 }
497 return protoLine;
498 }
499 //--------------------------------------------------------------------------
500
502
503 KODI_HTTP_HEADER m_handle;
504};
506//----------------------------------------------------------------------------
507
508//==============================================================================
547class ATTR_DLL_LOCAL CDirEntry
548{
549public:
550 //============================================================================
560 CDirEntry(const std::string& label = "",
561 const std::string& path = "",
562 bool folder = false,
563 int64_t size = -1,
564 time_t dateTime = 0)
565 : m_label(label), m_path(path), m_folder(folder), m_size(size), m_dateTime(dateTime)
566 {
567 }
568 //----------------------------------------------------------------------------
569
570 //============================================================================
571 // @note Not for addon development itself needed, thats why below is
572 // disabled for doxygen!
573 //
574 // @ingroup cpp_kodi_vfs_CDirEntry
575 // @brief Constructor to create own copy
576 //
577 // @param[in] dirEntry pointer to own class type
578 //
579 explicit CDirEntry(const VFSDirEntry& dirEntry)
580 : m_label(dirEntry.label ? dirEntry.label : ""),
581 m_path(dirEntry.path ? dirEntry.path : ""),
582 m_folder(dirEntry.folder),
583 m_size(dirEntry.size),
584 m_dateTime(dirEntry.date_time)
585 {
586 }
587 //----------------------------------------------------------------------------
588
604
608
609 //============================================================================
614 const std::string& Label(void) const { return m_label; }
615 //----------------------------------------------------------------------------
616
617 //============================================================================
622 const std::string& Title(void) const { return m_title; }
623 //----------------------------------------------------------------------------
624
625 //============================================================================
630 const std::string& Path(void) const { return m_path; }
631 //----------------------------------------------------------------------------
632
633 //============================================================================
638 bool IsFolder(void) const { return m_folder; }
639 //----------------------------------------------------------------------------
640
641 //============================================================================
646 int64_t Size(void) const { return m_size; }
647 //----------------------------------------------------------------------------
648
649 //============================================================================
654 time_t DateTime() { return m_dateTime; }
655 //----------------------------------------------------------------------------
656
657 //============================================================================
662 void SetLabel(const std::string& label) { m_label = label; }
663 //----------------------------------------------------------------------------
664
665 //============================================================================
670 void SetTitle(const std::string& title) { m_title = title; }
671 //----------------------------------------------------------------------------
672
673 //============================================================================
678 void SetPath(const std::string& path) { m_path = path; }
679 //----------------------------------------------------------------------------
680
681 //============================================================================
686 void SetFolder(bool folder) { m_folder = folder; }
687 //----------------------------------------------------------------------------
688
689 //============================================================================
694 void SetSize(int64_t size) { m_size = size; }
695 //----------------------------------------------------------------------------
696
697 //============================================================================
702 void SetDateTime(time_t dateTime) { m_dateTime = dateTime; }
703 //----------------------------------------------------------------------------
704
705 //============================================================================
715 void AddProperty(const std::string& id, const std::string& value) { m_properties[id] = value; }
716 //----------------------------------------------------------------------------
717
718 //============================================================================
721 void ClearProperties() { m_properties.clear(); }
722 //----------------------------------------------------------------------------
723
724 //============================================================================
729 const std::map<std::string, std::string>& GetProperties() const { return m_properties; }
730 //----------------------------------------------------------------------------
731
733
734private:
735 std::string m_label;
736 std::string m_title;
737 std::string m_path;
738 std::map<std::string, std::string> m_properties;
739 bool m_folder;
740 int64_t m_size;
741 time_t m_dateTime;
742};
744//------------------------------------------------------------------------------
745
746//}}}
747
748//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
749// "C++" Directory related functions
750//{{{
751
752//==============================================================================
778inline bool ATTR_DLL_LOCAL CreateDirectory(const std::string& path)
779{
780 using namespace kodi::addon;
781
782 return CPrivateBase::m_interface->toKodi->kodi_filesystem->create_directory(
783 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
784}
785//------------------------------------------------------------------------------
786
787//==============================================================================
810inline bool ATTR_DLL_LOCAL DirectoryExists(const std::string& path)
811{
812 using namespace kodi::addon;
813
814 return CPrivateBase::m_interface->toKodi->kodi_filesystem->directory_exists(
815 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
816}
817//------------------------------------------------------------------------------
818
819//==============================================================================
844inline bool ATTR_DLL_LOCAL RemoveDirectory(const std::string& path, bool recursive = false)
845{
846 using namespace kodi::addon;
847
848 if (!recursive)
849 return CPrivateBase::m_interface->toKodi->kodi_filesystem->remove_directory(
850 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
851 else
852 return CPrivateBase::m_interface->toKodi->kodi_filesystem->remove_directory_recursive(
853 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
854}
855//------------------------------------------------------------------------------
856
857//==============================================================================
893inline bool ATTR_DLL_LOCAL GetDirectory(const std::string& path,
894 const std::string& mask,
895 std::vector<kodi::vfs::CDirEntry>& items)
896{
897 using namespace kodi::addon;
898
899 VFSDirEntry* dir_list = nullptr;
900 unsigned int num_items = 0;
901 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->get_directory(
902 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), mask.c_str(), &dir_list,
903 &num_items))
904 {
905 if (dir_list)
906 {
907 for (unsigned int i = 0; i < num_items; ++i)
908 items.emplace_back(dir_list[i]);
909
910 CPrivateBase::m_interface->toKodi->kodi_filesystem->free_directory(
911 CPrivateBase::m_interface->toKodi->kodiBase, dir_list, num_items);
912 }
913
914 return true;
915 }
916 return false;
917}
918//------------------------------------------------------------------------------
919
920//}}}
921
922//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
923// "C++" File related functions
924//{{{
925
926//==============================================================================
945inline bool ATTR_DLL_LOCAL FileExists(const std::string& filename, bool usecache = false)
946{
947 using namespace kodi::addon;
948
949 return CPrivateBase::m_interface->toKodi->kodi_filesystem->file_exists(
950 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), usecache);
951}
952//------------------------------------------------------------------------------
953
954//==============================================================================
1000inline bool ATTR_DLL_LOCAL StatFile(const std::string& filename, kodi::vfs::FileStatus& buffer)
1001{
1002 using namespace kodi::addon;
1003
1004 return CPrivateBase::m_interface->toKodi->kodi_filesystem->stat_file(
1005 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), buffer);
1006}
1007//------------------------------------------------------------------------------
1008
1009//==============================================================================
1038inline bool ATTR_DLL_LOCAL DeleteFile(const std::string& filename)
1039{
1040 using namespace kodi::addon;
1041
1042 return CPrivateBase::m_interface->toKodi->kodi_filesystem->delete_file(
1043 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1044}
1045//------------------------------------------------------------------------------
1046
1047//==============================================================================
1056inline bool ATTR_DLL_LOCAL RenameFile(const std::string& filename, const std::string& newFileName)
1057{
1058 using namespace kodi::addon;
1059
1060 return CPrivateBase::m_interface->toKodi->kodi_filesystem->rename_file(
1061 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), newFileName.c_str());
1062}
1063//------------------------------------------------------------------------------
1064
1065//==============================================================================
1074inline bool ATTR_DLL_LOCAL CopyFile(const std::string& filename, const std::string& destination)
1075{
1076 using namespace kodi::addon;
1077
1078 return CPrivateBase::m_interface->toKodi->kodi_filesystem->copy_file(
1079 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), destination.c_str());
1080}
1081//------------------------------------------------------------------------------
1082
1083//}}}
1084
1085//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1086// "C++" General filesystem functions
1087//{{{
1088
1089//==============================================================================
1115inline std::string ATTR_DLL_LOCAL GetFileMD5(const std::string& path)
1116{
1117 using namespace kodi::addon;
1118
1119 std::string strReturn;
1120 char* strMd5 = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_md5(
1121 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1122 if (strMd5 != nullptr)
1123 {
1124 if (std::strlen(strMd5))
1125 strReturn = strMd5;
1126 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1127 strMd5);
1128 }
1129 return strReturn;
1130}
1131//------------------------------------------------------------------------------
1132
1133//==============================================================================
1159inline std::string ATTR_DLL_LOCAL GetCacheThumbName(const std::string& filename)
1160{
1161 using namespace kodi::addon;
1162
1163 std::string strReturn;
1164 char* strThumbName = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_cache_thumb_name(
1165 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1166 if (strThumbName != nullptr)
1167 {
1168 if (std::strlen(strThumbName))
1169 strReturn = strThumbName;
1170 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1171 strThumbName);
1172 }
1173 return strReturn;
1174}
1175//------------------------------------------------------------------------------
1176
1177//==============================================================================
1202inline std::string ATTR_DLL_LOCAL MakeLegalFileName(const std::string& filename)
1203{
1204 using namespace kodi::addon;
1205
1206 std::string strReturn;
1207 char* strLegalFileName = CPrivateBase::m_interface->toKodi->kodi_filesystem->make_legal_filename(
1208 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1209 if (strLegalFileName != nullptr)
1210 {
1211 if (std::strlen(strLegalFileName))
1212 strReturn = strLegalFileName;
1213 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1214 strLegalFileName);
1215 }
1216 return strReturn;
1217}
1218//------------------------------------------------------------------------------
1219
1220//==============================================================================
1245inline std::string ATTR_DLL_LOCAL MakeLegalPath(const std::string& path)
1246{
1247 using namespace kodi::addon;
1248
1249 std::string strReturn;
1250 char* strLegalPath = CPrivateBase::m_interface->toKodi->kodi_filesystem->make_legal_path(
1251 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1252 if (strLegalPath != nullptr)
1253 {
1254 if (std::strlen(strLegalPath))
1255 strReturn = strLegalPath;
1256 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1257 strLegalPath);
1258 }
1259 return strReturn;
1260}
1261//------------------------------------------------------------------------------
1262
1263//==============================================================================
1293inline std::string ATTR_DLL_LOCAL TranslateSpecialProtocol(const std::string& source)
1294{
1295 using namespace kodi::addon;
1296
1297 std::string strReturn;
1298 char* protocol = CPrivateBase::m_interface->toKodi->kodi_filesystem->translate_special_protocol(
1299 CPrivateBase::m_interface->toKodi->kodiBase, source.c_str());
1300 if (protocol != nullptr)
1301 {
1302 if (std::strlen(protocol))
1303 strReturn = protocol;
1304 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1305 protocol);
1306 }
1307 return strReturn;
1308}
1309//------------------------------------------------------------------------------
1310
1311//==============================================================================
1347inline bool ATTR_DLL_LOCAL GetDiskSpace(const std::string& path,
1348 uint64_t& capacity,
1349 uint64_t& free,
1350 uint64_t& available)
1351{
1352 using namespace kodi::addon;
1353
1354 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_disk_space(
1355 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), &capacity, &free, &available);
1356}
1357//------------------------------------------------------------------------------
1358
1359//==============================================================================
1377inline std::string ATTR_DLL_LOCAL GetFileName(const std::string& path)
1378{
1379 /* find the last slash */
1380 const size_t slash = path.find_last_of("/\\");
1381 return path.substr(slash + 1);
1382}
1383//------------------------------------------------------------------------------
1384
1385//==============================================================================
1403inline std::string ATTR_DLL_LOCAL GetDirectoryName(const std::string& path)
1404{
1405 // Will from a full filename return the directory the file resides in.
1406 // Keeps the final slash at end and possible |option=foo options.
1407
1408 size_t iPosSlash = path.find_last_of("/\\");
1409 if (iPosSlash == std::string::npos)
1410 return ""; // No slash, so no path (ignore any options)
1411
1412 size_t iPosBar = path.rfind('|');
1413 if (iPosBar == std::string::npos)
1414 return path.substr(0, iPosSlash + 1); // Only path
1415
1416 return path.substr(0, iPosSlash + 1) + path.substr(iPosBar); // Path + options
1417}
1418//------------------------------------------------------------------------------
1419
1420//==============================================================================
1438inline void ATTR_DLL_LOCAL RemoveSlashAtEnd(std::string& path)
1439{
1440 if (!path.empty())
1441 {
1442 char last = path[path.size() - 1];
1443 if (last == '/' || last == '\\')
1444 path.erase(path.size() - 1);
1445 }
1446}
1447//------------------------------------------------------------------------------
1448
1449//==============================================================================
1458inline unsigned int ATTR_DLL_LOCAL GetChunkSize(unsigned int chunk, unsigned int minimum)
1459{
1460 if (chunk)
1461 return chunk * ((minimum + chunk - 1) / chunk);
1462 else
1463 return minimum;
1464}
1465//------------------------------------------------------------------------------
1466
1467//==============================================================================
1515inline bool ATTR_DLL_LOCAL IsInternetStream(const std::string& path, bool strictCheck = false)
1516{
1517 using namespace kodi::addon;
1518
1519 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_internet_stream(
1520 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), strictCheck);
1521}
1522//------------------------------------------------------------------------------
1523
1524//==============================================================================
1547inline bool ATTR_DLL_LOCAL IsOnLAN(const std::string& path)
1548{
1549 using namespace kodi::addon;
1550
1551 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_on_lan(
1552 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1553}
1554//------------------------------------------------------------------------------
1555
1556//==============================================================================
1576inline bool ATTR_DLL_LOCAL IsRemote(const std::string& path)
1577{
1578 using namespace kodi::addon;
1579
1580 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_remote(
1581 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1582}
1583//------------------------------------------------------------------------------
1584
1585//==============================================================================
1592inline bool ATTR_DLL_LOCAL IsLocal(const std::string& path)
1593{
1594 using namespace kodi::addon;
1595
1596 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_local(
1597 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1598}
1599//------------------------------------------------------------------------------
1600
1601//==============================================================================
1623inline bool ATTR_DLL_LOCAL IsURL(const std::string& path)
1624{
1625 using namespace kodi::addon;
1626
1627 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_url(
1628 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1629}
1630//--------------------------------------------------------------------------
1631
1632//============================================================================
1656inline bool ATTR_DLL_LOCAL GetHttpHeader(const std::string& url, HttpHeader& header)
1657{
1658 using namespace ::kodi::addon;
1659
1660 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_http_header(
1661 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &header.m_handle);
1662}
1663//----------------------------------------------------------------------------
1664
1665//============================================================================
1687inline bool ATTR_DLL_LOCAL GetMimeType(const std::string& url,
1688 std::string& mimeType,
1689 const std::string& useragent = "")
1690{
1691 using namespace ::kodi::addon;
1692
1693 char* cMimeType = nullptr;
1694 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_mime_type(
1695 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cMimeType, useragent.c_str());
1696 if (cMimeType != nullptr)
1697 {
1698 mimeType = cMimeType;
1699 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1700 cMimeType);
1701 }
1702 return ret;
1703}
1704//----------------------------------------------------------------------------
1705
1706//============================================================================
1728inline bool ATTR_DLL_LOCAL GetContentType(const std::string& url,
1729 std::string& content,
1730 const std::string& useragent = "")
1731{
1732 using namespace ::kodi::addon;
1733
1734 char* cContent = nullptr;
1735 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_content_type(
1736 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cContent, useragent.c_str());
1737 if (cContent != nullptr)
1738 {
1739 content = cContent;
1740 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1741 cContent);
1742 }
1743 return ret;
1744}
1745//----------------------------------------------------------------------------
1746
1747//============================================================================
1770inline bool ATTR_DLL_LOCAL GetCookies(const std::string& url, std::string& cookies)
1771{
1772 using namespace ::kodi::addon;
1773
1774 char* cCookies = nullptr;
1775 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_cookies(
1776 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cCookies);
1777 if (cCookies != nullptr)
1778 {
1779 cookies = cCookies;
1780 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1781 cCookies);
1782 }
1783 return ret;
1784}
1785//----------------------------------------------------------------------------
1786
1787//}}}
1788
1789//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1790// "C++" CFile class
1791//{{{
1792
1793//==============================================================================
1834class ATTR_DLL_LOCAL CFile
1835{
1836public:
1837 //============================================================================
1841 CFile() = default;
1842 //----------------------------------------------------------------------------
1843
1844 //============================================================================
1849 virtual ~CFile() { Close(); }
1850 //--------------------------------------------------------------------------
1851
1852 //==========================================================================
1861 bool OpenFile(const std::string& filename, unsigned int flags = 0)
1862 {
1863 using namespace kodi::addon;
1864
1865 Close();
1866 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file(
1867 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), flags);
1868 return m_file != nullptr;
1869 }
1870 //--------------------------------------------------------------------------
1871
1872 //==========================================================================
1884 bool OpenFileForWrite(const std::string& filename, bool overwrite = false)
1885 {
1886 using namespace kodi::addon;
1887
1888 Close();
1889
1890 // Try to open the file. If it fails, check if we need to create the directory first
1891 // This way we avoid checking if the directory exists every time
1892 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1893 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1894 if (!m_file)
1895 {
1896 std::string cacheDirectory = kodi::vfs::GetDirectoryName(filename);
1897 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->directory_exists(
1898 CPrivateBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()) ||
1899 CPrivateBase::m_interface->toKodi->kodi_filesystem->create_directory(
1900 CPrivateBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()))
1901 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1902 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1903 }
1904 return m_file != nullptr;
1905 }
1906 //--------------------------------------------------------------------------
1907
1908 //==========================================================================
1914 bool IsOpen() const { return m_file != nullptr; }
1915 //--------------------------------------------------------------------------
1916
1917 //==========================================================================
1921 void Close()
1922 {
1923 using namespace kodi::addon;
1924
1925 if (!m_file)
1926 return;
1927 CPrivateBase::m_interface->toKodi->kodi_filesystem->close_file(
1928 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
1929 m_file = nullptr;
1930 }
1931 //--------------------------------------------------------------------------
1932
1933 //==========================================================================
1940 bool CURLCreate(const std::string& url)
1941 {
1942 using namespace kodi::addon;
1943
1944 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_create(
1945 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str());
1946 return m_file != nullptr;
1947 }
1948 //--------------------------------------------------------------------------
1949
1950 //==========================================================================
1959 bool CURLAddOption(CURLOptiontype type, const std::string& name, const std::string& value)
1960 {
1961 using namespace kodi::addon;
1962
1963 if (!m_file)
1964 {
1965 kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1966 return false;
1967 }
1968 return CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_add_option(
1969 CPrivateBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), value.c_str());
1970 }
1971 //--------------------------------------------------------------------------
1972
1973 //==========================================================================
1980 bool CURLOpen(unsigned int flags = 0)
1981 {
1982 using namespace kodi::addon;
1983
1984 if (!m_file)
1985 {
1986 kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1987 return false;
1988 }
1989 return CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_open(
1990 CPrivateBase::m_interface->toKodi->kodiBase, m_file, flags);
1991 }
1992 //--------------------------------------------------------------------------
1993
1994 //==========================================================================
2005 ssize_t Read(void* ptr, size_t size)
2006 {
2007 using namespace kodi::addon;
2008
2009 if (!m_file)
2010 return -1;
2011 return CPrivateBase::m_interface->toKodi->kodi_filesystem->read_file(
2012 CPrivateBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2013 }
2014 //--------------------------------------------------------------------------
2015
2016 //==========================================================================
2049 bool ReadLine(std::string& line)
2050 {
2051 using namespace kodi::addon;
2052
2053 line.clear();
2054 if (!m_file)
2055 return false;
2056 // Read 1024 chars into buffer. If file position advanced that many
2057 // chars, we didn't hit a newline. Otherwise, we read a newline
2058 // or we reached the end of the file.
2059 //
2060 // The strncpy idiom is used here (C++ allows a simpler implementation):
2061 //
2062 // char buffer[BUFFER_SIZE];
2063 // strncpy(buffer, sourceString, BUFFER_SIZE - 1);
2064 // buffer[BUFFER_SIZE - 1] = '\0';
2065 //
2066 char buffer[1025]{};
2067 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->read_file_string(
2068 CPrivateBase::m_interface->toKodi->kodiBase, m_file, buffer, sizeof(buffer) - 1))
2069 {
2070 line = buffer;
2071 return !line.empty();
2072 }
2073 return false;
2074 }
2075 //--------------------------------------------------------------------------
2076
2077 //==========================================================================
2087 ssize_t Write(const void* ptr, size_t size)
2088 {
2089 using namespace kodi::addon;
2090
2091 if (!m_file)
2092 return -1;
2093 return CPrivateBase::m_interface->toKodi->kodi_filesystem->write_file(
2094 CPrivateBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2095 }
2096 //--------------------------------------------------------------------------
2097
2098 //==========================================================================
2112 void Flush()
2113 {
2114 using namespace kodi::addon;
2115
2116 if (!m_file)
2117 return;
2118 CPrivateBase::m_interface->toKodi->kodi_filesystem->flush_file(
2119 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2120 }
2121 //--------------------------------------------------------------------------
2122
2123 //==========================================================================
2141 int64_t Seek(int64_t position, int whence = SEEK_SET)
2142 {
2143 using namespace kodi::addon;
2144
2145 if (!m_file)
2146 return -1;
2147 return CPrivateBase::m_interface->toKodi->kodi_filesystem->seek_file(
2148 CPrivateBase::m_interface->toKodi->kodiBase, m_file, position, whence);
2149 }
2150 //--------------------------------------------------------------------------
2151
2152 //==========================================================================
2159 int Truncate(int64_t size)
2160 {
2161 using namespace kodi::addon;
2162
2163 if (!m_file)
2164 return -1;
2165 return CPrivateBase::m_interface->toKodi->kodi_filesystem->truncate_file(
2166 CPrivateBase::m_interface->toKodi->kodiBase, m_file, size);
2167 }
2168 //--------------------------------------------------------------------------
2169
2170 //==========================================================================
2176 int64_t GetPosition() const
2177 {
2178 using namespace kodi::addon;
2179
2180 if (!m_file)
2181 return -1;
2182 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2183 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2184 }
2185 //--------------------------------------------------------------------------
2186
2187 //==========================================================================
2193 int64_t GetLength() const
2194 {
2195 using namespace kodi::addon;
2196
2197 if (!m_file)
2198 return -1;
2199 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2200 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2201 }
2202 //--------------------------------------------------------------------------
2203
2204 //==========================================================================
2210 bool AtEnd() const
2211 {
2212 using namespace kodi::addon;
2213
2214 if (!m_file)
2215 return true;
2216 int64_t length = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2217 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2218 int64_t position = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2219 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2220 return position >= length;
2221 }
2222 //--------------------------------------------------------------------------
2223
2224 //==========================================================================
2230 int GetChunkSize() const
2231 {
2232 using namespace kodi::addon;
2233
2234 if (!m_file)
2235 return -1;
2236 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_chunk_size(
2237 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2238 }
2239 //--------------------------------------------------------------------------
2240
2241 //==========================================================================
2248 {
2249 using namespace kodi::addon;
2250
2251 if (!m_file)
2252 return false;
2253 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_get_seek_possible(
2254 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2255 }
2256 //--------------------------------------------------------------------------
2257
2258 //==========================================================================
2269 {
2270 using namespace kodi::addon;
2271
2272 if (!m_file)
2273 return false;
2274 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_get_cache_status(
2275 CPrivateBase::m_interface->toKodi->kodiBase, m_file, status);
2276 }
2277 //--------------------------------------------------------------------------
2278
2279 //==========================================================================
2286 bool IoControlSetCacheRate(uint32_t rate)
2287 {
2288 using namespace kodi::addon;
2289
2290 if (!m_file)
2291 return false;
2292 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_set_cache_rate(
2293 CPrivateBase::m_interface->toKodi->kodiBase, m_file, rate);
2294 }
2295 //--------------------------------------------------------------------------
2296
2297 //==========================================================================
2304 bool IoControlSetRetry(bool retry)
2305 {
2306 using namespace kodi::addon;
2307
2308 if (!m_file)
2309 return false;
2310 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_set_retry(
2311 CPrivateBase::m_interface->toKodi->kodiBase, m_file, retry);
2312 }
2313 //--------------------------------------------------------------------------
2314
2315 //==========================================================================
2323 const std::string GetPropertyValue(FilePropertyTypes type, const std::string& name) const
2324 {
2325 using namespace kodi::addon;
2326
2327 if (!m_file)
2328 {
2330 "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValue!");
2331 return "";
2332 }
2333 std::vector<std::string> values = GetPropertyValues(type, name);
2334 if (values.empty())
2335 {
2336 return "";
2337 }
2338 return values[0];
2339 }
2340 //--------------------------------------------------------------------------
2341
2342 //==========================================================================
2350 const std::vector<std::string> GetPropertyValues(FilePropertyTypes type,
2351 const std::string& name) const
2352 {
2353 using namespace kodi::addon;
2354
2355 if (!m_file)
2356 {
2358 "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValues!");
2359 return std::vector<std::string>();
2360 }
2361 int numValues = 0;
2362 char** res(CPrivateBase::m_interface->toKodi->kodi_filesystem->get_property_values(
2363 CPrivateBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), &numValues));
2364 if (res)
2365 {
2366 std::vector<std::string> vecReturn;
2367 vecReturn.reserve(numValues);
2368 for (int i = 0; i < numValues; ++i)
2369 {
2370 vecReturn.emplace_back(res[i]);
2371 }
2372 CPrivateBase::m_interface->toKodi->free_string_array(
2373 CPrivateBase::m_interface->toKodi->kodiBase, res, numValues);
2374 return vecReturn;
2375 }
2376 return std::vector<std::string>();
2377 }
2378 //--------------------------------------------------------------------------
2379
2380 //==========================================================================
2387 {
2388 using namespace kodi::addon;
2389
2390 if (!m_file)
2391 return 0.0;
2392 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_download_speed(
2393 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2394 }
2395 //--------------------------------------------------------------------------
2396
2397private:
2398 void* m_file = nullptr;
2399};
2401//------------------------------------------------------------------------------
2402
2403//}}}
2404
2405} /* namespace vfs */
2406} /* namespace kodi */
2407
2408#endif /* __cplusplus */
Definition AddonBase.h:206
Definition Filesystem.h:548
Definition Filesystem.h:1835
Definition Filesystem.h:229
Definition Filesystem.h:96
Definition Filesystem.h:298
HttpHeader()
Http header parser class constructor.
Definition Filesystem.h:303
~HttpHeader()
Class destructor.
Definition Filesystem.h:315
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition addon_base.h:193
void AddProperty(const std::string &id, const std::string &value)
Add a by string defined property entry to directory entry.
Definition Filesystem.h:715
const std::map< std::string, std::string > & GetProperties() const
Get the present properties list on directory entry.
Definition Filesystem.h:729
void SetPath(const std::string &path)
Set the path of the entry.
Definition Filesystem.h:678
void SetTitle(const std::string &title)
Set the title name.
Definition Filesystem.h:670
const std::string & Path(void) const
Get the path of the entry.
Definition Filesystem.h:630
void SetDateTime(time_t dateTime)
Set file time and date for a new entry.
Definition Filesystem.h:702
void SetFolder(bool folder)
Set the entry defined as folder.
Definition Filesystem.h:686
void SetLabel(const std::string &label)
Set the label name.
Definition Filesystem.h:662
void ClearProperties()
Clear all present properties.
Definition Filesystem.h:721
time_t DateTime()
Get file time and date for a new entry.
Definition Filesystem.h:654
const std::string & Title(void) const
Get the optional title of entry.
Definition Filesystem.h:622
bool IsFolder(void) const
Used to check entry is folder.
Definition Filesystem.h:638
CDirEntry(const std::string &label="", const std::string &path="", bool folder=false, int64_t size=-1, time_t dateTime=0)
Constructor for VFS directory entry.
Definition Filesystem.h:560
int64_t Size(void) const
If file, the size of the file.
Definition Filesystem.h:646
const std::string & Label(void) const
Get the directory entry name.
Definition Filesystem.h:614
void SetSize(int64_t size)
Set a file size for a new entry.
Definition Filesystem.h:694
void Flush()
Flush buffered data.
Definition Filesystem.h:2112
bool IsOpen() const
Check file is opened.
Definition Filesystem.h:1914
bool IoControlSetCacheRate(uint32_t rate)
Unsigned int with speed limit for caching in bytes per second.
Definition Filesystem.h:2286
bool AtEnd() const
Checks the file access is on end position.
Definition Filesystem.h:2210
int64_t Seek(int64_t position, int whence=SEEK_SET)
Set the file's current position.
Definition Filesystem.h:2141
int64_t GetLength() const
Get the file size of an open file.
Definition Filesystem.h:2193
bool IoControlGetCacheStatus(CacheStatus &status) const
To check a running stream on file for state of his cache.
Definition Filesystem.h:2268
int GetChunkSize() const
Get the chunk size for an open file.
Definition Filesystem.h:2230
bool CURLOpen(unsigned int flags=0)
Open the curl file created with CURLCreate.
Definition Filesystem.h:1980
bool OpenFileForWrite(const std::string &filename, bool overwrite=false)
Open the file with filename via Kodi's CFile in write mode. Needs to be closed by calling Close() whe...
Definition Filesystem.h:1884
int Truncate(int64_t size)
Truncate a file to the requested size.
Definition Filesystem.h:2159
void Close()
Close an open file.
Definition Filesystem.h:1921
bool CURLCreate(const std::string &url)
Create a Curl representation.
Definition Filesystem.h:1940
bool IoControlGetSeekPossible() const
To check seek possible on current stream by file.
Definition Filesystem.h:2247
double GetFileDownloadSpeed() const
Get the current download speed of file if loaded from web.
Definition Filesystem.h:2386
bool OpenFile(const std::string &filename, unsigned int flags=0)
Open the file with filename via Kodi's CFile. Needs to be closed by calling Close() when done.
Definition Filesystem.h:1861
CFile()=default
Construct a new, unopened file.
virtual ~CFile()
Close() is called from the destructor, so explicitly closing the file isn't required.
Definition Filesystem.h:1849
const std::vector< std::string > GetPropertyValues(FilePropertyTypes type, const std::string &name) const
Retrieve file property values.
Definition Filesystem.h:2350
ssize_t Write(const void *ptr, size_t size)
Write to a file opened in write mode.
Definition Filesystem.h:2087
bool CURLAddOption(CURLOptiontype type, const std::string &name, const std::string &value)
Add options to the curl file created with CURLCreate.
Definition Filesystem.h:1959
bool IoControlSetRetry(bool retry)
Enable/disable retry within the protocol handler (if supported).
Definition Filesystem.h:2304
bool ReadLine(std::string &line)
Read a string from an open file.
Definition Filesystem.h:2049
const std::string GetPropertyValue(FilePropertyTypes type, const std::string &name) const
Retrieve a file property.
Definition Filesystem.h:2323
int64_t GetPosition() const
The current offset in an open file.
Definition Filesystem.h:2176
ssize_t Read(void *ptr, size_t size)
Read from an open file.
Definition Filesystem.h:2005
CURLOptiontype
Definition filesystem.h:117
uint32_t GetMaxRate()
Set maximum number of bytes per second cache is allowed to fill.
Definition Filesystem.h:265
uint32_t GetLowRate()
Get number of bytes per second for low speed rate.
Definition Filesystem.h:277
void SetMaxRate(uint32_t maxrate)
Set maximum number of bytes per second cache is allowed to fill.
Definition Filesystem.h:262
void SetCurrentRate(uint32_t currate)
Set number of bytes per second for average read rate from source file since last position change.
Definition Filesystem.h:268
void SetForward(uint64_t forward)
Set number of bytes cached forward of current position.
Definition Filesystem.h:256
uint32_t GetCurrentRate()
Get number of bytes per second for average read rate from source file since last position change.
Definition Filesystem.h:271
void SetLowRate(uint32_t lowrate)
Set number of bytes per second for low speed rate.
Definition Filesystem.h:274
uint64_t GetForward()
Get number of bytes cached forward of current position.
Definition Filesystem.h:259
FilePropertyTypes
Definition filesystem.h:162
bool GetIsRegular() const
Get stat url is a regular.
Definition Filesystem.h:207
uint64_t GetSize() const
Get total size, in bytes.
Definition Filesystem.h:150
bool GetIsBlock() const
Get stat url is a block special.
Definition Filesystem.h:189
bool GetIsSocket() const
Get stat url is a regular.
Definition Filesystem.h:213
void SetIsBlock(bool isBlock)
Set stat url as a block special.
Definition Filesystem.h:186
void SetIsFifo(bool isFifo)
Set stat url as a FIFO special.
Definition Filesystem.h:198
void SetIsDirectory(bool isDirectory)
Set the stat url is a directory.
Definition Filesystem.h:174
time_t GetAccessTime() const
Get time of last access.
Definition Filesystem.h:156
void SetStatusTime(time_t statusTime)
Set time of last status change.
Definition Filesystem.h:168
bool GetIsDirectory() const
The stat url is a directory if returns true.
Definition Filesystem.h:177
void SetDeviceId(uint32_t deviceId)
Set ID of device containing file.
Definition Filesystem.h:132
bool GetIsSymLink() const
Get stat url is a symbolic link.
Definition Filesystem.h:183
bool GetIsFifo() const
Get stat url is a FIFO special.
Definition Filesystem.h:201
bool GetIsCharacter() const
Get stat url is a character special.
Definition Filesystem.h:195
uint32_t GetDeviceId() const
Get ID of device containing file.
Definition Filesystem.h:135
void SetModificationTime(time_t modificationTime)
Set time of last modification.
Definition Filesystem.h:159
void SetAccessTime(time_t accessTime)
Set time of last access.
Definition Filesystem.h:153
void SetSize(uint64_t size)
Set total size, in bytes.
Definition Filesystem.h:147
time_t GetModificationTime() const
Get time of last modification.
Definition Filesystem.h:165
void SetIsCharacter(bool isCharacter)
Set stat url as a character special.
Definition Filesystem.h:192
void SetIsSocket(bool isSocket)
Set stat url is a socket.
Definition Filesystem.h:210
void SetFileSerialNumber(uint64_t fileSerialNumber)
Set the file serial number, which distinguishes this file from all other files on the same device.
Definition Filesystem.h:138
time_t GetStatusTime() const
Get time of last status change.
Definition Filesystem.h:171
uint64_t GetFileSerialNumber() const
Get the file serial number, which distinguishes this file from all other files on the same device.
Definition Filesystem.h:144
void SetIsRegular(bool isRegular)
Set stat url as a regular.
Definition Filesystem.h:204
void SetIsSymLink(bool isSymLink)
Set stat url as a symbolic link.
Definition Filesystem.h:180
std::string GetCharset() const
Get the charset associated with these HTTP headers.
Definition Filesystem.h:456
std::string GetValue(const std::string &param) const
Get the value associated with this parameter of these HTTP headers.
Definition Filesystem.h:348
std::string GetMimeType() const
Get the mime type associated with these HTTP headers.
Definition Filesystem.h:431
std::string GetHeader() const
Get the full header string associated with these HTTP headers.
Definition Filesystem.h:406
std::string GetProtoLine() const
The protocol line associated with these HTTP headers.
Definition Filesystem.h:481
std::vector< std::string > GetValues(const std::string &param) const
Get the values as list associated with this parameter of these HTTP headers.
Definition Filesystem.h:375
bool ATTR_DLL_LOCAL CreateDirectory(const std::string &path)
Make a directory.
Definition Filesystem.h:778
bool ATTR_DLL_LOCAL RemoveDirectory(const std::string &path, bool recursive=false)
Removes a directory.
Definition Filesystem.h:844
bool ATTR_DLL_LOCAL GetDirectory(const std::string &path, const std::string &mask, std::vector< kodi::vfs::CDirEntry > &items)
Lists a directory.
Definition Filesystem.h:893
bool ATTR_DLL_LOCAL DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition Filesystem.h:810
bool ATTR_DLL_LOCAL CopyFile(const std::string &filename, const std::string &destination)
Copy a file from source to destination.
Definition Filesystem.h:1074
bool ATTR_DLL_LOCAL DeleteFile(const std::string &filename)
Deletes a file.
Definition Filesystem.h:1038
bool ATTR_DLL_LOCAL StatFile(const std::string &filename, kodi::vfs::FileStatus &buffer)
Get file status.
Definition Filesystem.h:1000
bool ATTR_DLL_LOCAL FileExists(const std::string &filename, bool usecache=false)
Check if a file exists.
Definition Filesystem.h:945
bool ATTR_DLL_LOCAL RenameFile(const std::string &filename, const std::string &newFileName)
Rename a file name.
Definition Filesystem.h:1056
std::string ATTR_DLL_LOCAL GetFileMD5(const std::string &path)
Retrieve MD5sum of a file.
Definition Filesystem.h:1115
bool ATTR_DLL_LOCAL GetDiskSpace(const std::string &path, uint64_t &capacity, uint64_t &free, uint64_t &available)
Retrieves information about the amount of space that is available on a disk volume.
Definition Filesystem.h:1347
std::string ATTR_DLL_LOCAL TranslateSpecialProtocol(const std::string &source)
Returns the translated path.
Definition Filesystem.h:1293
bool ATTR_DLL_LOCAL IsURL(const std::string &path)
Checks specified path is a regular URL, e.g. "someprotocol://path/to/file".
Definition Filesystem.h:1623
std::string ATTR_DLL_LOCAL MakeLegalPath(const std::string &path)
Make directory name valid.
Definition Filesystem.h:1245
bool ATTR_DLL_LOCAL GetCookies(const std::string &url, std::string &cookies)
Get cookies stored by CURL in RFC 2109 format.
Definition Filesystem.h:1770
std::string ATTR_DLL_LOCAL GetDirectoryName(const std::string &path)
Return the directory name from given complete path string.
Definition Filesystem.h:1403
bool ATTR_DLL_LOCAL GetMimeType(const std::string &url, std::string &mimeType, const std::string &useragent="")
Get file mime type.
Definition Filesystem.h:1687
std::string ATTR_DLL_LOCAL MakeLegalFileName(const std::string &filename)
Make filename valid.
Definition Filesystem.h:1202
std::string ATTR_DLL_LOCAL GetCacheThumbName(const std::string &filename)
Returns a thumb cache filename.
Definition Filesystem.h:1159
void ATTR_DLL_LOCAL RemoveSlashAtEnd(std::string &path)
Remove the slash on given path name.
Definition Filesystem.h:1438
bool ATTR_DLL_LOCAL IsInternetStream(const std::string &path, bool strictCheck=false)
Checks the given path contains a known internet protocol.
Definition Filesystem.h:1515
bool ATTR_DLL_LOCAL IsLocal(const std::string &path)
Checks whether the given path refers to the own system.
Definition Filesystem.h:1592
bool ATTR_DLL_LOCAL IsRemote(const std::string &path)
Checks specified path for external network.
Definition Filesystem.h:1576
std::string ATTR_DLL_LOCAL GetFileName(const std::string &path)
Return the file name from given complete path string.
Definition Filesystem.h:1377
unsigned int ATTR_DLL_LOCAL GetChunkSize(unsigned int chunk, unsigned int minimum)
Return a size aligned to the chunk size at least as large as the chunk size.
Definition Filesystem.h:1458
bool ATTR_DLL_LOCAL GetContentType(const std::string &url, std::string &content, const std::string &useragent="")
Get file content-type.
Definition Filesystem.h:1728
bool ATTR_DLL_LOCAL GetHttpHeader(const std::string &url, HttpHeader &header)
To get HTTP header information.
Definition Filesystem.h:1656
bool ATTR_DLL_LOCAL IsOnLAN(const std::string &path)
Checks whether the specified path refers to a local network.
Definition Filesystem.h:1547
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1938
Definition filesystem.h:186
Definition filesystem.h:198
Definition filesystem.h:229
Definition filesystem.h:243