Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/libdbm/util/devicemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ DeviceMonitor::DeviceMonitor(QObject *parent) : QObject(parent)
m_timer->setInterval(2000);
connect(m_timer, &QTimer::timeout, this, [ = ] {
QList<DeviceInfo> list = Utils::ListUsbDrives();
qDebug() << "Detected" << list.length() << "USB devices";
QStringList devices;
for (int i = 0; i < list.size(); i++)
{
qDebug() << "Device" << i << "- Path:" << list.at(i).path
<< "Label:" << list.at(i).label
<< "Type:" << list.at(i).fstype
<< "Format needed:" << list.at(i).needFormat;
devices << list.at(i).path;
}
qDebug() << "Detected" << list.length() << "USB devices: " << devices;

QList<DeviceInfo> intersectList = this->getIntersectDevice(list);
qDebug() << "Found" << intersectList.size() << "unchanged devices";
Expand Down
36 changes: 0 additions & 36 deletions src/libdbm/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ bool isUsbDisk(const QString &dev)

QList<DeviceInfo> ListUsbDrives()
{
qDebug() << "Listing USB drives";
qDebug() << "Start getting device list";
QList<DeviceInfo> deviceList;
#ifdef Q_OS_WIN32
QFileInfoList extdrivesList = QDir::drives();
Expand All @@ -487,7 +485,6 @@ QList<DeviceInfo> ListUsbDrives()
QString deviceLetter = extdrivesList.at(i).path().toUpper();
if (QDir::toNativeSeparators(deviceLetter) != QDir::toNativeSeparators(QDir::rootPath().toUpper()) && !QDir::toNativeSeparators(deviceLetter).contains("A:") && !QDir::toNativeSeparators(deviceLetter).contains("B:")) {
if (GetDriveType(LPWSTR(deviceLetter.utf16())) == 2) {
qDebug() << "Found removable drive:" << deviceLetter;
DeviceInfo info;
info.path = QDir::toNativeSeparators(deviceLetter);
deviceList.push_back(info);
Expand All @@ -499,7 +496,6 @@ QList<DeviceInfo> ListUsbDrives()
#ifdef Q_OS_LINUX
QDir devlstdir("/dev/disk/by-id/");
QFileInfoList usbfileinfoL = devlstdir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
qDebug() << "Step 1: Scan /dev/disk/by-id/ directory, found" << usbfileinfoL.size() << "device files";

QMap<QString, DeviceInfo> dfDeviceInfos = CommandDfParse();
QMap<QString, DeviceInfo> lsblkDeviceInfos = CommandLsblkParse();
Expand All @@ -518,13 +514,7 @@ QList<DeviceInfo> ListUsbDrives()
removeDevice.insert(filePath, fileName);
}
}
qDebug() << "Step 4: Filter devices - Found" << removeDevice.size() << "USB/MMC devices from" << usbfileinfoL.size() << "total devices";

for (auto it = removeDevice.begin(); it != removeDevice.end(); ++it) {
qDebug() << " Device path:" << it.key() << "Device name:" << it.value();
}

qDebug() << "Step 5: Traverse device partitions and filter eligible devices";
int processedCount = 0;
int validCount = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider removing or repurposing processedCount/validCount now that they’re only used for logging.

Now that the related logging is gone, processedCount and validCount are maintained only for unused debug output, which adds noise and potential confusion. If they’re not used elsewhere, consider removing them or giving them a clear functional role (for example, asserting that deviceList.size() equals validCount).

Suggested implementation:

  1. If there are any remaining references to processedCount or validCount (e.g., in qDebug() or assertions) later in ListUsbDrives(), those should be removed or refactored as well.
  2. If you do want a functional role for such counters, reintroduce them with a clear purpose (for instance, int validDevices = deviceList.size(); Q_ASSERT(validDevices == deviceList.size());) instead of maintaining separate counters throughout the loop.


Expand All @@ -533,15 +523,13 @@ QList<DeviceInfo> ListUsbDrives()
if (!removeDevice.contains(devicePath)) {
continue;
}
qDebug() << "Processing device" << processedCount << ":" << devicePath << "with" << lsblkDeviceInfos.value(devicePath).children.size() << "partitions";
// find first partition
QString strDiskName = devicePath;
DeviceInfo diskinfo = lsblkDeviceInfos.value(devicePath);
QStringList partitionNames = diskinfo.children.keys();

if (partitionNames.isEmpty()) {
// 设备没有分区,作为整个磁盘展示
qDebug() << " Device" << devicePath << "has no partitions, showing as whole disk";
DeviceInfo wholeDevice = diskinfo;
wholeDevice.isDisk = true;
wholeDevice.strDev = "";
Expand All @@ -555,25 +543,17 @@ QList<DeviceInfo> ListUsbDrives()

deviceList.push_back(wholeDevice);
validCount++;
qDebug() << " Added to device list (item" << validCount << "):" << wholeDevice.path
<< "Label:" << wholeDevice.label
<< "Size:" << wholeDevice.total << "MB"
<< "Need format:" << wholeDevice.needFormat;
} else {
// 设备有分区,遍历分区
foreach (QString strPartionName, partitionNames) {
bool needformat = true;
DeviceInfo partitionInfo = diskinfo.children.value(strPartionName);

qDebug() << " Check partition" << strPartionName << "filesystem:" << partitionInfo.fstype;

if (partitionInfo.fstype != "vfat") {
needformat = true;
qDebug() << " Filesystem is not vfat, need format";
}
else {
needformat = false;
qDebug() << " Filesystem is vfat, no need to format";
}

DeviceInfo dfinfo = dfDeviceInfos.value(strPartionName);
Expand All @@ -587,14 +567,9 @@ QList<DeviceInfo> ListUsbDrives()
partitionInfo.needFormat = needformat;
deviceList.push_back(partitionInfo);
validCount++;
qDebug() << " Added to device list (item" << validCount << "):" << partitionInfo.path
<< "Size:" << partitionInfo.total << "MB"
<< "Need format:" << needformat;
qDebug() << partitionInfo.path << partitionInfo.used << partitionInfo.total << partitionInfo.target << partitionInfo.needFormat;
}
}
}
qDebug() << "Step 5 completed: Processed" << processedCount << "devices, added" << validCount << "partitions to list";
#endif

#ifdef Q_OS_MAC
Expand All @@ -610,7 +585,6 @@ QList<DeviceInfo> ListUsbDrives()
for (int i = 0; i < usbdevsL.size(); ++i) {
if (isUsbDisk("/dev/" + usbdevsL.at(i))) {
auto path = "/dev/" + usbdevsL.at(i);
qDebug() << "Found USB device:" << path;
fulldrivelist.append(path);

DeviceInfo info;
Expand All @@ -619,19 +593,9 @@ QList<DeviceInfo> ListUsbDrives()
}
}

qDebug() << "Found USB devices:" << fulldrivelist;
outfile.close();
outfile.remove();
#endif
qDebug() << "Get device list completed: Found" << deviceList.size() << "available devices";
for (int i = 0; i < deviceList.size(); ++i) {
qDebug() << " Device" << (i+1) << ":" << deviceList.at(i).path
<< "Label:" << deviceList.at(i).label
<< "Filesystem:" << deviceList.at(i).fstype
<< "Size:" << deviceList.at(i).total << "MB"
<< "Used:" << deviceList.at(i).used << "MB"
<< "Need format:" << deviceList.at(i).needFormat;
}
return deviceList;
}

Expand Down