2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "BlurayCallback.h"
12 #include "filesystem/Directory.h"
13 #include "filesystem/File.h"
14 #include "utils/URIUtils.h"
15 #include "utils/log.h"
17 using namespace XFILE
;
25 void CBlurayCallback::bluray_logger(const char* msg
)
27 CLog::Log(LOGDEBUG
, "CBlurayCallback::Logger - {}", msg
);
30 void CBlurayCallback::dir_close(BD_DIR_H
*dir
)
34 CLog::Log(LOGDEBUG
, "CBlurayCallback - Closed dir ({})", fmt::ptr(dir
));
35 delete static_cast<SDirState
*>(dir
->internal
);
40 BD_DIR_H
* CBlurayCallback::dir_open(void *handle
, const char* rel_path
)
42 std::string
strRelPath(rel_path
);
43 std::string
* strBasePath
= reinterpret_cast<std::string
*>(handle
);
46 CLog::Log(LOGDEBUG
, "CBlurayCallback - Error opening dir, null handle!");
50 std::string strDirname
= URIUtils::AddFileToFolder(*strBasePath
, strRelPath
);
51 if (URIUtils::HasSlashAtEnd(strDirname
))
52 URIUtils::RemoveSlashAtEnd(strDirname
);
54 CLog::Log(LOGDEBUG
, "CBlurayCallback - Opening dir {}", CURL::GetRedacted(strDirname
));
56 SDirState
*st
= new SDirState();
57 if (!CDirectory::GetDirectory(strDirname
, st
->list
, "", DIR_FLAG_DEFAULTS
))
59 if (!CFile::Exists(strDirname
))
60 CLog::Log(LOGDEBUG
, "CBlurayCallback - Error opening dir! ({})",
61 CURL::GetRedacted(strDirname
));
66 BD_DIR_H
*dir
= new BD_DIR_H
;
67 dir
->close
= dir_close
;
69 dir
->internal
= (void*)st
;
74 int CBlurayCallback::dir_read(BD_DIR_H
*dir
, BD_DIRENT
*entry
)
76 SDirState
* state
= static_cast<SDirState
*>(dir
->internal
);
78 if (state
->curr
>= state
->list
.Size())
81 strncpy(entry
->d_name
, state
->list
[state
->curr
]->GetLabel().c_str(), sizeof(entry
->d_name
) - 1);
82 entry
->d_name
[sizeof(entry
->d_name
) - 1] = 0;
88 void CBlurayCallback::file_close(BD_FILE_H
*file
)
92 delete static_cast<CFile
*>(file
->internal
);
97 int CBlurayCallback::file_eof(BD_FILE_H
*file
)
99 if (static_cast<CFile
*>(file
->internal
)->GetPosition() == static_cast<CFile
*>(file
->internal
)->GetLength())
105 BD_FILE_H
* CBlurayCallback::file_open(void *handle
, const char *rel_path
)
107 std::string
strRelPath(rel_path
);
108 std::string
* strBasePath
= reinterpret_cast<std::string
*>(handle
);
111 CLog::Log(LOGDEBUG
, "CBlurayCallback - Error opening dir, null handle!");
115 std::string strFilename
= URIUtils::AddFileToFolder(*strBasePath
, strRelPath
);
117 BD_FILE_H
*file
= new BD_FILE_H
;
119 file
->close
= file_close
;
120 file
->seek
= file_seek
;
121 file
->read
= file_read
;
122 file
->write
= file_write
;
123 file
->tell
= file_tell
;
124 file
->eof
= file_eof
;
126 CFile
* fp
= new CFile();
127 if (fp
->Open(strFilename
))
129 file
->internal
= (void*)fp
;
133 CLog::Log(LOGDEBUG
, "CBlurayCallback - Error opening file! ({})", CURL::GetRedacted(strFilename
));
141 int64_t CBlurayCallback::file_seek(BD_FILE_H
*file
, int64_t offset
, int32_t origin
)
143 return static_cast<CFile
*>(file
->internal
)->Seek(offset
, origin
);
146 int64_t CBlurayCallback::file_tell(BD_FILE_H
*file
)
148 return static_cast<CFile
*>(file
->internal
)->GetPosition();
151 int64_t CBlurayCallback::file_read(BD_FILE_H
*file
, uint8_t *buf
, int64_t size
)
153 return static_cast<int64_t>(static_cast<CFile
*>(file
->internal
)->Read(buf
, static_cast<size_t>(size
)));
156 int64_t CBlurayCallback::file_write(BD_FILE_H
*file
, const uint8_t *buf
, int64_t size
)
158 return static_cast<int64_t>(static_cast<CFile
*>(file
->internal
)->Write(buf
, static_cast<size_t>(size
)));