From aea1073d1391b9d53ec66709cde990195941e07a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 27 Jan 2007 04:50:33 +0000 Subject: [PATCH] added autoloading of extensions --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40403 --- core/sourcemod.cpp | 3 +++ core/systems/ExtensionSys.cpp | 49 ++++++++++++++++++++++++++++++++++- core/systems/ExtensionSys.h | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index d482506b..76bbe06d 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -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); diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index 0b47740a..066f616b 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -11,6 +11,7 @@ * Version: $Id$ */ +#include #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 +#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)) diff --git a/core/systems/ExtensionSys.h b/core/systems/ExtensionSys.h index e4d32375..a0202c74 100644 --- a/core/systems/ExtensionSys.h +++ b/core/systems/ExtensionSys.h @@ -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: