aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorJordi Vilalta Prat2008-05-13 13:24:49 +0000
committerJordi Vilalta Prat2008-05-13 13:24:49 +0000
commita392bc4b0e860429ec8ba7a79bc6ed4eab8f0335 (patch)
tree7f44a8a4491bce8929015d5c070c971ac8bf8502 /base
parentf7a682edf9c2c9a50cba9b869f447a9781def64b (diff)
downloadscummvm-rg350-a392bc4b0e860429ec8ba7a79bc6ed4eab8f0335.tar.gz
scummvm-rg350-a392bc4b0e860429ec8ba7a79bc6ed4eab8f0335.tar.bz2
scummvm-rg350-a392bc4b0e860429ec8ba7a79bc6ed4eab8f0335.zip
Taken care of FilePluginProvider's FIXMEs
svn-id: r32085
Diffstat (limited to 'base')
-rw-r--r--base/plugins.cpp49
-rw-r--r--base/plugins.h25
2 files changed, 40 insertions, 34 deletions
diff --git a/base/plugins.cpp b/base/plugins.cpp
index d4153f17d3..c39b877eb8 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -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
}
diff --git a/base/plugins.h b/base/plugins.h
index 8c0158a912..92b317498f 100644
--- a/base/plugins.h
+++ b/base/plugins.h
@@ -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.