diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 5dc15ac4059..b3c55f9892c 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -311,6 +312,15 @@ bool DeviceManager::isLoaded() const return d->writer; } +IDevice::ConstPtr DeviceManager::deviceForPath(const FilePath &path) +{ + for (IDevice::Ptr &dev : instance()->d->devices) { + if (dev->handlesFile(path)) + return dev; + } + return {}; +} + void DeviceManager::setDefaultDevice(Utils::Id id) { QTC_ASSERT(this != instance(), return); @@ -344,11 +354,68 @@ const IDeviceFactory *DeviceManager::restoreFactory(const QVariantMap &map) DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique()) { - if (isInstance) { - QTC_ASSERT(!m_instance, return); - m_instance = this; - connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, this, &DeviceManager::save); - } + QTC_ASSERT(isInstance == !m_instance, return); + + if (!isInstance) + return; + + m_instance = this; + connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, + this, &DeviceManager::save); + + DeviceFileHooks hooks; + + hooks.isExecutableFile = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return false); + return device->isExecutableFile(filePath); + }; + + hooks.isReadableFile = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return false); + return device->isReadableFile(filePath); + }; + + hooks.isReadableDir = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return false); + return device->isReadableDirectory(filePath); + }; + + hooks.isWritableDir = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return false); + return device->isWritableDirectory(filePath); + }; + + hooks.createDir = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return false); + return device->createDirectory(filePath); + }; + + hooks.dirEntries = [](const FilePath &filePath, + const QStringList &nameFilters, QDir::Filters filters) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return FilePaths()); + return device->directoryEntries(filePath, nameFilters, filters); + }; + + hooks.fileContents = [](const FilePath &filePath, int maxSize) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return QByteArray()); + return device->fileContents(filePath, maxSize); + }; + + FilePath::setDeviceFileHooks(hooks); + + QtcProcess::setRemoteStartProcessHook([](QtcProcess &process) { + FilePath filePath = process.commandLine().executable(); + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return); + device->runProcess(process); + }); } DeviceManager::~DeviceManager() diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.h b/src/plugins/projectexplorer/devicesupport/devicemanager.h index 0f9c0362484..ef8047e0a57 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.h +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.h @@ -69,6 +69,7 @@ public: void setDeviceState(Utils::Id deviceId, IDevice::DeviceState deviceState); bool isLoaded() const; + static IDevice::ConstPtr deviceForPath(const Utils::FilePath &path); signals: void deviceAdded(Utils::Id id);