added autoloading of extensions
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40403
This commit is contained in:
		
							parent
							
								
									b3b1978d10
								
							
						
					
					
						commit
						aea1073d13
					
				@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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))
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user