Visindigo::Utility::SevenZipBinder Class
class Visindigo::Utility::SevenZipBinderSevenZipBinder提供对7za.exe的简单绑定,以便压缩和解压文件. 详情...
| 头文件: | #include <SevenZipBinder> |
| 自以下版本: | Visindigo 0.16.0 |
公开类型
| enum | CompressFormat { __Both__, sevenz, xz, bzip2, gzip, …, zstd } |
公开成员函数
(自 Visindigo 0.16.0 引入) | ~SevenZipBinder() |
(自 Visindigo 0.16.0 引入) void | bind7zaBinary(const QString &exePath) |
(自 Visindigo 0.16.0 引入) bool | compressFilesToZip(const QStringList &filePaths, const QString &arcPath, Visindigo::Utility::SevenZipBinder::CompressFormat format = zip, const QString &password = "") |
(自 Visindigo 0.16.0 引入) bool | decompressFile(const QString &arcPath, const QString &outputPath, Visindigo::Utility::SevenZipBinder::CompressFormat format = zip, const QString &password = "") |
(自 Visindigo 0.16.0 引入) QString | get7zaBinaryPath() const |
(自 Visindigo 0.16.0 引入) bool | isBusy() const |
(自 Visindigo 0.17.0 引入) bool | isValid() const |
信号
(自 Visindigo 0.16.0 引入) void | processed(bool success) |
(自 Visindigo 0.16.0 引入) void | processing(const QString &fileName, float percent) |
静态公开成员
(自 Visindigo 0.16.0 引入) Visindigo::Utility::SevenZipBinder * | getInstance() |
详细说明
SevenZipBinder类提供了对7za.exe的简单绑定,允许用户通过Qt的信号槽机制来压缩和解压文件,并获取处理进度和结果。 这个类使用单例模式,确保在整个应用程序中只有一个SevenZipBinder实例。用户可以通过getInstance()函数来获取这个实例, 并使用它来执行压缩和解压操作。
要正确使用它,请确保在调用任何压缩或解压函数之前,已经通过bind7zaBinary()函数绑定了7za.exe的路径。默认情况下,路径为"./7za.exe"。 也就是说,只要软件的执行目录下拥有此文件,就可以直接使用而无需额外配置。
出于授权考虑,Visindigo的源代码仓库中不包含此文件,由开发者自行提供。
成员类型文档
enum SevenZipBinder::CompressFormat
定义了支持的压缩格式。
| Constant | Value | Description |
|---|---|---|
Visindigo::Utility::SevenZipBinder::__Both__ | 0 | 支持压缩和解压的格式的起始符,不应直接使用。 |
Visindigo::Utility::SevenZipBinder::sevenz | 1 | 7z格式。 |
Visindigo::Utility::SevenZipBinder::xz | 2 | xz格式。 |
Visindigo::Utility::SevenZipBinder::bzip2 | 3 | bzip2格式。 |
Visindigo::Utility::SevenZipBinder::gzip | 4 | gzip格式。 |
Visindigo::Utility::SevenZipBinder::tar | 5 | tar格式。 |
Visindigo::Utility::SevenZipBinder::zip | 6 | zip格式。 |
Visindigo::Utility::SevenZipBinder::wim | 7 | wim格式。 |
Visindigo::Utility::SevenZipBinder::__DecompOnly__ | 1000 | 仅支持解压的格式的起始符,不应直接使用。 |
下列取值由7za支持但只能用于解压,因此不单独编写格式化说明:
| Constant | Value | Description |
|---|---|---|
Visindigo::Utility::SevenZipBinder::ar | 1001 | ar格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::arj | 1002 | arj格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::cab | 1003 | cab格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::chm | 1004 | chm格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::cpio | 1005 | cpio格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::cramfs | 1006 | cramfs格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::dmg | 1007 | dmg格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::ext | 1008 | ext格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::fat | 1009 | fat格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::gpt | 1010 | gpt格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::hfs | 1011 | hfs格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::ihex | 1012 | ihex格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::iso | 1013 | iso格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::lzh | 1014 | lzh格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::lzma | 1015 | lzma格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::mbr | 1016 | mbr格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::msi | 1017 | msi格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::nsis | 1018 | nsis格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::ntfs | 1019 | ntfs格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::qcow2 | 1020 | qcow2格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::rar | 1021 | rar格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::rpm | 1022 | rpm格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::squashfs | 1023 | squashfs格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::udf | 1024 | udf格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::vhd | 1025 | vhd格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::vmdk | 1026 | vmdk格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::xar | 1027 | xar格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::z | 1028 | z格式,仅支持解压。 |
Visindigo::Utility::SevenZipBinder::zstd | 1029 | zstd格式,仅支持解压。 |
成员函数文档
[noexcept, since Visindigo 0.16.0] SevenZipBinder::~SevenZipBinder()
析构函数。由VisindigoCore在Disable时自动调用。
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.16.0] void SevenZipBinder::bind7zaBinary(const QString &exePath)
绑定7za.exe的路径,如果不设置,则默认为"./7za.exe",即软件执行目录下的7za.exe。
exePath 7za.exe的路径。
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.16.0] bool SevenZipBinder::compressFilesToZip(const QStringList &filePaths, const QString &arcPath, Visindigo::Utility::SevenZipBinder::CompressFormat format = zip, const QString &password = "")
压缩文件到指定的压缩包路径,支持多种压缩格式。filePaths可以是多个文件或一个文件夹(会压缩整个文件夹)。如果正在处理其他任务,则返回false。
filePaths 待压缩的文件或文件夹路径列表。 arcPath 输出压缩包的路径。 format 压缩格式,不能是仅支持解压的格式。 password 压缩包密码,为空表示不加密。
return 任务已开始返回true;正在处理其他任务或格式不支持压缩时返回false。
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.16.0] bool SevenZipBinder::decompressFile(const QString &arcPath, const QString &outputPath, Visindigo::Utility::SevenZipBinder::CompressFormat format = zip, const QString &password = "")
解压压缩包到指定的输出路径,支持多种压缩格式。如果正在处理其他任务,则返回false。
arcPath 待解压的压缩包路径。 outputPath 解压输出目录。 format 压缩包格式。 password 压缩包密码,为空表示未加密。
return 任务已开始返回true;正在处理其他任务时返回false。
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.16.0] QString SevenZipBinder::get7zaBinaryPath() const
获取当前绑定的7za.exe路径。
这个function 从 Visindigo 0.16.0 开始支持。
[static, since Visindigo 0.16.0] Visindigo::Utility::SevenZipBinder *SevenZipBinder::getInstance()
获取SevenZipBinder实例
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.16.0] bool SevenZipBinder::isBusy() const
检查7za.exe是否正在处理任务。
return 正在处理任务时返回true。
这个function 从 Visindigo 0.16.0 开始支持。
[since Visindigo 0.17.0] bool SevenZipBinder::isValid() const
检查压缩功能是否可用。
请注意,这个函数只是单纯检查目标文件是否存在,如果设置的是无效的7za.exe路径,或者7za.exe无法正常运行, 这个函数也不会检测到。请确保7za.exe是可执行的,并且在调用压缩或解压函数之前已经绑定了正确的路径。
return 已绑定的7za.exe文件存在时返回true。
这个function 从 Visindigo 0.17.0 开始支持。
[signal, since Visindigo 0.16.0] void SevenZipBinder::processed(bool success)
当7za.exe完成处理时发出此信号,success表示处理是否成功。
success 处理是否成功。
这个function 从 Visindigo 0.16.0 开始支持。
[signal, since Visindigo 0.16.0] void SevenZipBinder::processing(const QString &fileName, float percent)
当7za.exe正在处理文件时发出此信号,fileName是当前正在处理的文件名,percent是处理进度的百分比。
由于7za.exe的压缩逻辑,文件名的提示进度远远快于实际的压缩进度,譬如如果有100个文件,则可能会出现 从50%开始就只显示第100个文件的名字,因此请依赖百分比来判断实际的处理进度。fileName仅供显示参考。
fileName 当前正在处理的文件名,仅供显示参考。 percent 处理进度的百分比。
这个function 从 Visindigo 0.16.0 开始支持。