2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
2006-02-11 09:53:21 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-17 22:41:01 +00:00
|
|
|
#include "base/plugins.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2008-05-26 12:43:01 +00:00
|
|
|
#include "common/func.h"
|
|
|
|
|
2008-05-09 01:58:12 +00:00
|
|
|
#ifdef DYNAMIC_MODULES
|
|
|
|
#include "common/config-manager.h"
|
2008-09-03 11:22:51 +00:00
|
|
|
#include "common/fs.h"
|
2008-05-09 01:58:12 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
// Plugin versioning
|
|
|
|
|
2008-02-08 01:02:25 +00:00
|
|
|
int pluginTypeVersions[PLUGIN_TYPE_MAX] = {
|
|
|
|
PLUGIN_TYPE_ENGINE_VERSION,
|
2008-06-13 14:30:47 +00:00
|
|
|
PLUGIN_TYPE_MUSIC_VERSION,
|
2008-02-08 01:02:25 +00:00
|
|
|
};
|
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
|
|
|
|
// Abstract plugins
|
|
|
|
|
2008-02-08 00:02:23 +00:00
|
|
|
PluginType Plugin::getType() const {
|
|
|
|
return _type;
|
|
|
|
}
|
2006-03-09 12:52:10 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
const char *Plugin::getName() const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return _pluginObject->getName();
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
class StaticPlugin : public Plugin {
|
|
|
|
public:
|
2008-02-08 00:02:23 +00:00
|
|
|
StaticPlugin(PluginObject *pluginobject, PluginType type) {
|
2008-02-04 18:38:22 +00:00
|
|
|
assert(pluginobject);
|
2008-02-08 00:02:23 +00:00
|
|
|
assert(type < PLUGIN_TYPE_MAX);
|
2008-02-04 18:38:22 +00:00
|
|
|
_pluginObject = pluginobject;
|
2008-02-08 00:02:23 +00:00
|
|
|
_type = type;
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
2008-02-04 10:15:21 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
~StaticPlugin() {
|
2008-02-04 18:38:22 +00:00
|
|
|
delete _pluginObject;
|
2008-02-04 10:15:21 +00:00
|
|
|
}
|
2008-02-04 13:14:52 +00:00
|
|
|
|
|
|
|
virtual bool loadPlugin() { return true; }
|
|
|
|
virtual void unloadPlugin() {}
|
2003-09-08 17:13:40 +00:00
|
|
|
};
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
class StaticPluginProvider : public PluginProvider {
|
2003-09-18 18:23:53 +00:00
|
|
|
public:
|
2006-10-07 00:22:48 +00:00
|
|
|
StaticPluginProvider() {
|
2003-09-18 18:23:53 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
~StaticPluginProvider() {
|
2006-02-18 11:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
virtual PluginList getPlugins() {
|
|
|
|
PluginList pl;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
#define LINK_PLUGIN(ID) \
|
2008-02-08 01:45:46 +00:00
|
|
|
extern PluginType g_##ID##_type; \
|
2008-02-04 18:38:22 +00:00
|
|
|
extern PluginObject *g_##ID##_getObject(); \
|
2008-02-08 00:02:23 +00:00
|
|
|
pl.push_back(new StaticPlugin(g_##ID##_getObject(), g_##ID##_type));
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
// "Loader" for the static plugins.
|
|
|
|
// Iterate over all registered (static) plugins and load them.
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-05-14 14:56:29 +00:00
|
|
|
// Engine plugins
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SCUMM)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(SCUMM)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(AGI)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(AGI)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(AGOS)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(AGOS)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(CINE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(CINE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(CRUISE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(CRUISE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(DRASCULA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(DRASCULA)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(GOB)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(GOB)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(IGOR)
|
2007-10-29 23:35:50 +00:00
|
|
|
LINK_PLUGIN(IGOR)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(KYRA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(KYRA)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(LURE)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(LURE)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(M4)
|
2008-04-20 14:55:41 +00:00
|
|
|
LINK_PLUGIN(M4)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(MADE)
|
2008-04-20 14:55:41 +00:00
|
|
|
LINK_PLUGIN(MADE)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(PARALLACTION)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(PARALLACTION)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(QUEEN)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(QUEEN)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SAGA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SAGA)
|
2006-11-03 21:23:07 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SKY)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SKY)
|
2007-01-14 21:29:12 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SWORD1)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SWORD1)
|
2007-04-27 14:50:27 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SWORD2)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SWORD2)
|
|
|
|
#endif
|
2008-07-23 09:02:47 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TINSEL)
|
|
|
|
LINK_PLUGIN(TINSEL)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TOUCHE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(TOUCHE)
|
2007-07-17 21:35:01 +00:00
|
|
|
#endif
|
2006-10-07 01:05:12 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
// Music plugins
|
2008-05-14 14:56:29 +00:00
|
|
|
// TODO: Use defines to disable or enable each MIDI driver as a
|
|
|
|
// static/dynamic plugin, like it's done for the engines
|
|
|
|
LINK_PLUGIN(NULL)
|
|
|
|
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
|
|
|
LINK_PLUGIN(WINDOWS)
|
|
|
|
#endif
|
|
|
|
#if defined(UNIX) && defined(USE_ALSA)
|
|
|
|
LINK_PLUGIN(ALSA)
|
|
|
|
#endif
|
2008-08-27 18:52:21 +00:00
|
|
|
#if defined(UNIX) && !defined(__BEOS__) && !defined(__MAEMO__) && !defined(__MINT__)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(SEQ)
|
|
|
|
#endif
|
2008-08-27 18:52:21 +00:00
|
|
|
#if defined(__MINT__)
|
|
|
|
LINK_PLUGIN(STMIDI)
|
|
|
|
#endif
|
2008-05-14 14:56:29 +00:00
|
|
|
#if defined(IRIX)
|
|
|
|
LINK_PLUGIN(DMEDIA)
|
|
|
|
#endif
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
LINK_PLUGIN(CAMD)
|
|
|
|
#endif
|
|
|
|
#if defined(MACOSX)
|
|
|
|
LINK_PLUGIN(COREAUDIO)
|
|
|
|
LINK_PLUGIN(COREMIDI)
|
|
|
|
LINK_PLUGIN(QUICKTIME)
|
|
|
|
#endif
|
|
|
|
#if defined(PALMOS_MODE)
|
|
|
|
# if defined(COMPILE_CLIE)
|
|
|
|
LINK_PLUGIN(YPA1)
|
|
|
|
# elif defined(COMPILE_ZODIAC) && (!defined(ENABLE_SCUMM) || !defined(PALMOS_ARM))
|
|
|
|
LINK_PLUGIN(ZODIAC)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FLUIDSYNTH
|
|
|
|
LINK_PLUGIN(FLUIDSYNTH)
|
|
|
|
#endif
|
|
|
|
#ifdef USE_MT32EMU
|
|
|
|
LINK_PLUGIN(MT32)
|
|
|
|
#endif
|
|
|
|
LINK_PLUGIN(ADLIB)
|
|
|
|
LINK_PLUGIN(TOWNS)
|
|
|
|
#if defined (UNIX)
|
|
|
|
LINK_PLUGIN(TIMIDITY)
|
|
|
|
#endif
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
return pl;
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
2003-09-18 18:23:53 +00:00
|
|
|
};
|
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef DYNAMIC_MODULES
|
2008-05-02 14:30:06 +00:00
|
|
|
|
|
|
|
PluginList FilePluginProvider::getPlugins() {
|
|
|
|
PluginList pl;
|
|
|
|
|
|
|
|
// Prepare the list of directories to search
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList pluginDirs;
|
2008-05-09 01:58:12 +00:00
|
|
|
|
|
|
|
// Add the default directories
|
2008-09-03 11:22:51 +00:00
|
|
|
pluginDirs.push_back(Common::FilesystemNode("."));
|
|
|
|
pluginDirs.push_back(Common::FilesystemNode("plugins"));
|
2008-05-02 14:30:06 +00:00
|
|
|
|
|
|
|
// Add the provider's custom directories
|
|
|
|
addCustomDirectories(pluginDirs);
|
|
|
|
|
2008-05-09 01:58:12 +00:00
|
|
|
// Add the user specified directory
|
|
|
|
Common::String pluginsPath(ConfMan.get("pluginspath"));
|
2008-05-13 13:24:49 +00:00
|
|
|
if (!pluginsPath.empty())
|
2008-09-03 11:22:51 +00:00
|
|
|
pluginDirs.push_back(Common::FilesystemNode(pluginsPath));
|
2008-05-09 01:58:12 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList::const_iterator dir;
|
2008-05-13 13:24:49 +00:00
|
|
|
for (dir = pluginDirs.begin(); dir != pluginDirs.end(); dir++) {
|
2008-05-02 14:30:06 +00:00
|
|
|
// Load all plugins.
|
|
|
|
// Scan for all plugins in this directory
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList files;
|
|
|
|
if (!dir->getChildren(files, Common::FilesystemNode::kListFilesOnly)) {
|
2008-05-13 13:24:49 +00:00
|
|
|
debug(1, "Couldn't open plugin directory '%s'", dir->getPath().c_str());
|
2008-05-02 14:30:06 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2008-05-13 13:24:49 +00:00
|
|
|
debug(1, "Reading plugins from plugin directory '%s'", dir->getPath().c_str());
|
2008-05-02 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
for (Common::FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
|
2008-05-13 13:24:49 +00:00
|
|
|
if (isPluginFilename(i->getName())) {
|
2008-05-02 14:30:06 +00:00
|
|
|
pl.push_back(createPlugin(i->getPath()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pl;
|
|
|
|
}
|
|
|
|
|
2008-05-13 13:24:49 +00:00
|
|
|
bool FilePluginProvider::isPluginFilename(const Common::String &filename) const {
|
2008-05-02 14:30:06 +00:00
|
|
|
#ifdef PLUGIN_PREFIX
|
2008-05-13 13:24:49 +00:00
|
|
|
// Check the plugin prefix
|
|
|
|
if (!filename.hasPrefix(PLUGIN_PREFIX))
|
|
|
|
return false;
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PLUGIN_SUFFIX
|
2008-05-13 13:24:49 +00:00
|
|
|
// Check the plugin suffix
|
|
|
|
if (!filename.hasSuffix(PLUGIN_SUFFIX))
|
|
|
|
return false;
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
2008-05-13 13:24:49 +00:00
|
|
|
|
|
|
|
return true;
|
2008-05-02 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
void FilePluginProvider::addCustomDirectories(Common::FSList &dirs) const {
|
2008-05-02 14:30:06 +00:00
|
|
|
#ifdef PLUGIN_DIRECTORY
|
2008-09-03 11:22:51 +00:00
|
|
|
dirs.push_back(Common::FilesystemNode(PLUGIN_DIRECTORY));
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#endif // DYNAMIC_MODULES
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
#pragma mark -
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2007-05-27 11:40:03 +00:00
|
|
|
DECLARE_SINGLETON(PluginManager);
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
PluginManager::PluginManager() {
|
2008-05-06 03:00:26 +00:00
|
|
|
// Always add the static plugin provider.
|
2006-10-07 00:22:48 +00:00
|
|
|
addPluginProvider(new StaticPluginProvider());
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager::~PluginManager() {
|
|
|
|
// Explicitly unload all loaded plugins
|
|
|
|
unloadPlugins();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 01:05:12 +00:00
|
|
|
// Delete the plugin providers
|
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
|
|
|
delete *pp;
|
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2006-11-03 21:23:07 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
void PluginManager::addPluginProvider(PluginProvider *pp) {
|
|
|
|
_providers.push_back(pp);
|
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
|
|
|
|
void PluginManager::loadPlugins() {
|
2006-10-07 00:22:48 +00:00
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
2008-05-26 00:28:48 +00:00
|
|
|
PluginList pl((*pp)->getPlugins());
|
2008-05-26 12:12:51 +00:00
|
|
|
Common::for_each(pl.begin(), pl.end(), Common::bind1st(Common::mem_fun(&PluginManager::tryLoadPlugin), this));
|
2005-03-25 17:55:57 +00:00
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::unloadPlugins() {
|
2008-05-12 01:26:43 +00:00
|
|
|
for (int i = 0; i < PLUGIN_TYPE_MAX; i++)
|
|
|
|
unloadPluginsExcept((PluginType)i, NULL);
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-12 01:26:43 +00:00
|
|
|
void PluginManager::unloadPluginsExcept(PluginType type, const Plugin *plugin) {
|
2004-08-29 19:08:08 +00:00
|
|
|
Plugin *found = NULL;
|
2008-05-12 01:26:43 +00:00
|
|
|
for (PluginList::iterator p = _plugins[type].begin(); p != _plugins[type].end(); ++p) {
|
2006-10-07 01:05:12 +00:00
|
|
|
if (*p == plugin) {
|
|
|
|
found = *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
} else {
|
2008-05-26 00:28:48 +00:00
|
|
|
(*p)->unloadPlugin();
|
2006-10-07 01:05:12 +00:00
|
|
|
delete *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2008-05-12 01:26:43 +00:00
|
|
|
_plugins[type].clear();
|
2004-08-29 19:08:08 +00:00
|
|
|
if (found != NULL) {
|
2008-05-12 01:26:43 +00:00
|
|
|
_plugins[type].push_back(found);
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2003-09-18 18:23:53 +00:00
|
|
|
|
|
|
|
bool PluginManager::tryLoadPlugin(Plugin *plugin) {
|
|
|
|
assert(plugin);
|
|
|
|
// Try to load the plugin
|
|
|
|
if (plugin->loadPlugin()) {
|
2008-05-14 17:26:05 +00:00
|
|
|
// The plugin is valid, see if it provides the same module as an
|
|
|
|
// already loaded one and should replace it.
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
PluginList::iterator pl = _plugins[plugin->getType()].begin();
|
|
|
|
while (!found && pl != _plugins[plugin->getType()].end()) {
|
|
|
|
if (!strcmp(plugin->getName(), (*pl)->getName())) {
|
|
|
|
// Found a duplicated module. Replace the old one.
|
|
|
|
found = true;
|
|
|
|
delete *pl;
|
|
|
|
*pl = plugin;
|
|
|
|
debug(1, "Replaced the duplicated plugin: '%s'", plugin->getName());
|
|
|
|
}
|
|
|
|
pl++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
// If it provides a new module, just add it to the list of known plugins.
|
|
|
|
_plugins[plugin->getType()].push_back(plugin);
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-09-18 18:23:53 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// Failed to load the plugin
|
|
|
|
delete plugin;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-12-21 15:29:52 +00:00
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
|
|
|
|
// Engine plugins
|
|
|
|
|
|
|
|
#include "engines/metaengine.h"
|
|
|
|
|
|
|
|
DECLARE_SINGLETON(EngineManager);
|
|
|
|
|
|
|
|
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
|
|
|
// Find the GameDescriptor for this target
|
2008-05-26 00:28:48 +00:00
|
|
|
const EnginePlugin::List &plugins = getPlugins();
|
2008-05-12 00:26:29 +00:00
|
|
|
GameDescriptor result;
|
|
|
|
|
|
|
|
if (plugin)
|
|
|
|
*plugin = 0;
|
|
|
|
|
2008-05-26 00:28:48 +00:00
|
|
|
EnginePlugin::List::const_iterator iter = plugins.begin();
|
2008-05-12 00:26:29 +00:00
|
|
|
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
2008-05-13 09:30:23 +00:00
|
|
|
result = (**iter)->findGame(gameName.c_str());
|
2008-05-12 00:26:29 +00:00
|
|
|
if (!result.gameid().empty()) {
|
|
|
|
if (plugin)
|
|
|
|
*plugin = *iter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
GameList EngineManager::detectGames(const Common::FSList &fslist) const {
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList candidates;
|
2003-12-21 15:29:52 +00:00
|
|
|
|
2008-05-26 00:28:48 +00:00
|
|
|
const EnginePlugin::List &plugins = getPlugins();
|
2008-05-12 00:26:29 +00:00
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
// Iterate over all known games and for each check if it might be
|
|
|
|
// the game in the presented directory.
|
2008-05-26 00:28:48 +00:00
|
|
|
EnginePlugin::List::const_iterator iter;
|
2008-05-12 00:26:29 +00:00
|
|
|
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
2008-05-13 09:30:23 +00:00
|
|
|
candidates.push_back((**iter)->detectGames(fslist));
|
2003-12-21 15:29:52 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
return candidates;
|
|
|
|
}
|
2008-05-12 00:26:29 +00:00
|
|
|
|
2008-05-26 00:28:48 +00:00
|
|
|
const EnginePlugin::List &EngineManager::getPlugins() const {
|
|
|
|
return (const EnginePlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
2008-05-12 00:26:29 +00:00
|
|
|
}
|
2008-05-14 14:56:29 +00:00
|
|
|
|
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
// Music plugins
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
#include "sound/musicplugin.h"
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
DECLARE_SINGLETON(MusicManager);
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
const MusicPlugin::List &MusicManager::getPlugins() const {
|
|
|
|
return (const MusicPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
|
2008-05-14 14:56:29 +00:00
|
|
|
}
|