core/systems/ExtensionSys.cpp
changeset 397 d78fcaa24fbb
parent 370 d3a484f98f6d
child 592 c2a2c38f1331
     1.1 --- a/core/systems/ExtensionSys.cpp	Sat Jan 27 04:21:11 2007 +0000
     1.2 +++ b/core/systems/ExtensionSys.cpp	Sat Jan 27 04:50:33 2007 +0000
     1.3 @@ -11,6 +11,7 @@
     1.4   * Version: $Id$
     1.5   */
     1.6  
     1.7 +#include <stdlib.h>
     1.8  #include "ExtensionSys.h"
     1.9  #include "LibrarySys.h"
    1.10  #include "ShareSys.h"
    1.11 @@ -18,7 +19,7 @@
    1.12  #include "sourcemm_api.h"
    1.13  #include "PluginSys.h"
    1.14  #include "sm_srvcmds.h"
    1.15 -#include <stdlib.h>
    1.16 +#include "sm_stringutil.h"
    1.17  
    1.18  CExtensionManager g_Extensions;
    1.19  IdentityType_t g_ExtType;
    1.20 @@ -267,6 +268,52 @@
    1.21  	g_ShareSys.DestroyIdentType(g_ExtType);
    1.22  }
    1.23  
    1.24 +void CExtensionManager::TryAutoload()
    1.25 +{
    1.26 +	char path[PLATFORM_MAX_PATH];
    1.27 +
    1.28 +	g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "extensions");
    1.29 +
    1.30 +	IDirectory *pDir = g_LibSys.OpenDirectory(path);
    1.31 +	if (!pDir)
    1.32 +	{
    1.33 +		return;
    1.34 +	}
    1.35 +
    1.36 +	const char *lfile;
    1.37 +	size_t len;
    1.38 +	while (pDir->MoreFiles())
    1.39 +	{
    1.40 +		if (pDir->IsEntryDirectory())
    1.41 +		{
    1.42 +			pDir->NextEntry();
    1.43 +			continue;
    1.44 +		}
    1.45 +
    1.46 +		lfile = pDir->GetEntryName();
    1.47 +		len = strlen(lfile);
    1.48 +		if (len <= 9) /* size of ".autoload" */
    1.49 +		{
    1.50 +			pDir->NextEntry();
    1.51 +			continue;
    1.52 +		}
    1.53 +
    1.54 +		if (strcmp(&lfile[len - 9], ".autoload") != 0)
    1.55 +		{
    1.56 +			pDir->NextEntry();
    1.57 +			continue;
    1.58 +		}
    1.59 +
    1.60 +		char file[PLATFORM_MAX_PATH];
    1.61 +		len = UTIL_Format(file, sizeof(file), "%s", lfile);
    1.62 +		strcpy(&file[len - 9], ".ext." PLATFORM_LIB_EXT);
    1.63 +
    1.64 +		LoadAutoExtension(file);
    1.65 +		
    1.66 +		pDir->NextEntry();
    1.67 +	}
    1.68 +}
    1.69 +
    1.70  IExtension *CExtensionManager::LoadAutoExtension(const char *path)
    1.71  {
    1.72  	if (!strstr(path, "." PLATFORM_LIB_EXT))