Makes loadPlugIns deterministic when using relative path

What it says on the tin: a place to discuss proposed new features.
Post Reply
tisba
Kobold
Posts: 37
Joined: Sun Jan 26, 2003 1:17 am
Location: France (Paris)

Makes loadPlugIns deterministic when using relative path

Post by tisba »

At the current time, when the 'PluginFolder' setting of the plugins configuration file is a relative path, Ogre assumes that the current directory is the same as the folder containing the configuration file.

If the plug-ins configuration file is not located in the current directory, Ogre will fail to load the plug-ins.

I believe the correct solution would be to construct the relative path of the plug-ins using the path specified for the plug-ins configuration file, though I'm not sure how this work on OS X.

This limitation prevents sharing the same plug-ins configuration file between multiple applications located in different folders. Concret example: applications written using PyOgre and sharing the 'standard' plug-ins installed in the PyOgre module.

--tisba.
tisba
Kobold
Posts: 37
Joined: Sun Jan 26, 2003 1:17 am
Location: France (Paris)

Post by tisba »

I've implemented that feature. Works great for me, though I'm not sure what should be done on OS X.

Just plug the following code in Root::loadPlugins(). I tested it with both absolute and relative path on Windows.

Code: Select all

      pluginDir = cfg.getSetting("PluginFolder"); // Ignored on Mac OS X, uses Resources/ directory
      pluginList = cfg.getMultiSetting("Plugin");

      bool pluginDirIsAbsolute = StringUtil::startsWith( pluginDir, "/" ) // Unix
         || StringUtil::startsWith( pluginDir, "\\\\" )                  // UNC
         || pluginDir.find( ":\\" ) != String::npos;                     // DOS
      // If the plug-in directory is not absolute, then make it relative to the config file directory
      if ( !pluginDirIsAbsolute )
      {
         String::size_type endPath = pluginDir.find_last_of( "\\/" );
         if ( endPath != String::npos )
         {
            String pluginsfileDir = pluginDir.substr(0, endPath+1);
            pluginDir = pluginsfileDir + pluginsfileDir;
         }
      }
Post Reply