Don't store the absolute pathname of plugins in the configuration file,

just the basename like libPlugin_foo.dylib. Dolphin then loads the
plugins relative to the compiled-in plugins directory.

This means that you won't have to reselect the plugins when running 
different builds (in different directories) and is most obviously
beneficial on OS X where application bundles are not (should not) be
expected to stay in the place where they are first installed.

This is tested on OS X and Linux with local/global build options, but
not Windows. I don't anticipate any problems on Windows, but that OS
does have slightly different semantics with regard to path component
separators and file suffixes, so it's something to watch out for.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5621 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Soren Jorvang 2010-06-05 18:52:56 +00:00
parent 53f9858b94
commit 7d0f03cb61
4 changed files with 25 additions and 34 deletions

View File

@ -59,6 +59,9 @@ const char *DllGetLastError()
*/ */
int DynamicLibrary::Load(const char* filename) int DynamicLibrary::Load(const char* filename)
{ {
std::string LibraryPath = File::GetPluginsDirectory() + filename;
filename = LibraryPath.c_str();
INFO_LOG(COMMON, "DL: Loading dynamic library %s", filename); INFO_LOG(COMMON, "DL: Loading dynamic library %s", filename);
if (!filename || strlen(filename) == 0) { if (!filename || strlen(filename) == 0) {

View File

@ -581,13 +581,9 @@ std::string GetPluginsDirectory()
pluginsDir = GetBundleDirectory(); pluginsDir = GetBundleDirectory();
pluginsDir += DIR_SEP; pluginsDir += DIR_SEP;
pluginsDir += PLUGINS_DIR; pluginsDir += PLUGINS_DIR;
#elif defined __linux__
pluginsDir = PLUGINS_DIR;
// FIXME global install
#else #else
pluginsDir = PLUGINS_DIR; pluginsDir = PLUGINS_DIR;
#endif #endif
pluginsDir += DIR_SEP; pluginsDir += DIR_SEP;
INFO_LOG(COMMON, "GetPluginsDirectory: Setting to %s:", pluginsDir.c_str()); INFO_LOG(COMMON, "GetPluginsDirectory: Setting to %s:", pluginsDir.c_str());
@ -602,14 +598,11 @@ std::string GetSysDirectory()
sysDir = GetBundleDirectory(); sysDir = GetBundleDirectory();
sysDir += DIR_SEP; sysDir += DIR_SEP;
sysDir += SYSDATA_DIR; sysDir += SYSDATA_DIR;
#elif defined __linux__
sysDir = SYSDATA_DIR;
// FIXME global install
#else #else
sysDir = SYSDATA_DIR; sysDir = SYSDATA_DIR;
#endif #endif
sysDir += DIR_SEP; sysDir += DIR_SEP;
INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str());
return sysDir; return sysDir;
} }

View File

@ -182,13 +182,11 @@ void SConfig::LoadSettings()
IniFile ini; IniFile ini;
ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
std::string PluginsDir = File::GetPluginsDirectory(); // Hard coded defaults
m_DefaultGFXPlugin = DEFAULT_GFX_PLUGIN;
// Hard coded default m_DefaultDSPPlugin = DEFAULT_DSP_PLUGIN;
m_DefaultGFXPlugin = PluginsDir + DEFAULT_GFX_PLUGIN; m_DefaultPADPlugin = DEFAULT_PAD_PLUGIN;
m_DefaultDSPPlugin = PluginsDir + DEFAULT_DSP_PLUGIN; m_DefaultWiiMotePlugin = DEFAULT_WIIMOTE_PLUGIN;
m_DefaultPADPlugin = PluginsDir + DEFAULT_PAD_PLUGIN;
m_DefaultWiiMotePlugin = PluginsDir + DEFAULT_WIIMOTE_PLUGIN;
// General // General
{ {

View File

@ -224,7 +224,7 @@ CPluginInfo::CPluginInfo(const char *_rFilename)
: m_Filename(_rFilename) : m_Filename(_rFilename)
, m_Valid(false) , m_Valid(false)
{ {
if (!File::Exists(_rFilename)) if (!File::Exists((File::GetPluginsDirectory() + _rFilename).c_str()))
{ {
PanicAlert("Can't find plugin %s", _rFilename); PanicAlert("Can't find plugin %s", _rFilename);
return; return;
@ -273,17 +273,14 @@ void CPluginManager::GetPluginInfo(CPluginInfo *&info, std::string Filename)
below. */ below. */
void *CPluginManager::LoadPlugin(const char *_rFilename) void *CPluginManager::LoadPlugin(const char *_rFilename)
{ {
// Create a string of the filename if (!File::Exists((File::GetPluginsDirectory() + _rFilename).c_str())) {
std::string Filename = _rFilename;
if (!File::Exists(_rFilename)) {
PanicAlert("Error loading %s: can't find file", _rFilename); PanicAlert("Error loading %s: can't find file", _rFilename);
return NULL; return NULL;
} }
/* Avoid calling LoadLibrary() again and instead point to the plugin info that we found when /* Avoid calling LoadLibrary() again and instead point to the plugin info that we found when
Dolphin was started */ Dolphin was started */
CPluginInfo *info = NULL; CPluginInfo *info = NULL;
GetPluginInfo(info, Filename); GetPluginInfo(info, _rFilename);
if (!info) { if (!info) {
PanicAlert("Error loading %s: can't read info", _rFilename); PanicAlert("Error loading %s: can't read info", _rFilename);
return NULL; return NULL;
@ -342,11 +339,7 @@ void CPluginManager::ScanForPlugins()
// Get plugins dir // Get plugins dir
CFileSearch::XStringVector Directories; CFileSearch::XStringVector Directories;
#if defined(__APPLE__)
Directories.push_back(File::GetPluginsDirectory()); Directories.push_back(File::GetPluginsDirectory());
#else
Directories.push_back(std::string(PLUGINS_DIR));
#endif
CFileSearch::XStringVector Extensions; CFileSearch::XStringVector Extensions;
Extensions.push_back("*" PLUGIN_SUFFIX); Extensions.push_back("*" PLUGIN_SUFFIX);
@ -359,17 +352,21 @@ void CPluginManager::ScanForPlugins()
for (size_t i = 0; i < rFilenames.size(); i++) for (size_t i = 0; i < rFilenames.size(); i++)
{ {
std::string orig_name = rFilenames[i]; std::string orig_name = rFilenames[i];
std::string Filename; std::string Filename, Extension;
if (!SplitPath(rFilenames[i], NULL, &Filename, NULL)) { if (!SplitPath(rFilenames[i], NULL, &Filename, &Extension)) {
printf("Bad Path %s\n", rFilenames[i].c_str()); printf("Bad Path %s\n", rFilenames[i].c_str());
return; return;
} }
CPluginInfo PluginInfo(orig_name.c_str()); // Leave off the directory component
std::string StoredName = Filename;
StoredName += Extension;
CPluginInfo PluginInfo(StoredName.c_str());
if (PluginInfo.IsValid()) if (PluginInfo.IsValid())
{ {
// Save the PluginInfo // Save the Plugin
m_PluginInfos.push_back(PluginInfo); m_PluginInfos.push_back(PluginInfo);
} }
} }
@ -504,7 +501,8 @@ void CPluginManager::EmuStateChange(PLUGIN_EMUSTATE newState)
// Open config window. Input: _rFilename = Plugin filename , Type = Plugin type // Open config window. Input: _rFilename = Plugin filename , Type = Plugin type
void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type) void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type)
{ {
if (! File::Exists(_rFilename)) { if (! File::Exists((File::GetPluginsDirectory() + _rFilename).c_str()))
{
PanicAlert("Can't find plugin %s", _rFilename); PanicAlert("Can't find plugin %s", _rFilename);
return; return;
} }
@ -531,7 +529,7 @@ void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TY
// Open debugging window. Type = Video or DSP. Show = Show or hide window. // Open debugging window. Type = Video or DSP. Show = Show or hide window.
void CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show) void CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show)
{ {
if (!File::Exists(_rFilename)) if (! File::Exists((File::GetPluginsDirectory() + _rFilename).c_str()))
{ {
PanicAlert("Can't find plugin %s", _rFilename); PanicAlert("Can't find plugin %s", _rFilename);
return; return;
@ -549,4 +547,3 @@ void CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYP
PanicAlert("Type %d debug not supported in plugin %s", Type, _rFilename); PanicAlert("Type %d debug not supported in plugin %s", Type, _rFilename);
} }
} }