Skip to content

Commit

Permalink
fix: [disc] The capacity of the DVD+/-RW disc is displayed incorrectly
Browse files Browse the repository at this point in the history
For DVD+RW/DVD-RW discs burned, dfm-burn does not accurately get the capacity information, so it needs to be updated.

Log: fix disc bug

Bug: https://pms.uniontech.com/bug-view-230543.html
  • Loading branch information
Johnson-zs committed Nov 27, 2023
1 parent a55085a commit 4b72528
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/dfm-base/base/device/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ void DeviceManager::mountBlockDevAsync(const QString &id, const QVariantMap &opt
}

auto callback = [cb, id, this](bool ok, const OperationErrorInfo &err, const QString &mpt) {
// For DVD+RW/DVD-RW discs burned with PW,
// dfm-burn does not accurately get the capacity information,
// so it needs to be updated.
d->watcher->updateOpticalDevUsage(id, mpt);
Q_EMIT this->blockDevMountResult(id, ok);
if (ok)
Q_EMIT this->blockDevMountedManually(id, mpt); // redundant: to notify deviceproxymanager update the cache.
Expand Down
58 changes: 53 additions & 5 deletions src/dfm-base/base/device/private/devicewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,59 @@ void DeviceWatcher::queryOpticalDevUsage(const QString &id)
data[DeviceProperty::kOpticalMediaType] = static_cast<int>(info->mediaType());
data[DeviceProperty::kOpticalWriteSpeed] = info->writeSpeed();
}
if (sizeChanged) {
DeviceHelper::persistentOpticalInfo(data);
emit DevMngIns->devSizeChanged(id, data[DeviceProperty::kSizeTotal].toULongLong(), data[DeviceProperty::kSizeFree].toULongLong());
DevProxyMng->reloadOpticalInfo(id);
}
if (sizeChanged)
saveOpticalDevUsage(id, data);
}

/*!
* \brief DeviceWatcher::updateOpticalDevUsage
* \param id
* \param mpt
*
* TODO(zhangs): this is WORKAROUND!!!
* refactor: optical disc info by SCSI
*/
void DeviceWatcher::updateOpticalDevUsage(const QString &id, const QString &mpt)
{
FinallyUtil final([id] { qCInfo(logDFMBase) << "update optical usage finished for" << id; });
Q_UNUSED(final);
if (mpt.isEmpty())
return;

QVariantMap data = DeviceHelper::loadBlockInfo(id);
if (data.value(DeviceProperty::kId).toString().isEmpty() || !data.value(DeviceProperty::kOptical).toBool())
return;

const QString &mediaType { DeviceUtils::formatOpticalMediaType(data.value(DeviceProperty::kMedia).toString()) };
if (mediaType != "DVD+RW" && mediaType != "DVD-RW")
return;

const QString &fs { data.value(DeviceProperty::kFileSystem).toString() };
if (fs != "udf")
return;

const quint64 freeSize { data.value(DeviceProperty::kSizeFree).toULongLong() };
if (freeSize != 0)
return;

// Note: QStorageInfo::bytesTotal is not accurate for DVD-RW
// TODO(zhangs): For the total capacity of a DVD-RW disc,
// the current total capacity is only the capacity of the region being **formatted**,
// not the capacity of the physical disc. Although you can refer to the dvd+rw-mediainfo
// implementation, this involves a lot of low level code and is not suitable to be written in dde-file-manager,
// it should be implemented in `dfm-burn` in the future!
QStorageInfo si(mpt);
qint64 avai = si.bytesAvailable() > 0 ? si.bytesAvailable() : 0;
data[DeviceProperty::kSizeUsed] = static_cast<quint64>(si.bytesTotal() - avai);

saveOpticalDevUsage(id, data);
}

void DeviceWatcher::saveOpticalDevUsage(const QString &id, const QVariantMap &data)
{
DeviceHelper::persistentOpticalInfo(data);
emit DevMngIns->devSizeChanged(id, data[DeviceProperty::kSizeTotal].toULongLong(), data[DeviceProperty::kSizeFree].toULongLong());
DevProxyMng->reloadOpticalInfo(id);
}

void DeviceWatcher::startWatch()
Expand Down
2 changes: 2 additions & 0 deletions src/dfm-base/base/device/private/devicewatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DeviceWatcher : public QObject
void initDevDatas();

void queryOpticalDevUsage(const QString &id);
void updateOpticalDevUsage(const QString &id, const QString &mpt);
void saveOpticalDevUsage(const QString &id, const QVariantMap &data);

private Q_SLOTS:
void onBlkDevAdded(const QString &id);
Expand Down

0 comments on commit 4b72528

Please sign in to comment.