10 #include "../AddonBase.h"
11 #include "../Filesystem.h"
12 #include "../c-api/addon-instance/vfs.h"
85 std::string
GetURL()
const {
return m_cStructure->url; }
89 std::string
GetDomain()
const {
return m_cStructure->domain; }
94 std::string
GetHostname()
const {
return m_cStructure->hostname; }
98 std::string
GetFilename()
const {
return m_cStructure->filename; }
102 unsigned int GetPort()
const {
return m_cStructure->port; }
118 std::string
GetOptions()
const {
return m_cStructure->options; }
121 std::string
GetUsername()
const {
return m_cStructure->username; }
124 std::string
GetPassword()
const {
return m_cStructure->password; }
130 std::string
GetRedacted()
const {
return m_cStructure->redacted; }
140 std::string
GetProtocol()
const {
return m_cStructure->protocol; }
148 VFSUrl(
VFSURL* channel) : CStructHdl(channel) {}
455 explicit CInstanceVFS(KODI_HANDLE instance,
const std::string& kodiVersion =
"")
459 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
460 throw std::logic_error(
"kodi::addon::CInstanceVFS: Creation of multiple together with single "
461 "instance way is not allowed!");
463 SetAddonStruct(instance);
816 bool GetKeyboardInput(
const std::string& heading, std::string& input,
bool hiddenInput =
false)
818 char* cInput =
nullptr;
819 bool ret = m_cb->get_keyboard_input(m_cb->ctx, heading.c_str(), &cInput, hiddenInput);
823 ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(
824 ::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, cInput);
838 const std::string& line1,
839 const std::string& line2 =
"",
840 const std::string& line3 =
"")
842 m_cb->set_error_dialog(m_cb->ctx, heading.c_str(), line1.c_str(), line2.c_str(),
852 m_cb->require_authentication(m_cb->ctx, url.c_str());
887 std::vector<kodi::vfs::CDirEntry>& entries,
906 std::vector<kodi::vfs::CDirEntry>& entries,
907 std::string& rootPath)
915 void SetAddonStruct(KODI_HANDLE instance)
917 if (instance ==
nullptr)
918 throw std::logic_error(
"kodi::addon::CInstanceVFS: Creation with empty addon structure not "
919 "allowed, table must be given from Kodi!");
922 m_instanceData->toAddon->addonInstance =
this;
923 m_instanceData->toAddon->open = ADDON_Open;
924 m_instanceData->toAddon->open_for_write = ADDON_OpenForWrite;
925 m_instanceData->toAddon->read = ADDON_Read;
926 m_instanceData->toAddon->write = ADDON_Write;
927 m_instanceData->toAddon->seek = ADDON_Seek;
928 m_instanceData->toAddon->truncate = ADDON_Truncate;
929 m_instanceData->toAddon->get_length = ADDON_GetLength;
930 m_instanceData->toAddon->get_position = ADDON_GetPosition;
931 m_instanceData->toAddon->get_chunk_size = ADDON_GetChunkSize;
932 m_instanceData->toAddon->io_control_get_seek_possible = ADDON_IoControlGetSeekPossible;
933 m_instanceData->toAddon->io_control_get_cache_status = ADDON_IoControlGetCacheStatus;
934 m_instanceData->toAddon->io_control_set_cache_rate = ADDON_IoControlSetCacheRate;
935 m_instanceData->toAddon->io_control_set_retry = ADDON_IoControlSetRetry;
936 m_instanceData->toAddon->stat = ADDON_Stat;
937 m_instanceData->toAddon->close = ADDON_Close;
938 m_instanceData->toAddon->exists = ADDON_Exists;
939 m_instanceData->toAddon->clear_out_idle = ADDON_ClearOutIdle;
940 m_instanceData->toAddon->disconnect_all = ADDON_DisconnectAll;
941 m_instanceData->toAddon->delete_it = ADDON_Delete;
942 m_instanceData->toAddon->rename = ADDON_Rename;
943 m_instanceData->toAddon->directory_exists = ADDON_DirectoryExists;
944 m_instanceData->toAddon->remove_directory = ADDON_RemoveDirectory;
945 m_instanceData->toAddon->create_directory = ADDON_CreateDirectory;
946 m_instanceData->toAddon->get_directory = ADDON_GetDirectory;
947 m_instanceData->toAddon->free_directory = ADDON_FreeDirectory;
948 m_instanceData->toAddon->contains_files = ADDON_ContainsFiles;
954 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Open(url);
961 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
962 ->OpenForWrite(url, overWrite);
966 VFS_FILE_HANDLE context,
970 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
971 ->Read(context, buffer, uiBufSize);
975 VFS_FILE_HANDLE context,
976 const uint8_t* buffer,
979 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
980 ->Write(context, buffer, uiBufSize);
984 VFS_FILE_HANDLE context,
988 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
989 ->Seek(context, position, whence);
993 VFS_FILE_HANDLE context,
996 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Truncate(context, size);
1000 VFS_FILE_HANDLE context)
1002 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetLength(context);
1006 VFS_FILE_HANDLE context)
1008 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->GetPosition(context);
1012 VFS_FILE_HANDLE context)
1014 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
GetChunkSize(context);
1018 VFS_FILE_HANDLE context)
1020 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1021 ->IoControlGetSeekPossible(context);
1025 VFS_FILE_HANDLE context,
1029 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1030 ->IoControlGetCacheStatus(context, cppStatus);
1034 VFS_FILE_HANDLE context,
1037 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1038 ->IoControlSetCacheRate(context, rate);
1042 VFS_FILE_HANDLE context,
1045 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1046 ->IoControlSetRetry(context, retry);
1054 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Stat(url, cppBuffer);
1059 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Close(context);
1064 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Exists(url);
1069 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->ClearOutIdle();
1074 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->DisconnectAll();
1079 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Delete(url);
1086 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->Rename(url, url2);
1092 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
DirectoryExists(url);
1098 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
RemoveDirectory(url);
1104 return static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)->
CreateDirectory(url);
1113 std::vector<kodi::vfs::CDirEntry> addonEntries;
1114 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1115 ->
GetDirectory(url, addonEntries, CVFSCallbacks(callbacks));
1120 for (
unsigned int i = 0; i < addonEntries.size(); ++i)
1122 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1123 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1124 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1125 entries[i].
folder = addonEntries[i].IsFolder();
1126 entries[i].
size = addonEntries[i].Size();
1127 entries[i].
date_time = addonEntries[i].DateTime();
1130 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1135 for (
const auto& prop : props)
1145 *retEntries = entries;
1146 *num_entries =
static_cast<int>(addonEntries.size());
1155 for (
int i = 0; i < num_entries; ++i)
1157 if (entries[i].properties)
1159 for (
unsigned int j = 0; j < entries[i].
num_props; ++j)
1161 free(entries[i].properties[j].name);
1162 free(entries[i].properties[j].val);
1164 free(entries[i].properties);
1166 free(entries[i].label);
1167 free(entries[i].title);
1168 free(entries[i].path);
1179 std::string cppRootPath;
1180 std::vector<kodi::vfs::CDirEntry> addonEntries;
1181 bool ret =
static_cast<CInstanceVFS*
>(instance->toAddon->addonInstance)
1182 ->ContainsFiles(url, addonEntries, cppRootPath);
1185 strncpy(rootpath, cppRootPath.c_str(), ADDON_STANDARD_STRING_LENGTH);
1189 for (
size_t i = 0; i < addonEntries.size(); ++i)
1191 entries[i].
label = strdup(addonEntries[i].Label().c_str());
1192 entries[i].
title = strdup(addonEntries[i].Title().c_str());
1193 entries[i].
path = strdup(addonEntries[i].Path().c_str());
1194 entries[i].
folder = addonEntries[i].IsFolder();
1195 entries[i].
size = addonEntries[i].Size();
1196 entries[i].
date_time = addonEntries[i].DateTime();
1199 const std::map<std::string, std::string>& props = addonEntries[i].GetProperties();
1204 for (
const auto& prop : props)
1214 *retEntries = entries;
1215 *num_entries =
static_cast<int>(addonEntries.size());
Definition: AddonBase.h:250
Definition: AddonBase.h:186
Definition: Filesystem.h:226
Definition: Filesystem.h:96
@ ADDON_INSTANCE_VFS
Virtual Filesystem (VFS) instance, see kodi::addon::CInstanceVFS.
Definition: versions.h:241
std::string GetFilename() const
With this variable the desired path to a folder or file within the hostname is given (e....
Definition: VFS.h:98
std::string GetHostname() const
This includes the network address (e.g. 192.168.0.123) or if the addon refers to file packages the pa...
Definition: VFS.h:94
std::string GetSharename() const
The name which is taken as the basis by source and would be first in folder view.
Definition: VFS.h:137
std::string GetOptions() const
Special options on opened URL, this can e.g. on RAR packages ?flags=8&nextvalue=123 to inform about t...
Definition: VFS.h:118
std::string GetPassword() const
Desired password.
Definition: VFS.h:124
std::string GetURL() const
Desired URL of the file system to be edited.
Definition: VFS.h:85
std::string GetProtocol() const
Protocol name used on this stream, e.g. sftp.
Definition: VFS.h:140
std::string GetRedacted() const
The complete URL is passed on here, but the user name and password are not shown and only appear to t...
Definition: VFS.h:130
unsigned int GetPort() const
Networking port to use for protocol.
Definition: VFS.h:102
std::string GetUsername() const
Desired username.
Definition: VFS.h:121
std::string GetDomain() const
The associated domain name, which is optional and not available in all cases.
Definition: VFS.h:89
VFS_FILE_HANDLE VFSFileHandle
VFS add-on file handle This used to handle opened files of addon with related memory pointer about c...
Definition: VFS.h:33
virtual kodi::addon::VFSFileHandle Open(const kodi::addon::VFSUrl &url)
Open a file for input.
Definition: VFS.h:505
virtual bool IoControlGetCacheStatus(kodi::addon::VFSFileHandle context, kodi::vfs::CacheStatus &status)
To check a running stream on file for state of his cache.
Definition: VFS.h:642
virtual ssize_t Read(kodi::addon::VFSFileHandle context, uint8_t *buffer, size_t uiBufSize)
Read from a file.
Definition: VFS.h:541
virtual int64_t Seek(kodi::addon::VFSFileHandle context, int64_t position, int whence)
Seek in a file.
Definition: VFS.h:576
virtual int Truncate(kodi::addon::VFSFileHandle context, int64_t size)
Truncate a file.
Definition: VFS.h:590
virtual int GetChunkSize(kodi::addon::VFSFileHandle context)
Get chunk size of a file.
Definition: VFS.h:620
virtual int64_t GetPosition(kodi::addon::VFSFileHandle context)
Get current position in a file.
Definition: VFS.h:610
virtual ssize_t Write(kodi::addon::VFSFileHandle context, const uint8_t *buffer, size_t uiBufSize)
Write to a file.
Definition: VFS.h:556
virtual bool IoControlGetSeekPossible(kodi::addon::VFSFileHandle context)
To check seek possible on current stream by file.
Definition: VFS.h:629
virtual bool Close(kodi::addon::VFSFileHandle context)
Close a file.
Definition: VFS.h:529
virtual bool IoControlSetCacheRate(kodi::addon::VFSFileHandle context, unsigned int rate)
Unsigned int with speed limit for caching in bytes per second.
Definition: VFS.h:656
virtual bool IoControlSetRetry(kodi::addon::VFSFileHandle context, bool retry)
Enable/disable retry within the protocol handler (if supported).
Definition: VFS.h:669
virtual int64_t GetLength(kodi::addon::VFSFileHandle context)
Get total size of a file.
Definition: VFS.h:600
virtual kodi::addon::VFSFileHandle OpenForWrite(const kodi::addon::VFSUrl &url, bool overWrite)
Open a file for output.
Definition: VFS.h:516
void SetErrorDialog(const std::string &heading, const std::string &line1, const std::string &line2="", const std::string &line3="")
Display an error dialog.
Definition: VFS.h:837
bool GetKeyboardInput(const std::string &heading, std::string &input, bool hiddenInput=false)
Require keyboard input.
Definition: VFS.h:816
void RequireAuthentication(const std::string &url)
Prompt the user for authentication of a URL.
Definition: VFS.h:850
virtual void ClearOutIdle()
Clear out any idle connections.
Definition: VFS.h:704
virtual int Stat(const kodi::addon::VFSUrl &url, kodi::vfs::FileStatus &buffer)
Stat a file.
Definition: VFS.h:687
virtual bool RemoveDirectory(const kodi::addon::VFSUrl &url)
Remove a directory.
Definition: VFS.h:755
virtual void DisconnectAll()
Disconnect all connections.
Definition: VFS.h:711
virtual bool ContainsFiles(const kodi::addon::VFSUrl &url, std::vector< kodi::vfs::CDirEntry > &entries, std::string &rootPath)
Check if file should be presented as a directory (multiple streams)
Definition: VFS.h:905
virtual bool CreateDirectory(const kodi::addon::VFSUrl &url)
Create a directory.
Definition: VFS.h:765
virtual bool GetDirectory(const kodi::addon::VFSUrl &url, std::vector< kodi::vfs::CDirEntry > &entries, CVFSCallbacks callbacks)
List a directory.
Definition: VFS.h:886
virtual bool Delete(const kodi::addon::VFSUrl &url)
Delete a file.
Definition: VFS.h:721
virtual bool Exists(const kodi::addon::VFSUrl &url)
Check for file existence.
Definition: VFS.h:697
virtual bool DirectoryExists(const kodi::addon::VFSUrl &url)
Check for directory existence.
Definition: VFS.h:745
virtual bool Rename(const kodi::addon::VFSUrl &url, const kodi::addon::VFSUrl &url2)
Rename a file.
Definition: VFS.h:732
~CInstanceVFS() override=default
Destructor.
CInstanceVFS(KODI_HANDLE instance, const std::string &kodiVersion="")
VFS class constructor used to support multiple instance types.
Definition: VFS.h:455
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
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
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
Definition: filesystem.h:189
Definition: filesystem.h:220
Definition: filesystem.h:234
struct VFSProperty * properties
Properties.
Definition: filesystem.h:239
char * path
item path
Definition: filesystem.h:237
time_t date_time
file creation date & time
Definition: filesystem.h:240
unsigned int num_props
Number of properties attached to item.
Definition: filesystem.h:238
bool folder
Item is a folder.
Definition: filesystem.h:241
char * label
item label
Definition: filesystem.h:235
char * title
item title
Definition: filesystem.h:236
uint64_t size
Size of file represented by item.
Definition: filesystem.h:242
Definition: filesystem.h:228