core/logic/ExtensionSys.cpp
author David Anderson <dvander@alliedmods.net>
Sun Mar 31 13:30:22 2013 -0700 (2013-03-31)
changeset 3881 7ec742e7d629
parent 3880 48eed18701f0
child 3882 7dae5b0b8e28
permissions -rw-r--r--
Don't allocate/delete across static CRTs (no bug, irc r=fyren+psychonic).
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include <stdlib.h>
    33 #include "ExtensionSys.h"
    34 #include <ILibrarySys.h>
    35 #include <ISourceMod.h>
    36 #include "common_logic.h"
    37 #include "PluginSys.h"
    38 
    39 CExtensionManager g_Extensions;
    40 IdentityType_t g_ExtType;
    41 
    42 void CExtension::Initialize(const char *filename, const char *path)
    43 {
    44 	m_pAPI = NULL;
    45 	m_pIdentToken = NULL;
    46 	unload_code = 0;
    47 	m_bFullyLoaded = false;
    48 	m_File.assign(filename);
    49 	m_Path.assign(path);
    50 	char real_name[PLATFORM_MAX_PATH];
    51 	libsys->GetFileFromPath(real_name, sizeof(real_name), m_Path.c_str());
    52 	m_RealFile.assign(real_name);
    53 }
    54 
    55 CRemoteExtension::CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path)
    56 {
    57 	Initialize(filename, path);
    58 	m_pAPI = pAPI;
    59 }
    60 
    61 #if defined METAMOD_PLAPI_VERSION
    62 #if SOURCE_ENGINE == SE_LEFT4DEAD
    63 #define GAMEFIX "2.l4d"
    64 #elif SOURCE_ENGINE == SE_LEFT4DEAD2
    65 #define GAMEFIX "2.l4d2"
    66 #elif SOURCE_ENGINE == SE_ALIENSWARM
    67 #define GAMEFIX "2.swarm"
    68 #elif SOURCE_ENGINE == SE_ORANGEBOX
    69 #define GAMEFIX "2.ep2"
    70 #elif SOURCE_ENGINE == SE_BLOODYGOODTIME
    71 #define GAMEFIX "2.bgt"
    72 #elif SOURCE_ENGINE == SE_EYE
    73 #define GAMEFIX "2.eye"
    74 #elif SOURCE_ENGINE == SE_CSS
    75 #define GAMEFIX "2.css"
    76 #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE
    77 #define GAMEFIX "2.ep2v"
    78 #elif SOURCE_ENGINE == SE_DARKMESSIAH
    79 #define GAMEFIX "2.darkm"
    80 #elif SOURCE_ENGINE == SE_PORTAL2
    81 #define GAMEFIX "2.portal2"
    82 #elif SOURCE_ENGINE == SE_CSGO
    83 #define GAMEFIX "2.csgo"
    84 #elif SOURCE_ENGINE == SE_DOTA
    85 #define GAMEFIX "2.dota"
    86 #else
    87 #define GAMEFIX "2.ep1"
    88 #endif //(SOURCE_ENGINE == SE_LEFT4DEAD) || (SOURCE_ENGINE == SE_LEFT4DEAD2)
    89 #else  //METAMOD_PLAPI_VERSION
    90 #define GAMEFIX "1.ep1"
    91 #endif //METAMOD_PLAPI_VERSION
    92 
    93 CLocalExtension::CLocalExtension(const char *filename)
    94 {
    95 	m_PlId = 0;
    96 	m_pLib = NULL;
    97 
    98 	char path[PLATFORM_MAX_PATH];
    99 
   100 	/* Special case for new bintools binary */
   101 	if (strcmp(filename, "bintools.ext") == 0)
   102 	{
   103 		goto normal;
   104 	}
   105 
   106 	/* Zeroth, see if there is an engine specific build in the new place. */
   107 	g_pSM->BuildPath(Path_SM,
   108 		path,
   109 		PLATFORM_MAX_PATH,
   110 		"extensions/%s." GAMEFIX "." PLATFORM_LIB_EXT,
   111 		filename);
   112 
   113 	if (libsys->IsPathFile(path))
   114 	{
   115 		goto found;
   116 	}
   117 
   118 	/* First see if there is an engine specific build! */
   119 	g_pSM->BuildPath(Path_SM, 
   120 		path, 
   121 		PLATFORM_MAX_PATH,
   122 		"extensions/auto." GAMEFIX "/%s." PLATFORM_LIB_EXT,
   123 		filename);
   124 
   125 	/* Try the "normal" version */
   126 	if (!libsys->IsPathFile(path))
   127 	{
   128 		normal:
   129 		g_pSM->BuildPath(Path_SM,
   130 			path,
   131 			PLATFORM_MAX_PATH,
   132 			"extensions/%s." PLATFORM_LIB_EXT,
   133 			filename);
   134 	}
   135 
   136 found:
   137 	Initialize(filename, path);
   138 }
   139 
   140 bool CRemoteExtension::Load(char *error, size_t maxlength)
   141 {
   142 	if (!PerformAPICheck(error, maxlength))
   143 	{
   144 		m_pAPI = NULL;
   145 		return false;
   146 	}
   147 
   148 	if (!CExtension::Load(error, maxlength))
   149 	{
   150 		m_pAPI = NULL;
   151 		return false;
   152 	}
   153 
   154 	return true;
   155 }
   156 
   157 bool CLocalExtension::Load(char *error, size_t maxlength)
   158 {
   159 	m_pLib = libsys->OpenLibrary(m_Path.c_str(), error, maxlength);
   160 
   161 	if (m_pLib == NULL)
   162 	{
   163 		return false;
   164 	}
   165 
   166 	typedef IExtensionInterface *(*GETAPI)();
   167 	GETAPI pfnGetAPI = NULL;
   168 
   169 	if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
   170 	{
   171 		m_pLib->CloseLibrary();
   172 		m_pLib = NULL;
   173 		snprintf(error, maxlength, "Unable to find extension entry point");
   174 		return false;
   175 	}
   176 
   177 	m_pAPI = pfnGetAPI();
   178 
   179 	/* Check pointer and version */
   180 	if (!PerformAPICheck(error, maxlength))
   181 	{
   182 		m_pLib->CloseLibrary();
   183 		m_pLib = NULL;
   184 		m_pAPI = NULL;
   185 		return false;
   186 	}
   187 
   188 	/* Load as MM:S */
   189 	if (m_pAPI->IsMetamodExtension())
   190 	{
   191 		bool ok;
   192 		m_PlId = smcore.LoadMMSPlugin(m_Path.c_str(), &ok, error, maxlength);
   193 
   194 		if (!m_PlId || !ok)
   195 		{
   196 			m_pLib->CloseLibrary();
   197 			m_pLib = NULL;
   198 			m_pAPI = NULL;
   199 			return false;
   200 		}
   201 	}
   202 
   203 	if (!CExtension::Load(error, maxlength))
   204 	{
   205 		if (m_pAPI->IsMetamodExtension())
   206 		{
   207 			if (m_PlId)
   208 			{
   209 				smcore.UnloadMMSPlugin(m_PlId);
   210 				m_PlId = 0;
   211 			}
   212 		}
   213 		m_pLib->CloseLibrary();
   214 		m_pLib = NULL;
   215 		m_pAPI = NULL;
   216 		return false;
   217 	}
   218 
   219 	return true;
   220 }
   221 
   222 void CRemoteExtension::Unload()
   223 {
   224 }
   225 
   226 void CLocalExtension::Unload()
   227 {
   228 	if (m_pAPI != NULL && m_PlId)
   229 	{
   230 		smcore.UnloadMMSPlugin(m_PlId);
   231 		m_PlId = 0;
   232 	}
   233 
   234 	if (m_pLib != NULL)
   235 	{
   236 		m_pLib->CloseLibrary();
   237 		m_pLib = NULL;
   238 	}
   239 }
   240 
   241 bool CRemoteExtension::Reload(char *error, size_t maxlength)
   242 {
   243 	snprintf(error, maxlength, "Remote extensions do not support reloading");
   244 	return false;
   245 }
   246 
   247 bool CLocalExtension::Reload(char *error, size_t maxlength)
   248 {
   249 	if (m_pLib == NULL) // FIXME: just load it instead?
   250 		return false;
   251 	
   252 	m_pAPI->OnExtensionUnload();
   253 	Unload();
   254 	
   255 	return Load(error, maxlength);
   256 }
   257 
   258 bool CRemoteExtension::IsExternal()
   259 {
   260 	return true;
   261 }
   262 
   263 bool CLocalExtension::IsExternal()
   264 {
   265 	return false;
   266 }
   267 
   268 CExtension::~CExtension()
   269 {
   270 	DestroyIdentity();
   271 }
   272 
   273 bool CExtension::PerformAPICheck(char *error, size_t maxlength)
   274 {
   275 	if (!m_pAPI)
   276 	{
   277 		snprintf(error, maxlength, "No IExtensionInterface instance provided");
   278 		return false;
   279 	}
   280 	
   281 	if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
   282 	{
   283 		snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
   284 		return false;
   285 	}
   286 
   287 	return true;
   288 }
   289 
   290 bool CExtension::Load(char *error, size_t maxlength)
   291 {
   292 	CreateIdentity();
   293 	if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !smcore.IsMapLoading()))
   294 	{
   295 		DestroyIdentity();
   296 		return false;
   297 	}
   298 	else
   299 	{
   300 		/* Check if we're past load time */
   301 		if (!smcore.IsMapLoading())
   302 		{
   303 			m_pAPI->OnExtensionsAllLoaded();
   304 		}
   305 	}
   306 
   307 	return true;
   308 }
   309 
   310 void CExtension::CreateIdentity()
   311 {
   312 	if (m_pIdentToken != NULL)
   313 	{
   314 		return;
   315 	}
   316 
   317 	m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
   318 }
   319 
   320 void CExtension::DestroyIdentity()
   321 {
   322 	if (m_pIdentToken == NULL)
   323 	{
   324 		return;
   325 	}
   326 
   327 	g_ShareSys.DestroyIdentity(m_pIdentToken);
   328 	m_pIdentToken = NULL;
   329 }
   330 
   331 void CExtension::MarkAllLoaded()
   332 {
   333 	assert(m_bFullyLoaded == false);
   334 	if (!m_bFullyLoaded)
   335 	{
   336 		m_bFullyLoaded = true;
   337 		m_pAPI->OnExtensionsAllLoaded();
   338 	}
   339 }
   340 
   341 void CExtension::AddPlugin(CPlugin *pPlugin)
   342 {
   343 	/* Unfortunately we have to do this :( */
   344 	if (m_Dependents.find(pPlugin) != m_Dependents.end())
   345 	{
   346 		m_Dependents.push_back(pPlugin);
   347 	}
   348 }
   349 
   350 void CExtension::SetError(const char *error)
   351 {
   352 	m_Error.assign(error);
   353 }
   354 
   355 IExtensionInterface *CExtension::GetAPI()
   356 {
   357 	return m_pAPI;
   358 }
   359 
   360 const char *CExtension::GetFilename()
   361 {
   362 	return m_RealFile.c_str();
   363 }
   364 
   365 const char *CExtension::GetPath() const
   366 {
   367 	return m_Path.c_str();
   368 }
   369 
   370 IdentityToken_t *CExtension::GetIdentity()
   371 {
   372 	return m_pIdentToken;
   373 }
   374 
   375 bool CRemoteExtension::IsLoaded()
   376 {
   377 	return (m_pAPI != NULL);
   378 }
   379 
   380 bool CLocalExtension::IsLoaded()
   381 {
   382 	return (m_pLib != NULL);
   383 }
   384 
   385 void CExtension::AddDependency(const IfaceInfo *pInfo)
   386 {
   387 	if (m_Deps.find(*pInfo) == m_Deps.end())
   388 	{
   389 		m_Deps.push_back(*pInfo);
   390 	}
   391 }
   392 
   393 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
   394 {
   395 	return (i1.iface == i2.iface) && (i1.owner == i2.owner);
   396 }
   397 
   398 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
   399 {
   400 	IfaceInfo info;
   401 	info.iface = iface;
   402 	info.owner = pOther;
   403 
   404 	List<IfaceInfo>::iterator iter;
   405 	for (iter = m_ChildDeps.begin();
   406 		 iter != m_ChildDeps.end();
   407 		 iter++)
   408 	{
   409 		IfaceInfo &other = (*iter);
   410 		if (other == info)
   411 		{
   412 			return;
   413 		}
   414 	}
   415 
   416 	m_ChildDeps.push_back(info);
   417 }
   418 
   419 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
   420 {
   421 	List<IfaceInfo>::iterator iter = m_Deps.begin();
   422 
   423 	if (iter == m_Deps.end())
   424 	{
   425 		return NULL;
   426 	}
   427 
   428 	if (pOwner)
   429 	{
   430 		*pOwner = (*iter).owner;
   431 	}
   432 	if (pInterface)
   433 	{
   434 		*pInterface = (*iter).iface;
   435 	}
   436 
   437 	List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
   438 
   439 	return (ITERATOR *)pIter;
   440 }
   441 
   442 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
   443 {
   444 	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   445 	List<IfaceInfo>::iterator _iter;
   446 
   447 	if (_iter == m_Deps.end())
   448 	{
   449 		return false;
   450 	}
   451 
   452 	_iter++;
   453 
   454 	if (pOwner)
   455 	{
   456 		*pOwner = (*_iter).owner;
   457 	}
   458 	if (pInterface)
   459 	{
   460 		*pInterface = (*_iter).iface;
   461 	}
   462 
   463 	*pIter = _iter;
   464 
   465 	if (_iter == m_Deps.end())
   466 	{
   467 		return false;
   468 	}
   469 
   470 	return true;
   471 }
   472 
   473 void CExtension::FreeDependencyIterator(ITERATOR *iter)
   474 {
   475 	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   476 
   477 	delete pIter;
   478 }
   479 
   480 void CExtension::AddInterface(SMInterface *pInterface)
   481 {
   482 	m_Interfaces.push_back(pInterface);
   483 }
   484 
   485 bool CExtension::IsRunning(char *error, size_t maxlength)
   486 {
   487 	if (!IsLoaded())
   488 	{
   489 		if (error)
   490 		{
   491 			snprintf(error, maxlength, "%s", m_Error.c_str());
   492 		}
   493 		return false;
   494 	}
   495 
   496 	return m_pAPI->QueryRunning(error, maxlength);
   497 }
   498 
   499 void CExtension::AddLibrary(const char *library)
   500 {
   501 	m_Libraries.push_back(library);
   502 }
   503 
   504 /*********************
   505  * EXTENSION MANAGER *
   506  *********************/
   507 
   508 void CExtensionManager::OnSourceModAllInitialized()
   509 {
   510 	g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
   511 	pluginsys->AddPluginsListener(this);
   512 	g_ShareSys.AddInterface(NULL, this);
   513 }
   514 
   515 void CExtensionManager::OnSourceModShutdown()
   516 {
   517 	pluginsys->RemovePluginsListener(this);
   518 	g_ShareSys.DestroyIdentType(g_ExtType);
   519 }
   520 
   521 void CExtensionManager::Shutdown()
   522 {
   523 	List<CExtension *>::iterator iter;
   524 
   525 	while ((iter = m_Libs.begin()) != m_Libs.end())
   526 	{
   527 		UnloadExtension((*iter));
   528 	}
   529 }
   530 
   531 void CExtensionManager::TryAutoload()
   532 {
   533 	char path[PLATFORM_MAX_PATH];
   534 
   535 	g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions");
   536 
   537 	IDirectory *pDir = libsys->OpenDirectory(path);
   538 	if (!pDir)
   539 	{
   540 		return;
   541 	}
   542 
   543 	const char *lfile;
   544 	size_t len;
   545 	while (pDir->MoreFiles())
   546 	{
   547 		if (pDir->IsEntryDirectory())
   548 		{
   549 			pDir->NextEntry();
   550 			continue;
   551 		}
   552 
   553 		lfile = pDir->GetEntryName();
   554 		len = strlen(lfile);
   555 		if (len <= 9) /* size of ".autoload" */
   556 		{
   557 			pDir->NextEntry();
   558 			continue;
   559 		}
   560 
   561 		if (strcmp(&lfile[len - 9], ".autoload") != 0)
   562 		{
   563 			pDir->NextEntry();
   564 			continue;
   565 		}
   566 
   567 		char file[PLATFORM_MAX_PATH];
   568 		len = smcore.Format(file, sizeof(file), "%s", lfile);
   569 		strcpy(&file[len - 9], ".ext");
   570 
   571 		LoadAutoExtension(file);
   572 		
   573 		pDir->NextEntry();
   574 	}
   575 }
   576 
   577 IExtension *CExtensionManager::LoadAutoExtension(const char *path)
   578 {
   579 	/* Remove platform extension if it's there. Compat hack. */
   580 	const char *ext = libsys->GetFileExtension(path);
   581 	if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
   582 	{
   583 		char path2[PLATFORM_MAX_PATH];
   584 		smcore.Format(path2, sizeof(path2), "%s", path);
   585 		path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
   586 		return LoadAutoExtension(path2);
   587 	}
   588 
   589 	IExtension *pAlready;
   590 	if ((pAlready=FindExtensionByFile(path)) != NULL)
   591 	{
   592 		return pAlready;
   593 	}
   594 
   595 	char error[256];
   596 	CExtension *p = new CLocalExtension(path);
   597 
   598 	/* We put us in the list beforehand so extensions that check for each other
   599 	 * won't recursively load each other.
   600 	 */
   601 	m_Libs.push_back(p);
   602 
   603 	if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
   604 	{
   605 		smcore.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
   606 		p->SetError(error);
   607 	}
   608 
   609 	return p;
   610 }
   611 
   612 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
   613 {
   614 	List<CExtension *>::iterator iter;
   615 	CExtension *pExt;
   616 
   617 	/* Chomp off the path */
   618 	char lookup[PLATFORM_MAX_PATH];
   619 	libsys->GetFileFromPath(lookup, sizeof(lookup), file);
   620 
   621 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   622 	{
   623 		pExt = (*iter);
   624 		if (pExt->IsSameFile(lookup))
   625 		{
   626 			return pExt;
   627 		}
   628 	}
   629 
   630 	return NULL;
   631 }
   632 
   633 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
   634 {
   635 	List<CExtension *>::iterator iter;
   636 	CExtension *pExt;
   637 	IExtensionInterface *pAPI;
   638 	const char *name;
   639 
   640 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   641 	{
   642 		pExt = (*iter);
   643 		if (!pExt->IsLoaded())
   644 		{
   645 			continue;
   646 		}
   647 		if ((pAPI = pExt->GetAPI()) == NULL)
   648 		{
   649 			continue;
   650 		}
   651 		name = pAPI->GetExtensionName();
   652 		if (!name)
   653 		{
   654 			continue;
   655 		}
   656 		if (strcmp(name, ext) == 0)
   657 		{
   658 			return pExt;
   659 		}
   660 	}
   661 
   662 	return NULL;
   663 }
   664 
   665 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
   666 {
   667 	/* Remove platform extension if it's there. Compat hack. */
   668 	const char *ext = libsys->GetFileExtension(file);
   669 	if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
   670 	{
   671 		char path2[PLATFORM_MAX_PATH];
   672 		smcore.Format(path2, sizeof(path2), "%s", file);
   673 		path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
   674 		return LoadExtension(path2, error, maxlength);
   675 	}
   676 
   677 	IExtension *pAlready;
   678 	if ((pAlready=FindExtensionByFile(file)) != NULL)
   679 	{
   680 		return pAlready;
   681 	}
   682 
   683 	CExtension *pExt = new CLocalExtension(file);
   684 
   685 	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
   686 	{
   687 		pExt->Unload();
   688 		delete pExt;
   689 		return NULL;
   690 	}
   691 
   692 	/* :TODO: do QueryRunning check if the map is loaded */
   693 
   694 	m_Libs.push_back(pExt);
   695 
   696 	return pExt;
   697 }
   698 
   699 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
   700 {
   701 	CExtension *pExt = (CExtension *)pRequester;
   702 	CExtension *pOwner = (CExtension *)pInfo->owner;
   703 
   704 	pExt->AddDependency(pInfo);
   705 
   706 	IExtensionInterface *pAPI = pExt->GetAPI();
   707 	if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
   708 	{
   709 		pOwner->AddChildDependent(pExt, pInfo->iface);
   710 	}
   711 }
   712 
   713 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
   714 {
   715 	CExtension *pExt = (CExtension *)ext;
   716 	CExtension *pOwner = GetExtensionFromIdent(other);
   717 
   718 	IfaceInfo info;
   719 
   720 	info.iface = (SMInterface *)iface;
   721 	info.owner = pOwner;
   722 
   723 	pExt->AddDependency(&info);
   724 	pOwner->AddChildDependent(pExt, (SMInterface *)iface);
   725 }
   726 
   727 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
   728 {
   729 	CExtension *pExt = (CExtension *)pOwner;
   730 
   731 	pExt->AddInterface(pInterface);
   732 }
   733 
   734 void CExtensionManager::BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin)
   735 {
   736 	CExtension *pExt = (CExtension *)pParent;
   737 
   738 	pExt->AddPlugin(static_cast<CPlugin *>(pPlugin));
   739 }
   740 
   741 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
   742 {
   743 	List<CExtension *>::iterator iter;
   744 
   745 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   746 	{
   747 		(*iter)->DropRefsTo(static_cast<CPlugin *>(plugin));
   748 	}
   749 }
   750 
   751 CExtension *CExtensionManager::FindByOrder(unsigned int num)
   752 {
   753 	if (num < 1 || num > m_Libs.size())
   754 	{
   755 		return NULL;
   756 	}
   757 
   758 	List<CExtension *>::iterator iter = m_Libs.begin();
   759 
   760 	while (iter != m_Libs.end())
   761 	{
   762 		if (--num == 0)
   763 		{
   764 			return (*iter);
   765 		}
   766 		iter++;
   767 	}
   768 
   769 	return NULL;
   770 }
   771 
   772 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
   773 {
   774 	if (!_pExt)
   775 	{
   776 		return false;
   777 	}
   778 
   779 	CExtension *pExt = (CExtension *)_pExt;
   780 
   781 	if (m_Libs.find(pExt) == m_Libs.end())
   782 	{
   783 		return false;
   784 	}
   785 
   786 	/* Tell it to unload */
   787 	if (pExt->IsLoaded())
   788 	{
   789 		IExtensionInterface *pAPI = pExt->GetAPI();
   790 		pAPI->OnExtensionUnload();
   791 	}
   792 
   793 	/* First remove us from internal lists */
   794 	g_ShareSys.RemoveInterfaces(_pExt);
   795 	m_Libs.remove(pExt);
   796 
   797 	List<CExtension *> UnloadQueue;
   798 
   799 	/* Handle dependencies */
   800 	if (pExt->IsLoaded())
   801 	{
   802 		/* Unload any dependent plugins */
   803 		List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
   804 		while (p_iter != pExt->m_Dependents.end())
   805 		{
   806 			/* We have to manually unlink ourselves here, since we're no longer being managed */
   807 			scripts->UnloadPlugin((*p_iter));
   808 			p_iter = pExt->m_Dependents.erase(p_iter);
   809 		}
   810 
   811 		List<String>::iterator s_iter;
   812 		for (s_iter = pExt->m_Libraries.begin();
   813 			 s_iter != pExt->m_Libraries.end();
   814 			 s_iter++)
   815 		{
   816 			scripts->OnLibraryAction((*s_iter).c_str(), LibraryAction_Removed);
   817 		}
   818 
   819 		/* Notify and/or unload all dependencies */
   820 		List<CExtension *>::iterator c_iter;
   821 		CExtension *pDep;
   822 		IExtensionInterface *pAPI;
   823 		for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
   824 		{
   825 			pDep = (*c_iter);
   826 			if ((pAPI=pDep->GetAPI()) == NULL)
   827 			{
   828 				continue;
   829 			}
   830 			if (pDep == pExt)
   831 			{
   832 				continue;
   833 			}
   834 			/* Now, get its dependency list */
   835 			bool dropped = false;
   836 			List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
   837 			while (i_iter != pDep->m_Deps.end())
   838 			{
   839 				if ((*i_iter).owner == _pExt)
   840 				{
   841 					if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
   842 					{
   843 						if (!dropped)
   844 						{
   845 							dropped = true;
   846 							UnloadQueue.push_back(pDep);
   847 						}
   848 					}
   849 					pAPI->NotifyInterfaceDrop((*i_iter).iface);
   850 					i_iter = pDep->m_Deps.erase(i_iter);
   851 				}
   852 				else
   853 				{
   854 					i_iter++;
   855 				}
   856 			}
   857 			/* Flush out any back references to this plugin */
   858 			i_iter = pDep->m_ChildDeps.begin();
   859 			while (i_iter != pDep->m_ChildDeps.end())
   860 			{
   861 				if ((*i_iter).owner == pExt)
   862 				{
   863 					i_iter = pDep->m_ChildDeps.erase(i_iter);
   864 				}
   865 				else
   866 				{
   867 					i_iter++;
   868 				}
   869 			}
   870 		}
   871 
   872 		/* Unbind our natives from Core */
   873 		pExt->DropEverything();
   874 	}
   875 
   876 	IdentityToken_t *pIdentity;
   877 	if ((pIdentity = pExt->GetIdentity()) != NULL)
   878 	{
   879 		SMGlobalClass *glob = SMGlobalClass::head;
   880 		while (glob)
   881 		{
   882 			glob->OnSourceModIdentityDropped(pIdentity);
   883 			glob = glob->m_pGlobalClassNext;
   884 		}
   885 	}
   886 
   887 	pExt->Unload();
   888 	delete pExt;
   889 
   890 	List<CExtension *>::iterator iter;
   891 	for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
   892 	{
   893 		/* NOTE: This is safe because the unload function backs out of anything not present */
   894 		UnloadExtension((*iter));
   895 	}
   896 
   897 	return true;
   898 }
   899 
   900 void CExtensionManager::MarkAllLoaded()
   901 {
   902 	List<CExtension *>::iterator iter;
   903 	CExtension *pExt;
   904 
   905 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   906 	{
   907 		pExt = (*iter);
   908 		if (!pExt->IsLoaded())
   909 		{
   910 			continue;
   911 		}
   912 		if (pExt->m_bFullyLoaded)
   913 		{
   914 			continue;
   915 		}
   916 		pExt->MarkAllLoaded();
   917 	}
   918 }
   919 
   920 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
   921 {
   922 	/* This function doesn't really need to do anything now.  We make sure the 
   923 	 * other extension is loaded, but handling of dependencies is really done 
   924 	 * by the interface fetcher.
   925 	 */
   926 	if (required || autoload)
   927 	{
   928 		LoadAutoExtension(file);
   929 	}
   930 }
   931 
   932 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
   933 {
   934 	int argcount = smcore.Argc(command);
   935 	if (argcount >= 3)
   936 	{
   937 		const char *cmd = smcore.Arg(command, 2);
   938 		if (strcmp(cmd, "list") == 0)
   939 		{
   940 			List<CExtension *>::iterator iter;
   941 			CExtension *pExt;
   942 			unsigned int num = 1;
   943 			switch (m_Libs.size())
   944 			{
   945 			case 1:
   946 				{
   947 					rootmenu->ConsolePrint("[SM] Displaying 1 extension:");
   948 					break;
   949 				}
   950 			case 0:
   951 				{
   952 					rootmenu->ConsolePrint("[SM] No extensions are loaded.");
   953 					break;
   954 				}
   955 			default:
   956 				{
   957 					rootmenu->ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
   958 					break;
   959 				}
   960 			}
   961 			for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
   962 			{
   963 				pExt = (*iter);
   964 				if (pExt->IsLoaded())
   965 				{
   966 					char error[255];
   967 					if (!pExt->IsRunning(error, sizeof(error)))
   968 					{
   969 						rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
   970 					}
   971 					else
   972 					{
   973 						IExtensionInterface *pAPI = pExt->GetAPI();
   974 						const char *name = pAPI->GetExtensionName();
   975 						const char *version = pAPI->GetExtensionVerString();
   976 						const char *descr = pAPI->GetExtensionDescription();
   977 						rootmenu->ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
   978 					}
   979 				} else {
   980 					rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
   981 				}
   982 			}
   983 			return;
   984 		}
   985 		else if (strcmp(cmd, "load") == 0)
   986 		{
   987 			if (argcount < 4)
   988 			{
   989 				rootmenu->ConsolePrint("[SM] Usage: sm exts load <file>");
   990 				return;
   991 			}
   992 
   993 			const char *filename = smcore.Arg(command, 3);
   994 			char path[PLATFORM_MAX_PATH];
   995 			char error[256];
   996 
   997 			smcore.Format(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "",
   998 				!strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : "");
   999 			
  1000 			if (FindExtensionByFile(path) != NULL)
  1001 			{
  1002 				rootmenu->ConsolePrint("[SM] Extension %s is already loaded.", path);
  1003 				return;
  1004 			}
  1005 			
  1006 			if (LoadExtension(path, error, sizeof(error)))
  1007 			{
  1008 				rootmenu->ConsolePrint("[SM] Loaded extension %s successfully.", path);
  1009 			} else
  1010 			{
  1011 				rootmenu->ConsolePrint("[SM] Extension %s failed to load: %s", path, error);
  1012 			}
  1013 			
  1014 			return;
  1015 		}
  1016 		else if (strcmp(cmd, "info") == 0)
  1017 		{
  1018 			if (argcount < 4)
  1019 			{
  1020 				rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>");
  1021 				return;
  1022 			}
  1023 
  1024 			const char *sId = smcore.Arg(command, 3);
  1025 			unsigned int id = atoi(sId);
  1026 			if (id <= 0)
  1027 			{
  1028 				rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>");
  1029 				return;
  1030 			}
  1031 
  1032 			if (m_Libs.size() == 0)
  1033 			{
  1034 				rootmenu->ConsolePrint("[SM] No extensions are loaded.");
  1035 				return;
  1036 			}
  1037 
  1038 			if (id > m_Libs.size())
  1039 			{
  1040 				rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id);
  1041 				return;
  1042 			}
  1043 
  1044 			List<CExtension *>::iterator iter = m_Libs.begin();
  1045 			CExtension *pExt = NULL;
  1046 			while (iter != m_Libs.end())
  1047 			{
  1048 				if (--id == 0)
  1049 				{
  1050 					pExt = (*iter);
  1051 					break;
  1052 				}
  1053 				iter++;
  1054 			}
  1055 			/* This should never happen */
  1056 			if (!pExt)
  1057 			{
  1058 				rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id);
  1059 				return;
  1060 			}
  1061 
  1062 			if (!pExt->IsLoaded())
  1063 			{
  1064 				rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1065 				rootmenu->ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
  1066 			}
  1067 			else
  1068 			{
  1069 				char error[255];
  1070 				if (!pExt->IsRunning(error, sizeof(error)))
  1071 				{
  1072 					rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1073 					rootmenu->ConsolePrint(" Loaded: Yes");
  1074 					rootmenu->ConsolePrint(" Running: No (%s)", error);
  1075 				}
  1076 				else
  1077 				{
  1078 					IExtensionInterface *pAPI = pExt->GetAPI();
  1079 					rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1080 					rootmenu->ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
  1081 					rootmenu->ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
  1082 					rootmenu->ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
  1083 					rootmenu->ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
  1084 
  1085 					if (pExt->IsExternal())
  1086 					{
  1087 						rootmenu->ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
  1088 					}
  1089 					else if (pAPI->IsMetamodExtension())
  1090 					{
  1091 						rootmenu->ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
  1092 					}
  1093 					else
  1094 					{
  1095 						rootmenu->ConsolePrint(" Method: Loaded by SourceMod");
  1096 					}
  1097 				}
  1098 			}
  1099 			return;
  1100 		}
  1101 		else if (strcmp(cmd, "unload") == 0)
  1102 		{
  1103 			if (argcount < 4)
  1104 			{
  1105 				rootmenu->ConsolePrint("[SM] Usage: sm exts unload <#> [code]");
  1106 				return;
  1107 			}
  1108 
  1109 			const char *arg = smcore.Arg(command, 3);
  1110 			unsigned int num = atoi(arg);
  1111 			CExtension *pExt = FindByOrder(num);
  1112 
  1113 			if (!pExt)
  1114 			{
  1115 				rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num);
  1116 				return;
  1117 			}
  1118 
  1119 			if (argcount > 4 && pExt->unload_code)
  1120 			{
  1121 				const char *unload = smcore.Arg(command, 4);
  1122 				if (pExt->unload_code == (unsigned)atoi(unload))
  1123 				{
  1124 					char filename[PLATFORM_MAX_PATH];
  1125 					snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1126 					UnloadExtension(pExt);
  1127 					rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1128 				}
  1129 				else
  1130 				{
  1131 					rootmenu->ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
  1132 				}
  1133 				return;
  1134 			}
  1135 
  1136 			if (!pExt->IsLoaded() 
  1137 				|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
  1138 			{
  1139 				char filename[PLATFORM_MAX_PATH];
  1140 				snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1141 				UnloadExtension(pExt);
  1142 				rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1143 				return;
  1144 			}
  1145 			else
  1146 			{
  1147 				List<CPlugin *> plugins;
  1148 				if (pExt->m_ChildDeps.size())
  1149 				{
  1150 					rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
  1151 					List<CExtension *>::iterator iter;
  1152 					CExtension *pOther;
  1153 					/* Get list of all extensions */
  1154 					for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1155 					{
  1156 						List<IfaceInfo>::iterator i_iter;
  1157 						pOther = (*iter);
  1158 						if (!pOther->IsLoaded() || pOther == pExt)
  1159 						{
  1160 							continue;
  1161 						}
  1162 						/* Get their dependencies */
  1163 						for (i_iter=pOther->m_Deps.begin();
  1164 							 i_iter!=pOther->m_Deps.end();
  1165 							 i_iter++)
  1166 						{
  1167 							/* Is this dependency to us? */
  1168 							if ((*i_iter).owner != pExt)
  1169 							{
  1170 								continue;
  1171 							}
  1172 							/* Will our dependent care? */
  1173 							if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
  1174 							{
  1175 								rootmenu->ConsolePrint(" -> %s", pExt->GetFilename());
  1176 								/* Add to plugin unload list */
  1177 								List<CPlugin *>::iterator p_iter;
  1178 								for (p_iter=pOther->m_Dependents.begin();
  1179 									 p_iter!=pOther->m_Dependents.end();
  1180 									 p_iter++)
  1181 								{
  1182 									if (plugins.find((*p_iter)) == plugins.end())
  1183 									{
  1184 										plugins.push_back((*p_iter));
  1185 									}
  1186 								}
  1187 							}
  1188 						}
  1189 					}
  1190 				}
  1191 				if (pExt->m_Dependents.size())
  1192 				{
  1193 					rootmenu->ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
  1194 					List<CPlugin *>::iterator iter;
  1195 					CPlugin *pPlugin;
  1196 					for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
  1197 					{
  1198 						pPlugin = (*iter);
  1199 						if (plugins.find(pPlugin) == plugins.end())
  1200 						{
  1201 							plugins.push_back(pPlugin);
  1202 						}
  1203 					}
  1204 					for (iter = plugins.begin(); iter != plugins.end(); iter++)
  1205 					{
  1206 						pPlugin = (*iter);
  1207 						rootmenu->ConsolePrint(" -> %s", pPlugin->GetFilename());
  1208 					}
  1209 				}
  1210 				srand(static_cast<int>(time(NULL)));
  1211 				pExt->unload_code = (rand() % 877) + 123;	//123 to 999
  1212 				rootmenu->ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
  1213 				rootmenu->ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
  1214 
  1215 				return;
  1216 			}
  1217 		}
  1218 		else if (strcmp(cmd, "reload") == 0)
  1219 		{
  1220 			if (argcount < 4)
  1221 			{
  1222 				rootmenu->ConsolePrint("[SM] Usage: sm exts reload <#>");
  1223 				return;
  1224 			}
  1225 			
  1226 			const char *arg = smcore.Arg(command, 3);
  1227 			unsigned int num = atoi(arg);
  1228 			CExtension *pExt = FindByOrder(num);
  1229 
  1230 			if (!pExt)
  1231 			{
  1232 				rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num);
  1233 				return;
  1234 			}
  1235 			
  1236 			if (pExt->IsLoaded())
  1237 			{
  1238 				char filename[PLATFORM_MAX_PATH];
  1239 				char error[255];
  1240 				
  1241 				snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1242 				
  1243 				if (pExt->Reload(error, sizeof(error)))
  1244 				{
  1245 					rootmenu->ConsolePrint("[SM] Extension %s is now reloaded.", filename);
  1246 				}
  1247 				else
  1248 				{
  1249 					rootmenu->ConsolePrint("[SM] Extension %s failed to reload: %s", filename, error);
  1250 				}
  1251 					
  1252 				return;
  1253 			} 
  1254 			else
  1255 			{
  1256 				rootmenu->ConsolePrint("[SM] Extension %s is not loaded.", pExt->GetFilename());
  1257 				
  1258 				return;
  1259 			}
  1260 			
  1261 		}
  1262 	}
  1263 
  1264 	rootmenu->ConsolePrint("SourceMod Extensions Menu:");
  1265 	rootmenu->DrawGenericOption("info", "Extra extension information");
  1266 	rootmenu->DrawGenericOption("list", "List extensions");
  1267 	rootmenu->DrawGenericOption("load", "Load an extension");
  1268 	rootmenu->DrawGenericOption("reload", "Reload an extension");
  1269 	rootmenu->DrawGenericOption("unload", "Unload an extension");
  1270 }
  1271 
  1272 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
  1273 {
  1274 	if (ptr->type == g_ExtType)
  1275 	{
  1276 		return (CExtension *)(ptr->ptr);
  1277 	}
  1278 
  1279 	return NULL;
  1280 }
  1281 
  1282 CExtensionManager::CExtensionManager()
  1283 {
  1284 }
  1285 
  1286 CExtensionManager::~CExtensionManager()
  1287 {
  1288 }
  1289 
  1290 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
  1291 {
  1292 	CExtension *pExt = (CExtension *)pSource;
  1293 	pExt->AddLibrary(library);
  1294 	scripts->OnLibraryAction(library, LibraryAction_Added);
  1295 }
  1296 
  1297 bool CExtensionManager::LibraryExists(const char *library)
  1298 {
  1299 	CExtension *pExt;
  1300 
  1301 	for (List<CExtension *>::iterator iter = m_Libs.begin();
  1302 		 iter != m_Libs.end();
  1303 		 iter++)
  1304 	{
  1305 		pExt = (*iter);
  1306 		for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
  1307 			 s_iter != pExt->m_Libraries.end();
  1308 			 s_iter++)
  1309 		{
  1310 			if ((*s_iter).compare(library) == 0)
  1311 			{
  1312 				return true;
  1313 			}
  1314 		}
  1315 	}
  1316 
  1317 	return false;
  1318 }
  1319 
  1320 IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
  1321 											const char *filepath,
  1322 											const char *filename,
  1323 											char *error,
  1324 											size_t maxlength)
  1325 {
  1326 	IExtension *pAlready;
  1327 	if ((pAlready=FindExtensionByFile(filename)) != NULL)
  1328 	{
  1329 		return pAlready;
  1330 	}
  1331 
  1332 	CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
  1333 
  1334 	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
  1335 	{
  1336 		pExt->Unload();
  1337 		delete pExt;
  1338 		return NULL;
  1339 	}
  1340 
  1341 	m_Libs.push_back(pExt);
  1342 
  1343 	return pExt;
  1344 }
  1345 
  1346 void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
  1347 {
  1348 	IExtensionInterface *pAPI;
  1349 	List<CExtension *>::iterator iter;
  1350 
  1351 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1352 	{
  1353 		if ((pAPI = (*iter)->GetAPI()) == NULL)
  1354 		{
  1355 			continue;
  1356 		}
  1357 		if (pAPI->GetExtensionVersion() > 3)
  1358 		{
  1359 			pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);
  1360 		}
  1361 	}
  1362 }
  1363 
  1364 const CVector<IExtension *> *CExtensionManager::ListExtensions()
  1365 {
  1366 	CVector<IExtension *> *list = new CVector<IExtension *>();
  1367 	for (List<CExtension *>::iterator iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
  1368 		list->push_back(*iter);
  1369 	return list;
  1370 }
  1371 
  1372 void CExtensionManager::FreeExtensionList(const CVector<IExtension *> *list)
  1373 {
  1374 	delete const_cast<CVector<IExtension *> *>(list);
  1375 }
  1376 
  1377 bool CLocalExtension::IsSameFile(const char *file)
  1378 {
  1379 	/* Only care about the shortened name. */
  1380 	return strcmp(file, m_File.c_str()) == 0;
  1381 }
  1382 
  1383 bool CRemoteExtension::IsSameFile(const char *file)
  1384 {
  1385 	/* :TODO: this could be better, but no one uses this API anyway. */
  1386 	return strcmp(file, m_Path.c_str()) == 0;
  1387 }
  1388