diff --git a/.gitignore b/.gitignore index e60bf14..6c964ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ *.user .build +build .qmake.stash *.qm +.cache/* +.claude/* .vscode # AI diff --git a/CMakeLists.txt b/CMakeLists.txt index 7184e0f..75aac59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,19 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fPIE") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now -z noexecstack -pie") -set(QT_VERSION_MAJOR 6) -if (${QT_VERSION_MAJOR} GREATER_EQUAL 6) +# Qt 版本检测 +find_package(Qt6 QUIET) +if(Qt6_FOUND) + message("Found Qt6.") + + set(QT_VERSION_MAJOR 6) set(DTK_VERSION 6) +else() + message("Found Qt5.") + + set(QT_VERSION_MAJOR 5) + add_compile_definitions(NO_DBUS_CALLER_AUTH_CHECK) + message("NO_DBUS_CALLER_AUTH_CHECK is on.") endif() # 检查内存泄漏代码 diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 09f1f61..f5954a7 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -65,11 +65,11 @@ endforeach() file(GLOB ALL_SOURCES "*.cpp" "./partedproxy/*.cpp" "./widgets/*.cpp" "./widgets/customcontrol/*.cpp" "./widgets/accessible/*.cpp") file(GLOB ALL_HEADERS "*.h" "./partedproxy/*.h" "./widgets/*.h" "./widgets/customcontrol/*.h" "./widgets/accessible/*.h") file (GLOB DTNG_TS_FILES translations/*.ts) -qt_create_translation(DTNG_QM_FILES - ${CMAKE_SOURCE_DIR} - ${DTNG_TS_FILES} - ) - +if(Qt6_FOUND) + qt_create_translation(DTNG_QM_FILES ${CMAKE_SOURCE_DIR} ${DTNG_TS_FILES}) +else() + qt5_create_translation(DTNG_QM_FILES ${CMAKE_SOURCE_DIR} ${DTNG_TS_FILES}) +endif() include_directories(../basestruct) #link_directories(${PROJECT_BINARY_DIR}) diff --git a/application/widgets/customcontrol/waterloadingwidget.cpp b/application/widgets/customcontrol/waterloadingwidget.cpp index 4a9c2a8..5cbb541 100644 --- a/application/widgets/customcontrol/waterloadingwidget.cpp +++ b/application/widgets/customcontrol/waterloadingwidget.cpp @@ -9,6 +9,7 @@ #if QT_VERSION_MAJOR > 5 #include #endif +#include WaterLoadingWidget::WaterLoadingWidget(QWidget *parent) : QWidget(parent) { diff --git a/basestruct/deviceinfo.cpp b/basestruct/deviceinfo.cpp index 6282ffd..98846f4 100644 --- a/basestruct/deviceinfo.cpp +++ b/basestruct/deviceinfo.cpp @@ -4,6 +4,7 @@ #include "deviceinfo.h" #include +#include /*********************************** stCustest *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const stCustest &stcus) diff --git a/basestruct/utils.cpp b/basestruct/utils.cpp index 4c9854f..03cfffe 100644 --- a/basestruct/utils.cpp +++ b/basestruct/utils.cpp @@ -510,8 +510,8 @@ int Utils::getMountedFileSystemUsage(const QString &mountpoint, Byte_Value &file int ret; ret = statvfs(mountpoint.toStdString().c_str(), &sfs); if (ret == 0) { - fileSystemSize = static_cast(sfs.f_blocks) * sfs.f_frsize; - fileSystemFree = static_cast(sfs.f_bfree) * sfs.f_bsize; + fileSystemSize = static_cast(sfs.f_blocks) * sfs.f_bsize; + fileSystemFree = static_cast(sfs.f_bavail) * sfs.f_bsize; } else { qWarning() << "Utils::getMountedFileSystemUsage - Failed for:" << mountpoint << "Error:" << errno; QString errorMessage("statvfs(\"%1\"):%2 "); // = "statvfs(\"" + mountpoint + "\"): " + Glib::strerror(errno) ; diff --git a/debian/control b/debian/control index 209d076..2994af7 100644 --- a/debian/control +++ b/debian/control @@ -7,15 +7,15 @@ Build-Depends: cmake, pkg-config, libc6-dev, - qt6-tools-dev, - qt6-base-dev, + qt6-tools-dev | qttools5-dev, + qt6-base-dev | qtbase5-dev, libx11-dev, - libdtk6widget-dev, - qt6-tools-dev-tools, - qt6-base-private-dev, + libdtk6widget-dev | libdtkwidget-dev, + qt6-tools-dev-tools | qttools5-dev-tools, + qt6-base-private-dev | qtbase5-private-dev, libparted-dev, libparted-fs-resize0, - libpolkit-qt6-1-dev, + libpolkit-qt6-1-dev | libpolkit-qt5-1-dev, libgtest-dev, libgmock-dev, deepin-gettext-tools @@ -23,7 +23,7 @@ Standards-Version: 4.1.3 Package: deepin-diskmanager Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, smartmontools, exfat-fuse, pkexec +Depends: ${shlibs:Depends}, ${misc:Depends}, smartmontools, pkexec Description: Disk Utility is a disk management tool for creating, reorganizing and formatting partitions. Disk Utility is a disk management tool for disk. diff --git a/debian/rules b/debian/rules index f7c0261..2bd31a4 100755 --- a/debian/rules +++ b/debian/rules @@ -1,7 +1,5 @@ #!/usr/bin/make -f -export QT_SELECT=5 - include /usr/share/dpkg/default.mk override_dh_auto_configure: diff --git a/log/log.cpp b/log/log.cpp index 481eda2..004f376 100644 --- a/log/log.cpp +++ b/log/log.cpp @@ -126,7 +126,7 @@ void WriteVersion() QTextStream ts(&outFile); auto appName = QCoreApplication::applicationName(); auto version = QCoreApplication::applicationVersion(); - ts << appName << " " << version << Qt::endl; + ts << appName << " " << version << "\n"; outFile.close(); s_logMutex.unlock(); } @@ -154,6 +154,9 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons case QtDebugMsg: logInfo = QString("Debug:"); break; + case QtInfoMsg: + logInfo = QString("Info:"); + break; case QtWarningMsg: logInfo = QString("Warning:"); break; @@ -177,7 +180,7 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons return; QTextStream ts(&outFile); - ts << message.toUtf8() << Qt::endl; + ts << message.toUtf8() << "\n"; outFile.close(); s_logMutex.unlock(); } diff --git a/service/diskmanagerservice.cpp b/service/diskmanagerservice.cpp index 0733c73..9a5bc1e 100644 --- a/service/diskmanagerservice.cpp +++ b/service/diskmanagerservice.cpp @@ -495,6 +495,10 @@ int DiskManagerService::test() bool DiskManagerService::checkAuthorization(void) { +#ifdef NO_DBUS_CALLER_AUTH_CHECK + qDebug() << "Authorization check was skipped"; + return true; +#else QString actionId("com.deepin.pkexec.deepin-diskmanager"); QString serviceName = message().service(); @@ -508,6 +512,7 @@ bool DiskManagerService::checkAuthorization(void) sendErrorReply(QDBusError::AccessDenied); return false; } +#endif } } // namespace DiskManager diff --git a/service/diskoperation/DeviceStorage.cpp b/service/diskoperation/DeviceStorage.cpp index 8e21833..4ca62cc 100755 --- a/service/diskoperation/DeviceStorage.cpp +++ b/service/diskoperation/DeviceStorage.cpp @@ -649,6 +649,26 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) } } + cmd = "udevadm info " + devicePath; + exitcode = Utils::executCmd(cmd, outPut, error); + if (exitcode != 0) { + qDebug() << "Failed to execute udevadm command, error:" << error; + return; + } + QString key = "ID_MODEL="; + int start = outPut.indexOf(key); + if (start != -1) { + start += key.length(); // 移动到等号后面 + int end = outPut.indexOf('\n', start); // 找到行尾 + if (end == -1) end = outPut.length(); // 如果是最后一行 + + model = outPut.mid(start, end - start).trimmed(); + if (!model.isEmpty()) + return; + } + + qWarning() << "tried a lot but got nothing about model for" << devicePath; + // 若未获取到型号名,返回未知 qDebug() << "model not found, set to UnKnow"; model = "UnKnow"; @@ -729,7 +749,13 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int QString spec_version = Utils::readContent("/sys/block/sdd/device/spec_version").trimmed(); if (!spec_version.isEmpty()) { qDebug() << "spec_version is not empty"; - interface = (spec_version == "300") ? "UFS 3.0" : "UFS 3.1"; + if (spec_version.contains("300")) { + interface = "UFS 3.0"; + } else if (spec_version.contains("310")) { + interface = "UFS 3.1"; + } else if (spec_version.contains("400")) { + interface = "UFS 4.0"; + } } } file.close(); diff --git a/service/diskoperation/filesystems/ext2.cpp b/service/diskoperation/filesystems/ext2.cpp index a684add..c660611 100644 --- a/service/diskoperation/filesystems/ext2.cpp +++ b/service/diskoperation/filesystems/ext2.cpp @@ -137,73 +137,95 @@ FS EXT2::getFilesystemSupport() void EXT2::setUsedSectors(Partition &partition) { qDebug() << "Setting used sectors for ext2/3/4 partition:" << partition.getPath(); - QString output, error, strmatch, strcmd; - m_blocksSize = m_numOfFreeOrUsedBlocks = m_totalNumOfBlock = -1; + QString output, error, strcmd; strcmd = QString("dumpe2fs -h %1").arg(partition.getPath()); + + qDebug() << "Executing dumpe2fs command to get filesystem information"; if (!Utils::executCmd(strcmd, output, error)) { - strmatch = ("Block count:"); + long long blockCount = -1; + long long blockSize = -1; + long long freeBlocks = -1; + long long reservedBlocks = 0; + + // 获取总块数 + QString strmatch = "Block count:"; int index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found block count"; - m_totalNumOfBlock = Utils::regexpLabel(output, QString("(?<=Block count:).*(?=\n)")).trimmed().toLong(); + qDebug() << "Found block count information"; + blockCount = Utils::regexpLabel(output, QString("(?<=Block count:).*(?=\n)")).trimmed().toLong(); } -// qDebug() << output; -// qDebug() << output.mid(index, strmatch.length()).toLatin1() << m_totalNumOfBlock; - strmatch = ("Block size:"); + + // 获取块大小 + strmatch = "Block size:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found block size"; - m_blocksSize = Utils::regexpLabel(output, QString("(?<=Block size:).*(?=\n)")).trimmed().toLong(); + qDebug() << "Found block size information"; + blockSize = Utils::regexpLabel(output, QString("(?<=Block size:).*(?=\n)")).trimmed().toLong(); } -// qDebug() << output << output.mid(index, strmatch.length()).toLatin1() << m_blocksSize; - - if (partition.m_busy) { - qDebug() << "Partition is busy, getting usage from mounted filesystem"; - Byte_Value fs_all; - Byte_Value fs_free; - if (Utils::getMountedFileSystemUsage(partition.getMountPoint(), fs_all, fs_free) == 0) { - qDebug() << "Successfully got mounted filesystem usage"; - partition.setSectorUsage(qRound64(fs_all / double(partition.m_sectorSize)), qRound64(fs_free / double(partition.m_sectorSize))); - partition.m_fsBlockSize = m_blocksSize; - } - } else { - qDebug() << "Partition is not busy, estimating minimum size"; - // Resize2fs won't shrink a file system smaller than it's own - // estimated minimum size, so use that to derive the free space. - m_numOfFreeOrUsedBlocks = -1; - if (!Utils::executCmd(QString("resize2fs -P %1").arg(partition.getPath()), output, error)) { - qDebug() << "resize2fs -P successful"; - if (sscanf(output.toLatin1(), "Estimated minimum size of the filesystem: %lld", &m_numOfFreeOrUsedBlocks) == 1 - || sscanf(output.toStdString().c_str(), "预计文件系统的最小尺寸:%lld", &m_numOfFreeOrUsedBlocks) == 1) { - qDebug() << "Parsed estimated minimum size"; - m_numOfFreeOrUsedBlocks = m_totalNumOfBlock - m_numOfFreeOrUsedBlocks; - } - } - // Resize2fs can fail reporting please run fsck first. Fall back - // to reading dumpe2fs output for free space. - if (m_numOfFreeOrUsedBlocks == -1) { - qDebug() << "resize2fs -P failed or did not provide minimum size, falling back to dumpe2fs"; - strmatch = "Free blocks:"; - index = output.indexOf(strmatch); - if (index < output.length()) { - qDebug() << "Found free blocks in dumpe2fs output"; - sscanf(output.mid(index, strmatch.length()).toLatin1(), "Free blocks: %lld", &m_numOfFreeOrUsedBlocks); + + // 获取空闲块数 + strmatch = "Free blocks:"; + index = output.indexOf(strmatch); + if (index >= 0 && index < output.length()) { + qDebug() << "Found free blocks information"; + freeBlocks = Utils::regexpLabel(output, QString("(?<=Free blocks:).*(?=\n)")).trimmed().toLong(); + } + + // 获取保留块数 + strmatch = "Reserved block count:"; + index = output.indexOf(strmatch); + if (index >= 0 && index < output.length()) { + qDebug() << "Found reserved blocks information"; + reservedBlocks = Utils::regexpLabel(output, QString("(?<=Reserved block count:).*(?=\n)")).trimmed().toLong(); + } + + // 验证数据有效性并计算扇区使用情况 + if (blockCount > 0 && blockSize > 0 && freeBlocks >= 0 && reservedBlocks >= 0) { + qDebug() << "Filesystem information validation successful, calculating sector usage"; + + // 计算用户实际可用的空闲块数:可用 = (freeBlocks - reservedBlocks) + long long userAvailableBlocks = (freeBlocks > reservedBlocks) ? (freeBlocks - reservedBlocks) : 0; + + // 转换为扇区数 + Sector totalSectors = qRound64(blockCount * (blockSize / double(partition.m_sectorSize))); + Sector availableSectors = qRound64(userAvailableBlocks * (blockSize / double(partition.m_sectorSize))); + + qDebug() << "EXT* usage calculation: blockCount=" << blockCount + << "blockSize=" << blockSize + << "freeBlocks=" << freeBlocks + << "reservedBlocks=" << reservedBlocks + << "userAvailableBlocks=" << userAvailableBlocks + << "totalSectors=" << totalSectors + << "availableSectors=" << availableSectors; + + // 如果分区已挂载,使用 stat 获取更准确的可用块数 + if (partition.m_busy && !partition.getMountPoints().empty()) { + qDebug() << "Partition is mounted, using stat for more accurate available space calculation"; + Byte_Value statTotalSize, statAvailableSize; + if (Utils::getMountedFileSystemUsage(partition.getMountPoint(), statTotalSize, statAvailableSize) == 0) { + // 使用 stat 获取的可用空间(已经排除了保留空间) + Sector statAvailableSectors = qRound64(statAvailableSize / double(partition.m_sectorSize)); + qDebug() << "Using stat data for mounted partition: statAvailableSectors=" << statAvailableSectors; + partition.setSectorUsage(totalSectors, statAvailableSectors); + qDebug() << "Sector usage set successfully using stat data"; + } else { + qDebug() << "Failed to get mounted filesystem usage, using calculated available sectors"; + partition.setSectorUsage(totalSectors, availableSectors); + qDebug() << "Sector usage set successfully using calculated data"; } + } else { + qDebug() << "Partition is not mounted, using calculated available sectors"; + partition.setSectorUsage(totalSectors, availableSectors); + qDebug() << "Sector usage set successfully"; } - - if (m_totalNumOfBlock > -1 && m_numOfFreeOrUsedBlocks > -1 && m_blocksSize > -1) { - qDebug() << "Calculating and setting sector usage from block counts"; - m_totalNumOfBlock = qRound64(m_totalNumOfBlock * (m_blocksSize / double(partition.m_sectorSize))); - m_numOfFreeOrUsedBlocks = qRound64(m_numOfFreeOrUsedBlocks * (m_blocksSize / double(partition.m_sectorSize))); - qDebug() << "111111111111111111111111" << m_totalNumOfBlock << m_numOfFreeOrUsedBlocks << m_blocksSize; - partition.setSectorUsage(m_totalNumOfBlock, m_numOfFreeOrUsedBlocks); - partition.m_fsBlockSize = m_blocksSize; - } + partition.m_fsBlockSize = blockSize; + qDebug() << "Filesystem block size set to:" << blockSize; + } else { + qDebug() << "Filesystem information validation failed, invalid parameters detected"; } - - } else { - qDebug() << __FUNCTION__ << "dumpe2fs -h failed :" << output << error; + qDebug() << "dumpe2fs command execution failed, error:" << error; + qDebug() << "Failed to set used sectors for partition:" << partition.getPath(); } } diff --git a/service/diskoperation/partedcore.cpp b/service/diskoperation/partedcore.cpp index 6d83256..94f99af 100644 --- a/service/diskoperation/partedcore.cpp +++ b/service/diskoperation/partedcore.cpp @@ -1076,7 +1076,7 @@ bool PartedCore::hidePartition() } else { qDebug() << "open file for write"; QTextStream out(&file); - out << QString("ENV{ID_FS_UUID}==\"%1\", ENV{UDISKS_IGNORE}=\"1\"").arg(m_curpartition.m_uuid) << Qt::endl; + out << QString("ENV{ID_FS_UUID}==\"%1\", ENV{UDISKS_IGNORE}=\"1\"").arg(m_curpartition.m_uuid) << "\n"; } // qDebug() << __FUNCTION__ << "Hide Partition end"; @@ -2283,7 +2283,7 @@ void PartedCore::onRefreshDeviceInfo(int type, bool arg1, QString arg2) if (m_workerThreadProbe == nullptr) { qDebug() << "m_workerThreadProbe is null, creating new thread"; m_workerThreadProbe = new QThread(); - qDebug() << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << Qt::endl; + qDebug() << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << "\n"; qDebug() << " ----------------------! 0 !--------------------- :" << m_probeThread.thread(); m_probeThread.moveToThread(m_workerThreadProbe); m_workerThreadProbe->start(); diff --git a/service/diskoperation/supportedfilesystems.cpp b/service/diskoperation/supportedfilesystems.cpp index 1d5b0bd..3684402 100644 --- a/service/diskoperation/supportedfilesystems.cpp +++ b/service/diskoperation/supportedfilesystems.cpp @@ -41,7 +41,7 @@ SupportedFileSystems::SupportedFileSystems() m_fsObjects[FS_EXT4] = new EXT2(FS_EXT4); // m_fs_objects[FS_F2FS] = new f2fs(); // m_fs_objects[FS_FAT16] = new fat16(FS_FAT16); - m_fsObjects[FS_FAT32] = new FAT16(FS_FAT32); + // m_fsObjects[FS_FAT32] = new FAT16(FS_FAT32); // m_fs_objects[FS_HFS] = new hfs(); // m_fs_objects[FS_HFSPLUS] = new hfsplus(); // m_fs_objects[FS_JFS] = new jfs();