Kodi Development  20.0
for Binary and Script based Add-Ons
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 
20 namespace kodi
21 {
22 namespace 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 //==============================================================================
95 class ATTRIBUTE_HIDDEN FileStatus : public kodi::addon::CStructHdl<FileStatus, STAT_STRUCTURE>
96 {
97 public:
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) { m_cStructure->fileSerialNumber = fileSerialNumber; }
139 
141  uint64_t GetFileSerialNumber() const { return m_cStructure->fileSerialNumber; }
142 
144  void SetSize(uint64_t size) { m_cStructure->size = size; }
145 
147  uint64_t GetSize() const { return m_cStructure->size; }
148 
150  void SetAccessTime(time_t accessTime) { m_cStructure->accessTime = accessTime; }
151 
153  time_t GetAccessTime() const { return m_cStructure->accessTime; }
154 
156  void SetModificationTime(time_t modificationTime)
157  {
158  m_cStructure->modificationTime = modificationTime;
159  }
160 
162  time_t GetModificationTime() const { return m_cStructure->modificationTime; }
163 
165  void SetStatusTime(time_t statusTime) { m_cStructure->statusTime = statusTime; }
166 
168  time_t GetStatusTime() const { return m_cStructure->statusTime; }
169 
171  void SetIsDirectory(bool isDirectory) { m_cStructure->isDirectory = isDirectory; }
172 
174  bool GetIsDirectory() const { return m_cStructure->isDirectory; }
175 
177  void SetIsSymLink(bool isSymLink) { m_cStructure->isSymLink = isSymLink; }
178 
180  bool GetIsSymLink() const { return m_cStructure->isSymLink; }
181 
183  void SetIsBlock(bool isBlock) { m_cStructure->isBlock = isBlock; }
184 
186  bool GetIsBlock() const { return m_cStructure->isBlock; }
187 
189  void SetIsCharacter(bool isCharacter) { m_cStructure->isCharacter = isCharacter; }
190 
192  bool GetIsCharacter() const { return m_cStructure->isCharacter; }
193 
195  void SetIsFifo(bool isFifo) { m_cStructure->isFifo = isFifo; }
196 
198  bool GetIsFifo() const { return m_cStructure->isFifo; }
199 
201  void SetIsRegular(bool isRegular) { m_cStructure->isRegular = isRegular; }
202 
204  bool GetIsRegular() const { return m_cStructure->isRegular; }
205 
207  void SetIsSocket(bool isSocket) { m_cStructure->isSocket = isSocket; }
208 
210  bool GetIsSocket() const { return m_cStructure->isSocket; }
212 };
214 //------------------------------------------------------------------------------
215 
216 //==============================================================================
224 class ATTRIBUTE_HIDDEN CacheStatus
225  : public kodi::addon::CStructHdl<CacheStatus, VFS_CACHE_STATUS_DATA>
226 {
227 public:
229  CacheStatus() { memset(m_cStructure, 0, sizeof(VFS_CACHE_STATUS_DATA)); }
230  CacheStatus(const CacheStatus& channel) : CStructHdl(channel) {}
231  CacheStatus(const VFS_CACHE_STATUS_DATA* channel) : CStructHdl(channel) {}
232  CacheStatus(VFS_CACHE_STATUS_DATA* channel) : CStructHdl(channel) {}
247 
251 
253  void SetForward(uint64_t forward) { m_cStructure->forward = forward; }
254 
256  uint64_t GetForward() { return m_cStructure->forward; }
257 
259  void SetMaxRate(unsigned int maxrate) { m_cStructure->maxrate = maxrate; }
260 
262  unsigned int GetMaxRate() { return m_cStructure->maxrate; }
263 
265  void SetCurrentRate(unsigned int currate) { m_cStructure->currate = currate; }
266 
268  unsigned int GetCurrentRate() { return m_cStructure->currate; }
269 
271  void SetLowspeed(bool lowspeed) { m_cStructure->lowspeed = lowspeed; }
272 
274  bool GetLowspeed() { return m_cStructure->lowspeed; }
275 
277 };
279 //------------------------------------------------------------------------------
280 
281 //==============================================================================
294 class ATTRIBUTE_HIDDEN HttpHeader
295 {
296 public:
297  //==========================================================================
301  {
302  using namespace ::kodi::addon;
303 
304  CAddonBase::m_interface->toKodi->kodi_filesystem->http_header_create(
305  CAddonBase::m_interface->toKodi->kodiBase, &m_handle);
306  }
307  //--------------------------------------------------------------------------
308 
309  //==========================================================================
313  {
314  using namespace ::kodi::addon;
315 
316  CAddonBase::m_interface->toKodi->kodi_filesystem->http_header_free(
317  CAddonBase::m_interface->toKodi->kodiBase, &m_handle);
318  }
319  //--------------------------------------------------------------------------
320 
334 
337 
338  //==========================================================================
345  std::string GetValue(const std::string& param) const
346  {
347  using namespace ::kodi::addon;
348 
349  if (!m_handle.handle)
350  return "";
351 
352  std::string protoLine;
353  char* string = m_handle.get_value(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle,
354  param.c_str());
355  if (string != nullptr)
356  {
357  protoLine = string;
358  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
359  string);
360  }
361  return protoLine;
362  }
363  //--------------------------------------------------------------------------
364 
365  //==========================================================================
372  std::vector<std::string> GetValues(const std::string& param) const
373  {
374  using namespace kodi::addon;
375 
376  if (!m_handle.handle)
377  return std::vector<std::string>();
378 
379  int numValues = 0;
380  char** res(m_handle.get_values(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle,
381  param.c_str(), &numValues));
382  if (res)
383  {
384  std::vector<std::string> vecReturn;
385  vecReturn.reserve(numValues);
386  for (int i = 0; i < numValues; ++i)
387  {
388  vecReturn.emplace_back(res[i]);
389  }
390  CAddonBase::m_interface->toKodi->free_string_array(CAddonBase::m_interface->toKodi->kodiBase,
391  res, numValues);
392  return vecReturn;
393  }
394  return std::vector<std::string>();
395  }
396  //--------------------------------------------------------------------------
397 
398  //==========================================================================
403  std::string GetHeader() const
404  {
405  using namespace ::kodi::addon;
406 
407  if (!m_handle.handle)
408  return "";
409 
410  std::string header;
411  char* string = m_handle.get_header(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle);
412  if (string != nullptr)
413  {
414  header = string;
415  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
416  string);
417  }
418  return header;
419  }
420  //--------------------------------------------------------------------------
421 
422  //==========================================================================
427  std::string GetMimeType() const
428  {
429  using namespace ::kodi::addon;
430 
431  if (!m_handle.handle)
432  return "";
433 
434  std::string protoLine;
435  char* string =
436  m_handle.get_mime_type(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle);
437  if (string != nullptr)
438  {
439  protoLine = string;
440  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
441  string);
442  }
443  return protoLine;
444  }
445  //--------------------------------------------------------------------------
446 
447  //==========================================================================
452  std::string GetCharset() const
453  {
454  using namespace ::kodi::addon;
455 
456  if (!m_handle.handle)
457  return "";
458 
459  std::string protoLine;
460  char* string = m_handle.get_charset(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle);
461  if (string != nullptr)
462  {
463  protoLine = string;
464  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
465  string);
466  }
467  return protoLine;
468  }
469  //--------------------------------------------------------------------------
470 
471  //==========================================================================
476  std::string GetProtoLine() const
477  {
478  using namespace ::kodi::addon;
479 
480  if (!m_handle.handle)
481  return "";
482 
483  std::string protoLine;
484  char* string =
485  m_handle.get_proto_line(CAddonBase::m_interface->toKodi->kodiBase, m_handle.handle);
486  if (string != nullptr)
487  {
488  protoLine = string;
489  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
490  string);
491  }
492  return protoLine;
493  }
494  //--------------------------------------------------------------------------
495 
497 
498  KODI_HTTP_HEADER m_handle;
499 };
501 //----------------------------------------------------------------------------
502 
503 //==============================================================================
542 class ATTRIBUTE_HIDDEN CDirEntry
543 {
544 public:
545  //============================================================================
555  CDirEntry(const std::string& label = "",
556  const std::string& path = "",
557  bool folder = false,
558  int64_t size = -1,
559  time_t dateTime = 0)
560  : m_label(label), m_path(path), m_folder(folder), m_size(size), m_dateTime(dateTime)
561  {
562  }
563  //----------------------------------------------------------------------------
564 
565  //============================================================================
566  // @note Not for addon development itself needed, thats why below is
567  // disabled for doxygen!
568  //
569  // @ingroup cpp_kodi_vfs_CDirEntry
570  // @brief Constructor to create own copy
571  //
572  // @param[in] dirEntry pointer to own class type
573  //
574  explicit CDirEntry(const VFSDirEntry& dirEntry)
575  : m_label(dirEntry.label ? dirEntry.label : ""),
576  m_path(dirEntry.path ? dirEntry.path : ""),
577  m_folder(dirEntry.folder),
578  m_size(dirEntry.size),
579  m_dateTime(dirEntry.date_time)
580  {
581  }
582  //----------------------------------------------------------------------------
583 
599 
603 
604  //============================================================================
609  const std::string& Label(void) const { return m_label; }
610  //----------------------------------------------------------------------------
611 
612  //============================================================================
617  const std::string& Title(void) const { return m_title; }
618  //----------------------------------------------------------------------------
619 
620  //============================================================================
625  const std::string& Path(void) const { return m_path; }
626  //----------------------------------------------------------------------------
627 
628  //============================================================================
633  bool IsFolder(void) const { return m_folder; }
634  //----------------------------------------------------------------------------
635 
636  //============================================================================
641  int64_t Size(void) const { return m_size; }
642  //----------------------------------------------------------------------------
643 
644  //============================================================================
649  time_t DateTime() { return m_dateTime; }
650  //----------------------------------------------------------------------------
651 
652  //============================================================================
657  void SetLabel(const std::string& label) { m_label = label; }
658  //----------------------------------------------------------------------------
659 
660  //============================================================================
665  void SetTitle(const std::string& title) { m_title = title; }
666  //----------------------------------------------------------------------------
667 
668  //============================================================================
673  void SetPath(const std::string& path) { m_path = path; }
674  //----------------------------------------------------------------------------
675 
676  //============================================================================
681  void SetFolder(bool folder) { m_folder = folder; }
682  //----------------------------------------------------------------------------
683 
684  //============================================================================
689  void SetSize(int64_t size) { m_size = size; }
690  //----------------------------------------------------------------------------
691 
692  //============================================================================
697  void SetDateTime(time_t dateTime) { m_dateTime = dateTime; }
698  //----------------------------------------------------------------------------
699 
700  //============================================================================
710  void AddProperty(const std::string& id, const std::string& value) { m_properties[id] = value; }
711  //----------------------------------------------------------------------------
712 
713  //============================================================================
716  void ClearProperties() { m_properties.clear(); }
717  //----------------------------------------------------------------------------
718 
719  //============================================================================
724  const std::map<std::string, std::string>& GetProperties() const { return m_properties; }
725  //----------------------------------------------------------------------------
726 
728 
729 private:
730  std::string m_label;
731  std::string m_title;
732  std::string m_path;
733  std::map<std::string, std::string> m_properties;
734  bool m_folder;
735  int64_t m_size;
736  time_t m_dateTime;
737 };
739 //------------------------------------------------------------------------------
740 
741 //}}}
742 
743 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
744 // "C++" Directory related functions
745 //{{{
746 
747 //==============================================================================
773 inline bool ATTRIBUTE_HIDDEN CreateDirectory(const std::string& path)
774 {
775  using namespace kodi::addon;
776 
777  return CAddonBase::m_interface->toKodi->kodi_filesystem->create_directory(
778  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
779 }
780 //------------------------------------------------------------------------------
781 
782 //==============================================================================
805 inline bool ATTRIBUTE_HIDDEN DirectoryExists(const std::string& path)
806 {
807  using namespace kodi::addon;
808 
809  return CAddonBase::m_interface->toKodi->kodi_filesystem->directory_exists(
810  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
811 }
812 //------------------------------------------------------------------------------
813 
814 //==============================================================================
839 inline bool ATTRIBUTE_HIDDEN RemoveDirectory(const std::string& path, bool recursive = false)
840 {
841  using namespace kodi::addon;
842 
843  if (!recursive)
844  return CAddonBase::m_interface->toKodi->kodi_filesystem->remove_directory(
845  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
846  else
847  return CAddonBase::m_interface->toKodi->kodi_filesystem->remove_directory_recursive(
848  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
849 }
850 //------------------------------------------------------------------------------
851 
852 //==============================================================================
888 inline bool ATTRIBUTE_HIDDEN GetDirectory(const std::string& path,
889  const std::string& mask,
890  std::vector<kodi::vfs::CDirEntry>& items)
891 {
892  using namespace kodi::addon;
893 
894  VFSDirEntry* dir_list = nullptr;
895  unsigned int num_items = 0;
896  if (CAddonBase::m_interface->toKodi->kodi_filesystem->get_directory(
897  CAddonBase::m_interface->toKodi->kodiBase, path.c_str(), mask.c_str(), &dir_list,
898  &num_items))
899  {
900  if (dir_list)
901  {
902  for (unsigned int i = 0; i < num_items; ++i)
903  items.emplace_back(dir_list[i]);
904 
905  CAddonBase::m_interface->toKodi->kodi_filesystem->free_directory(
906  CAddonBase::m_interface->toKodi->kodiBase, dir_list, num_items);
907  }
908 
909  return true;
910  }
911  return false;
912 }
913 //------------------------------------------------------------------------------
914 
915 //}}}
916 
917 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
918 // "C++" File related functions
919 //{{{
920 
921 //==============================================================================
940 inline bool ATTRIBUTE_HIDDEN FileExists(const std::string& filename, bool usecache = false)
941 {
942  using namespace kodi::addon;
943 
944  return CAddonBase::m_interface->toKodi->kodi_filesystem->file_exists(
945  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), usecache);
946 }
947 //------------------------------------------------------------------------------
948 
949 //==============================================================================
995 inline bool ATTRIBUTE_HIDDEN StatFile(const std::string& filename, kodi::vfs::FileStatus& buffer)
996 {
997  using namespace kodi::addon;
998 
999  return CAddonBase::m_interface->toKodi->kodi_filesystem->stat_file(
1000  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), buffer);
1001 }
1002 //------------------------------------------------------------------------------
1003 
1004 //==============================================================================
1033 inline bool ATTRIBUTE_HIDDEN DeleteFile(const std::string& filename)
1034 {
1035  using namespace kodi::addon;
1036 
1037  return CAddonBase::m_interface->toKodi->kodi_filesystem->delete_file(
1038  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str());
1039 }
1040 //------------------------------------------------------------------------------
1041 
1042 //==============================================================================
1051 inline bool ATTRIBUTE_HIDDEN RenameFile(const std::string& filename, const std::string& newFileName)
1052 {
1053  using namespace kodi::addon;
1054 
1055  return CAddonBase::m_interface->toKodi->kodi_filesystem->rename_file(
1056  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), newFileName.c_str());
1057 }
1058 //------------------------------------------------------------------------------
1059 
1060 //==============================================================================
1069 inline bool ATTRIBUTE_HIDDEN CopyFile(const std::string& filename, const std::string& destination)
1070 {
1071  using namespace kodi::addon;
1072 
1073  return CAddonBase::m_interface->toKodi->kodi_filesystem->copy_file(
1074  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), destination.c_str());
1075 }
1076 //------------------------------------------------------------------------------
1077 
1078 //}}}
1079 
1080 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1081 // "C++" General filesystem functions
1082 //{{{
1083 
1084 //==============================================================================
1110 inline std::string ATTRIBUTE_HIDDEN GetFileMD5(const std::string& path)
1111 {
1112  using namespace kodi::addon;
1113 
1114  std::string strReturn;
1115  char* strMd5 = CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_md5(
1116  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1117  if (strMd5 != nullptr)
1118  {
1119  if (std::strlen(strMd5))
1120  strReturn = strMd5;
1121  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, strMd5);
1122  }
1123  return strReturn;
1124 }
1125 //------------------------------------------------------------------------------
1126 
1127 //==============================================================================
1153 inline std::string ATTRIBUTE_HIDDEN GetCacheThumbName(const std::string& filename)
1154 {
1155  using namespace kodi::addon;
1156 
1157  std::string strReturn;
1158  char* strThumbName = CAddonBase::m_interface->toKodi->kodi_filesystem->get_cache_thumb_name(
1159  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str());
1160  if (strThumbName != nullptr)
1161  {
1162  if (std::strlen(strThumbName))
1163  strReturn = strThumbName;
1164  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1165  strThumbName);
1166  }
1167  return strReturn;
1168 }
1169 //------------------------------------------------------------------------------
1170 
1171 //==============================================================================
1196 inline std::string ATTRIBUTE_HIDDEN MakeLegalFileName(const std::string& filename)
1197 {
1198  using namespace kodi::addon;
1199 
1200  std::string strReturn;
1201  char* strLegalFileName = CAddonBase::m_interface->toKodi->kodi_filesystem->make_legal_filename(
1202  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str());
1203  if (strLegalFileName != nullptr)
1204  {
1205  if (std::strlen(strLegalFileName))
1206  strReturn = strLegalFileName;
1207  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1208  strLegalFileName);
1209  }
1210  return strReturn;
1211 }
1212 //------------------------------------------------------------------------------
1213 
1214 //==============================================================================
1239 inline std::string ATTRIBUTE_HIDDEN MakeLegalPath(const std::string& path)
1240 {
1241  using namespace kodi::addon;
1242 
1243  std::string strReturn;
1244  char* strLegalPath = CAddonBase::m_interface->toKodi->kodi_filesystem->make_legal_path(
1245  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1246  if (strLegalPath != nullptr)
1247  {
1248  if (std::strlen(strLegalPath))
1249  strReturn = strLegalPath;
1250  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1251  strLegalPath);
1252  }
1253  return strReturn;
1254 }
1255 //------------------------------------------------------------------------------
1256 
1257 //==============================================================================
1287 inline std::string ATTRIBUTE_HIDDEN TranslateSpecialProtocol(const std::string& source)
1288 {
1289  using namespace kodi::addon;
1290 
1291  std::string strReturn;
1292  char* protocol = CAddonBase::m_interface->toKodi->kodi_filesystem->translate_special_protocol(
1293  CAddonBase::m_interface->toKodi->kodiBase, source.c_str());
1294  if (protocol != nullptr)
1295  {
1296  if (std::strlen(protocol))
1297  strReturn = protocol;
1298  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1299  protocol);
1300  }
1301  return strReturn;
1302 }
1303 //------------------------------------------------------------------------------
1304 
1305 //==============================================================================
1341 inline bool ATTRIBUTE_HIDDEN GetDiskSpace(const std::string& path,
1342  uint64_t& capacity,
1343  uint64_t& free,
1344  uint64_t& available)
1345 {
1346  using namespace kodi::addon;
1347 
1348  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_disk_space(
1349  CAddonBase::m_interface->toKodi->kodiBase, path.c_str(), &capacity, &free, &available);
1350 }
1351 //------------------------------------------------------------------------------
1352 
1353 //==============================================================================
1371 inline std::string ATTRIBUTE_HIDDEN GetFileName(const std::string& path)
1372 {
1373  /* find the last slash */
1374  const size_t slash = path.find_last_of("/\\");
1375  return path.substr(slash + 1);
1376 }
1377 //------------------------------------------------------------------------------
1378 
1379 //==============================================================================
1397 inline std::string ATTRIBUTE_HIDDEN GetDirectoryName(const std::string& path)
1398 {
1399  // Will from a full filename return the directory the file resides in.
1400  // Keeps the final slash at end and possible |option=foo options.
1401 
1402  size_t iPosSlash = path.find_last_of("/\\");
1403  if (iPosSlash == std::string::npos)
1404  return ""; // No slash, so no path (ignore any options)
1405 
1406  size_t iPosBar = path.rfind('|');
1407  if (iPosBar == std::string::npos)
1408  return path.substr(0, iPosSlash + 1); // Only path
1409 
1410  return path.substr(0, iPosSlash + 1) + path.substr(iPosBar); // Path + options
1411 }
1412 //------------------------------------------------------------------------------
1413 
1414 //==============================================================================
1432 inline void ATTRIBUTE_HIDDEN RemoveSlashAtEnd(std::string& path)
1433 {
1434  if (!path.empty())
1435  {
1436  char last = path[path.size() - 1];
1437  if (last == '/' || last == '\\')
1438  path.erase(path.size() - 1);
1439  }
1440 }
1441 //------------------------------------------------------------------------------
1442 
1443 //==============================================================================
1452 inline unsigned int ATTRIBUTE_HIDDEN GetChunkSize(unsigned int chunk, unsigned int minimum)
1453 {
1454  if (chunk)
1455  return chunk * ((minimum + chunk - 1) / chunk);
1456  else
1457  return minimum;
1458 }
1459 //------------------------------------------------------------------------------
1460 
1461 //==============================================================================
1509 inline bool ATTRIBUTE_HIDDEN IsInternetStream(const std::string& path, bool strictCheck = false)
1510 {
1511  using namespace kodi::addon;
1512 
1513  return CAddonBase::m_interface->toKodi->kodi_filesystem->is_internet_stream(
1514  CAddonBase::m_interface->toKodi->kodiBase, path.c_str(), strictCheck);
1515 }
1516 //------------------------------------------------------------------------------
1517 
1518 //==============================================================================
1541 inline bool ATTRIBUTE_HIDDEN IsOnLAN(const std::string& path)
1542 {
1543  using namespace kodi::addon;
1544 
1545  return CAddonBase::m_interface->toKodi->kodi_filesystem->is_on_lan(
1546  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1547 }
1548 //------------------------------------------------------------------------------
1549 
1550 //==============================================================================
1570 inline bool ATTRIBUTE_HIDDEN IsRemote(const std::string& path)
1571 {
1572  using namespace kodi::addon;
1573 
1574  return CAddonBase::m_interface->toKodi->kodi_filesystem->is_remote(
1575  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1576 }
1577 //------------------------------------------------------------------------------
1578 
1579 //==============================================================================
1586 inline bool ATTRIBUTE_HIDDEN IsLocal(const std::string& path)
1587 {
1588  using namespace kodi::addon;
1589 
1590  return CAddonBase::m_interface->toKodi->kodi_filesystem->is_local(
1591  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1592 }
1593 //------------------------------------------------------------------------------
1594 
1595 //==============================================================================
1617 inline bool ATTRIBUTE_HIDDEN IsURL(const std::string& path)
1618 {
1619  using namespace kodi::addon;
1620 
1621  return CAddonBase::m_interface->toKodi->kodi_filesystem->is_url(
1622  CAddonBase::m_interface->toKodi->kodiBase, path.c_str());
1623 }
1624 //--------------------------------------------------------------------------
1625 
1626 //============================================================================
1650 inline bool ATTRIBUTE_HIDDEN GetHttpHeader(const std::string& url, HttpHeader& header)
1651 {
1652  using namespace ::kodi::addon;
1653 
1654  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_http_header(
1655  CAddonBase::m_interface->toKodi->kodiBase, url.c_str(), &header.m_handle);
1656 }
1657 //----------------------------------------------------------------------------
1658 
1659 //============================================================================
1681 inline bool ATTRIBUTE_HIDDEN GetMimeType(const std::string& url,
1682  std::string& mimeType,
1683  const std::string& useragent = "")
1684 {
1685  using namespace ::kodi::addon;
1686 
1687  char* cMimeType = nullptr;
1688  bool ret = CAddonBase::m_interface->toKodi->kodi_filesystem->get_mime_type(
1689  CAddonBase::m_interface->toKodi->kodiBase, url.c_str(), &cMimeType, useragent.c_str());
1690  if (cMimeType != nullptr)
1691  {
1692  mimeType = cMimeType;
1693  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1694  cMimeType);
1695  }
1696  return ret;
1697 }
1698 //----------------------------------------------------------------------------
1699 
1700 //============================================================================
1722 inline bool ATTRIBUTE_HIDDEN GetContentType(const std::string& url,
1723  std::string& content,
1724  const std::string& useragent = "")
1725 {
1726  using namespace ::kodi::addon;
1727 
1728  char* cContent = nullptr;
1729  bool ret = CAddonBase::m_interface->toKodi->kodi_filesystem->get_content_type(
1730  CAddonBase::m_interface->toKodi->kodiBase, url.c_str(), &cContent, useragent.c_str());
1731  if (cContent != nullptr)
1732  {
1733  content = cContent;
1734  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1735  cContent);
1736  }
1737  return ret;
1738 }
1739 //----------------------------------------------------------------------------
1740 
1741 //============================================================================
1764 inline bool ATTRIBUTE_HIDDEN GetCookies(const std::string& url, std::string& cookies)
1765 {
1766  using namespace ::kodi::addon;
1767 
1768  char* cCookies = nullptr;
1769  bool ret = CAddonBase::m_interface->toKodi->kodi_filesystem->get_cookies(
1770  CAddonBase::m_interface->toKodi->kodiBase, url.c_str(), &cCookies);
1771  if (cCookies != nullptr)
1772  {
1773  cookies = cCookies;
1774  CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
1775  cCookies);
1776  }
1777  return ret;
1778 }
1779 //----------------------------------------------------------------------------
1780 
1781 //}}}
1782 
1783 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1784 // "C++" CFile class
1785 //{{{
1786 
1787 //==============================================================================
1828 class ATTRIBUTE_HIDDEN CFile
1829 {
1830 public:
1831  //============================================================================
1835  CFile() = default;
1836  //----------------------------------------------------------------------------
1837 
1838  //============================================================================
1843  virtual ~CFile() { Close(); }
1844  //--------------------------------------------------------------------------
1845 
1846  //==========================================================================
1855  bool OpenFile(const std::string& filename, unsigned int flags = 0)
1856  {
1857  using namespace kodi::addon;
1858 
1859  Close();
1860  m_file = CAddonBase::m_interface->toKodi->kodi_filesystem->open_file(
1861  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), flags);
1862  return m_file != nullptr;
1863  }
1864  //--------------------------------------------------------------------------
1865 
1866  //==========================================================================
1878  bool OpenFileForWrite(const std::string& filename, bool overwrite = false)
1879  {
1880  using namespace kodi::addon;
1881 
1882  Close();
1883 
1884  // Try to open the file. If it fails, check if we need to create the directory first
1885  // This way we avoid checking if the directory exists every time
1886  m_file = CAddonBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1887  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1888  if (!m_file)
1889  {
1890  std::string cacheDirectory = kodi::vfs::GetDirectoryName(filename);
1891  if (CAddonBase::m_interface->toKodi->kodi_filesystem->directory_exists(
1892  CAddonBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()) ||
1893  CAddonBase::m_interface->toKodi->kodi_filesystem->create_directory(
1894  CAddonBase::m_interface->toKodi->kodiBase, cacheDirectory.c_str()))
1895  m_file = CAddonBase::m_interface->toKodi->kodi_filesystem->open_file_for_write(
1896  CAddonBase::m_interface->toKodi->kodiBase, filename.c_str(), overwrite);
1897  }
1898  return m_file != nullptr;
1899  }
1900  //--------------------------------------------------------------------------
1901 
1902  //==========================================================================
1908  bool IsOpen() const { return m_file != nullptr; }
1909  //--------------------------------------------------------------------------
1910 
1911  //==========================================================================
1915  void Close()
1916  {
1917  using namespace kodi::addon;
1918 
1919  if (!m_file)
1920  return;
1921  CAddonBase::m_interface->toKodi->kodi_filesystem->close_file(
1922  CAddonBase::m_interface->toKodi->kodiBase, m_file);
1923  m_file = nullptr;
1924  }
1925  //--------------------------------------------------------------------------
1926 
1927  //==========================================================================
1934  bool CURLCreate(const std::string& url)
1935  {
1936  using namespace kodi::addon;
1937 
1938  m_file = CAddonBase::m_interface->toKodi->kodi_filesystem->curl_create(
1939  CAddonBase::m_interface->toKodi->kodiBase, url.c_str());
1940  return m_file != nullptr;
1941  }
1942  //--------------------------------------------------------------------------
1943 
1944  //==========================================================================
1953  bool CURLAddOption(CURLOptiontype type, const std::string& name, const std::string& value)
1954  {
1955  using namespace kodi::addon;
1956 
1957  if (!m_file)
1958  {
1959  kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1960  return false;
1961  }
1962  return CAddonBase::m_interface->toKodi->kodi_filesystem->curl_add_option(
1963  CAddonBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), value.c_str());
1964  }
1965  //--------------------------------------------------------------------------
1966 
1967  //==========================================================================
1974  bool CURLOpen(unsigned int flags = 0)
1975  {
1976  using namespace kodi::addon;
1977 
1978  if (!m_file)
1979  {
1980  kodi::Log(ADDON_LOG_ERROR, "kodi::vfs::CURLCreate(...) needed to call before!");
1981  return false;
1982  }
1983  return CAddonBase::m_interface->toKodi->kodi_filesystem->curl_open(
1984  CAddonBase::m_interface->toKodi->kodiBase, m_file, flags);
1985  }
1986  //--------------------------------------------------------------------------
1987 
1988  //==========================================================================
1999  ssize_t Read(void* ptr, size_t size)
2000  {
2001  using namespace kodi::addon;
2002 
2003  if (!m_file)
2004  return -1;
2005  return CAddonBase::m_interface->toKodi->kodi_filesystem->read_file(
2006  CAddonBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2007  }
2008  //--------------------------------------------------------------------------
2009 
2010  //==========================================================================
2017  bool ReadLine(std::string& line)
2018  {
2019  using namespace kodi::addon;
2020 
2021  line.clear();
2022  if (!m_file)
2023  return false;
2024  // TODO: Read 1024 chars into buffer. If file position advanced that many
2025  // chars, we didn't hit a newline. Otherwise, if file position is 1 or 2
2026  // past the number of bytes read, we read (and skipped) a newline sequence.
2027  char buffer[1025];
2028  if (CAddonBase::m_interface->toKodi->kodi_filesystem->read_file_string(
2029  CAddonBase::m_interface->toKodi->kodiBase, m_file, buffer, sizeof(buffer)))
2030  {
2031  line = buffer;
2032  return !line.empty();
2033  }
2034  return false;
2035  }
2036  //--------------------------------------------------------------------------
2037 
2038  //==========================================================================
2048  ssize_t Write(const void* ptr, size_t size)
2049  {
2050  using namespace kodi::addon;
2051 
2052  if (!m_file)
2053  return -1;
2054  return CAddonBase::m_interface->toKodi->kodi_filesystem->write_file(
2055  CAddonBase::m_interface->toKodi->kodiBase, m_file, ptr, size);
2056  }
2057  //--------------------------------------------------------------------------
2058 
2059  //==========================================================================
2073  void Flush()
2074  {
2075  using namespace kodi::addon;
2076 
2077  if (!m_file)
2078  return;
2079  CAddonBase::m_interface->toKodi->kodi_filesystem->flush_file(
2080  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2081  }
2082  //--------------------------------------------------------------------------
2083 
2084  //==========================================================================
2102  int64_t Seek(int64_t position, int whence = SEEK_SET)
2103  {
2104  using namespace kodi::addon;
2105 
2106  if (!m_file)
2107  return -1;
2108  return CAddonBase::m_interface->toKodi->kodi_filesystem->seek_file(
2109  CAddonBase::m_interface->toKodi->kodiBase, m_file, position, whence);
2110  }
2111  //--------------------------------------------------------------------------
2112 
2113  //==========================================================================
2120  int Truncate(int64_t size)
2121  {
2122  using namespace kodi::addon;
2123 
2124  if (!m_file)
2125  return -1;
2126  return CAddonBase::m_interface->toKodi->kodi_filesystem->truncate_file(
2127  CAddonBase::m_interface->toKodi->kodiBase, m_file, size);
2128  }
2129  //--------------------------------------------------------------------------
2130 
2131  //==========================================================================
2137  int64_t GetPosition() const
2138  {
2139  using namespace kodi::addon;
2140 
2141  if (!m_file)
2142  return -1;
2143  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2144  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2145  }
2146  //--------------------------------------------------------------------------
2147 
2148  //==========================================================================
2154  int64_t GetLength() const
2155  {
2156  using namespace kodi::addon;
2157 
2158  if (!m_file)
2159  return -1;
2160  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2161  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2162  }
2163  //--------------------------------------------------------------------------
2164 
2165  //==========================================================================
2171  bool AtEnd() const
2172  {
2173  using namespace kodi::addon;
2174 
2175  if (!m_file)
2176  return true;
2177  int64_t length = CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_length(
2178  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2179  int64_t position = CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_position(
2180  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2181  return position >= length;
2182  }
2183  //--------------------------------------------------------------------------
2184 
2185  //==========================================================================
2191  int GetChunkSize() const
2192  {
2193  using namespace kodi::addon;
2194 
2195  if (!m_file)
2196  return -1;
2197  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_chunk_size(
2198  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2199  }
2200  //--------------------------------------------------------------------------
2201 
2202  //==========================================================================
2209  {
2210  using namespace kodi::addon;
2211 
2212  if (!m_file)
2213  return false;
2214  return CAddonBase::m_interface->toKodi->kodi_filesystem->io_control_get_seek_possible(
2215  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2216  }
2217  //--------------------------------------------------------------------------
2218 
2219  //==========================================================================
2230  {
2231  using namespace kodi::addon;
2232 
2233  if (!m_file)
2234  return false;
2235  return CAddonBase::m_interface->toKodi->kodi_filesystem->io_control_get_cache_status(
2236  CAddonBase::m_interface->toKodi->kodiBase, m_file, status);
2237  }
2238  //--------------------------------------------------------------------------
2239 
2240  //==========================================================================
2247  bool IoControlSetCacheRate(unsigned int rate)
2248  {
2249  using namespace kodi::addon;
2250 
2251  if (!m_file)
2252  return false;
2253  return CAddonBase::m_interface->toKodi->kodi_filesystem->io_control_set_cache_rate(
2254  CAddonBase::m_interface->toKodi->kodiBase, m_file, rate);
2255  }
2256  //--------------------------------------------------------------------------
2257 
2258  //==========================================================================
2265  bool IoControlSetRetry(bool retry)
2266  {
2267  using namespace kodi::addon;
2268 
2269  if (!m_file)
2270  return false;
2271  return CAddonBase::m_interface->toKodi->kodi_filesystem->io_control_set_retry(
2272  CAddonBase::m_interface->toKodi->kodiBase, m_file, retry);
2273  }
2274  //--------------------------------------------------------------------------
2275 
2276  //==========================================================================
2284  const std::string GetPropertyValue(FilePropertyTypes type, const std::string& name) const
2285  {
2286  using namespace kodi::addon;
2287 
2288  if (!m_file)
2289  {
2291  "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValue!");
2292  return "";
2293  }
2294  std::vector<std::string> values = GetPropertyValues(type, name);
2295  if (values.empty())
2296  {
2297  return "";
2298  }
2299  return values[0];
2300  }
2301  //--------------------------------------------------------------------------
2302 
2303  //==========================================================================
2311  const std::vector<std::string> GetPropertyValues(FilePropertyTypes type,
2312  const std::string& name) const
2313  {
2314  using namespace kodi::addon;
2315 
2316  if (!m_file)
2317  {
2319  "kodi::vfs::CURLCreate(...) needed to call before GetPropertyValues!");
2320  return std::vector<std::string>();
2321  }
2322  int numValues = 0;
2323  char** res(CAddonBase::m_interface->toKodi->kodi_filesystem->get_property_values(
2324  CAddonBase::m_interface->toKodi->kodiBase, m_file, type, name.c_str(), &numValues));
2325  if (res)
2326  {
2327  std::vector<std::string> vecReturn;
2328  vecReturn.reserve(numValues);
2329  for (int i = 0; i < numValues; ++i)
2330  {
2331  vecReturn.emplace_back(res[i]);
2332  }
2333  CAddonBase::m_interface->toKodi->free_string_array(CAddonBase::m_interface->toKodi->kodiBase,
2334  res, numValues);
2335  return vecReturn;
2336  }
2337  return std::vector<std::string>();
2338  }
2339  //--------------------------------------------------------------------------
2340 
2341  //==========================================================================
2347  double GetFileDownloadSpeed() const
2348  {
2349  using namespace kodi::addon;
2350 
2351  if (!m_file)
2352  return 0.0;
2353  return CAddonBase::m_interface->toKodi->kodi_filesystem->get_file_download_speed(
2354  CAddonBase::m_interface->toKodi->kodiBase, m_file);
2355  }
2356  //--------------------------------------------------------------------------
2357 
2358 private:
2359  void* m_file = nullptr;
2360 };
2362 //------------------------------------------------------------------------------
2363 
2364 //}}}
2365 
2366 } /* namespace vfs */
2367 } /* namespace kodi */
2368 
2369 #endif /* __cplusplus */
Definition: AddonBase.h:250
Definition: Filesystem.h:543
Definition: Filesystem.h:1829
Definition: Filesystem.h:226
Definition: Filesystem.h:96
Definition: Filesystem.h:295
HttpHeader()
Http header parser class constructor.
Definition: Filesystem.h:300
~HttpHeader()
Class destructor.
Definition: Filesystem.h:312
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition: addon_base.h:183
void AddProperty(const std::string &id, const std::string &value)
Add a by string defined property entry to directory entry.
Definition: Filesystem.h:710
const std::string & Label(void) const
Get the directory entry name.
Definition: Filesystem.h:609
void SetPath(const std::string &path)
Set the path of the entry.
Definition: Filesystem.h:673
void SetTitle(const std::string &title)
Set the title name.
Definition: Filesystem.h:665
const std::string & Path(void) const
Get the path of the entry.
Definition: Filesystem.h:625
void SetDateTime(time_t dateTime)
Set file time and date for a new entry.
Definition: Filesystem.h:697
const std::string & Title(void) const
Get the optional title of entry.
Definition: Filesystem.h:617
void SetFolder(bool folder)
Set the entry defined as folder.
Definition: Filesystem.h:681
void SetLabel(const std::string &label)
Set the label name.
Definition: Filesystem.h:657
void ClearProperties()
Clear all present properties.
Definition: Filesystem.h:716
time_t DateTime()
Get file time and date for a new entry.
Definition: Filesystem.h:649
bool IsFolder(void) const
Used to check entry is folder.
Definition: Filesystem.h:633
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:555
int64_t Size(void) const
If file, the size of the file.
Definition: Filesystem.h:641
void SetSize(int64_t size)
Set a file size for a new entry.
Definition: Filesystem.h:689
const std::map< std::string, std::string > & GetProperties() const
Get the present properties list on directory entry.
Definition: Filesystem.h:724
void Flush()
Flush buffered data.
Definition: Filesystem.h:2073
bool IsOpen() const
Check file is opened.
Definition: Filesystem.h:1908
const std::vector< std::string > GetPropertyValues(FilePropertyTypes type, const std::string &name) const
Retrieve file property values.
Definition: Filesystem.h:2311
bool AtEnd() const
Checks the file access is on end position.
Definition: Filesystem.h:2171
int64_t Seek(int64_t position, int whence=SEEK_SET)
Set the file's current position.
Definition: Filesystem.h:2102
int64_t GetLength() const
Get the file size of an open file.
Definition: Filesystem.h:2154
bool IoControlGetCacheStatus(CacheStatus &status) const
To check a running stream on file for state of his cache.
Definition: Filesystem.h:2229
int GetChunkSize() const
Get the chunk size for an open file.
Definition: Filesystem.h:2191
bool IoControlSetCacheRate(unsigned int rate)
Unsigned int with speed limit for caching in bytes per second.
Definition: Filesystem.h:2247
bool CURLOpen(unsigned int flags=0)
Open the curl file created with CURLCreate.
Definition: Filesystem.h:1974
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:1878
int Truncate(int64_t size)
Truncate a file to the requested size.
Definition: Filesystem.h:2120
void Close()
Close an open file.
Definition: Filesystem.h:1915
bool CURLCreate(const std::string &url)
Create a Curl representation.
Definition: Filesystem.h:1934
bool IoControlGetSeekPossible() const
To check seek possible on current stream by file.
Definition: Filesystem.h:2208
double GetFileDownloadSpeed() const
Get the current download speed of file if loaded from web.
Definition: Filesystem.h:2347
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:1855
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:1843
ssize_t Write(const void *ptr, size_t size)
Write to a file opened in write mode.
Definition: Filesystem.h:2048
bool CURLAddOption(CURLOptiontype type, const std::string &name, const std::string &value)
Add options to the curl file created with CURLCreate.
Definition: Filesystem.h:1953
bool IoControlSetRetry(bool retry)
Enable/disable retry within the protocol handler (if supported).
Definition: Filesystem.h:2265
bool ReadLine(std::string &line)
Read a string from an open file.
Definition: Filesystem.h:2017
const std::string GetPropertyValue(FilePropertyTypes type, const std::string &name) const
Retrieve a file property.
Definition: Filesystem.h:2284
int64_t GetPosition() const
The current offset in an open file.
Definition: Filesystem.h:2137
ssize_t Read(void *ptr, size_t size)
Read from an open file.
Definition: Filesystem.h:1999
CURLOptiontype
Definition: filesystem.h:109
void SetMaxRate(unsigned int maxrate)
Set maximum number of bytes per second cache is allowed to fill.
Definition: Filesystem.h:259
void SetCurrentRate(unsigned int currate)
Set average read rate from source file since last position change.
Definition: Filesystem.h:265
unsigned int GetMaxRate()
Set maximum number of bytes per second cache is allowed to fill.
Definition: Filesystem.h:262
void SetLowspeed(bool lowspeed)
Set cache low speed condition detected.
Definition: Filesystem.h:271
bool GetLowspeed()
Get cache low speed condition detected.
Definition: Filesystem.h:274
unsigned int GetCurrentRate()
Get 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:253
uint64_t GetForward()
Get number of bytes cached forward of current position.
Definition: Filesystem.h:256
FilePropertyTypes
Definition: filesystem.h:153
bool GetIsRegular() const
Get stat url is a regular.
Definition: Filesystem.h:204
uint64_t GetSize() const
Get total size, in bytes.
Definition: Filesystem.h:147
bool GetIsBlock() const
Get stat url is a block special.
Definition: Filesystem.h:186
bool GetIsSocket() const
Get stat url is a regular.
Definition: Filesystem.h:210
void SetIsBlock(bool isBlock)
Set stat url as a block special.
Definition: Filesystem.h:183
void SetIsFifo(bool isFifo)
Set stat url as a FIFO special.
Definition: Filesystem.h:195
void SetIsDirectory(bool isDirectory)
Set the stat url is a directory.
Definition: Filesystem.h:171
time_t GetAccessTime() const
Get time of last access.
Definition: Filesystem.h:153
void SetStatusTime(time_t statusTime)
Set time of last status change.
Definition: Filesystem.h:165
bool GetIsDirectory() const
The stat url is a directory if returns true.
Definition: Filesystem.h:174
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:180
bool GetIsFifo() const
Get stat url is a FIFO special.
Definition: Filesystem.h:198
bool GetIsCharacter() const
Get stat url is a character special.
Definition: Filesystem.h:192
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:156
void SetAccessTime(time_t accessTime)
Set time of last access.
Definition: Filesystem.h:150
void SetSize(uint64_t size)
Set total size, in bytes.
Definition: Filesystem.h:144
time_t GetModificationTime() const
Get time of last modification.
Definition: Filesystem.h:162
void SetIsCharacter(bool isCharacter)
Set stat url as a character special.
Definition: Filesystem.h:189
void SetIsSocket(bool isSocket)
Set stat url is a socket.
Definition: Filesystem.h:207
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:168
uint64_t GetFileSerialNumber() const
Get the file serial number, which distinguishes this file from all other files on the same device.
Definition: Filesystem.h:141
void SetIsRegular(bool isRegular)
Set stat url as a regular.
Definition: Filesystem.h:201
void SetIsSymLink(bool isSymLink)
Set stat url as a symbolic link.
Definition: Filesystem.h:177
std::string GetCharset() const
Get the charset associated with these HTTP headers.
Definition: Filesystem.h:452
std::string GetValue(const std::string &param) const
Get the value associated with this parameter of these HTTP headers.
Definition: Filesystem.h:345
std::string GetMimeType() const
Get the mime type associated with these HTTP headers.
Definition: Filesystem.h:427
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:372
std::string GetHeader() const
Get the full header string associated with these HTTP headers.
Definition: Filesystem.h:403
std::string GetProtoLine() const
The protocol line associated with these HTTP headers.
Definition: Filesystem.h:476
bool ATTRIBUTE_HIDDEN CreateDirectory(const std::string &path)
Make a directory.
Definition: Filesystem.h:773
bool ATTRIBUTE_HIDDEN GetDirectory(const std::string &path, const std::string &mask, std::vector< kodi::vfs::CDirEntry > &items)
Lists a directory.
Definition: Filesystem.h:888
bool ATTRIBUTE_HIDDEN DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition: Filesystem.h:805
bool ATTRIBUTE_HIDDEN RemoveDirectory(const std::string &path, bool recursive=false)
Removes a directory.
Definition: Filesystem.h:839
bool ATTRIBUTE_HIDDEN DeleteFile(const std::string &filename)
Deletes a file.
Definition: Filesystem.h:1033
bool ATTRIBUTE_HIDDEN StatFile(const std::string &filename, kodi::vfs::FileStatus &buffer)
Get file status.
Definition: Filesystem.h:995
bool ATTRIBUTE_HIDDEN RenameFile(const std::string &filename, const std::string &newFileName)
Rename a file name.
Definition: Filesystem.h:1051
bool ATTRIBUTE_HIDDEN FileExists(const std::string &filename, bool usecache=false)
Check if a file exists.
Definition: Filesystem.h:940
bool ATTRIBUTE_HIDDEN CopyFile(const std::string &filename, const std::string &destination)
Copy a file from source to destination.
Definition: Filesystem.h:1069
std::string ATTRIBUTE_HIDDEN TranslateSpecialProtocol(const std::string &source)
Returns the translated path.
Definition: Filesystem.h:1287
std::string ATTRIBUTE_HIDDEN MakeLegalFileName(const std::string &filename)
Make filename valid.
Definition: Filesystem.h:1196
bool ATTRIBUTE_HIDDEN GetContentType(const std::string &url, std::string &content, const std::string &useragent="")
Get file content-type.
Definition: Filesystem.h:1722
std::string ATTRIBUTE_HIDDEN GetFileName(const std::string &path)
Return the file name from given complate path string.
Definition: Filesystem.h:1371
bool ATTRIBUTE_HIDDEN IsInternetStream(const std::string &path, bool strictCheck=false)
Checks the given path contains a known internet protocol.
Definition: Filesystem.h:1509
bool ATTRIBUTE_HIDDEN GetHttpHeader(const std::string &url, HttpHeader &header)
To get HTTP header information.
Definition: Filesystem.h:1650
std::string ATTRIBUTE_HIDDEN MakeLegalPath(const std::string &path)
Make directory name valid.
Definition: Filesystem.h:1239
bool ATTRIBUTE_HIDDEN GetMimeType(const std::string &url, std::string &mimeType, const std::string &useragent="")
Get file mime type.
Definition: Filesystem.h:1681
void ATTRIBUTE_HIDDEN RemoveSlashAtEnd(std::string &path)
Remove the slash on given path name.
Definition: Filesystem.h:1432
std::string ATTRIBUTE_HIDDEN GetFileMD5(const std::string &path)
Retrieve MD5sum of a file.
Definition: Filesystem.h:1110
std::string ATTRIBUTE_HIDDEN GetDirectoryName(const std::string &path)
Return the directory name from given complate path string.
Definition: Filesystem.h:1397
bool ATTRIBUTE_HIDDEN IsURL(const std::string &path)
Checks specified path is a regular URL, e.g. "someprotocol://path/to/file".
Definition: Filesystem.h:1617
bool ATTRIBUTE_HIDDEN IsOnLAN(const std::string &path)
Checks whether the specified path refers to a local network.
Definition: Filesystem.h:1541
bool ATTRIBUTE_HIDDEN 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:1341
bool ATTRIBUTE_HIDDEN GetCookies(const std::string &url, std::string &cookies)
Get cookies stored by CURL in RFC 2109 format.
Definition: Filesystem.h:1764
std::string ATTRIBUTE_HIDDEN GetCacheThumbName(const std::string &filename)
Returns a thumb cache filename.
Definition: Filesystem.h:1153
bool ATTRIBUTE_HIDDEN IsRemote(const std::string &path)
Checks specified path for external network.
Definition: Filesystem.h:1570
unsigned int ATTRIBUTE_HIDDEN 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:1452
bool ATTRIBUTE_HIDDEN IsLocal(const std::string &path)
Checks whether the given path refers to the own system.
Definition: Filesystem.h:1586
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749
Definition: filesystem.h:177
Definition: filesystem.h:189
Definition: filesystem.h:220
Definition: filesystem.h:234