core/logic/ExtensionSys.cpp
author David Anderson <dvander@alliedmods.net>
Sun Aug 25 11:59:48 2013 -0700 (2013-08-25)
changeset 4069 336e32fe098f
parent 4045 2891bbc5932b
child 4131 b6d0746d0337
permissions -rw-r--r--
Switch HalfLife2 off KTrie (bug 5884 part 7, r=ds).
     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 CLocalExtension::CLocalExtension(const char *filename)
    62 {
    63 	m_PlId = 0;
    64 	m_pLib = NULL;
    65 
    66 	char path[PLATFORM_MAX_PATH];
    67 
    68 	/* Special case for new bintools binary */
    69 	if (strcmp(filename, "bintools.ext") == 0)
    70 	{
    71 		goto normal;
    72 	}
    73 
    74 	/* Zeroth, see if there is an engine specific build in the new place. */
    75 	g_pSM->BuildPath(Path_SM,
    76 		path,
    77 		PLATFORM_MAX_PATH,
    78 		"extensions/%s.%s." PLATFORM_LIB_EXT,
    79 		filename,
    80 		smcore.gamesuffix);
    81 
    82 	if (libsys->IsPathFile(path))
    83 	{
    84 		goto found;
    85 	}
    86 
    87 	/* COMPAT HACK: One-halfth, if ep2v, see if there is an engine specific build in the new place with old naming */
    88 	if (strcmp(smcore.gamesuffix, "2.tf2") == 0
    89 		|| strcmp(smcore.gamesuffix, "2.dods") == 0
    90 		|| strcmp(smcore.gamesuffix, "2.hl2dm") == 0
    91 		)
    92 	{
    93 		g_pSM->BuildPath(Path_SM,
    94 			path,
    95 			PLATFORM_MAX_PATH,
    96 			"extensions/%s.2.ep2v." PLATFORM_LIB_EXT,
    97 			filename);
    98 
    99 		if (libsys->IsPathFile(path))
   100 		{
   101 			goto found;
   102 		}
   103 	}
   104 	else if (strcmp(smcore.gamesuffix, "2.nd") == 0)
   105 	{
   106 		g_pSM->BuildPath(Path_SM,
   107 			path,
   108 			PLATFORM_MAX_PATH,
   109 			"extensions/%s.2.l4d2." PLATFORM_LIB_EXT,
   110 			filename);
   111 
   112 		if (libsys->IsPathFile(path))
   113 		{
   114 			goto found;
   115 		}
   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.%s/%s." PLATFORM_LIB_EXT,
   123 		filename,
   124 		smcore.gamesuffix);
   125 
   126 	/* Try the "normal" version */
   127 	if (!libsys->IsPathFile(path))
   128 	{
   129 		normal:
   130 		g_pSM->BuildPath(Path_SM,
   131 			path,
   132 			PLATFORM_MAX_PATH,
   133 			"extensions/%s." PLATFORM_LIB_EXT,
   134 			filename);
   135 	}
   136 
   137 found:
   138 	Initialize(filename, path);
   139 }
   140 
   141 bool CRemoteExtension::Load(char *error, size_t maxlength)
   142 {
   143 	if (!PerformAPICheck(error, maxlength))
   144 	{
   145 		m_pAPI = NULL;
   146 		return false;
   147 	}
   148 
   149 	if (!CExtension::Load(error, maxlength))
   150 	{
   151 		m_pAPI = NULL;
   152 		return false;
   153 	}
   154 
   155 	return true;
   156 }
   157 
   158 bool CLocalExtension::Load(char *error, size_t maxlength)
   159 {
   160 	m_pLib = libsys->OpenLibrary(m_Path.c_str(), error, maxlength);
   161 
   162 	if (m_pLib == NULL)
   163 	{
   164 		return false;
   165 	}
   166 
   167 	typedef IExtensionInterface *(*GETAPI)();
   168 	GETAPI pfnGetAPI = NULL;
   169 
   170 	if ((pfnGetAPI=(GETAPI)m_pLib->GetSymbolAddress("GetSMExtAPI")) == NULL)
   171 	{
   172 		m_pLib->CloseLibrary();
   173 		m_pLib = NULL;
   174 		snprintf(error, maxlength, "Unable to find extension entry point");
   175 		return false;
   176 	}
   177 
   178 	m_pAPI = pfnGetAPI();
   179 
   180 	/* Check pointer and version */
   181 	if (!PerformAPICheck(error, maxlength))
   182 	{
   183 		m_pLib->CloseLibrary();
   184 		m_pLib = NULL;
   185 		m_pAPI = NULL;
   186 		return false;
   187 	}
   188 
   189 	/* Load as MM:S */
   190 	if (m_pAPI->IsMetamodExtension())
   191 	{
   192 		bool ok;
   193 		m_PlId = smcore.LoadMMSPlugin(m_Path.c_str(), &ok, error, maxlength);
   194 
   195 		if (!m_PlId || !ok)
   196 		{
   197 			m_pLib->CloseLibrary();
   198 			m_pLib = NULL;
   199 			m_pAPI = NULL;
   200 			return false;
   201 		}
   202 	}
   203 
   204 	if (!CExtension::Load(error, maxlength))
   205 	{
   206 		if (m_pAPI->IsMetamodExtension())
   207 		{
   208 			if (m_PlId)
   209 			{
   210 				smcore.UnloadMMSPlugin(m_PlId);
   211 				m_PlId = 0;
   212 			}
   213 		}
   214 		m_pLib->CloseLibrary();
   215 		m_pLib = NULL;
   216 		m_pAPI = NULL;
   217 		return false;
   218 	}
   219 
   220 	return true;
   221 }
   222 
   223 void CRemoteExtension::Unload()
   224 {
   225 }
   226 
   227 void CLocalExtension::Unload()
   228 {
   229 	if (m_pAPI != NULL && m_PlId)
   230 	{
   231 		smcore.UnloadMMSPlugin(m_PlId);
   232 		m_PlId = 0;
   233 	}
   234 
   235 	if (m_pLib != NULL)
   236 	{
   237 		m_pLib->CloseLibrary();
   238 		m_pLib = NULL;
   239 	}
   240 }
   241 
   242 bool CRemoteExtension::Reload(char *error, size_t maxlength)
   243 {
   244 	snprintf(error, maxlength, "Remote extensions do not support reloading");
   245 	return false;
   246 }
   247 
   248 bool CLocalExtension::Reload(char *error, size_t maxlength)
   249 {
   250 	if (m_pLib == NULL) // FIXME: just load it instead?
   251 		return false;
   252 	
   253 	m_pAPI->OnExtensionUnload();
   254 	Unload();
   255 	
   256 	return Load(error, maxlength);
   257 }
   258 
   259 bool CRemoteExtension::IsExternal()
   260 {
   261 	return true;
   262 }
   263 
   264 bool CLocalExtension::IsExternal()
   265 {
   266 	return false;
   267 }
   268 
   269 CExtension::~CExtension()
   270 {
   271 	DestroyIdentity();
   272 }
   273 
   274 bool CExtension::PerformAPICheck(char *error, size_t maxlength)
   275 {
   276 	if (!m_pAPI)
   277 	{
   278 		snprintf(error, maxlength, "No IExtensionInterface instance provided");
   279 		return false;
   280 	}
   281 	
   282 	if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
   283 	{
   284 		snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
   285 		return false;
   286 	}
   287 
   288 	return true;
   289 }
   290 
   291 bool CExtension::Load(char *error, size_t maxlength)
   292 {
   293 	CreateIdentity();
   294 	if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !smcore.IsMapLoading()))
   295 	{
   296 		DestroyIdentity();
   297 		return false;
   298 	}
   299 	else
   300 	{
   301 		/* Check if we're past load time */
   302 		if (!smcore.IsMapLoading())
   303 		{
   304 			m_pAPI->OnExtensionsAllLoaded();
   305 		}
   306 	}
   307 
   308 	return true;
   309 }
   310 
   311 void CExtension::CreateIdentity()
   312 {
   313 	if (m_pIdentToken != NULL)
   314 	{
   315 		return;
   316 	}
   317 
   318 	m_pIdentToken = g_ShareSys.CreateIdentity(g_ExtType, this);
   319 }
   320 
   321 void CExtension::DestroyIdentity()
   322 {
   323 	if (m_pIdentToken == NULL)
   324 	{
   325 		return;
   326 	}
   327 
   328 	g_ShareSys.DestroyIdentity(m_pIdentToken);
   329 	m_pIdentToken = NULL;
   330 }
   331 
   332 void CExtension::MarkAllLoaded()
   333 {
   334 	assert(m_bFullyLoaded == false);
   335 	if (!m_bFullyLoaded)
   336 	{
   337 		m_bFullyLoaded = true;
   338 		m_pAPI->OnExtensionsAllLoaded();
   339 	}
   340 }
   341 
   342 void CExtension::AddPlugin(CPlugin *pPlugin)
   343 {
   344 	/* Unfortunately we have to do this :( */
   345 	if (m_Dependents.find(pPlugin) != m_Dependents.end())
   346 	{
   347 		m_Dependents.push_back(pPlugin);
   348 	}
   349 }
   350 
   351 void CExtension::SetError(const char *error)
   352 {
   353 	m_Error.assign(error);
   354 }
   355 
   356 IExtensionInterface *CExtension::GetAPI()
   357 {
   358 	return m_pAPI;
   359 }
   360 
   361 const char *CExtension::GetFilename()
   362 {
   363 	return m_RealFile.c_str();
   364 }
   365 
   366 const char *CExtension::GetPath() const
   367 {
   368 	return m_Path.c_str();
   369 }
   370 
   371 IdentityToken_t *CExtension::GetIdentity()
   372 {
   373 	return m_pIdentToken;
   374 }
   375 
   376 bool CRemoteExtension::IsLoaded()
   377 {
   378 	return (m_pAPI != NULL);
   379 }
   380 
   381 bool CLocalExtension::IsLoaded()
   382 {
   383 	return (m_pLib != NULL);
   384 }
   385 
   386 void CExtension::AddDependency(const IfaceInfo *pInfo)
   387 {
   388 	if (m_Deps.find(*pInfo) == m_Deps.end())
   389 	{
   390 		m_Deps.push_back(*pInfo);
   391 	}
   392 }
   393 
   394 bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
   395 {
   396 	return (i1.iface == i2.iface) && (i1.owner == i2.owner);
   397 }
   398 
   399 void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
   400 {
   401 	IfaceInfo info;
   402 	info.iface = iface;
   403 	info.owner = pOther;
   404 
   405 	List<IfaceInfo>::iterator iter;
   406 	for (iter = m_ChildDeps.begin();
   407 		 iter != m_ChildDeps.end();
   408 		 iter++)
   409 	{
   410 		IfaceInfo &other = (*iter);
   411 		if (other == info)
   412 		{
   413 			return;
   414 		}
   415 	}
   416 
   417 	m_ChildDeps.push_back(info);
   418 }
   419 
   420 ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
   421 {
   422 	List<IfaceInfo>::iterator iter = m_Deps.begin();
   423 
   424 	if (iter == m_Deps.end())
   425 	{
   426 		return NULL;
   427 	}
   428 
   429 	if (pOwner)
   430 	{
   431 		*pOwner = (*iter).owner;
   432 	}
   433 	if (pInterface)
   434 	{
   435 		*pInterface = (*iter).iface;
   436 	}
   437 
   438 	List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
   439 
   440 	return (ITERATOR *)pIter;
   441 }
   442 
   443 bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
   444 {
   445 	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   446 	List<IfaceInfo>::iterator _iter;
   447 
   448 	if (_iter == m_Deps.end())
   449 	{
   450 		return false;
   451 	}
   452 
   453 	_iter++;
   454 
   455 	if (pOwner)
   456 	{
   457 		*pOwner = (*_iter).owner;
   458 	}
   459 	if (pInterface)
   460 	{
   461 		*pInterface = (*_iter).iface;
   462 	}
   463 
   464 	*pIter = _iter;
   465 
   466 	if (_iter == m_Deps.end())
   467 	{
   468 		return false;
   469 	}
   470 
   471 	return true;
   472 }
   473 
   474 void CExtension::FreeDependencyIterator(ITERATOR *iter)
   475 {
   476 	List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
   477 
   478 	delete pIter;
   479 }
   480 
   481 void CExtension::AddInterface(SMInterface *pInterface)
   482 {
   483 	m_Interfaces.push_back(pInterface);
   484 }
   485 
   486 bool CExtension::IsRunning(char *error, size_t maxlength)
   487 {
   488 	if (!IsLoaded())
   489 	{
   490 		if (error)
   491 		{
   492 			snprintf(error, maxlength, "%s", m_Error.c_str());
   493 		}
   494 		return false;
   495 	}
   496 
   497 	return m_pAPI->QueryRunning(error, maxlength);
   498 }
   499 
   500 void CExtension::AddLibrary(const char *library)
   501 {
   502 	m_Libraries.push_back(library);
   503 }
   504 
   505 /*********************
   506  * EXTENSION MANAGER *
   507  *********************/
   508 
   509 void CExtensionManager::OnSourceModAllInitialized()
   510 {
   511 	g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
   512 	pluginsys->AddPluginsListener(this);
   513 	rootmenu->AddRootConsoleCommand("exts", "Manage extensions", this);
   514 	g_ShareSys.AddInterface(NULL, this);
   515 }
   516 
   517 void CExtensionManager::OnSourceModShutdown()
   518 {
   519 	rootmenu->RemoveRootConsoleCommand("exts", this);
   520 	pluginsys->RemovePluginsListener(this);
   521 	g_ShareSys.DestroyIdentType(g_ExtType);
   522 }
   523 
   524 void CExtensionManager::Shutdown()
   525 {
   526 	List<CExtension *>::iterator iter;
   527 
   528 	while ((iter = m_Libs.begin()) != m_Libs.end())
   529 	{
   530 		UnloadExtension((*iter));
   531 	}
   532 }
   533 
   534 void CExtensionManager::TryAutoload()
   535 {
   536 	char path[PLATFORM_MAX_PATH];
   537 
   538 	g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions");
   539 
   540 	IDirectory *pDir = libsys->OpenDirectory(path);
   541 	if (!pDir)
   542 	{
   543 		return;
   544 	}
   545 
   546 	const char *lfile;
   547 	size_t len;
   548 	while (pDir->MoreFiles())
   549 	{
   550 		if (pDir->IsEntryDirectory())
   551 		{
   552 			pDir->NextEntry();
   553 			continue;
   554 		}
   555 
   556 		lfile = pDir->GetEntryName();
   557 		len = strlen(lfile);
   558 		if (len <= 9) /* size of ".autoload" */
   559 		{
   560 			pDir->NextEntry();
   561 			continue;
   562 		}
   563 
   564 		if (strcmp(&lfile[len - 9], ".autoload") != 0)
   565 		{
   566 			pDir->NextEntry();
   567 			continue;
   568 		}
   569 
   570 		char file[PLATFORM_MAX_PATH];
   571 		len = smcore.Format(file, sizeof(file), "%s", lfile);
   572 		strcpy(&file[len - 9], ".ext");
   573 
   574 		LoadAutoExtension(file);
   575 		
   576 		pDir->NextEntry();
   577 	}
   578 }
   579 
   580 IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOnMissing)
   581 {
   582 	/* Remove platform extension if it's there. Compat hack. */
   583 	const char *ext = libsys->GetFileExtension(path);
   584 	if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
   585 	{
   586 		char path2[PLATFORM_MAX_PATH];
   587 		smcore.Format(path2, sizeof(path2), "%s", path);
   588 		path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
   589 		return LoadAutoExtension(path2, bErrorOnMissing);
   590 	}
   591 
   592 	IExtension *pAlready;
   593 	if ((pAlready=FindExtensionByFile(path)) != NULL)
   594 	{
   595 		return pAlready;
   596 	}
   597 
   598 	char error[256];
   599 	CExtension *p = new CLocalExtension(path);
   600 
   601 	/* We put us in the list beforehand so extensions that check for each other
   602 	 * won't recursively load each other.
   603 	 */
   604 	m_Libs.push_back(p);
   605 
   606 	if (!p->Load(error, sizeof(error)) || !p->IsLoaded())
   607 	{
   608 		if (bErrorOnMissing || libsys->IsPathFile(p->GetPath()))
   609 		{
   610 			smcore.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
   611 		}
   612 		
   613 		p->SetError(error);
   614 	}
   615 
   616 	return p;
   617 }
   618 
   619 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
   620 {
   621 	List<CExtension *>::iterator iter;
   622 	CExtension *pExt;
   623 
   624 	/* Chomp off the path */
   625 	char lookup[PLATFORM_MAX_PATH];
   626 	libsys->GetFileFromPath(lookup, sizeof(lookup), file);
   627 
   628 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   629 	{
   630 		pExt = (*iter);
   631 		if (pExt->IsSameFile(lookup))
   632 		{
   633 			return pExt;
   634 		}
   635 	}
   636 
   637 	return NULL;
   638 }
   639 
   640 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
   641 {
   642 	List<CExtension *>::iterator iter;
   643 	CExtension *pExt;
   644 	IExtensionInterface *pAPI;
   645 	const char *name;
   646 
   647 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   648 	{
   649 		pExt = (*iter);
   650 		if (!pExt->IsLoaded())
   651 		{
   652 			continue;
   653 		}
   654 		if ((pAPI = pExt->GetAPI()) == NULL)
   655 		{
   656 			continue;
   657 		}
   658 		name = pAPI->GetExtensionName();
   659 		if (!name)
   660 		{
   661 			continue;
   662 		}
   663 		if (strcmp(name, ext) == 0)
   664 		{
   665 			return pExt;
   666 		}
   667 	}
   668 
   669 	return NULL;
   670 }
   671 
   672 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
   673 {
   674 	/* Remove platform extension if it's there. Compat hack. */
   675 	const char *ext = libsys->GetFileExtension(file);
   676 	if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
   677 	{
   678 		char path2[PLATFORM_MAX_PATH];
   679 		smcore.Format(path2, sizeof(path2), "%s", file);
   680 		path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
   681 		return LoadExtension(path2, error, maxlength);
   682 	}
   683 
   684 	IExtension *pAlready;
   685 	if ((pAlready=FindExtensionByFile(file)) != NULL)
   686 	{
   687 		return pAlready;
   688 	}
   689 
   690 	CExtension *pExt = new CLocalExtension(file);
   691 
   692 	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
   693 	{
   694 		pExt->Unload();
   695 		delete pExt;
   696 		return NULL;
   697 	}
   698 
   699 	/* :TODO: do QueryRunning check if the map is loaded */
   700 
   701 	m_Libs.push_back(pExt);
   702 
   703 	return pExt;
   704 }
   705 
   706 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
   707 {
   708 	CExtension *pExt = (CExtension *)pRequester;
   709 	CExtension *pOwner = (CExtension *)pInfo->owner;
   710 
   711 	pExt->AddDependency(pInfo);
   712 
   713 	IExtensionInterface *pAPI = pExt->GetAPI();
   714 	if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
   715 	{
   716 		pOwner->AddChildDependent(pExt, pInfo->iface);
   717 	}
   718 }
   719 
   720 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
   721 {
   722 	CExtension *pExt = (CExtension *)ext;
   723 	CExtension *pOwner = GetExtensionFromIdent(other);
   724 
   725 	IfaceInfo info;
   726 
   727 	info.iface = (SMInterface *)iface;
   728 	info.owner = pOwner;
   729 
   730 	pExt->AddDependency(&info);
   731 	pOwner->AddChildDependent(pExt, (SMInterface *)iface);
   732 }
   733 
   734 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
   735 {
   736 	CExtension *pExt = (CExtension *)pOwner;
   737 
   738 	pExt->AddInterface(pInterface);
   739 }
   740 
   741 void CExtensionManager::BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin)
   742 {
   743 	CExtension *pExt = (CExtension *)pParent;
   744 
   745 	pExt->AddPlugin(static_cast<CPlugin *>(pPlugin));
   746 }
   747 
   748 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
   749 {
   750 	List<CExtension *>::iterator iter;
   751 
   752 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   753 	{
   754 		(*iter)->DropRefsTo(static_cast<CPlugin *>(plugin));
   755 	}
   756 }
   757 
   758 CExtension *CExtensionManager::FindByOrder(unsigned int num)
   759 {
   760 	if (num < 1 || num > m_Libs.size())
   761 	{
   762 		return NULL;
   763 	}
   764 
   765 	List<CExtension *>::iterator iter = m_Libs.begin();
   766 
   767 	while (iter != m_Libs.end())
   768 	{
   769 		if (--num == 0)
   770 		{
   771 			return (*iter);
   772 		}
   773 		iter++;
   774 	}
   775 
   776 	return NULL;
   777 }
   778 
   779 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
   780 {
   781 	if (!_pExt)
   782 		return false;
   783 
   784 	CExtension *pExt = (CExtension *)_pExt;
   785 
   786 	if (m_Libs.find(pExt) == m_Libs.end())
   787 		return false;
   788 
   789 	/* Tell it to unload */
   790 	if (pExt->IsLoaded())
   791 		pExt->GetAPI()->OnExtensionUnload();
   792 
   793 	// Remove us from internal lists. Note that because we do this, it's
   794 	// possible that our extension could be added back if another plugin
   795 	// tries to load during this process. If we ever find this to happen,
   796 	// we can just block plugin loading.
   797 	g_ShareSys.RemoveInterfaces(_pExt);
   798 	m_Libs.remove(pExt);
   799 
   800 	List<CExtension *> UnloadQueue;
   801 
   802 	/* Handle dependencies */
   803 	if (pExt->IsLoaded())
   804 	{
   805 		/* Unload any dependent plugins */
   806 		List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
   807 		while (p_iter != pExt->m_Dependents.end())
   808 		{
   809 			/* We have to manually unlink ourselves here, since we're no longer being managed */
   810 			scripts->UnloadPlugin((*p_iter));
   811 			p_iter = pExt->m_Dependents.erase(p_iter);
   812 		}
   813 
   814 		List<String>::iterator s_iter;
   815 		for (s_iter = pExt->m_Libraries.begin();
   816 			 s_iter != pExt->m_Libraries.end();
   817 			 s_iter++)
   818 		{
   819 			scripts->OnLibraryAction((*s_iter).c_str(), LibraryAction_Removed);
   820 		}
   821 
   822 		/* Notify and/or unload all dependencies */
   823 		List<CExtension *>::iterator c_iter;
   824 		CExtension *pDep;
   825 		IExtensionInterface *pAPI;
   826 		for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
   827 		{
   828 			pDep = (*c_iter);
   829 			if ((pAPI=pDep->GetAPI()) == NULL)
   830 				continue;
   831 			if (pDep == pExt)
   832 				continue;
   833 			/* Now, get its dependency list */
   834 			bool dropped = false;
   835 			List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
   836 			while (i_iter != pDep->m_Deps.end())
   837 			{
   838 				if ((*i_iter).owner == _pExt)
   839 				{
   840 					if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
   841 					{
   842 						if (!dropped)
   843 						{
   844 							dropped = true;
   845 							UnloadQueue.push_back(pDep);
   846 						}
   847 					}
   848 					pAPI->NotifyInterfaceDrop((*i_iter).iface);
   849 					i_iter = pDep->m_Deps.erase(i_iter);
   850 				}
   851 				else
   852 				{
   853 					i_iter++;
   854 				}
   855 			}
   856 			/* Flush out any back references to this plugin */
   857 			i_iter = pDep->m_ChildDeps.begin();
   858 			while (i_iter != pDep->m_ChildDeps.end())
   859 			{
   860 				if ((*i_iter).owner == pExt)
   861 					i_iter = pDep->m_ChildDeps.erase(i_iter);
   862 				else
   863 					i_iter++;
   864 			}
   865 		}
   866 
   867 		/* Unbind our natives from Core */
   868 		pExt->DropEverything();
   869 	}
   870 
   871 	IdentityToken_t *pIdentity;
   872 	if ((pIdentity = pExt->GetIdentity()) != NULL)
   873 	{
   874 		SMGlobalClass *glob = SMGlobalClass::head;
   875 		while (glob)
   876 		{
   877 			glob->OnSourceModIdentityDropped(pIdentity);
   878 			glob = glob->m_pGlobalClassNext;
   879 		}
   880 	}
   881 
   882 	// Everything has been informed that we're unloading, so give the
   883 	// extension one last notification.
   884 	if (pExt->IsLoaded() && pExt->GetAPI()->GetExtensionVersion() >= 7)
   885 		pExt->GetAPI()->OnDependenciesDropped();
   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