@@ -774,11 +774,11 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int
774774 return ;
775775}
776776
777- void DeviceStorage::updateForHWDevice (const QString &devicePath)
777+ void DeviceStorage::updateForHWDevice (const QString &/* devicePath*/ )
778778{
779779 qDebug () << " DeviceStorage::updateForHWDevice BEGIN" ;
780- if (m_model != Utils::readContent (" /proc/bootdevice/product_name" ).trimmed ()) {
781- qDebug () << " m_model is not boot device , return" ;
780+ if (Utils::readContent (" /proc/bootdevice/product_name" ).trimmed (). isEmpty ())
781+ qDebug () << " Fail to read the product_name file or the file is empty , return" ;
782782 return ;
783783 }
784784
@@ -794,6 +794,44 @@ void DeviceStorage::updateForHWDevice(const QString &devicePath)
794794 // hide model and vendor
795795 m_model = " " ;
796796 m_vendor = " " ;
797+
798+ // Normalize disk size
799+ if (!m_size.isEmpty ()) {
800+ // Convert size string to bytes
801+ qint64 bytes = 0 ;
802+ QString sizeStr = m_size.toLower ();
803+
804+ if (sizeStr.contains (" bytes" )) {
805+ sizeStr = sizeStr.split (" bytes" ).first ().trimmed ();
806+ bytes = sizeStr.toLongLong ();
807+ } else {
808+ // Handle GB/TB directly
809+ double value = sizeStr.split (" " ).first ().toDouble ();
810+ if (sizeStr.contains (" gb" )) {
811+ bytes = value * 1000 * 1000 * 1000 ;
812+ } else if (sizeStr.contains (" tb" )) {
813+ bytes = value * 1000 * 1000 * 1000 * 1000 ;
814+ }
815+ }
816+
817+ // Convert to standardized format
818+ if (bytes > 0 ) {
819+ // Convert to GB and round to standard sizes
820+ int gb = qRound (bytes / (1000.0 * 1000 * 1000 ));
821+ if (gb < 200 ) {
822+ return ;
823+ } else if (gb <= 300 ) {
824+ m_size = " 256 GB" ;
825+ } else if (gb <= 600 ) {
826+ m_size = " 512 GB" ;
827+ } else if (gb <= 1200 ){
828+ m_size = " 1 TB" ;
829+ } else if (gb <= 2200 ) {
830+ m_size = " 2 TB" ;
831+ }
832+ }
833+ }
834+
797835 qDebug () << " DeviceStorage::updateForHWDevice END" ;
798836}
799837
0 commit comments