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),
566 m_path(path),
567 m_folder(folder),
568 m_size(size),
569 m_dateTime(dateTime)
570 {
571 }
572 //----------------------------------------------------------------------------
573
574 //============================================================================
575 // @note Not necessary for addon development, therefore it's
576 // disabled for doxygen below!
577 //
578 // @ingroup cpp_kodi_vfs_CDirEntry
579 // @brief Constructor to create own copy
580 //
581 // @param[in] dirEntry pointer to own class type
582 //
583 explicit CDirEntry(const VFSDirEntry& dirEntry)
584 : m_label(dirEntry.label ? dirEntry.label : ""),
585 m_path(dirEntry.path ? dirEntry.path : ""),
586 m_folder(dirEntry.folder),
587 m_size(dirEntry.size),
588 m_dateTime(dirEntry.date_time)
589 {
590 }
591 //----------------------------------------------------------------------------
592
608
612
613 //============================================================================
618 const std::string& Label(void) const { return m_label; }
619 //----------------------------------------------------------------------------
620
621 //============================================================================
626 const std::string& Title(void) const { return m_title; }
627 //----------------------------------------------------------------------------
628
629 //============================================================================
634 const std::string& Path(void) const { return m_path; }
635 //----------------------------------------------------------------------------
636
637 //============================================================================
642 bool IsFolder(void) const { return m_folder; }
643 //----------------------------------------------------------------------------
644
645 //============================================================================
650 int64_t Size(void) const { return m_size; }
651 //----------------------------------------------------------------------------
652
653 //============================================================================
658 time_t DateTime() { return m_dateTime; }
659 //----------------------------------------------------------------------------
660
661 //============================================================================
666 void SetLabel(const std::string& label) { m_label = label; }
667 //----------------------------------------------------------------------------
668
669 //============================================================================
674 void SetTitle(const std::string& title) { m_title = title; }
675 //----------------------------------------------------------------------------
676
677 //============================================================================
682 void SetPath(const std::string& path) { m_path = path; }
683 //----------------------------------------------------------------------------
684
685 //============================================================================
690 void SetFolder(bool folder) { m_folder = folder; }
691 //----------------------------------------------------------------------------
692
693 //============================================================================
698 void SetSize(int64_t size) { m_size = size; }
699 //----------------------------------------------------------------------------
700
701 //============================================================================
706 void SetDateTime(time_t dateTime) { m_dateTime = dateTime; }
707 //----------------------------------------------------------------------------
708
709 //============================================================================
719 void AddProperty(const std::string& id, const std::string& value) { m_properties[id] = value; }
720 //----------------------------------------------------------------------------
721
722 //============================================================================
725 void ClearProperties() { m_properties.clear(); }
726 //----------------------------------------------------------------------------
727
728 //============================================================================
733 const std::map<std::string, std::string>& GetProperties() const { return m_properties; }
734 //----------------------------------------------------------------------------
735
737
738private:
739 std::string m_label;
740 std::string m_title;
741 std::string m_path;
742 std::map<std::string, std::string> m_properties;
743 bool m_folder;
744 int64_t m_size;
745 time_t m_dateTime;
746};
748//------------------------------------------------------------------------------
749
750//}}}
751
752//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
753// "C++" Directory related functions
754//{{{
755
756//==============================================================================
782inline bool ATTR_DLL_LOCAL CreateDirectory(const std::string& path)
783{
784 using namespace kodi::addon;
785
786 return CPrivateBase::m_interface->toKodi->kodi_filesystem->create_directory(
787 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
788}
789//------------------------------------------------------------------------------
790
791//==============================================================================
814inline bool ATTR_DLL_LOCAL DirectoryExists(const std::string& path)
815{
816 using namespace kodi::addon;
817
818 return CPrivateBase::m_interface->toKodi->kodi_filesystem->directory_exists(
819 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
820}
821//------------------------------------------------------------------------------
822
823//==============================================================================
848inline bool ATTR_DLL_LOCAL RemoveDirectory(const std::string& path, bool recursive = false)
849{
850 using namespace kodi::addon;
851
852 if (!recursive)
853 return CPrivateBase::m_interface->toKodi->kodi_filesystem->remove_directory(
854 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
855 else
856 return CPrivateBase::m_interface->toKodi->kodi_filesystem->remove_directory_recursive(
857 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
858}
859//------------------------------------------------------------------------------
860
861//==============================================================================
897inline bool ATTR_DLL_LOCAL GetDirectory(const std::string& path,
898 const std::string& mask,
899 std::vector<kodi::vfs::CDirEntry>& items)
900{
901 using namespace kodi::addon;
902
903 VFSDirEntry* dir_list = nullptr;
904 unsigned int num_items = 0;
905 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->get_directory(
906 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), mask.c_str(), &dir_list,
907 &num_items))
908 {
909 if (dir_list)
910 {
911 for (unsigned int i = 0; i < num_items; ++i)
912 items.emplace_back(dir_list[i]);
913
914 CPrivateBase::m_interface->toKodi->kodi_filesystem->free_directory(
915 CPrivateBase::m_interface->toKodi->kodiBase, dir_list, num_items);
916 }
917
918 return true;
919 }
920 return false;
921}
922//------------------------------------------------------------------------------
923
924//}}}
925
926//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
927// "C++" File related functions
928//{{{
929
930//==============================================================================
949inline bool ATTR_DLL_LOCAL FileExists(const std::string& filename, bool usecache = false)
950{
951 using namespace kodi::addon;
952
953 return CPrivateBase::m_interface->toKodi->kodi_filesystem->file_exists(
954 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), usecache);
955}
956//------------------------------------------------------------------------------
957
958//==============================================================================
1004inline bool ATTR_DLL_LOCAL StatFile(const std::string& filename, kodi::vfs::FileStatus& buffer)
1005{
1006 using namespace kodi::addon;
1007
1008 return CPrivateBase::m_interface->toKodi->kodi_filesystem->stat_file(
1009 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), buffer);
1010}
1011//------------------------------------------------------------------------------
1012
1013//==============================================================================
1042inline bool ATTR_DLL_LOCAL DeleteFile(const std::string& filename)
1043{
1044 using namespace kodi::addon;
1045
1046 return CPrivateBase::m_interface->toKodi->kodi_filesystem->delete_file(
1047 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1048}
1049//------------------------------------------------------------------------------
1050
1051//==============================================================================
1060inline bool ATTR_DLL_LOCAL RenameFile(const std::string& filename, const std::string& newFileName)
1061{
1062 using namespace kodi::addon;
1063
1064 return CPrivateBase::m_interface->toKodi->kodi_filesystem->rename_file(
1065 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), newFileName.c_str());
1066}
1067//------------------------------------------------------------------------------
1068
1069//==============================================================================
1078inline bool ATTR_DLL_LOCAL CopyFile(const std::string& filename, const std::string& destination)
1079{
1080 using namespace kodi::addon;
1081
1082 return CPrivateBase::m_interface->toKodi->kodi_filesystem->copy_file(
1083 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), destination.c_str());
1084}
1085//------------------------------------------------------------------------------
1086
1087//}}}
1088
1089//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1090// "C++" General filesystem functions
1091//{{{
1092
1093//==============================================================================
1119inline std::string ATTR_DLL_LOCAL GetFileMD5(const std::string& path)
1120{
1121 using namespace kodi::addon;
1122
1123 std::string strReturn;
1124 char* strMd5 = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_md5(
1125 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1126 if (strMd5 != nullptr)
1127 {
1128 if (std::strlen(strMd5))
1129 strReturn = strMd5;
1130 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1131 strMd5);
1132 }
1133 return strReturn;
1134}
1135//------------------------------------------------------------------------------
1136
1137//==============================================================================
1163inline std::string ATTR_DLL_LOCAL GetCacheThumbName(const std::string& filename)
1164{
1165 using namespace kodi::addon;
1166
1167 std::string strReturn;
1168 char* strThumbName = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_cache_thumb_name(
1169 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1170 if (strThumbName != nullptr)
1171 {
1172 if (std::strlen(strThumbName))
1173 strReturn = strThumbName;
1174 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1175 strThumbName);
1176 }
1177 return strReturn;
1178}
1179//------------------------------------------------------------------------------
1180
1181//==============================================================================
1206inline std::string ATTR_DLL_LOCAL MakeLegalFileName(const std::string& filename)
1207{
1208 using namespace kodi::addon;
1209
1210 std::string strReturn;
1211 char* strLegalFileName = CPrivateBase::m_interface->toKodi->kodi_filesystem->make_legal_filename(
1212 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str());
1213 if (strLegalFileName != nullptr)
1214 {
1215 if (std::strlen(strLegalFileName))
1216 strReturn = strLegalFileName;
1217 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1218 strLegalFileName);
1219 }
1220 return strReturn;
1221}
1222//------------------------------------------------------------------------------
1223
1224//==============================================================================
1249inline std::string ATTR_DLL_LOCAL MakeLegalPath(const std::string& path)
1250{
1251 using namespace kodi::addon;
1252
1253 std::string strReturn;
1254 char* strLegalPath = CPrivateBase::m_interface->toKodi->kodi_filesystem->make_legal_path(
1255 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1256 if (strLegalPath != nullptr)
1257 {
1258 if (std::strlen(strLegalPath))
1259 strReturn = strLegalPath;
1260 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1261 strLegalPath);
1262 }
1263 return strReturn;
1264}
1265//------------------------------------------------------------------------------
1266
1267//==============================================================================
1297inline std::string ATTR_DLL_LOCAL TranslateSpecialProtocol(const std::string& source)
1298{
1299 using namespace kodi::addon;
1300
1301 std::string strReturn;
1302 char* protocol = CPrivateBase::m_interface->toKodi->kodi_filesystem->translate_special_protocol(
1303 CPrivateBase::m_interface->toKodi->kodiBase, source.c_str());
1304 if (protocol != nullptr)
1305 {
1306 if (std::strlen(protocol))
1307 strReturn = protocol;
1308 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1309 protocol);
1310 }
1311 return strReturn;
1312}
1313//------------------------------------------------------------------------------
1314
1315//==============================================================================
1351inline bool ATTR_DLL_LOCAL GetDiskSpace(const std::string& path,
1352 uint64_t& capacity,
1353 uint64_t& free,
1354 uint64_t& available)
1355{
1356 using namespace kodi::addon;
1357
1358 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_disk_space(
1359 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), &capacity, &free, &available);
1360}
1361//------------------------------------------------------------------------------
1362
1363//==============================================================================
1381inline std::string ATTR_DLL_LOCAL GetFileName(const std::string& path)
1382{
1383 /* find the last slash */
1384 const size_t slash = path.find_last_of("/\\");
1385 return path.substr(slash + 1);
1386}
1387//------------------------------------------------------------------------------
1388
1389//==============================================================================
1407inline std::string ATTR_DLL_LOCAL GetDirectoryName(const std::string& path)
1408{
1409 // Will from a full filename return the directory the file resides in.
1410 // Keeps the final slash at end and possible |option=foo options.
1411
1412 size_t iPosSlash = path.find_last_of("/\\");
1413 if (iPosSlash == std::string::npos)
1414 return ""; // No slash, so no path (ignore any options)
1415
1416 size_t iPosBar = path.rfind('|');
1417 if (iPosBar == std::string::npos)
1418 return path.substr(0, iPosSlash + 1); // Only path
1419
1420 return path.substr(0, iPosSlash + 1) + path.substr(iPosBar); // Path + options
1421}
1422//------------------------------------------------------------------------------
1423
1424//==============================================================================
1442inline void ATTR_DLL_LOCAL RemoveSlashAtEnd(std::string& path)
1443{
1444 if (!path.empty())
1445 {
1446 char last = path[path.size() - 1];
1447 if (last == '/' || last == '\\')
1448 path.erase(path.size() - 1);
1449 }
1450}
1451//------------------------------------------------------------------------------
1452
1453//==============================================================================
1462inline unsigned int ATTR_DLL_LOCAL GetChunkSize(unsigned int chunk, unsigned int minimum)
1463{
1464 if (chunk)
1465 return chunk * ((minimum + chunk - 1) / chunk);
1466 else
1467 return minimum;
1468}
1469//------------------------------------------------------------------------------
1470
1471//==============================================================================
1519inline bool ATTR_DLL_LOCAL IsInternetStream(const std::string& path, bool strictCheck = false)
1520{
1521 using namespace kodi::addon;
1522
1523 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_internet_stream(
1524 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str(), strictCheck);
1525}
1526//------------------------------------------------------------------------------
1527
1528//==============================================================================
1551inline bool ATTR_DLL_LOCAL IsOnLAN(const std::string& path)
1552{
1553 using namespace kodi::addon;
1554
1555 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_on_lan(
1556 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1557}
1558//------------------------------------------------------------------------------
1559
1560//==============================================================================
1580inline bool ATTR_DLL_LOCAL IsRemote(const std::string& path)
1581{
1582 using namespace kodi::addon;
1583
1584 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_remote(
1585 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1586}
1587//------------------------------------------------------------------------------
1588
1589//==============================================================================
1596inline bool ATTR_DLL_LOCAL IsLocal(const std::string& path)
1597{
1598 using namespace kodi::addon;
1599
1600 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_local(
1601 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1602}
1603//------------------------------------------------------------------------------
1604
1605//==============================================================================
1627inline bool ATTR_DLL_LOCAL IsURL(const std::string& path)
1628{
1629 using namespace kodi::addon;
1630
1631 return CPrivateBase::m_interface->toKodi->kodi_filesystem->is_url(
1632 CPrivateBase::m_interface->toKodi->kodiBase, path.c_str());
1633}
1634//--------------------------------------------------------------------------
1635
1636//============================================================================
1660inline bool ATTR_DLL_LOCAL GetHttpHeader(const std::string& url, HttpHeader& header)
1661{
1662 using namespace ::kodi::addon;
1663
1664 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_http_header(
1665 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &header.m_handle);
1666}
1667//----------------------------------------------------------------------------
1668
1669//============================================================================
1691inline bool ATTR_DLL_LOCAL GetMimeType(const std::string& url,
1692 std::string& mimeType,
1693 const std::string& useragent = "")
1694{
1695 using namespace ::kodi::addon;
1696
1697 char* cMimeType = nullptr;
1698 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_mime_type(
1699 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cMimeType, useragent.c_str());
1700 if (cMimeType != nullptr)
1701 {
1702 mimeType = cMimeType;
1703 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1704 cMimeType);
1705 }
1706 return ret;
1707}
1708//----------------------------------------------------------------------------
1709
1710//============================================================================
1732inline bool ATTR_DLL_LOCAL GetContentType(const std::string& url,
1733 std::string& content,
1734 const std::string& useragent = "")
1735{
1736 using namespace ::kodi::addon;
1737
1738 char* cContent = nullptr;
1739 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_content_type(
1740 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cContent, useragent.c_str());
1741 if (cContent != nullptr)
1742 {
1743 content = cContent;
1744 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1745 cContent);
1746 }
1747 return ret;
1748}
1749//----------------------------------------------------------------------------
1750
1751//============================================================================
1774inline bool ATTR_DLL_LOCAL GetCookies(const std::string& url, std::string& cookies)
1775{
1776 using namespace ::kodi::addon;
1777
1778 char* cCookies = nullptr;
1779 bool ret = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_cookies(
1780 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str(), &cCookies);
1781 if (cCookies != nullptr)
1782 {
1783 cookies = cCookies;
1784 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
1785 cCookies);
1786 }
1787 return ret;
1788}
1789//----------------------------------------------------------------------------
1790
1791//}}}
1792
1793//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1794// "C++" CFile class
1795//{{{
1796
1797//==============================================================================
1838class ATTR_DLL_LOCAL CFile
1839{
1840public:
1841 //============================================================================
1845 CFile() = default;
1846 //----------------------------------------------------------------------------
1847
1848 //============================================================================
1853 virtual ~CFile() { Close(); }
1854 //--------------------------------------------------------------------------
1855
1856 //==========================================================================
1865 bool OpenFile(const std::string& filename, unsigned int flags = 0)
1866 {
1867 using namespace kodi::addon;
1868
1869 Close();
1870 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file(
1871 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), flags);
1872 return m_file != nullptr;
1873 }
1874 //--------------------------------------------------------------------------
1875
1876 //==========================================================================
1888 bool OpenFileForWrite(const std::string& filename, bool overwrite = false)
1889 {
1890 using namespace kodi::addon;
1891
1892 Close();
1893
1894 // Try to open the file. If it fails, check if we need to create the directory first
1895 // This way we avoid checking if the directory exists every time
1896 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1897 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1898 if (!m_file)
1899 {
1900 std::string cacheDirectory = kodi::vfs::GetDirectoryName(filename);
1901 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->directory_exists(
1902 CPrivateBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()) ||
1903 CPrivateBase::m_interface->toKodi->kodi_filesystem->create_directory(
1904 CPrivateBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()))
1905 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1906 CPrivateBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1907 }
1908 return m_file != nullptr;
1909 }
1910 //--------------------------------------------------------------------------
1911
1912 //==========================================================================
1918 bool IsOpen() const { return m_file != nullptr; }
1919 //--------------------------------------------------------------------------
1920
1921 //==========================================================================
1925 void Close()
1926 {
1927 using namespace kodi::addon;
1928
1929 if (!m_file)
1930 return;
1931 CPrivateBase::m_interface->toKodi->kodi_filesystem->close_file(
1932 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
1933 m_file = nullptr;
1934 }
1935 //--------------------------------------------------------------------------
1936
1937 //==========================================================================
1944 bool CURLCreate(const std::string& url)
1945 {
1946 using namespace kodi::addon;
1947
1948 m_file = CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_create(
1949 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str());
1950 return m_file != nullptr;
1951 }
1952 //--------------------------------------------------------------------------
1953
1954 //==========================================================================
1963 bool CURLAddOption(CURLOptiontype type, const std::string& name, const std::string& value)
1964 {
1965 using namespace kodi::addon;
1966
1967 if (!m_file)
1968 {
1969 kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1970 return false;
1971 }
1972 return CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_add_option(
1973 CPrivateBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), value.c_str());
1974 }
1975 //--------------------------------------------------------------------------
1976
1977 //==========================================================================
1984 bool CURLOpen(unsigned int flags = 0)
1985 {
1986 using namespace kodi::addon;
1987
1988 if (!m_file)
1989 {
1990 kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1991 return false;
1992 }
1993 return CPrivateBase::m_interface->toKodi->kodi_filesystem->curl_open(
1994 CPrivateBase::m_interface->toKodi->kodiBase, m_file, flags);
1995 }
1996 //--------------------------------------------------------------------------
1997
1998 //==========================================================================
2009 ssize_t Read(void* ptr, size_t size)
2010 {
2011 using namespace kodi::addon;
2012
2013 if (!m_file)
2014 return -1;
2015 return CPrivateBase::m_interface->toKodi->kodi_filesystem->read_file(
2016 CPrivateBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2017 }
2018 //--------------------------------------------------------------------------
2019
2020 //==========================================================================
2053 bool ReadLine(std::string& line)
2054 {
2055 using namespace kodi::addon;
2056
2057 line.clear();
2058 if (!m_file)
2059 return false;
2060 // Read 1024 chars into buffer. If file position advanced that many
2061 // chars, we didn't hit a newline. Otherwise, we read a newline
2062 // or we reached the end of the file.
2063 //
2064 // The strncpy idiom is used here (C++ allows a simpler implementation):
2065 //
2066 // char buffer[BUFFER_SIZE];
2067 // strncpy(buffer, sourceString, BUFFER_SIZE - 1);
2068 // buffer[BUFFER_SIZE - 1] = '\0';
2069 //
2070 char buffer[1025]{};
2071 if (CPrivateBase::m_interface->toKodi->kodi_filesystem->read_file_string(
2072 CPrivateBase::m_interface->toKodi->kodiBase, m_file, buffer, sizeof(buffer) - 1))
2073 {
2074 line = buffer;
2075 return !line.empty();
2076 }
2077 return false;
2078 }
2079 //--------------------------------------------------------------------------
2080
2081 //==========================================================================
2091 ssize_t Write(const void* ptr, size_t size)
2092 {
2093 using namespace kodi::addon;
2094
2095 if (!m_file)
2096 return -1;
2097 return CPrivateBase::m_interface->toKodi->kodi_filesystem->write_file(
2098 CPrivateBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2099 }
2100 //--------------------------------------------------------------------------
2101
2102 //==========================================================================
2116 void Flush()
2117 {
2118 using namespace kodi::addon;
2119
2120 if (!m_file)
2121 return;
2122 CPrivateBase::m_interface->toKodi->kodi_filesystem->flush_file(
2123 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2124 }
2125 //--------------------------------------------------------------------------
2126
2127 //==========================================================================
2145 int64_t Seek(int64_t position, int whence = SEEK_SET)
2146 {
2147 using namespace kodi::addon;
2148
2149 if (!m_file)
2150 return -1;
2151 return CPrivateBase::m_interface->toKodi->kodi_filesystem->seek_file(
2152 CPrivateBase::m_interface->toKodi->kodiBase, m_file, position, whence);
2153 }
2154 //--------------------------------------------------------------------------
2155
2156 //==========================================================================
2163 int Truncate(int64_t size)
2164 {
2165 using namespace kodi::addon;
2166
2167 if (!m_file)
2168 return -1;
2169 return CPrivateBase::m_interface->toKodi->kodi_filesystem->truncate_file(
2170 CPrivateBase::m_interface->toKodi->kodiBase, m_file, size);
2171 }
2172 //--------------------------------------------------------------------------
2173
2174 //==========================================================================
2180 int64_t GetPosition() const
2181 {
2182 using namespace kodi::addon;
2183
2184 if (!m_file)
2185 return -1;
2186 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2187 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2188 }
2189 //--------------------------------------------------------------------------
2190
2191 //==========================================================================
2197 int64_t GetLength() const
2198 {
2199 using namespace kodi::addon;
2200
2201 if (!m_file)
2202 return -1;
2203 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2204 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2205 }
2206 //--------------------------------------------------------------------------
2207
2208 //==========================================================================
2214 bool AtEnd() const
2215 {
2216 using namespace kodi::addon;
2217
2218 if (!m_file)
2219 return true;
2220 int64_t length = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2221 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2222 int64_t position = CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2223 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2224 return position >= length;
2225 }
2226 //--------------------------------------------------------------------------
2227
2228 //==========================================================================
2234 int GetChunkSize() const
2235 {
2236 using namespace kodi::addon;
2237
2238 if (!m_file)
2239 return -1;
2240 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_chunk_size(
2241 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2242 }
2243 //--------------------------------------------------------------------------
2244
2245 //==========================================================================
2252 {
2253 using namespace kodi::addon;
2254
2255 if (!m_file)
2256 return false;
2257 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_get_seek_possible(
2258 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2259 }
2260 //--------------------------------------------------------------------------
2261
2262 //==========================================================================
2273 {
2274 using namespace kodi::addon;
2275
2276 if (!m_file)
2277 return false;
2278 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_get_cache_status(
2279 CPrivateBase::m_interface->toKodi->kodiBase, m_file, status);
2280 }
2281 //--------------------------------------------------------------------------
2282
2283 //==========================================================================
2290 bool IoControlSetCacheRate(uint32_t rate)
2291 {
2292 using namespace kodi::addon;
2293
2294 if (!m_file)
2295 return false;
2296 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_set_cache_rate(
2297 CPrivateBase::m_interface->toKodi->kodiBase, m_file, rate);
2298 }
2299 //--------------------------------------------------------------------------
2300
2301 //==========================================================================
2308 bool IoControlSetRetry(bool retry)
2309 {
2310 using namespace kodi::addon;
2311
2312 if (!m_file)
2313 return false;
2314 return CPrivateBase::m_interface->toKodi->kodi_filesystem->io_control_set_retry(
2315 CPrivateBase::m_interface->toKodi->kodiBase, m_file, retry);
2316 }
2317 //--------------------------------------------------------------------------
2318
2319 //==========================================================================
2327 const std::string GetPropertyValue(FilePropertyTypes type, const std::string& name) const
2328 {
2329 using namespace kodi::addon;
2330
2331 if (!m_file)
2332 {
2334 "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValue!");
2335 return "";
2336 }
2337 std::vector<std::string> values = GetPropertyValues(type, name);
2338 if (values.empty())
2339 {
2340 return "";
2341 }
2342 return values[0];
2343 }
2344 //--------------------------------------------------------------------------
2345
2346 //==========================================================================
2354 const std::vector<std::string> GetPropertyValues(FilePropertyTypes type,
2355 const std::string& name) const
2356 {
2357 using namespace kodi::addon;
2358
2359 if (!m_file)
2360 {
2362 "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValues!");
2363 return std::vector<std::string>();
2364 }
2365 int numValues = 0;
2366 char** res(CPrivateBase::m_interface->toKodi->kodi_filesystem->get_property_values(
2367 CPrivateBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), &numValues));
2368 if (res)
2369 {
2370 std::vector<std::string> vecReturn;
2371 vecReturn.reserve(numValues);
2372 for (int i = 0; i < numValues; ++i)
2373 {
2374 vecReturn.emplace_back(res[i]);
2375 }
2376 CPrivateBase::m_interface->toKodi->free_string_array(
2377 CPrivateBase::m_interface->toKodi->kodiBase, res, numValues);
2378 return vecReturn;
2379 }
2380 return std::vector<std::string>();
2381 }
2382 //--------------------------------------------------------------------------
2383
2384 //==========================================================================
2391 {
2392 using namespace kodi::addon;
2393
2394 if (!m_file)
2395 return 0.0;
2396 return CPrivateBase::m_interface->toKodi->kodi_filesystem->get_file_download_speed(
2397 CPrivateBase::m_interface->toKodi->kodiBase, m_file);
2398 }
2399 //--------------------------------------------------------------------------
2400
2401private:
2402 void* m_file = nullptr;
2403};
2405//------------------------------------------------------------------------------
2406
2407//}}}
2408
2409} /* namespace vfs */
2410} /* namespace kodi */
2411
2412#endif /* __cplusplus */
Definition AddonBase.h:206
Definition Filesystem.h:548
Definition Filesystem.h:1839
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:719
const std::map< std::string, std::string > & GetProperties() const
Get the present properties list on directory entry.
Definition Filesystem.h:733
void SetPath(const std::string &path)
Set the path of the entry.
Definition Filesystem.h:682
void SetTitle(const std::string &title)
Set the title name.
Definition Filesystem.h:674
const std::string & Path(void) const
Get the path of the entry.
Definition Filesystem.h:634
void SetDateTime(time_t dateTime)
Set file time and date for a new entry.
Definition Filesystem.h:706
void SetFolder(bool folder)
Set the entry defined as folder.
Definition Filesystem.h:690
void SetLabel(const std::string &label)
Set the label name.
Definition Filesystem.h:666
void ClearProperties()
Clear all present properties.
Definition Filesystem.h:725
time_t DateTime()
Get file time and date for a new entry.
Definition Filesystem.h:658
const std::string & Title(void) const
Get the optional title of entry.
Definition Filesystem.h:626
bool IsFolder(void) const
Used to check entry is folder.
Definition Filesystem.h:642
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:650
const std::string & Label(void) const
Get the directory entry name.
Definition Filesystem.h:618
void SetSize(int64_t size)
Set a file size for a new entry.
Definition Filesystem.h:698
void Flush()
Flush buffered data.
Definition Filesystem.h:2116
bool IsOpen() const
Check file is opened.
Definition Filesystem.h:1918
bool IoControlSetCacheRate(uint32_t rate)
Unsigned int with speed limit for caching in bytes per second.
Definition Filesystem.h:2290
bool AtEnd() const
Checks the file access is on end position.
Definition Filesystem.h:2214
int64_t Seek(int64_t position, int whence=SEEK_SET)
Set the file's current position.
Definition Filesystem.h:2145
int64_t GetLength() const
Get the file size of an open file.
Definition Filesystem.h:2197
bool IoControlGetCacheStatus(CacheStatus &status) const
To check a running stream on file for state of his cache.
Definition Filesystem.h:2272
int GetChunkSize() const
Get the chunk size for an open file.
Definition Filesystem.h:2234
bool CURLOpen(unsigned int flags=0)
Open the curl file created with CURLCreate.
Definition Filesystem.h:1984
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:1888
int Truncate(int64_t size)
Truncate a file to the requested size.
Definition Filesystem.h:2163
void Close()
Close an open file.
Definition Filesystem.h:1925
bool CURLCreate(const std::string &url)
Create a Curl representation.
Definition Filesystem.h:1944
bool IoControlGetSeekPossible() const
To check seek possible on current stream by file.
Definition Filesystem.h:2251
double GetFileDownloadSpeed() const
Get the current download speed of file if loaded from web.
Definition Filesystem.h:2390
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:1865
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:1853
const std::vector< std::string > GetPropertyValues(FilePropertyTypes type, const std::string &name) const
Retrieve file property values.
Definition Filesystem.h:2354
ssize_t Write(const void *ptr, size_t size)
Write to a file opened in write mode.
Definition Filesystem.h:2091
bool CURLAddOption(CURLOptiontype type, const std::string &name, const std::string &value)
Add options to the curl file created with CURLCreate.
Definition Filesystem.h:1963
bool IoControlSetRetry(bool retry)
Enable/disable retry within the protocol handler (if supported).
Definition Filesystem.h:2308
bool ReadLine(std::string &line)
Read a string from an open file.
Definition Filesystem.h:2053
const std::string GetPropertyValue(FilePropertyTypes type, const std::string &name) const
Retrieve a file property.
Definition Filesystem.h:2327
int64_t GetPosition() const
The current offset in an open file.
Definition Filesystem.h:2180
ssize_t Read(void *ptr, size_t size)
Read from an open file.
Definition Filesystem.h:2009
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:782
bool ATTR_DLL_LOCAL RemoveDirectory(const std::string &path, bool recursive=false)
Removes a directory.
Definition Filesystem.h:848
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:897
bool ATTR_DLL_LOCAL DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition Filesystem.h:814
bool ATTR_DLL_LOCAL CopyFile(const std::string &filename, const std::string &destination)
Copy a file from source to destination.
Definition Filesystem.h:1078
bool ATTR_DLL_LOCAL DeleteFile(const std::string &filename)
Deletes a file.
Definition Filesystem.h:1042
bool ATTR_DLL_LOCAL StatFile(const std::string &filename, kodi::vfs::FileStatus &buffer)
Get file status.
Definition Filesystem.h:1004
bool ATTR_DLL_LOCAL FileExists(const std::string &filename, bool usecache=false)
Check if a file exists.
Definition Filesystem.h:949
bool ATTR_DLL_LOCAL RenameFile(const std::string &filename, const std::string &newFileName)
Rename a file name.
Definition Filesystem.h:1060
std::string ATTR_DLL_LOCAL GetFileMD5(const std::string &path)
Retrieve MD5sum of a file.
Definition Filesystem.h:1119
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:1351
std::string ATTR_DLL_LOCAL TranslateSpecialProtocol(const std::string &source)
Returns the translated path.
Definition Filesystem.h:1297
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:1627
std::string ATTR_DLL_LOCAL MakeLegalPath(const std::string &path)
Make directory name valid.
Definition Filesystem.h:1249
bool ATTR_DLL_LOCAL GetCookies(const std::string &url, std::string &cookies)
Get cookies stored by CURL in RFC 2109 format.
Definition Filesystem.h:1774
std::string ATTR_DLL_LOCAL GetDirectoryName(const std::string &path)
Return the directory name from given complete path string.
Definition Filesystem.h:1407
bool ATTR_DLL_LOCAL GetMimeType(const std::string &url, std::string &mimeType, const std::string &useragent="")
Get file mime type.
Definition Filesystem.h:1691
std::string ATTR_DLL_LOCAL MakeLegalFileName(const std::string &filename)
Make filename valid.
Definition Filesystem.h:1206
std::string ATTR_DLL_LOCAL GetCacheThumbName(const std::string &filename)
Returns a thumb cache filename.
Definition Filesystem.h:1163
void ATTR_DLL_LOCAL RemoveSlashAtEnd(std::string &path)
Remove the slash on given path name.
Definition Filesystem.h:1442
bool ATTR_DLL_LOCAL IsInternetStream(const std::string &path, bool strictCheck=false)
Checks the given path contains a known internet protocol.
Definition Filesystem.h:1519
bool ATTR_DLL_LOCAL IsLocal(const std::string &path)
Checks whether the given path refers to the own system.
Definition Filesystem.h:1596
bool ATTR_DLL_LOCAL IsRemote(const std::string &path)
Checks specified path for external network.
Definition Filesystem.h:1580
std::string ATTR_DLL_LOCAL GetFileName(const std::string &path)
Return the file name from given complete path string.
Definition Filesystem.h:1381
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:1462
bool ATTR_DLL_LOCAL GetContentType(const std::string &url, std::string &content, const std::string &useragent="")
Get file content-type.
Definition Filesystem.h:1732
bool ATTR_DLL_LOCAL GetHttpHeader(const std::string &url, HttpHeader &header)
To get HTTP header information.
Definition Filesystem.h:1660
bool ATTR_DLL_LOCAL IsOnLAN(const std::string &path)
Checks whether the specified path refers to a local network.
Definition Filesystem.h:1551
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition AddonBase.h:1939
Definition filesystem.h:186
Definition filesystem.h:198
Definition filesystem.h:229
Definition filesystem.h:243