@@ -608,7 +608,7 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int
608608 return ;
609609}
610610
611- void DeviceStorage::updateForHWDevice (const QString &devicePath)
611+ void DeviceStorage::updateForHWDevice (const QString &/* devicePath*/ )
612612{
613613 if (m_model != Utils::readContent (" /proc/bootdevice/product_name" ).trimmed ())
614614 return ;
@@ -622,6 +622,58 @@ void DeviceStorage::updateForHWDevice(const QString &devicePath)
622622 // hide mode and vendor
623623 m_model = " " ;
624624 m_vendor = " " ;
625+
626+ // Normalize disk size
627+ if (!m_size.isEmpty ()) {
628+ // Convert size string to bytes
629+ qint64 bytes = 0 ;
630+ QString sizeStr = m_size.toLower ();
631+
632+ if (sizeStr.contains (" bytes" )) {
633+ sizeStr = sizeStr.split (" bytes" ).first ().trimmed ();
634+ bytes = sizeStr.toLongLong ();
635+ } else {
636+ // Handle GB/TB directly
637+ double value = sizeStr.split (" " ).first ().toDouble ();
638+ if (sizeStr.contains (" gb" )) {
639+ bytes = value * 1000 * 1000 * 1000 ;
640+ } else if (sizeStr.contains (" tb" )) {
641+ bytes = value * 1000 * 1000 * 1000 * 1000 ;
642+ }
643+ }
644+
645+ // Convert to standardized format
646+ if (bytes > 0 ) {
647+ // Convert to GB and round to standard sizes
648+ int gb = qRound (bytes / (1000.0 * 1000 * 1000 ));
649+ if (gb <= 300 ) {
650+ m_size = " 256 GB" ;
651+ } else if (gb <= 600 ) {
652+ m_size = " 512 GB" ;
653+ } else if (gb <= 1200 ){
654+ m_size = " 1 TB" ;
655+ } else if (gb <= 2200 ) {
656+ m_size = " 2 TB" ;
657+ }
658+ }
659+ }
660+ }
661+
662+ void DeviceStorage::formatDeviceSize ()
663+ {
664+ static QRegularExpression numRegex (" (\\ d+)(?:\\ .\\ d+)?\\ s*(TB|GB|MB)" );
665+ QRegularExpressionMatch match = numRegex.match (m_size);
666+ if (match.hasMatch ()) {
667+ double number = match.captured (1 ).toDouble ();
668+ QString unit = match.captured (2 );
669+ // 如果小数部分为0,转换为整数显示,否则保留小数
670+ if (qFuzzyCompare (number, qRound (number))) {
671+ m_size = QString (" %1 %2" ).arg (qRound (number)).arg (unit);
672+ } else {
673+ m_size = QString (" %1 %2" ).arg (number, 0 , ' f' , 2 ).arg (unit);
674+ }
675+ return ;
676+ }
625677}
626678
627679void DeviceStorage::getMapInfoFromSmartctl (QMap<QString, QString> &mapInfo, const QString &info, const QString &ch)
0 commit comments