DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DAZipArchive.h
1#ifndef DAZIPARCHIVE_H
2#define DAZIPARCHIVE_H
3#include "DAGuiAPI.h"
4#include "DAAbstractArchive.h"
5class QuaZip;
6namespace DA
7{
11class DAGUI_API DAZipArchive : public DAAbstractArchive
12{
13 Q_OBJECT
14 DA_DECLARE_PRIVATE(DAZipArchive)
15public:
16 DAZipArchive(QObject* par = nullptr);
17 DAZipArchive(const QString& zipPath, QObject* par = nullptr);
19
20 // 设置zip文件名
21 virtual bool setBaseFilePath(const QString& path) override;
22 // 设置zip文件名,包含完整路径的名字
23 bool setZipFileName(const QString& fileName);
24 // 打开
25 bool open();
26 bool create();
27 // 是否打开
28 bool isOpened() const;
29 // 关闭
30 bool close();
31 // 写数据
32 bool write(const QString& relatePath, const QByteArray& byte) override;
33 // 将本地文件写入ZIP压缩包中的指定路径
34 bool writeFileToZip(const QString& relatePath, const QString& localFilePath, std::size_t chunk_mb = 4);
35 // 读取数据
36 QByteArray read(const QString& relatePath) override;
37 // 从 ZIP 归档中提取指定文件到本地路径
38 bool readToFile(const QString& zipRelatePath, const QString& localFilePath, std::size_t chunk_mb = 4);
39 // 删除文件--注意,此函数非常耗时,轻易不要使用
40 bool remove(const QString& fileToRemove) override;
41
42 //==============
43 // 文件管理
44 //==============
45 // 列出所有文件
46 QStringList getAllFiles() const;
47 // 检查文件是否存在
48 bool contains(const QString& relatePath) const;
49
50 //==============
51 // 归档信息
52 //==============
53 // 获取 ZIP 文件大小
54 qint64 getFileSize() const;
55 // 获取文件数量
56 int getFileCount() const;
57 // 获取注释
58 QString getComment() const;
59 // 设置注释
60 void setComment(const QString& comment);
61
62 //==============
63 // 整体解压到目录下
64 //==============
65 // 把zip整体解压到目录下
66 bool extractToDirectory(const QString& extractDir);
67 // 把一个zip整体压缩到压缩包
68 bool compressDirectory(const QString& folderPath);
69 // 获取文件列表
70 QStringList getFileNameList() const;
71 // 获取zip中一个文件夹下的所有文件列表,注意不包括这个文件下的子目录及子目录下的文件
72 QStringList getFolderFileNameList(const QString& zipFolderPath) const;
73 // 获取QuaZip指针
74 QuaZip* quazip() const;
75 // 获取最后的错误内容
76 QString getLastErrorString() const;
77public Q_SLOTS:
78 // 保存所有,执行任务队列
79 virtual void saveAll(const QString& filePath) override;
80 // 读取所有,执行任务队列,内个任务的读取结果通过taskProgress信号携带
81 virtual void loadAll(const QString& filePath) override;
82
83public:
84 // 判断是否是正确的工程
85 static bool isCorrectFile(const QString& filePath);
86 static bool extractToDirectory(const QString& zipFilePath, const QString& extractDir);
87 static bool extractToDirectory(QuaZip* zip, const QString& extractDir);
88 static bool compressDirectory(const QString& folderPath, const QString& zipFilePath);
89 static bool compressDirectory(const QString& folderPath, QuaZip* zip, const QString& relativeBase = QString("./"));
90 static bool writeFileToZip(QuaZip* zip, const QString& relatePath, const QString& localFilePath, std::size_t chunk_mb = 4);
91 static bool readToFile(QuaZip* zip, const QString& zipRelatePath, const QString& localFilePath, std::size_t chunk_mb = 4);
92};
93}
94
95#endif // DAZIPARCHIVE_H
持久化的基类
Definition DAAbstractArchive.h:16
zip档案
Definition DAZipArchive.h:12
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44