diff --git a/src/plugins/openmv/openmvplugin.cpp b/src/plugins/openmv/openmvplugin.cpp index 5e2d22320f4..b2e06dc6cea 100644 --- a/src/plugins/openmv/openmvplugin.cpp +++ b/src/plugins/openmv/openmvplugin.cpp @@ -2445,7 +2445,7 @@ bool OpenMVPlugin::delayedInitialize() } }); - connect(scanDrivesThread, &ScanDriveThread::driveScanned, this, [this] (const QList > &output) { + connect(scanDrivesThread, &ScanDriveThread::driveScanned, this, [this] (const QList > &output) { m_availableDrives = output; }); @@ -3957,18 +3957,18 @@ void OpenMVPlugin::setPortPath(bool silent) { QStringList drives; - for(const QPair &pair : m_availableDrives) + for(const QPair &pair : m_availableDrives) { - const QStorageInfo info = pair.first; + const QString rootPath = pair.first; const QString serialNumber = pair.second; if((((m_major < OPENMV_DISK_ADDED_MAJOR) || ((m_major == OPENMV_DISK_ADDED_MAJOR) && (m_minor < OPENMV_DISK_ADDED_MINOR)) || ((m_major == OPENMV_DISK_ADDED_MAJOR) && (m_minor == OPENMV_DISK_ADDED_MINOR) && (m_patch < OPENMV_DISK_ADDED_PATCH))) - || QFile::exists(info.rootPath() + QStringLiteral(OPENMV_DISK_ADDED_NAME))) + || QFile::exists(rootPath + QStringLiteral(OPENMV_DISK_ADDED_NAME))) && (serialNumber.toLower() == m_portDriveSerialNumber.toLower())) { - drives.append(info.rootPath()); + drives.append(rootPath); } } diff --git a/src/plugins/openmv/openmvplugin.h b/src/plugins/openmv/openmvplugin.h index 4c9ad026bb2..2d0154df07a 100644 --- a/src/plugins/openmv/openmvplugin.h +++ b/src/plugins/openmv/openmvplugin.h @@ -335,7 +335,7 @@ class ScanDriveThread: public QObject public: explicit ScanDriveThread() { } public slots: void scanDrivesSlot() { - QList > drives; + QList > drives; for(const QStorageInfo &info : QStorageInfo::mountedVolumes()) { if(info.isValid() && info.isReady() @@ -349,12 +349,12 @@ class ScanDriveThread: public QObject info.rootPath().startsWith(QStringLiteral("/mnt/"), Qt::CaseInsensitive) || info.rootPath().startsWith(QStringLiteral("/run/"), Qt::CaseInsensitive))) { - drives.append(QPair(info, driveSerialNumber(info.rootPath()))); + drives.append(QPair(info.rootPath(), driveSerialNumber(info.rootPath()))); } } emit driveScanned(drives); } - signals: void driveScanned(const QList > &output); + signals: void driveScanned(const QList > &output); }; class OpenMVPlugin : public ExtensionSystem::IPlugin @@ -577,7 +577,7 @@ public slots: // private QMap m_argumentsByHierarchy; QMap m_returnTypesByHierarchy; QList m_availableWifiPorts; - QList > m_availableDrives; + QList > m_availableDrives; typedef struct openTerminalMenuData { diff --git a/src/plugins/openmv/tools/driveserialnumber.cpp b/src/plugins/openmv/tools/driveserialnumber.cpp index 5bb96c2f63f..909f574bbcf 100644 --- a/src/plugins/openmv/tools/driveserialnumber.cpp +++ b/src/plugins/openmv/tools/driveserialnumber.cpp @@ -9,6 +9,8 @@ namespace OpenMV { namespace Internal { +extern QMutex dfu_util_working; + QString serialPortDriveSerialNumber(const QString &portName) { #if defined(Q_OS_WIN) @@ -20,7 +22,7 @@ QString serialPortDriveSerialNumber(const QString &portName) QStringList() << QStringLiteral("-Command") << QString(QStringLiteral("(Get-PnpDeviceProperty -InstanceId (Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -eq '%1' }).PNPDeviceId | Where-Object { $_.KeyName -eq 'DEVPKEY_Device_Parent' }).Data")).arg(QString(portName)))); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if(process.result() == Utils::ProcessResult::FinishedWithSuccess) { @@ -46,7 +48,7 @@ QString driveSerialNumber(const QString &drivePath) QStringList() << QStringLiteral("-Command") << QString(QStringLiteral("(Get-Disk -Number (Get-Partition -DriveLetter '%1').DiskNumber).SerialNumber")).arg(QString(drivePath).remove(QStringLiteral(":")).remove(QStringLiteral("/"))))); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if(process.result() == Utils::ProcessResult::FinishedWithSuccess) { @@ -54,6 +56,8 @@ QString driveSerialNumber(const QString &drivePath) return serialNumber; } #elif defined(Q_OS_LINUX) + if(!dfu_util_working.try_lock()) return QString(); + Utils::Process process; std::chrono::seconds timeout(10); process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine); @@ -63,13 +67,13 @@ QString driveSerialNumber(const QString &drivePath) << QStringLiteral("-J") << QStringLiteral("-o") << QStringLiteral("MOUNTPOINT,NAME,SERIAL"))); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if(process.result() == Utils::ProcessResult::FinishedWithSuccess) { QJsonDocument doc = QJsonDocument::fromJson(process.stdOut().toUtf8()); - if (doc.isObject()) + if (!doc.isNull()) { QString cleanDrivePath = QDir::fromNativeSeparators(QDir::cleanPath(drivePath)); @@ -81,6 +85,7 @@ QString driveSerialNumber(const QString &drivePath) if (mountPoint == cleanDrivePath) { + dfu_util_working.unlock(); return serialNumber; } @@ -92,12 +97,15 @@ QString driveSerialNumber(const QString &drivePath) if (childMountPoint == cleanDrivePath) { + dfu_util_working.unlock(); return childSerialNumber.isEmpty() ? serialNumber : childSerialNumber; } } } } } + + dfu_util_working.unlock(); #elif defined(Q_OS_MAC) Utils::Process process; std::chrono::seconds timeout(10); @@ -106,13 +114,13 @@ QString driveSerialNumber(const QString &drivePath) process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("system_profiler")), QStringList() << QStringLiteral("SPUSBDataType") << QStringLiteral("-json"))); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if(process.result() == Utils::ProcessResult::FinishedWithSuccess) { QJsonDocument doc = QJsonDocument::fromJson(process.stdOut().toUtf8()); - if (doc.isObject()) + if (!doc.isNull()) { for (const QJsonValue &val : doc.object().value(QStringLiteral("SPUSBDataType")).toArray()) { @@ -134,7 +142,7 @@ QString driveSerialNumber(const QString &drivePath) << QStringLiteral("list") << QStringLiteral("-plist") << diskName)); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if (process.stdOut().contains(QString(QStringLiteral("%1")).arg(drivePath))) { diff --git a/src/plugins/openmv/tools/myqserialportinfo.cpp b/src/plugins/openmv/tools/myqserialportinfo.cpp index ad18bf933a6..e98058be771 100644 --- a/src/plugins/openmv/tools/myqserialportinfo.cpp +++ b/src/plugins/openmv/tools/myqserialportinfo.cpp @@ -83,7 +83,7 @@ MyQSerialPortInfo::MyQSerialPortInfo(const QSerialPortInfo &info) << QStringLiteral("-v") << QStringLiteral("-d") << QString(QStringLiteral("%1:%2")).arg(m_vendorIdentifier, 4, 16, QLatin1Char('0')).arg(m_productIdentifier, 4, 16, QLatin1Char('0')))); - process.runBlocking(timeout, Utils::EventLoopMode::On); + process.runBlocking(timeout, Utils::EventLoopMode::Off); if(process.result() == Utils::ProcessResult::FinishedWithSuccess) { diff --git a/src/plugins/tabbededitor/tabbar.cpp b/src/plugins/tabbededitor/tabbar.cpp index f21fc9d10ba..c6027faa822 100644 --- a/src/plugins/tabbededitor/tabbar.cpp +++ b/src/plugins/tabbededitor/tabbar.cpp @@ -136,7 +136,9 @@ void TabBar::activateEditor(int index) void TabBar::addEditorTab(Core::IEditor *editor) { + if (!editor) return; Core::IDocument *document = editor->document(); + if (!document) return; const int index = addTab(document->displayName()); // OPENMV-DIFF //