Taken care of FilePluginProvider's FIXMEs

svn-id: r32085
This commit is contained in:
Jordi Vilalta Prat 2008-05-13 13:24:49 +00:00
parent f7a682edf9
commit a392bc4b0e
6 changed files with 59 additions and 39 deletions

View file

@ -83,9 +83,17 @@ public:
};
Plugin* SDLPluginProvider::createPlugin(const Common::String &filename) const {
Plugin* DCPluginProvider::createPlugin(const Common::String &filename) const {
return new DCPlugin(filename);
}
bool DCPluginProvider::isPluginFilename(const Common::String &filename) const {
// Check the plugin suffix
if (!filename.hasSuffix(".PLG"))
return false;
return true;
}
#endif // defined(DYNAMIC_MODULES) && defined(__DC__)

View file

@ -34,8 +34,7 @@ class DCPluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::String &filename) const;
virtual const char* getPrefix() const { return ""; }
virtual const char* getSuffix() const { return ".PLG"; }
bool isPluginFilename(const Common::String &filename) const;
virtual void addCustomDirectories(Common::StringList &dirs) const {
dirs.push_back("/");

View file

@ -107,5 +107,13 @@ Plugin* Win32PluginProvider::createPlugin(const Common::String &filename) const
return new Win32Plugin(filename);
}
bool Win32PluginProvider::isPluginFilename(const Common::String &filename) const {
// Check the plugin suffix
if (!filename.hasSuffix(".dll"))
return false;
return true;
}
#endif // defined(DYNAMIC_MODULES) && defined(_WIN32)

View file

@ -34,8 +34,7 @@ class Win32PluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::String &filename) const;
virtual const char* getPrefix() const { return ""; }
virtual const char* getSuffix() const { return ".dll"; }
bool isPluginFilename(const Common::String &filename) const;
virtual void addCustomDirectories(Common::StringList &dirs) const {}
};

View file

@ -27,7 +27,6 @@
#ifdef DYNAMIC_MODULES
#include "common/config-manager.h"
#include "common/fs.h"
#endif
// Plugin versioning
@ -151,38 +150,34 @@ PluginList FilePluginProvider::getPlugins() {
PluginList pl;
// Prepare the list of directories to search
Common::StringList pluginDirs;
FSList pluginDirs;
// Add the default directories
pluginDirs.push_back(".");
pluginDirs.push_back("plugins");
pluginDirs.push_back(FilesystemNode("."));
pluginDirs.push_back(FilesystemNode("plugins"));
// Add the provider's custom directories
addCustomDirectories(pluginDirs);
// Add the user specified directory
Common::String pluginsPath(ConfMan.get("pluginspath"));
if (!pluginsPath.empty()) {
FilesystemNode dir(pluginsPath);
pluginDirs.push_back(dir.getPath());
}
if (!pluginsPath.empty())
pluginDirs.push_back(FilesystemNode(pluginsPath));
Common::StringList::const_iterator d;
for (d = pluginDirs.begin(); d != pluginDirs.end(); d++) {
FSList::const_iterator dir;
for (dir = pluginDirs.begin(); dir != pluginDirs.end(); dir++) {
// Load all plugins.
// Scan for all plugins in this directory
FilesystemNode dir(*d);
FSList files;
if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) {
debug(1, "Couldn't open plugin directory '%s'", d->c_str());
if (!dir->getChildren(files, FilesystemNode::kListFilesOnly)) {
debug(1, "Couldn't open plugin directory '%s'", dir->getPath().c_str());
continue;
} else {
debug(1, "Reading plugins from plugin directory '%s'", d->c_str());
debug(1, "Reading plugins from plugin directory '%s'", dir->getPath().c_str());
}
for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
Common::String name(i->getName());
if (name.hasPrefix(getPrefix()) && name.hasSuffix(getSuffix())) {
if (isPluginFilename(i->getName())) {
pl.push_back(createPlugin(i->getPath()));
}
}
@ -191,25 +186,25 @@ PluginList FilePluginProvider::getPlugins() {
return pl;
}
const char* FilePluginProvider::getPrefix() const {
bool FilePluginProvider::isPluginFilename(const Common::String &filename) const {
#ifdef PLUGIN_PREFIX
return PLUGIN_PREFIX;
#else
return "";
// Check the plugin prefix
if (!filename.hasPrefix(PLUGIN_PREFIX))
return false;
#endif
}
const char* FilePluginProvider::getSuffix() const {
#ifdef PLUGIN_SUFFIX
return PLUGIN_SUFFIX;
#else
return "";
// Check the plugin suffix
if (!filename.hasSuffix(PLUGIN_SUFFIX))
return false;
#endif
return true;
}
void FilePluginProvider::addCustomDirectories(Common::StringList &dirs) const {
void FilePluginProvider::addCustomDirectories(FSList &dirs) const {
#ifdef PLUGIN_DIRECTORY
dirs.push_back(PLUGIN_DIRECTORY);
dirs.push_back(FilesystemNode(PLUGIN_DIRECTORY));
#endif
}

View file

@ -31,6 +31,9 @@
#include "common/singleton.h"
#include "base/game.h"
#ifdef DYNAMIC_MODULES
#include "common/fs.h"
#endif
/**
* @page pagePlugins An overview of the ScummVM plugin system
@ -212,6 +215,8 @@ public:
virtual PluginList getPlugins() = 0;
};
#ifdef DYNAMIC_MODULES
/**
* Abstract base class for Plugin factories which load binary code from files.
* Subclasses only have to implement the createPlugin() method, and optionally
@ -238,24 +243,30 @@ protected:
*
* @param filename the name of the loadable code module
* @return a pointer to a Plugin instance, or 0 if an error occurred.
*
* FIXME: Instead of using getPrefix & getSuffix, how about adding a
* isPluginFilename() class, so that more flexible checks can be performed?
*/
virtual Plugin* createPlugin(const Common::String &filename) const = 0;
virtual const char* getPrefix() const;
virtual const char* getSuffix() const;
/**
* Check if the supplied filename corresponds to a loadable plugin file in
* the current platform.
*
* @param filename the name of the file to check
* @return true if the filename corresponds to a plugin, false otherwise
*/
virtual bool isPluginFilename(const Common::String &filename) const;
/**
* Optionally add to the list of directories to be searched for
* plugins by getPlugins().
*
* FIXME: This should be using FSNodes, not strings!
* @param dirs the reference to the list of directories to be used when
* searching for plugins.
*/
virtual void addCustomDirectories(Common::StringList &dirs) const;
virtual void addCustomDirectories(FSList &dirs) const;
};
#endif // DYNAMIC_MODULES
/**
* Singleton class which manages all plugins, including loading them,
* managing all Plugin class instances, and unloading them.