| 1 |
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#ifndef DTK_NO_PROJECT |
| 8 |
#include <DObject> |
| 9 |
#include <dtkcore_global.h> |
| 10 |
#else |
| 11 |
#define DCORE_BEGIN_NAMESPACE |
| 12 |
#define DCORE_END_NAMESPACE |
| 13 |
#define LIBDTKCORESHARED_EXPORT |
| 14 |
#define D_DECLARE_PRIVATE(Class) Class##Private *d; |
| 15 |
#endif |
| 16 |
|
| 17 |
#include <QStringList> |
| 18 |
|
| 19 |
QT_BEGIN_NAMESPACE |
| 20 |
class QIODevice; |
| 21 |
QT_END_NAMESPACE |
| 22 |
|
| 23 |
DCORE_BEGIN_NAMESPACE |
| 24 |
|
| 25 |
class DDciFilePrivate; |
| 26 |
class LIBDTKCORESHARED_EXPORT DDciFile |
| 27 |
#ifndef DTK_NO_PROJECT |
| 28 |
: public DObject |
| 29 |
#endif |
| 30 |
{ |
| 31 |
D_DECLARE_PRIVATE(DDciFile) |
| 32 |
public: |
| 33 |
enum FileType { |
| 34 |
UnknowFile, |
| 35 |
File = 1, |
| 36 |
Directory = 2, |
| 37 |
Symlink = 3 |
| 38 |
}; |
| 39 |
|
| 40 |
static void registerFileEngine(); |
| 41 |
|
| 42 |
DDciFile(); |
| 43 |
explicit DDciFile(const QString &fileName); |
| 44 |
explicit DDciFile(const QByteArray &data); |
| 45 |
|
| 46 |
bool isValid() const; |
| 47 |
QString lastErrorString() const; |
| 48 |
|
| 49 |
bool writeToFile(const QString &fileName) const; |
| 50 |
bool writeToDevice(QIODevice *device) const; |
| 51 |
QByteArray toData() const; |
| 52 |
|
| 53 |
static constexpr int metadataSizeV1(); |
| 54 |
|
| 55 |
// for reader |
| 56 |
QStringList list(const QString &dir, bool onlyFileName = false) const; |
| 57 |
int childrenCount(const QString &dir) const; |
| 58 |
bool exists(const QString &filePath) const; |
| 59 |
FileType type(const QString &filePath) const; |
| 60 |
QByteArray dataRef(const QString &filePath) const; |
| 61 |
QString name(const QString &filePath) const; |
| 62 |
QString symlinkTarget(const QString &filePath, bool originData = false) const; |
| 63 |
|
| 64 |
// for writer |
| 65 |
bool mkdir(const QString &filePath); |
| 66 |
bool writeFile(const QString &filePath, const QByteArray &data, bool override = false); |
| 67 |
bool remove(const QString &filePath); |
| 68 |
bool rename(const QString &filePath, const QString &newFilePath, bool override = false); |
| 69 |
bool copy(const QString &from, const QString &to); |
| 70 |
bool link(const QString &source, const QString &to); |
| 71 |
}; |
| 72 |
|
| 73 |
DCORE_END_NAMESPACE |