Allow to get the partition nr from the device node
This commit is contained in:
parent
6f28900350
commit
afcc0c6c47
40
src/main.cpp
40
src/main.cpp
|
@ -25,6 +25,45 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
std::pair<QString, QString> parseDevice(const QString& selectedDevice)
|
||||||
|
{
|
||||||
|
QString device;
|
||||||
|
QString partitionNr;
|
||||||
|
if (selectedDevice.length()) {
|
||||||
|
const bool isNvme = selectedDevice.startsWith(QStringLiteral("nvme"));
|
||||||
|
// calculate the number of numbers on the last part of the info.
|
||||||
|
int numSize = 0;
|
||||||
|
for (int i = selectedDevice.length() - 1; i > 0; i--) {
|
||||||
|
if (selectedDevice[i].isNumber()) {
|
||||||
|
numSize += 1;
|
||||||
|
} else {
|
||||||
|
if (isNvme) {
|
||||||
|
// the entry is just an nvme without a partition.
|
||||||
|
if (selectedDevice[i] != QLatin1Char('p')) {
|
||||||
|
numSize = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
partitionNr = selectedDevice.mid(selectedDevice.length() - numSize);
|
||||||
|
|
||||||
|
if (numSize != 0) {
|
||||||
|
// nvme has a `p` that also needs to be removed.
|
||||||
|
if (isNvme) {
|
||||||
|
numSize += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
device = selectedDevice.mid(0, selectedDevice.length() - numSize);
|
||||||
|
} else {
|
||||||
|
device = selectedDevice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {device, partitionNr};
|
||||||
|
}
|
||||||
|
|
||||||
int Q_DECL_IMPORT main(int argc, char* argv[])
|
int Q_DECL_IMPORT main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -75,6 +114,7 @@ int Q_DECL_IMPORT main(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const QString selectedDevice = parser.value(deviceOption);
|
const QString selectedDevice = parser.value(deviceOption);
|
||||||
|
auto [device, partitionNr] = parseDevice(selectedDevice);
|
||||||
|
|
||||||
MainWindow* mainWindow = new MainWindow();
|
MainWindow* mainWindow = new MainWindow();
|
||||||
QObject::connect(mainWindow, &MainWindow::scanFinished, mainWindow, [mainWindow, selectedDevice] {
|
QObject::connect(mainWindow, &MainWindow::scanFinished, mainWindow, [mainWindow, selectedDevice] {
|
||||||
|
|
Loading…
Reference in New Issue