core/systems/ExtensionSys.cpp
changeset 941 c66657809b44
parent 868 bdbf922e246f
child 1018 e466e7319a68
     1.1 --- a/core/systems/ExtensionSys.cpp	Fri Jun 15 21:40:09 2007 +0000
     1.2 +++ b/core/systems/ExtensionSys.cpp	Sat Jun 16 01:34:05 2007 +0000
     1.3 @@ -36,12 +36,18 @@
     1.4  
     1.5  	char path[PLATFORM_MAX_PATH];
     1.6  	g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "extensions/%s", filename);
     1.7 +	m_Path.assign(path);
     1.8  
     1.9 -	m_pLib = g_LibSys.OpenLibrary(path, error, maxlength);
    1.10 +	m_pLib = NULL;
    1.11 +}
    1.12 +
    1.13 +bool CExtension::Load(char *error, size_t maxlength)
    1.14 +{
    1.15 +	m_pLib = g_LibSys.OpenLibrary(m_Path.c_str(), error, maxlength);
    1.16  
    1.17  	if (m_pLib == NULL)
    1.18  	{
    1.19 -		return;
    1.20 +		return false;
    1.21  	}
    1.22  
    1.23  	typedef IExtensionInterface *(*GETAPI)();
    1.24 @@ -52,7 +58,7 @@
    1.25  		m_pLib->CloseLibrary();
    1.26  		m_pLib = NULL;
    1.27  		snprintf(error, maxlength, "Unable to find extension entry point");
    1.28 -		return;
    1.29 +		return false;
    1.30  	}
    1.31  
    1.32  	m_pAPI = pfnGetAPI();
    1.33 @@ -61,13 +67,13 @@
    1.34  		m_pLib->CloseLibrary();
    1.35  		m_pLib = NULL;
    1.36  		snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
    1.37 -		return;
    1.38 +		return false;
    1.39  	}
    1.40  
    1.41  	if (m_pAPI->IsMetamodExtension())
    1.42  	{
    1.43  		bool already;
    1.44 -		m_PlId = g_pMMPlugins->Load(path, g_PLID, already, error, maxlength);
    1.45 +		m_PlId = g_pMMPlugins->Load(m_Path.c_str(), g_PLID, already, error, maxlength);
    1.46  	}
    1.47  
    1.48  	m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
    1.49 @@ -88,7 +94,7 @@
    1.50  		m_pLib = NULL;
    1.51  		g_ShareSys.DestroyIdentity(m_pIdentToken);
    1.52  		m_pIdentToken = NULL;
    1.53 -		return;
    1.54 +		return false;
    1.55  	} else {
    1.56  		/* Check if we're past load time */
    1.57  		if (!g_SourceMod.IsMapLoading())
    1.58 @@ -96,6 +102,8 @@
    1.59  			m_pAPI->OnExtensionsAllLoaded();
    1.60  		}
    1.61  	}
    1.62 +
    1.63 +	return true;
    1.64  }
    1.65  
    1.66  CExtension::~CExtension()
    1.67 @@ -336,14 +344,17 @@
    1.68  	char error[256];
    1.69  	CExtension *p = new CExtension(path, error, sizeof(error));
    1.70  
    1.71 -	if (!p->IsLoaded())
    1.72 +	/* We put us in the list beforehand so extensions that check for each other
    1.73 +	 * won't recursively load each other.
    1.74 +	 */
    1.75 +	m_Libs.push_back(p);
    1.76 +
    1.77 +	if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
    1.78  	{
    1.79  		g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
    1.80  		p->SetError(error);
    1.81  	}
    1.82  
    1.83 -	m_Libs.push_back(p);
    1.84 -
    1.85  	return p;
    1.86  }
    1.87  
    1.88 @@ -419,7 +430,7 @@
    1.89  
    1.90  	/* :NOTE: lifetime is currently ignored */
    1.91  
    1.92 -	if (!pExt->IsLoaded())
    1.93 +	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
    1.94  	{
    1.95  		delete pExt;
    1.96  		return NULL;
    1.97 @@ -631,8 +642,14 @@
    1.98  
    1.99  void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
   1.100  {
   1.101 -	/* :TODO: implement */
   1.102 -	return;
   1.103 +	/* This function doesn't really need to do anything now.  We make sure the 
   1.104 +	 * other extension is loaded, but handling of dependencies is really done 
   1.105 +	 * by the interface fetcher.
   1.106 +	 */
   1.107 +	if (required || autoload)
   1.108 +	{
   1.109 +		LoadAutoExtension(file);
   1.110 +	}
   1.111  }
   1.112  
   1.113  void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argcount)