added autoloading of extensions

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40403
This commit is contained in:
David Anderson 2007-01-27 04:50:33 +00:00
parent b3b1978d10
commit aea1073d13
3 changed files with 52 additions and 1 deletions

View File

@ -216,6 +216,9 @@ void SourceModBase::DoGlobalPluginLoads()
sizeof(plugins_path),
"plugins");
/* Load any auto extensions */
g_Extensions.TryAutoload();
/* Run the first pass */
g_PluginSys.LoadAll_FirstPass(config_path, plugins_path);

View File

@ -11,6 +11,7 @@
* Version: $Id$
*/
#include <stdlib.h>
#include "ExtensionSys.h"
#include "LibrarySys.h"
#include "ShareSys.h"
@ -18,7 +19,7 @@
#include "sourcemm_api.h"
#include "PluginSys.h"
#include "sm_srvcmds.h"
#include <stdlib.h>
#include "sm_stringutil.h"
CExtensionManager g_Extensions;
IdentityType_t g_ExtType;
@ -267,6 +268,52 @@ void CExtensionManager::OnSourceModShutdown()
g_ShareSys.DestroyIdentType(g_ExtType);
}
void CExtensionManager::TryAutoload()
{
char path[PLATFORM_MAX_PATH];
g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
IDirectory *pDir = g_LibSys.OpenDirectory(path);
if (!pDir)
{
return;
}
const char *lfile;
size_t len;
while (pDir->MoreFiles())
{
if (pDir->IsEntryDirectory())
{
pDir->NextEntry();
continue;
}
lfile = pDir->GetEntryName();
len = strlen(lfile);
if (len <= 9) /* size of ".autoload" */
{
pDir->NextEntry();
continue;
}
if (strcmp(&lfile[len - 9], ".autoload") != 0)
{
pDir->NextEntry();
continue;
}
char file[PLATFORM_MAX_PATH];
len = UTIL_Format(file, sizeof(file), "%s", lfile);
strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
LoadAutoExtension(file);
pDir->NextEntry();
}
}
IExtension *CExtensionManager::LoadAutoExtension(const char *path)
{
if (!strstr(path, "." PLATFORM_LIB_EXT))

View File

@ -94,6 +94,7 @@ public:
void BindAllNativesToPlugin(IPlugin *pPlugin);
void MarkAllLoaded();
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
void TryAutoload();
private:
CExtension *FindByOrder(unsigned int num);
private: