dtkburn 是对 deepin/UOS 系统上的底层光驱业务接口的封装,为应用层开发者提供了光盘的信息获取、光盘数据刻录、光盘镜像刻录、光盘镜像导出、光盘擦除、光盘校验的常见业务功能,其目的是在于方便第三方开发者轻松且快速的调用接口进行开发。
接口文档
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QMetaProperty>
#include <QDebug>
#include <DOpticalDiscManager>
#include <DOpticalDiscInfo>
#include <DOpticalDiscOperator>
DBURN_USE_NAMESPACE
void print(const QString &device)
{
qInfo() << __PRETTY_FUNCTION__;
auto expected { DOpticalDiscManager::createOpticalDiscInfo(device) };
if (!expected) {
qWarning() << expected.error();
return;
}
DOpticalDiscInfo *info { expected.value() };
if (!info)
return;
auto meta { info->metaObject() };
int count { meta->propertyCount() };
qInfo() << "===============Begin visit info===============";
for (int i = 1; i != count; ++i) {
const QMetaProperty &property { meta->property(i) };
qInfo() << "-> Property: " << property.name() << info->property(property.name());
}
qInfo() << "===============End visit info===============";
delete info;
}
void erase(const QString &device)
{
qInfo() << __PRETTY_FUNCTION__;
auto expected { DOpticalDiscManager::createOpticalDiscOperator(device) };
if (!expected) {
qWarning() << expected.error();
return;
}
DOpticalDiscOperator *oprator { expected.value() };
if (!oprator)
return;
QObject::connect(oprator, &DOpticalDiscOperator::jobStatusChanged,
[](JobStatus status, int progress, QString speed, QStringList message) {
qDebug() << "erase progress: " << int(status) << progress << speed << message;
});
oprator->erase();
delete oprator;
}
void burn(const QString &device, const QString &stagePath, const QString &fs)
{
Q_UNUSED(fs)
qInfo() << __PRETTY_FUNCTION__;
auto expected { DOpticalDiscManager::createOpticalDiscOperator(device) };
if (!expected) {
qWarning() << expected.error();
return;
}
DOpticalDiscOperator *oprator { expected.value() };
if (!oprator)
return;
QObject::connect(oprator, &DOpticalDiscOperator::jobStatusChanged,
[](JobStatus status, int progress, QString speed, QStringList message) {
qDebug() << "burn progress: " << int(status) << progress << speed << message;
});
BurnOptions opts { BurnOption::KeepAppendable };
opts |= BurnOption::JolietSupported;
oprator->burn(stagePath, opts);
delete oprator;
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription(QString("%1 helper").arg(QCoreApplication::applicationName()));
parser.addOption(QCommandLineOption({ "dev", "device" }, "Set disc device(like '/dev/sr0').", "device"));
parser.addOption(QCommandLineOption({ "fs", "filesystem" },
"Set filesystem for burn files (iso9660', 'joliet', 'rockridge' and 'udf' supported).",
"filesystem name", "joliet"));
parser.addOption(QCommandLineOption({ "p", "print" }, "Print disc info."));
parser.addOption(QCommandLineOption("erase", "Erase a disc."));
parser.addOption(QCommandLineOption("check", "Check media."));
parser.addOption(QCommandLineOption("dump", "Dump a iso file from disc to local <directory>.", "directory"));
parser.addOption(QCommandLineOption("write", "Write a image file to disc.", "image directory"));
parser.addOption(QCommandLineOption("burn", "Burn files from local <directory> to disc.", "directory"));
parser.addHelpOption();
parser.process(app);
const QString &device { parser.value("dev") };
if (device.isEmpty()) {
qWarning() << "Cannot find 'device'";
exit(-1);
}
{
if (parser.isSet("p")) {
print(device);
exit(0);
}
if (parser.isSet("erase")) {
erase(device);
::exit(0);
}
if (parser.isSet("burn")) {
const QString &fs { parser.value("fs") };
const QString &path { parser.value("burn") };
burn(device, path, fs);
::exit(0);
}
qWarning() << "No operation was performed";
}
return app.exec();
}