Skip to content

Commit

Permalink
PluginManager: properly handle UTF-8 filenames also on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Feb 5, 2017
1 parent 49be6d0 commit 2328ba3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doc/corrade-changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace Corrade {

### PluginManager library

- @ref PluginManager::Manager now properly loads plugins from UTF-8 encoded
paths also on Windows
- @ref PluginManager::Manager can now be constructed without specifying
plugin directory

Expand Down
14 changes: 8 additions & 6 deletions src/Corrade/PluginManager/AbstractManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#include <sstream>
#include <utility>

#include "Corrade/PluginManager/AbstractPlugin.h"
#include "Corrade/Utility/Assert.h"
#include "Corrade/Utility/Directory.h"
#include "Corrade/Utility/Configuration.h"

#ifndef CORRADE_TARGET_WINDOWS
#if !defined(CORRADE_TARGET_NACL_NEWLIB) && !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_IOS) && !defined(CORRADE_TARGET_ANDROID)
#include <dlfcn.h>
Expand All @@ -41,13 +46,10 @@
#define dlsym GetProcAddress
#define dlerror GetLastError
#define dlclose FreeLibrary
#include "Corrade/Utility/Unicode.h"
using Corrade::Utility::Unicode::widen;
#endif

#include "Corrade/PluginManager/AbstractPlugin.h"
#include "Corrade/Utility/Assert.h"
#include "Corrade/Utility/Directory.h"
#include "Corrade/Utility/Configuration.h"

#include "configure.h"

using namespace Corrade::Utility;
Expand Down Expand Up @@ -366,7 +368,7 @@ LoadState AbstractManager::loadInternal(Plugin& plugin) {
#ifndef CORRADE_TARGET_WINDOWS
void* module = dlopen(filename.data(), RTLD_NOW|RTLD_GLOBAL);
#else
HMODULE module = LoadLibraryA(filename.data());
HMODULE module = LoadLibraryW(widen(filename).data());
#endif
if(!module) {
Error() << "PluginManager::Manager::load(): cannot open plugin file" << '"' + filename + "\":" << dlerror();
Expand Down
3 changes: 2 additions & 1 deletion src/Corrade/PluginManager/AbstractManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ class CORRADE_PLUGINMANAGER_EXPORT AbstractManager {
* @brief Set another plugin directory
*
* Keeps loaded plugins untouched, removes unloaded plugins which are
* not existing anymore and adds newly found plugins.
* not existing anymore and adds newly found plugins. The directory is
* expected to be in UTF-8.
* @partialsupport Only static plugins are supported in
* @ref CORRADE_TARGET_NACL_NEWLIB "NaCl newlib",
* @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten",
Expand Down
4 changes: 2 additions & 2 deletions src/Corrade/PluginManager/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ template<class T> class Manager: public AbstractManager {
public:
/**
* @brief Constructor
* @param pluginDirectory Directory where plugins will be searched.
* No recursive processing is done.
* @param pluginDirectory Directory where plugins will be searched,
* encoded in UTF-8. No recursive processing is done.
*
* First goes through list of static plugins and finds ones that use
* the same interface as this manager instance. Then gets list of all
Expand Down

0 comments on commit 2328ba3

Please sign in to comment.