9#include <QCoreApplication>
11#include <QtCore/QJniEnvironment>
12#include <QtCore/QJniObject>
25 file.replace(
"//"_L1,
"/"_L1);
26 if (
file.startsWith(u
'/'))
28 if (
file.endsWith(u
'/'))
36 path.replace(
"//"_L1,
"/"_L1);
50 if (
name.endsWith(u
'/')) {
71 if ((*folder)->empty() || !m_assetsCache.
insert(
path, folder)) {
83 return AssetItem::Type::Folder;
90 return val.name < assetItem.name;
93 return AssetItem::Type::Invalid;
105 , m_path(
other.m_path)
115 "(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;",
117 if (
files.isValid()) {
119 jobjectArray jFiles =
files.object<jobjectArray>();
120 const jint nFiles = env->GetArrayLength(jFiles);
121 for (
int i = 0;
i < nFiles; ++
i) {
122 AssetItem item{QJniObject::fromLocalRef(env->GetObjectArrayElement(jFiles,
i)).toString()};
124 return a.name <
b.name;
129 m_path.
replace(
"//"_L1,
"/"_L1);
134 if (m_index < 0 || m_index >=
size())
136 return at(m_index).name;
140 if (m_index < 0 || m_index >=
size())
142 return m_path +
at(m_index).name;
150 std::optional<std::pair<QString, AssetItem>>
next()
162 static QMutex m_assetsCacheMutex;
166Q_CONSTINIT
QMutex FolderIterator::m_assetsCacheMutex;
186 if (!m_currentIterator)
193 if (!m_currentIterator)
200 if (!m_currentIterator)
202 return m_currentIterator->
hasNext();
207 if (!m_currentIterator)
209 auto res = m_currentIterator->
next();
223 : m_assetManager(assetManager)
233 bool open(QIODevice::OpenMode openMode, std::optional<QFile::Permissions> permissions)
override
240 m_assetFile = AAssetManager_open(m_assetManager, m_fileName.
toUtf8(), AASSET_MODE_BUFFER);
247 AAsset_close(m_assetFile);
257 return m_assetInfo->
size;
264 return AAsset_seek(m_assetFile, 0, SEEK_CUR);
271 return pos == AAsset_seek(m_assetFile,
pos, SEEK_SET);
278 return AAsset_read(m_assetFile,
data, maxlen);
292 if (m_assetInfo->
type == AssetItem::Type::File)
294 else if (m_assetInfo->
type == AssetItem::Type::Folder)
310 return m_fileName.
mid(
pos + 1);
336 m_assetInfo = *assetInfoPtr;
343 m_assetInfo = *newAssetInfoPtr;
344 m_assetInfo->
name = m_fileName;
345 m_assetInfo->
type = AssetItem::Type::Invalid;
347 m_assetFile = AAssetManager_open(m_assetManager, m_fileName.
toUtf8(), AASSET_MODE_BUFFER);
350 m_assetInfo->
type = AssetItem::Type::File;
351 m_assetInfo->
size = AAsset_getLength(m_assetFile);
353 auto *assetDir = AAssetManager_openDir(m_assetManager, m_fileName.
toUtf8());
355 if (AAssetDir_getNextFileName(assetDir)
360 m_assetInfo->
type = AssetItem::Type::Folder;
362 AAssetDir_close(assetDir);
367 m_assetsInfoCache.
insert(m_fileName, newAssetInfoPtr);
372 if (m_assetInfo && m_assetInfo->
type == AssetItem::Type::Folder)
378 AAsset *m_assetFile =
nullptr;
379 AAssetManager *m_assetManager =
nullptr;
385 static QMutex m_assetsInfoCacheMutex;
389Q_CONSTINIT
QMutex AndroidAbstractFileEngine::m_assetsInfoCacheMutex;
405 path.replace(
"//"_L1,
"/"_L1);
406 if (
path.startsWith(u
'/'))
408 if (
path.endsWith(u
'/'))
QString next() override
This pure virtual function advances the iterator to the next directory entry, and returns the file pa...
AndroidAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, const QString &path)
QString currentFileName() const override
This pure virtual function returns the name of the current directory entry, excluding the path.
QString currentFilePath() const override
Returns the path to the current directory entry.
QFileInfo currentFileInfo() const override
The virtual function returns a QFileInfo for the current directory entry.
bool hasNext() const override
This pure virtual function returns true if there is at least one more entry in the current directory ...
~AndroidAbstractFileEngine()
void setFileName(const QString &file) override
Sets the file engine's file name to file.
FileFlags fileFlags(FileFlags type=FileInfoAll) const override
This function should return the set of OR'd flags that are true for the file engine's file,...
qint64 size() const override
Returns the size of the file.
qint64 pos() const override
Returns the current file position.
bool caseSensitive() const override
Should return true if the underlying file system is case-sensitive; otherwise return false.
bool seek(qint64 pos) override
Sets the file position to the given offset.
qint64 read(char *data, qint64 maxlen) override
Reads a number of characters from the file into data.
bool close() override
Closes the file, returning true if successful; otherwise returns false.
bool open(QIODevice::OpenMode openMode, std::optional< QFile::Permissions > permissions) override
Opens the file in the specified mode.
QString fileName(FileName file=DefaultName) const override
Return the file engine's current file name in the format specified by file.
Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames) override
Returns an instance of a QAbstractFileEngineIterator using filters for entry filtering and filterName...
AndroidAbstractFileEngine(AAssetManager *assetManager, const QString &fileName)
QAbstractFileEngine * create(const QString &fileName) const override
Creates a file engine for file fileName.
AndroidAssetsFileEngineHandler()
static QSharedPointer< FolderIterator > fromCache(const QString &path, bool clone)
QString currentFilePath() const
std::optional< std::pair< QString, AssetItem > > next()
FolderIterator(const QString &path)
static AssetItem::Type fileType(const QString &filePath)
FolderIterator(const FolderIterator &other)
QString currentFileName() const
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
QDir::Filters filters() const
Returns the entry filters for this iterator.
QStringList nameFilters() const
Returns the name filters for this iterator.
\inmodule QtCore \reentrant
FileName
These values are used to request a file name in a particular format.
T * object(const Key &key) const noexcept
bool insert(const Key &key, T *object, qsizetype cost=1)
\inmodule QtCore \reentrant
bool remove()
Removes the file specified by fileName().
qsizetype size() const noexcept
iterator insert(qsizetype i, parameter_type t)
bool empty() const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
QString & replace(qsizetype i, qsizetype len, QChar after)
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & append(QChar c)
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
QByteArray toUtf8() const &
QSet< QString >::iterator it
Combined button and popup list for selecting options.
jclass applicationClass()
AAssetManager * assetManager()
static QString prefixedPath(QString path)
static const int prefixSize
static const auto assetsPrefix
static QString cleanedAssetPath(QString file)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLuint * paths
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
AssetItem(const QString &rawName)