2003-09-08 15:38:34 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
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
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-03-09 12:52:10 +00:00
|
|
|
|
|
|
|
void DetectedGame::updateDesc(const char *extra) {
|
|
|
|
// TODO: The format used here (LANG/PLATFORM/EXTRA) is not set in stone.
|
|
|
|
// We may want to change the order (PLATFORM/EXTRA/LANG, anybody?), or
|
|
|
|
// the seperator (instead of '/' use ', ' or ' ').
|
|
|
|
const bool hasCustomLanguage = (language != Common::UNK_LANG);
|
|
|
|
const bool hasCustomPlatform = (platform != Common::kPlatformUnknown);
|
|
|
|
const bool hasExtraDesc = (extra && extra[0]);
|
|
|
|
|
|
|
|
// Adapt the description string if custom platform/language is set.
|
|
|
|
if (hasCustomLanguage || hasCustomPlatform || hasExtraDesc) {
|
|
|
|
description += " (";
|
|
|
|
if (hasCustomLanguage)
|
|
|
|
description += Common::getLanguageDescription(language);
|
|
|
|
if (hasCustomPlatform) {
|
|
|
|
if (hasCustomLanguage)
|
|
|
|
description += "/";
|
|
|
|
description += Common::getPlatformDescription(platform);
|
|
|
|
}
|
|
|
|
if (hasExtraDesc) {
|
|
|
|
if (hasCustomPlatform || hasCustomLanguage)
|
|
|
|
description += "/";
|
|
|
|
description += extra;
|
|
|
|
}
|
|
|
|
description += ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2005-11-21 09:52:22 +00:00
|
|
|
#ifndef DYNAMIC_MODULES
|
2003-10-26 12:44:20 +00:00
|
|
|
class StaticPlugin : public Plugin {
|
2005-11-19 17:57:24 +00:00
|
|
|
PluginRegistrator *_plugin;
|
2003-09-08 17:13:40 +00:00
|
|
|
public:
|
2005-11-19 17:57:24 +00:00
|
|
|
StaticPlugin(PluginRegistrator *plugin)
|
|
|
|
: _plugin(plugin) {
|
2006-02-18 11:15:37 +00:00
|
|
|
assert(_plugin);
|
2005-11-19 17:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~StaticPlugin() {
|
|
|
|
delete _plugin;
|
2003-09-08 17:13:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
virtual bool loadPlugin() { return true; }
|
|
|
|
virtual void unloadPlugin() {}
|
|
|
|
|
2005-11-19 17:57:24 +00:00
|
|
|
const char *getName() const { return _plugin->_name; }
|
2006-07-31 13:41:21 +00:00
|
|
|
const char *getCopyright() const { return _plugin->_copyright; }
|
2003-09-08 17:13:40 +00:00
|
|
|
|
2006-04-29 00:27:20 +00:00
|
|
|
PluginError createInstance(OSystem *syst, Engine **engine) const {
|
2006-02-18 11:15:37 +00:00
|
|
|
assert(_plugin->_ef);
|
2006-04-29 00:27:20 +00:00
|
|
|
return (*_plugin->_ef)(syst, engine);
|
2003-09-08 17:13:40 +00:00
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2005-11-19 17:57:24 +00:00
|
|
|
GameList getSupportedGames() const { return _plugin->_games; }
|
2006-02-18 11:15:37 +00:00
|
|
|
|
2006-03-09 02:52:51 +00:00
|
|
|
GameDescriptor findGame(const char *gameid) const {
|
2006-02-18 11:15:37 +00:00
|
|
|
assert(_plugin->_qf);
|
|
|
|
return (*_plugin->_qf)(gameid);
|
|
|
|
}
|
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
DetectedGameList detectGames(const FSList &fslist) const {
|
2006-02-18 11:15:37 +00:00
|
|
|
assert(_plugin->_df);
|
2005-11-19 17:57:24 +00:00
|
|
|
return (*_plugin->_df)(fslist);
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
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
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
#define LINK_PLUGIN(ID) \
|
|
|
|
extern PluginRegistrator *g_##ID##_PluginReg; \
|
|
|
|
extern void g_##ID##_PluginReg_alloc(); \
|
|
|
|
g_##ID##_PluginReg_alloc(); \
|
|
|
|
plugin = g_##ID##_PluginReg; \
|
|
|
|
pl.push_back(new StaticPlugin(plugin));
|
|
|
|
|
|
|
|
// "Loader" for the static plugins.
|
|
|
|
// Iterate over all registered (static) plugins and load them.
|
|
|
|
PluginRegistrator *plugin;
|
|
|
|
|
|
|
|
#ifndef DISABLE_SCUMM
|
|
|
|
LINK_PLUGIN(SCUMM)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SKY
|
|
|
|
LINK_PLUGIN(SKY)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SWORD1
|
|
|
|
LINK_PLUGIN(SWORD1)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SWORD2
|
|
|
|
LINK_PLUGIN(SWORD2)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_AGOS
|
|
|
|
LINK_PLUGIN(AGOS)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_QUEEN
|
|
|
|
LINK_PLUGIN(QUEEN)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SAGA
|
|
|
|
LINK_PLUGIN(SAGA)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_KYRA
|
|
|
|
LINK_PLUGIN(KYRA)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_GOB
|
|
|
|
LINK_PLUGIN(GOB)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_LURE
|
|
|
|
LINK_PLUGIN(LURE)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_CINE
|
|
|
|
LINK_PLUGIN(CINE)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_AGI
|
|
|
|
LINK_PLUGIN(AGI)
|
|
|
|
#endif
|
2006-10-07 01:05:12 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2005-06-05 12:55:33 +00:00
|
|
|
#endif
|
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
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
DECLARE_SINGLETON(PluginManager);
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
PluginManager::PluginManager() {
|
2006-10-07 01:05:12 +00:00
|
|
|
#ifndef DYNAMIC_MODULES
|
|
|
|
// Add the static plugin provider if we do not build with dynamic
|
|
|
|
// plugins.
|
2006-10-07 00:22:48 +00:00
|
|
|
addPluginProvider(new StaticPluginProvider());
|
|
|
|
#endif
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager::~PluginManager() {
|
|
|
|
// Explicitly unload all loaded plugins
|
|
|
|
unloadPlugins();
|
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-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) {
|
|
|
|
PluginList pl((**pp).getPlugins());
|
|
|
|
for (PluginList::iterator plugin = pl.begin(); plugin != pl.end(); ++plugin) {
|
|
|
|
tryLoadPlugin(*plugin);
|
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() {
|
2004-08-29 19:08:08 +00:00
|
|
|
unloadPluginsExcept(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
|
|
|
|
Plugin *found = NULL;
|
2004-02-05 00:19:57 +00:00
|
|
|
uint i;
|
2006-10-07 01:05:12 +00:00
|
|
|
for (PluginList::iterator p = _plugins.begin(); p != _plugins.end(); ++p)
|
2003-09-08 15:38:34 +00:00
|
|
|
for (i = 0; i < _plugins.size(); i++) {
|
2006-10-07 01:05:12 +00:00
|
|
|
if (*p == plugin) {
|
|
|
|
found = *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
} else {
|
2006-10-07 01:05:12 +00:00
|
|
|
(**p).unloadPlugin();
|
|
|
|
delete *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
_plugins.clear();
|
2004-08-29 19:08:08 +00:00
|
|
|
if (found != NULL) {
|
|
|
|
_plugins.push_back(found);
|
|
|
|
}
|
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()) {
|
2003-11-07 02:31:44 +00:00
|
|
|
// If successful, add it to the list of known plugins and return.
|
2003-09-18 18:23:53 +00:00
|
|
|
_plugins.push_back(plugin);
|
2006-10-07 00:22:48 +00:00
|
|
|
|
|
|
|
// TODO/FIXME: We should perform some additional checks here:
|
|
|
|
// * Check for some kind of "API version" (possibly derived from the
|
|
|
|
// SVN tree revision?)
|
|
|
|
// * If two plugins provide the same engine, we should only load one.
|
|
|
|
// To detect this situation, we could just compare the plugin name.
|
|
|
|
// To handle it, simply prefer modules loaded earlier to those coming.
|
|
|
|
// Or vice versa... to be determined... :-)
|
|
|
|
|
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
|
|
|
|
|
|
|
DetectedGameList PluginManager::detectGames(const FSList &fslist) const {
|
|
|
|
DetectedGameList candidates;
|
|
|
|
|
|
|
|
// Iterate over all known games and for each check if it might be
|
|
|
|
// the game in the presented directory.
|
2004-02-05 00:19:57 +00:00
|
|
|
PluginList::const_iterator iter;
|
2003-12-21 15:29:52 +00:00
|
|
|
for (iter = _plugins.begin(); iter != _plugins.end(); ++iter) {
|
|
|
|
candidates.push_back((*iter)->detectGames(fslist));
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
return candidates;
|
|
|
|
}
|