Skip to content

Commit 417b23f

Browse files
committed
fix: Fix the issue of errors in the hard disk capacity of certain specific models
Fix the issue of errors in the hard disk capacity of certain specific models Log: Fix the issue of errors in the hard disk capacity of certain specific models Bug: https://pms.uniontech.com/bug-view-251377.html
1 parent f59a391 commit 417b23f

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ void DeviceManager::mergeDisk()
743743
if (serialIDs.size() < 2)
744744
continue;
745745
DeviceStorage *fDevice = dynamic_cast<DeviceStorage *>(m_ListDeviceStorage[serialIDs[0] ]);
746-
for (int i = 1; i < serialIDs.size(); ++i) {
746+
for (int i = serialIDs.size() - 1; i > 0; --i) {
747747
DeviceStorage *curDevice = dynamic_cast<DeviceStorage *>(m_ListDeviceStorage[serialIDs[i] ]);
748748
fDevice->appendDisk(curDevice);
749749
m_ListDeviceStorage.removeAt(serialIDs[i]);

deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ TomlFixMethod DeviceStorage::setInfoFromTomlOneByOne(const QMap<QString, QString
4444
return ret;
4545
}
4646

47+
static QString decimalkilos(quint64 value)
48+
{
49+
const QString prefixes("KMGTPEZY");
50+
int i = 0;
51+
quint64 curValue = value;
52+
while ((i < prefixes.size()) && ((curValue > 1000) || (curValue % 1000 == 0)))
53+
{
54+
value = curValue;
55+
curValue = curValue / 1000;
56+
i++;
57+
}
58+
59+
if (i < 4) {
60+
quint64 diffValue = value - curValue * 1000;
61+
double calValue = diffValue / 1000.0 + 0.1;
62+
curValue += static_cast<quint64>(calValue);;
63+
}
64+
65+
QString valueStr = QString::number(curValue) + " ";
66+
if ((i > 0) && (i <= prefixes.size())) {
67+
valueStr += prefixes[i - 1];
68+
}
69+
valueStr += "B";
70+
return valueStr;
71+
}
72+
4773
bool DeviceStorage::setHwinfoInfo(const QMap<QString, QString> &mapInfo)
4874
{
4975
// 龙芯机器中 hwinfo --disk会列出所有的分区信息
@@ -76,7 +102,18 @@ bool DeviceStorage::setHwinfoInfo(const QMap<QString, QString> &mapInfo)
76102
setAttribute(mapInfo, "Capacity", m_Size);
77103

78104
// hwinfo里面显示的内容是 14 GB (15376000000 bytes) 需要处理
79-
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
105+
QRegExp reSize(".*\\((.*)bytes\\).*");
106+
if (reSize.exactMatch(m_Size)) {
107+
bool ok = false;
108+
quint64 bytesSize = reSize.cap(1).trimmed().toULongLong(&ok);
109+
if (ok) {
110+
m_Size = decimalkilos(bytesSize);
111+
} else {
112+
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
113+
}
114+
} else {
115+
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
116+
}
80117

81118
// 如果既没有capacity也没有序列号则认为该磁盘无效,否则都属于有效磁盘
82119
if ((m_Size.startsWith("0") || m_Size == "") && m_SerialNumber == "")
@@ -172,7 +209,18 @@ bool DeviceStorage::setKLUHwinfoInfo(const QMap<QString, QString> &mapInfo)
172209
setAttribute(mapInfo, "Capacity", m_Size);
173210

174211
// hwinfo里面显示的内容是 14 GB (15376000000 bytes) 需要处理
175-
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
212+
QRegExp reSize(".*\\((.*)bytes\\).*");
213+
if (reSize.exactMatch(m_Size)) {
214+
bool ok = false;
215+
quint64 bytesSize = reSize.cap(1).trimmed().toULongLong(&ok);
216+
if (ok) {
217+
m_Size = decimalkilos(bytesSize);
218+
} else {
219+
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
220+
}
221+
} else {
222+
m_Size.replace(QRegExp("\\(.*\\)"), "").replace(" ", "");
223+
}
176224
if (m_Size.startsWith("0") || m_Size == "")
177225
return false;
178226

@@ -423,7 +471,7 @@ void DeviceStorage::checkDiskSize()
423471
double num1 = num - int(num);
424472
QString type = m_Size.right(m_Size.length() - reg.cap(0).size()).trimmed();
425473
if (!qFuzzyCompare(num1, 0.0) && type == "GB") {
426-
m_Size = QString::number(int(num) + 1) + type;
474+
m_Size = QString::number(int(num) + 1) + " " + type;
427475
}
428476
}
429477
}
@@ -570,7 +618,7 @@ void DeviceStorage::getInfoFromLshw(const QMap<QString, QString> &mapInfo)
570618
setAttribute(mapInfo, "serial", m_SerialNumber, false);
571619
setAttribute(mapInfo, "product", m_Name);
572620
setAttribute(mapInfo, "description", m_Description);
573-
setAttribute(mapInfo, "size", m_Size);
621+
setAttribute(mapInfo, "size", m_Size, false);
574622
// 223GiB (240GB)
575623
QRegExp re(".*\\((.*)\\)$");
576624
if (re.exactMatch(m_Size))

0 commit comments

Comments
 (0)