| 1 | /* |
| 2 | * Copyright (C) 2022 Damir Porobic <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "WinPluginLoader.h" |
| 21 | |
| 22 | WinPluginLoader::WinPluginLoader(const QSharedPointer<ILogger> &logger) : |
| 23 | PluginLoader(logger), |
| 24 | mLogger(logger) |
| 25 | { |
| 26 | |
| 27 | } |
| 28 | |
| 29 | QObject *WinPluginLoader::load(const QString &path) const |
| 30 | { |
| 31 | // Under Windows the 3rd Party Dlls are next to the plugin in the same directory |
| 32 | // in order to find them we set the current directory to the plugin directory |
| 33 | auto currentDir = QDir::current(); |
| 34 | auto pluginDir = QFileInfo(path).path(); |
| 35 | auto isDirectoryChanged = QDir::setCurrent(pluginDir); |
| 36 | |
| 37 | if(!isDirectoryChanged) { |
| 38 | mLogger->log(QString("Unable to change to plugin directory %1").arg(pluginDir)); |
| 39 | } |
| 40 | |
| 41 | auto plugin = PluginLoader::load(path); |
| 42 | |
| 43 | // Return previous current directory |
| 44 | QDir::setCurrent(currentDir.absolutePath()); |
| 45 | |
| 46 | return plugin; |
| 47 | } |