447 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
448 throw std::logic_error(
"kodi::addon::CInstanceVFS: Creation of multiple together with single "
449 "instance way is not allowed!");
451 SetAddonStruct(instance);
804 bool GetKeyboardInput(
const std::string& heading, std::string& input,
bool hiddenInput =
false)
806 char* cInput =
nullptr;
807 bool ret = m_cb->get_keyboard_input(m_cb->ctx, heading.c_str(), &cInput, hiddenInput);
811 ::kodi::addon::CPrivateBase::m_interface->toKodi->free_string(
812 ::kodi::addon::CPrivateBase::m_interface->toKodi->kodiBase, cInput);
826 const std::string& line1,
827 const std::string& line2 =
"",
828 const std::string& line3 =
"")
830 m_cb->set_error_dialog(m_cb->ctx, heading.c_str(), line1.c_str(), line2.c_str(),
840 m_cb->require_authentication(m_cb->ctx, url.c_str());
875 std::vector<kodi::vfs::CDirEntry>& entries,
894 std::vector<kodi::vfs::CDirEntry>& entries,
895 std::string& rootPath)
905 m_instanceData = instance;
906 m_instanceData->hdl =
this;
907 m_instanceData->vfs->toAddon->addonInstance =
this;
908 m_instanceData->vfs->toAddon->open = ADDON_Open;
909 m_instanceData->vfs->toAddon->open_for_write = ADDON_OpenForWrite;
910 m_instanceData->vfs->toAddon->read = ADDON_Read;
911 m_instanceData->vfs->toAddon->write = ADDON_Write;
912 m_instanceData->vfs->toAddon->seek = ADDON_Seek;
913 m_instanceData->vfs->toAddon->truncate = ADDON_Truncate;
914 m_instanceData->vfs->toAddon->get_length = ADDON_GetLength;
915 m_instanceData->vfs->toAddon->get_position = ADDON_GetPosition;
916 m_instanceData->vfs->toAddon->get_chunk_size = ADDON_GetChunkSize;
917 m_instanceData->vfs->toAddon->io_control_get_seek_possible = ADDON_IoControlGetSeekPossible;
918 m_instanceData->vfs->toAddon->io_control_get_cache_status = ADDON_IoControlGetCacheStatus;
919 m_instanceData->vfs->toAddon->io_control_set_cache_rate = ADDON_IoControlSetCacheRate;
920 m_instanceData->vfs->toAddon->io_control_set_retry = ADDON_IoControlSetRetry;
921 m_instanceData->vfs->toAddon->stat = ADDON_Stat;
922 m_instanceData->vfs->toAddon->close = ADDON_Close;
923 m_instanceData->vfs->toAddon->exists = ADDON_Exists;
924 m_instanceData->vfs->toAddon->clear_out_idle = ADDON_ClearOutIdle;
925 m_instanceData->vfs->toAddon->disconnect_all = ADDON_DisconnectAll;
926 m_instanceData->vfs->toAddon->delete_it = ADDON_Delete;
927 m_instanceData->vfs->toAddon->rename = ADDON_Rename;
928 m_instanceData->vfs->toAddon->directory_exists = ADDON_DirectoryExists;
929 m_instanceData->vfs->toAddon->remove_directory = ADDON_RemoveDirectory;
930 m_instanceData->vfs->toAddon->create_directory = ADDON_CreateDirectory;
931 m_instanceData->vfs->toAddon->get_directory = ADDON_GetDirectory;
932 m_instanceData->vfs->toAddon->free_directory = ADDON_FreeDirectory;
933 m_instanceData->vfs->toAddon->contains_files = ADDON_ContainsFiles;
939 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Open(url);
946 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
947 ->OpenForWrite(url, overWrite);
950 inline static ssize_t ADDON_Read(
const AddonInstance_VFSEntry* instance,
951 VFS_FILE_HANDLE context,
955 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
956 ->Read(context, buffer, uiBufSize);
959 inline static ssize_t ADDON_Write(
const AddonInstance_VFSEntry* instance,
960 VFS_FILE_HANDLE context,
961 const uint8_t* buffer,
964 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
965 ->Write(context, buffer, uiBufSize);
968 inline static int64_t ADDON_Seek(
const AddonInstance_VFSEntry* instance,
969 VFS_FILE_HANDLE context,
973 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
974 ->Seek(context, position, whence);
977 inline static int ADDON_Truncate(
const AddonInstance_VFSEntry* instance,
978 VFS_FILE_HANDLE context,
981 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Truncate(context, size);
984 inline static int64_t ADDON_GetLength(
const AddonInstance_VFSEntry* instance,
985 VFS_FILE_HANDLE context)
987 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetLength(context);
990 inline static int64_t ADDON_GetPosition(
const AddonInstance_VFSEntry* instance,
991 VFS_FILE_HANDLE context)
993 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetPosition(context);
996 inline static int ADDON_GetChunkSize(
const AddonInstance_VFSEntry* instance,
997 VFS_FILE_HANDLE context)
999 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
GetChunkSize(context);
1002 inline static bool ADDON_IoControlGetSeekPossible(
const AddonInstance_VFSEntry* instance,
1003 VFS_FILE_HANDLE context)
1005 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1006 ->IoControlGetSeekPossible(context);
1009 inline static bool ADDON_IoControlGetCacheStatus(
const struct AddonInstance_VFSEntry* instance,
1010 VFS_FILE_HANDLE context,
1011 VFS_CACHE_STATUS_DATA* status)
1013 kodi::vfs::CacheStatus cppStatus(status);
1014 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1015 ->IoControlGetCacheStatus(context, cppStatus);
1018 inline static bool ADDON_IoControlSetCacheRate(
const struct AddonInstance_VFSEntry* instance,
1019 VFS_FILE_HANDLE context,
1022 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1023 ->IoControlSetCacheRate(context, rate);
1026 inline static bool ADDON_IoControlSetRetry(
const struct AddonInstance_VFSEntry* instance,
1027 VFS_FILE_HANDLE context,
1030 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1031 ->IoControlSetRetry(context, retry);
1034 inline static int ADDON_Stat(
const AddonInstance_VFSEntry* instance,
1036 struct STAT_STRUCTURE* buffer)
1038 kodi::vfs::FileStatus cppBuffer(buffer);
1039 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Stat(url, cppBuffer);
1042 inline static bool ADDON_Close(
const AddonInstance_VFSEntry* instance, VFS_FILE_HANDLE context)
1044 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Close(context);
1047 inline static bool ADDON_Exists(
const AddonInstance_VFSEntry* instance,
const VFSURL* url)
1049 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Exists(url);
1052 inline static void ADDON_ClearOutIdle(
const AddonInstance_VFSEntry* instance)
1054 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->ClearOutIdle();
1057 inline static void ADDON_DisconnectAll(
const AddonInstance_VFSEntry* instance)
1059 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->DisconnectAll();
1062 inline static bool ADDON_Delete(
const AddonInstance_VFSEntry* instance,
const VFSURL* url)
1064 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Delete(url);
1067 inline static bool ADDON_Rename(
const AddonInstance_VFSEntry* instance,
1071 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Rename(url, url2);
1074 inline static bool ADDON_DirectoryExists(
const AddonInstance_VFSEntry* instance,
1077 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
DirectoryExists(url);
1080 inline static bool ADDON_RemoveDirectory(
const AddonInstance_VFSEntry* instance,
1083 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
RemoveDirectory(url);
1086 inline static bool ADDON_CreateDirectory(
const AddonInstance_VFSEntry* instance,
1089 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
CreateDirectory(url);
1092 inline static bool ADDON_GetDirectory(
const AddonInstance_VFSEntry* instance,
1094 VFSDirEntry** retEntries,
1096 VFSGetDirectoryCallbacks* callbacks)
1098 std::vector<kodi::vfs::CDirEntry> addonEntries;
1099 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1100 ->
GetDirectory(url, addonEntries, CVFSCallbacks(callbacks));
1103 VFSDirEntry* entries =
1104 static_cast<VFSDirEntry*
>(malloc(
sizeof(VFSDirEntry) * addonEntries.size()));
1105 for (
unsigned int i = 0; i < addonEntries.size(); ++i)
1107 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1108 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1109 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1110 entries[i].
folder = addonEntries[i].IsFolder();
1111 entries[i].
size = addonEntries[i].Size();
1112 entries[i].
date_time = addonEntries[i].DateTime();
1115 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1119 static_cast<VFSProperty*
>(malloc(
sizeof(VFSProperty) * props.size()));
1120 for (
const auto& prop : props)
1130 *retEntries = entries;
1131 *num_entries =
static_cast<int>(addonEntries.size());
1136 inline static void ADDON_FreeDirectory(
const AddonInstance_VFSEntry* instance,
1137 VFSDirEntry* entries,
1140 for (
int i = 0; i < num_entries; ++i)
1142 if (entries[i].properties)
1144 for (
unsigned int j = 0; j < entries[i].
num_props; ++j)
1146 free(entries[i].properties[j].name);
1147 free(entries[i].properties[j].val);
1149 free(entries[i].properties);
1151 free(entries[i].label);
1152 free(entries[i].title);
1153 free(entries[i].path);
1158 inline static bool ADDON_ContainsFiles(
const AddonInstance_VFSEntry* instance,
1160 VFSDirEntry** retEntries,
1164 std::string cppRootPath;
1165 std::vector<kodi::vfs::CDirEntry> addonEntries;
1166 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1167 ->ContainsFiles(url, addonEntries, cppRootPath);
1170 strncpy(rootpath, cppRootPath.c_str(), ADDON_STANDARD_STRING_LENGTH);
1172 VFSDirEntry* entries =
1173 static_cast<VFSDirEntry*
>(malloc(
sizeof(VFSDirEntry) * addonEntries.size()));
1174 for (
size_t i = 0; i < addonEntries.size(); ++i)
1176 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1177 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1178 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1179 entries[i].
folder = addonEntries[i].IsFolder();
1180 entries[i].
size = addonEntries[i].Size();
1181 entries[i].
date_time = addonEntries[i].DateTime();
1184 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1188 static_cast<VFSProperty*
>(malloc(
sizeof(VFSProperty) * props.size()));
1189 for (
const auto& prop : props)
1199 *retEntries = entries;
1200 *num_entries =
static_cast<int>(addonEntries.size());
1205 KODI_ADDON_INSTANCE_STRUCT* m_instanceData{
nullptr};