core/logic/ExtensionSys.cpp
author David Anderson <dvander@alliedmods.net>
Thu Aug 22 14:05:44 2013 -0700 (2013-08-22)
changeset 4029 cf8bdfcf6503
parent 4005 617def4b1770
child 4045 2891bbc5932b
permissions -rw-r--r--
Fix various problems with unloading ClientPrefs and SourceMod (bug 5874, 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)
   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);
   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 		smcore.LogError("[SM] Unable to load extension \"%s\": %s", path, error);
   609 		p->SetError(error);
   610 	}
   611 
   612 	return p;
   613 }
   614 
   615 IExtension *CExtensionManager::FindExtensionByFile(const char *file)
   616 {
   617 	List<CExtension *>::iterator iter;
   618 	CExtension *pExt;
   619 
   620 	/* Chomp off the path */
   621 	char lookup[PLATFORM_MAX_PATH];
   622 	libsys->GetFileFromPath(lookup, sizeof(lookup), file);
   623 
   624 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   625 	{
   626 		pExt = (*iter);
   627 		if (pExt->IsSameFile(lookup))
   628 		{
   629 			return pExt;
   630 		}
   631 	}
   632 
   633 	return NULL;
   634 }
   635 
   636 IExtension *CExtensionManager::FindExtensionByName(const char *ext)
   637 {
   638 	List<CExtension *>::iterator iter;
   639 	CExtension *pExt;
   640 	IExtensionInterface *pAPI;
   641 	const char *name;
   642 
   643 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   644 	{
   645 		pExt = (*iter);
   646 		if (!pExt->IsLoaded())
   647 		{
   648 			continue;
   649 		}
   650 		if ((pAPI = pExt->GetAPI()) == NULL)
   651 		{
   652 			continue;
   653 		}
   654 		name = pAPI->GetExtensionName();
   655 		if (!name)
   656 		{
   657 			continue;
   658 		}
   659 		if (strcmp(name, ext) == 0)
   660 		{
   661 			return pExt;
   662 		}
   663 	}
   664 
   665 	return NULL;
   666 }
   667 
   668 IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
   669 {
   670 	/* Remove platform extension if it's there. Compat hack. */
   671 	const char *ext = libsys->GetFileExtension(file);
   672 	if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
   673 	{
   674 		char path2[PLATFORM_MAX_PATH];
   675 		smcore.Format(path2, sizeof(path2), "%s", file);
   676 		path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
   677 		return LoadExtension(path2, error, maxlength);
   678 	}
   679 
   680 	IExtension *pAlready;
   681 	if ((pAlready=FindExtensionByFile(file)) != NULL)
   682 	{
   683 		return pAlready;
   684 	}
   685 
   686 	CExtension *pExt = new CLocalExtension(file);
   687 
   688 	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
   689 	{
   690 		pExt->Unload();
   691 		delete pExt;
   692 		return NULL;
   693 	}
   694 
   695 	/* :TODO: do QueryRunning check if the map is loaded */
   696 
   697 	m_Libs.push_back(pExt);
   698 
   699 	return pExt;
   700 }
   701 
   702 void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
   703 {
   704 	CExtension *pExt = (CExtension *)pRequester;
   705 	CExtension *pOwner = (CExtension *)pInfo->owner;
   706 
   707 	pExt->AddDependency(pInfo);
   708 
   709 	IExtensionInterface *pAPI = pExt->GetAPI();
   710 	if (pAPI && !pAPI->QueryInterfaceDrop(pInfo->iface))
   711 	{
   712 		pOwner->AddChildDependent(pExt, pInfo->iface);
   713 	}
   714 }
   715 
   716 void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
   717 {
   718 	CExtension *pExt = (CExtension *)ext;
   719 	CExtension *pOwner = GetExtensionFromIdent(other);
   720 
   721 	IfaceInfo info;
   722 
   723 	info.iface = (SMInterface *)iface;
   724 	info.owner = pOwner;
   725 
   726 	pExt->AddDependency(&info);
   727 	pOwner->AddChildDependent(pExt, (SMInterface *)iface);
   728 }
   729 
   730 void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
   731 {
   732 	CExtension *pExt = (CExtension *)pOwner;
   733 
   734 	pExt->AddInterface(pInterface);
   735 }
   736 
   737 void CExtensionManager::BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin)
   738 {
   739 	CExtension *pExt = (CExtension *)pParent;
   740 
   741 	pExt->AddPlugin(static_cast<CPlugin *>(pPlugin));
   742 }
   743 
   744 void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
   745 {
   746 	List<CExtension *>::iterator iter;
   747 
   748 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   749 	{
   750 		(*iter)->DropRefsTo(static_cast<CPlugin *>(plugin));
   751 	}
   752 }
   753 
   754 CExtension *CExtensionManager::FindByOrder(unsigned int num)
   755 {
   756 	if (num < 1 || num > m_Libs.size())
   757 	{
   758 		return NULL;
   759 	}
   760 
   761 	List<CExtension *>::iterator iter = m_Libs.begin();
   762 
   763 	while (iter != m_Libs.end())
   764 	{
   765 		if (--num == 0)
   766 		{
   767 			return (*iter);
   768 		}
   769 		iter++;
   770 	}
   771 
   772 	return NULL;
   773 }
   774 
   775 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
   776 {
   777 	if (!_pExt)
   778 		return false;
   779 
   780 	CExtension *pExt = (CExtension *)_pExt;
   781 
   782 	if (m_Libs.find(pExt) == m_Libs.end())
   783 		return false;
   784 
   785 	/* Tell it to unload */
   786 	if (pExt->IsLoaded())
   787 		pExt->GetAPI()->OnExtensionUnload();
   788 
   789 	// Remove us from internal lists. Note that because we do this, it's
   790 	// possible that our extension could be added back if another plugin
   791 	// tries to load during this process. If we ever find this to happen,
   792 	// we can just block plugin loading.
   793 	g_ShareSys.RemoveInterfaces(_pExt);
   794 	m_Libs.remove(pExt);
   795 
   796 	List<CExtension *> UnloadQueue;
   797 
   798 	/* Handle dependencies */
   799 	if (pExt->IsLoaded())
   800 	{
   801 		/* Unload any dependent plugins */
   802 		List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
   803 		while (p_iter != pExt->m_Dependents.end())
   804 		{
   805 			/* We have to manually unlink ourselves here, since we're no longer being managed */
   806 			scripts->UnloadPlugin((*p_iter));
   807 			p_iter = pExt->m_Dependents.erase(p_iter);
   808 		}
   809 
   810 		List<String>::iterator s_iter;
   811 		for (s_iter = pExt->m_Libraries.begin();
   812 			 s_iter != pExt->m_Libraries.end();
   813 			 s_iter++)
   814 		{
   815 			scripts->OnLibraryAction((*s_iter).c_str(), LibraryAction_Removed);
   816 		}
   817 
   818 		/* Notify and/or unload all dependencies */
   819 		List<CExtension *>::iterator c_iter;
   820 		CExtension *pDep;
   821 		IExtensionInterface *pAPI;
   822 		for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
   823 		{
   824 			pDep = (*c_iter);
   825 			if ((pAPI=pDep->GetAPI()) == NULL)
   826 				continue;
   827 			if (pDep == pExt)
   828 				continue;
   829 			/* Now, get its dependency list */
   830 			bool dropped = false;
   831 			List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
   832 			while (i_iter != pDep->m_Deps.end())
   833 			{
   834 				if ((*i_iter).owner == _pExt)
   835 				{
   836 					if (!pAPI->QueryInterfaceDrop((*i_iter).iface))
   837 					{
   838 						if (!dropped)
   839 						{
   840 							dropped = true;
   841 							UnloadQueue.push_back(pDep);
   842 						}
   843 					}
   844 					pAPI->NotifyInterfaceDrop((*i_iter).iface);
   845 					i_iter = pDep->m_Deps.erase(i_iter);
   846 				}
   847 				else
   848 				{
   849 					i_iter++;
   850 				}
   851 			}
   852 			/* Flush out any back references to this plugin */
   853 			i_iter = pDep->m_ChildDeps.begin();
   854 			while (i_iter != pDep->m_ChildDeps.end())
   855 			{
   856 				if ((*i_iter).owner == pExt)
   857 					i_iter = pDep->m_ChildDeps.erase(i_iter);
   858 				else
   859 					i_iter++;
   860 			}
   861 		}
   862 
   863 		/* Unbind our natives from Core */
   864 		pExt->DropEverything();
   865 	}
   866 
   867 	IdentityToken_t *pIdentity;
   868 	if ((pIdentity = pExt->GetIdentity()) != NULL)
   869 	{
   870 		SMGlobalClass *glob = SMGlobalClass::head;
   871 		while (glob)
   872 		{
   873 			glob->OnSourceModIdentityDropped(pIdentity);
   874 			glob = glob->m_pGlobalClassNext;
   875 		}
   876 	}
   877 
   878 	// Everything has been informed that we're unloading, so give the
   879 	// extension one last notification.
   880 	if (pExt->IsLoaded() && pExt->GetAPI()->GetExtensionVersion() >= 7)
   881 		pExt->GetAPI()->OnDependenciesDropped();
   882 
   883 	pExt->Unload();
   884 	delete pExt;
   885 
   886 	List<CExtension *>::iterator iter;
   887 	for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
   888 	{
   889 		/* NOTE: This is safe because the unload function backs out of anything not present */
   890 		UnloadExtension((*iter));
   891 	}
   892 
   893 	return true;
   894 }
   895 
   896 void CExtensionManager::MarkAllLoaded()
   897 {
   898 	List<CExtension *>::iterator iter;
   899 	CExtension *pExt;
   900 
   901 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
   902 	{
   903 		pExt = (*iter);
   904 		if (!pExt->IsLoaded())
   905 		{
   906 			continue;
   907 		}
   908 		if (pExt->m_bFullyLoaded)
   909 		{
   910 			continue;
   911 		}
   912 		pExt->MarkAllLoaded();
   913 	}
   914 }
   915 
   916 void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
   917 {
   918 	/* This function doesn't really need to do anything now.  We make sure the 
   919 	 * other extension is loaded, but handling of dependencies is really done 
   920 	 * by the interface fetcher.
   921 	 */
   922 	if (required || autoload)
   923 	{
   924 		LoadAutoExtension(file);
   925 	}
   926 }
   927 
   928 void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
   929 {
   930 	int argcount = smcore.Argc(command);
   931 	if (argcount >= 3)
   932 	{
   933 		const char *cmd = smcore.Arg(command, 2);
   934 		if (strcmp(cmd, "list") == 0)
   935 		{
   936 			List<CExtension *>::iterator iter;
   937 			CExtension *pExt;
   938 			unsigned int num = 1;
   939 			switch (m_Libs.size())
   940 			{
   941 			case 1:
   942 				{
   943 					rootmenu->ConsolePrint("[SM] Displaying 1 extension:");
   944 					break;
   945 				}
   946 			case 0:
   947 				{
   948 					rootmenu->ConsolePrint("[SM] No extensions are loaded.");
   949 					break;
   950 				}
   951 			default:
   952 				{
   953 					rootmenu->ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
   954 					break;
   955 				}
   956 			}
   957 			for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
   958 			{
   959 				pExt = (*iter);
   960 				if (pExt->IsLoaded())
   961 				{
   962 					char error[255];
   963 					if (!pExt->IsRunning(error, sizeof(error)))
   964 					{
   965 						rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), error);
   966 					}
   967 					else
   968 					{
   969 						IExtensionInterface *pAPI = pExt->GetAPI();
   970 						const char *name = pAPI->GetExtensionName();
   971 						const char *version = pAPI->GetExtensionVerString();
   972 						const char *descr = pAPI->GetExtensionDescription();
   973 						rootmenu->ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
   974 					}
   975 				} else {
   976 					rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
   977 				}
   978 			}
   979 			return;
   980 		}
   981 		else if (strcmp(cmd, "load") == 0)
   982 		{
   983 			if (argcount < 4)
   984 			{
   985 				rootmenu->ConsolePrint("[SM] Usage: sm exts load <file>");
   986 				return;
   987 			}
   988 
   989 			const char *filename = smcore.Arg(command, 3);
   990 			char path[PLATFORM_MAX_PATH];
   991 			char error[256];
   992 
   993 			smcore.Format(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "",
   994 				!strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : "");
   995 			
   996 			if (FindExtensionByFile(path) != NULL)
   997 			{
   998 				rootmenu->ConsolePrint("[SM] Extension %s is already loaded.", path);
   999 				return;
  1000 			}
  1001 			
  1002 			if (LoadExtension(path, error, sizeof(error)))
  1003 			{
  1004 				rootmenu->ConsolePrint("[SM] Loaded extension %s successfully.", path);
  1005 			} else
  1006 			{
  1007 				rootmenu->ConsolePrint("[SM] Extension %s failed to load: %s", path, error);
  1008 			}
  1009 			
  1010 			return;
  1011 		}
  1012 		else if (strcmp(cmd, "info") == 0)
  1013 		{
  1014 			if (argcount < 4)
  1015 			{
  1016 				rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>");
  1017 				return;
  1018 			}
  1019 
  1020 			const char *sId = smcore.Arg(command, 3);
  1021 			unsigned int id = atoi(sId);
  1022 			if (id <= 0)
  1023 			{
  1024 				rootmenu->ConsolePrint("[SM] Usage: sm exts info <#>");
  1025 				return;
  1026 			}
  1027 
  1028 			if (m_Libs.size() == 0)
  1029 			{
  1030 				rootmenu->ConsolePrint("[SM] No extensions are loaded.");
  1031 				return;
  1032 			}
  1033 
  1034 			if (id > m_Libs.size())
  1035 			{
  1036 				rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id);
  1037 				return;
  1038 			}
  1039 
  1040 			List<CExtension *>::iterator iter = m_Libs.begin();
  1041 			CExtension *pExt = NULL;
  1042 			while (iter != m_Libs.end())
  1043 			{
  1044 				if (--id == 0)
  1045 				{
  1046 					pExt = (*iter);
  1047 					break;
  1048 				}
  1049 				iter++;
  1050 			}
  1051 			/* This should never happen */
  1052 			if (!pExt)
  1053 			{
  1054 				rootmenu->ConsolePrint("[SM] No extension was found with id %d.", id);
  1055 				return;
  1056 			}
  1057 
  1058 			if (!pExt->IsLoaded())
  1059 			{
  1060 				rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1061 				rootmenu->ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
  1062 			}
  1063 			else
  1064 			{
  1065 				char error[255];
  1066 				if (!pExt->IsRunning(error, sizeof(error)))
  1067 				{
  1068 					rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1069 					rootmenu->ConsolePrint(" Loaded: Yes");
  1070 					rootmenu->ConsolePrint(" Running: No (%s)", error);
  1071 				}
  1072 				else
  1073 				{
  1074 					IExtensionInterface *pAPI = pExt->GetAPI();
  1075 					rootmenu->ConsolePrint(" File: %s", pExt->GetFilename());
  1076 					rootmenu->ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
  1077 					rootmenu->ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
  1078 					rootmenu->ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
  1079 					rootmenu->ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
  1080 
  1081 					if (pExt->IsExternal())
  1082 					{
  1083 						rootmenu->ConsolePrint(" Method: Loaded by Metamod:Source, attached to SourceMod");
  1084 					}
  1085 					else if (pAPI->IsMetamodExtension())
  1086 					{
  1087 						rootmenu->ConsolePrint(" Method: Loaded by SourceMod, attached to Metamod:Source");
  1088 					}
  1089 					else
  1090 					{
  1091 						rootmenu->ConsolePrint(" Method: Loaded by SourceMod");
  1092 					}
  1093 				}
  1094 			}
  1095 			return;
  1096 		}
  1097 		else if (strcmp(cmd, "unload") == 0)
  1098 		{
  1099 			if (argcount < 4)
  1100 			{
  1101 				rootmenu->ConsolePrint("[SM] Usage: sm exts unload <#> [code]");
  1102 				return;
  1103 			}
  1104 
  1105 			const char *arg = smcore.Arg(command, 3);
  1106 			unsigned int num = atoi(arg);
  1107 			CExtension *pExt = FindByOrder(num);
  1108 
  1109 			if (!pExt)
  1110 			{
  1111 				rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num);
  1112 				return;
  1113 			}
  1114 
  1115 			if (argcount > 4 && pExt->unload_code)
  1116 			{
  1117 				const char *unload = smcore.Arg(command, 4);
  1118 				if (pExt->unload_code == (unsigned)atoi(unload))
  1119 				{
  1120 					char filename[PLATFORM_MAX_PATH];
  1121 					snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1122 					UnloadExtension(pExt);
  1123 					rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1124 				}
  1125 				else
  1126 				{
  1127 					rootmenu->ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
  1128 				}
  1129 				return;
  1130 			}
  1131 
  1132 			if (!pExt->IsLoaded() 
  1133 				|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
  1134 			{
  1135 				char filename[PLATFORM_MAX_PATH];
  1136 				snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1137 				UnloadExtension(pExt);
  1138 				rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
  1139 				return;
  1140 			}
  1141 			else
  1142 			{
  1143 				List<CPlugin *> plugins;
  1144 				if (pExt->m_ChildDeps.size())
  1145 				{
  1146 					rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
  1147 					List<CExtension *>::iterator iter;
  1148 					CExtension *pOther;
  1149 					/* Get list of all extensions */
  1150 					for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1151 					{
  1152 						List<IfaceInfo>::iterator i_iter;
  1153 						pOther = (*iter);
  1154 						if (!pOther->IsLoaded() || pOther == pExt)
  1155 						{
  1156 							continue;
  1157 						}
  1158 						/* Get their dependencies */
  1159 						for (i_iter=pOther->m_Deps.begin();
  1160 							 i_iter!=pOther->m_Deps.end();
  1161 							 i_iter++)
  1162 						{
  1163 							/* Is this dependency to us? */
  1164 							if ((*i_iter).owner != pExt)
  1165 							{
  1166 								continue;
  1167 							}
  1168 							/* Will our dependent care? */
  1169 							if (!pExt->GetAPI()->QueryInterfaceDrop((*i_iter).iface))
  1170 							{
  1171 								rootmenu->ConsolePrint(" -> %s", pExt->GetFilename());
  1172 								/* Add to plugin unload list */
  1173 								List<CPlugin *>::iterator p_iter;
  1174 								for (p_iter=pOther->m_Dependents.begin();
  1175 									 p_iter!=pOther->m_Dependents.end();
  1176 									 p_iter++)
  1177 								{
  1178 									if (plugins.find((*p_iter)) == plugins.end())
  1179 									{
  1180 										plugins.push_back((*p_iter));
  1181 									}
  1182 								}
  1183 							}
  1184 						}
  1185 					}
  1186 				}
  1187 				if (pExt->m_Dependents.size())
  1188 				{
  1189 					rootmenu->ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
  1190 					List<CPlugin *>::iterator iter;
  1191 					CPlugin *pPlugin;
  1192 					for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
  1193 					{
  1194 						pPlugin = (*iter);
  1195 						if (plugins.find(pPlugin) == plugins.end())
  1196 						{
  1197 							plugins.push_back(pPlugin);
  1198 						}
  1199 					}
  1200 					for (iter = plugins.begin(); iter != plugins.end(); iter++)
  1201 					{
  1202 						pPlugin = (*iter);
  1203 						rootmenu->ConsolePrint(" -> %s", pPlugin->GetFilename());
  1204 					}
  1205 				}
  1206 				srand(static_cast<int>(time(NULL)));
  1207 				pExt->unload_code = (rand() % 877) + 123;	//123 to 999
  1208 				rootmenu->ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
  1209 				rootmenu->ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
  1210 
  1211 				return;
  1212 			}
  1213 		}
  1214 		else if (strcmp(cmd, "reload") == 0)
  1215 		{
  1216 			if (argcount < 4)
  1217 			{
  1218 				rootmenu->ConsolePrint("[SM] Usage: sm exts reload <#>");
  1219 				return;
  1220 			}
  1221 			
  1222 			const char *arg = smcore.Arg(command, 3);
  1223 			unsigned int num = atoi(arg);
  1224 			CExtension *pExt = FindByOrder(num);
  1225 
  1226 			if (!pExt)
  1227 			{
  1228 				rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num);
  1229 				return;
  1230 			}
  1231 			
  1232 			if (pExt->IsLoaded())
  1233 			{
  1234 				char filename[PLATFORM_MAX_PATH];
  1235 				char error[255];
  1236 				
  1237 				snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
  1238 				
  1239 				if (pExt->Reload(error, sizeof(error)))
  1240 				{
  1241 					rootmenu->ConsolePrint("[SM] Extension %s is now reloaded.", filename);
  1242 				}
  1243 				else
  1244 				{
  1245 					rootmenu->ConsolePrint("[SM] Extension %s failed to reload: %s", filename, error);
  1246 				}
  1247 					
  1248 				return;
  1249 			} 
  1250 			else
  1251 			{
  1252 				rootmenu->ConsolePrint("[SM] Extension %s is not loaded.", pExt->GetFilename());
  1253 				
  1254 				return;
  1255 			}
  1256 			
  1257 		}
  1258 	}
  1259 
  1260 	rootmenu->ConsolePrint("SourceMod Extensions Menu:");
  1261 	rootmenu->DrawGenericOption("info", "Extra extension information");
  1262 	rootmenu->DrawGenericOption("list", "List extensions");
  1263 	rootmenu->DrawGenericOption("load", "Load an extension");
  1264 	rootmenu->DrawGenericOption("reload", "Reload an extension");
  1265 	rootmenu->DrawGenericOption("unload", "Unload an extension");
  1266 }
  1267 
  1268 CExtension *CExtensionManager::GetExtensionFromIdent(IdentityToken_t *ptr)
  1269 {
  1270 	if (ptr->type == g_ExtType)
  1271 	{
  1272 		return (CExtension *)(ptr->ptr);
  1273 	}
  1274 
  1275 	return NULL;
  1276 }
  1277 
  1278 CExtensionManager::CExtensionManager()
  1279 {
  1280 }
  1281 
  1282 CExtensionManager::~CExtensionManager()
  1283 {
  1284 }
  1285 
  1286 void CExtensionManager::AddLibrary(IExtension *pSource, const char *library)
  1287 {
  1288 	CExtension *pExt = (CExtension *)pSource;
  1289 	pExt->AddLibrary(library);
  1290 	scripts->OnLibraryAction(library, LibraryAction_Added);
  1291 }
  1292 
  1293 bool CExtensionManager::LibraryExists(const char *library)
  1294 {
  1295 	CExtension *pExt;
  1296 
  1297 	for (List<CExtension *>::iterator iter = m_Libs.begin();
  1298 		 iter != m_Libs.end();
  1299 		 iter++)
  1300 	{
  1301 		pExt = (*iter);
  1302 		for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
  1303 			 s_iter != pExt->m_Libraries.end();
  1304 			 s_iter++)
  1305 		{
  1306 			if ((*s_iter).compare(library) == 0)
  1307 			{
  1308 				return true;
  1309 			}
  1310 		}
  1311 	}
  1312 
  1313 	return false;
  1314 }
  1315 
  1316 IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
  1317 											const char *filepath,
  1318 											const char *filename,
  1319 											char *error,
  1320 											size_t maxlength)
  1321 {
  1322 	IExtension *pAlready;
  1323 	if ((pAlready=FindExtensionByFile(filename)) != NULL)
  1324 	{
  1325 		return pAlready;
  1326 	}
  1327 
  1328 	CExtension *pExt = new CRemoteExtension(pInterface, filename, filepath);
  1329 
  1330 	if (!pExt->Load(error, maxlength) || !pExt->IsLoaded())
  1331 	{
  1332 		pExt->Unload();
  1333 		delete pExt;
  1334 		return NULL;
  1335 	}
  1336 
  1337 	m_Libs.push_back(pExt);
  1338 
  1339 	return pExt;
  1340 }
  1341 
  1342 void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
  1343 {
  1344 	IExtensionInterface *pAPI;
  1345 	List<CExtension *>::iterator iter;
  1346 
  1347 	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
  1348 	{
  1349 		if ((pAPI = (*iter)->GetAPI()) == NULL)
  1350 		{
  1351 			continue;
  1352 		}
  1353 		if (pAPI->GetExtensionVersion() > 3)
  1354 		{
  1355 			pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax);
  1356 		}
  1357 	}
  1358 }
  1359 
  1360 const CVector<IExtension *> *CExtensionManager::ListExtensions()
  1361 {
  1362 	CVector<IExtension *> *list = new CVector<IExtension *>();
  1363 	for (List<CExtension *>::iterator iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
  1364 		list->push_back(*iter);
  1365 	return list;
  1366 }
  1367 
  1368 void CExtensionManager::FreeExtensionList(const CVector<IExtension *> *list)
  1369 {
  1370 	delete const_cast<CVector<IExtension *> *>(list);
  1371 }
  1372 
  1373 bool CLocalExtension::IsSameFile(const char *file)
  1374 {
  1375 	/* Only care about the shortened name. */
  1376 	return strcmp(file, m_File.c_str()) == 0;
  1377 }
  1378 
  1379 bool CRemoteExtension::IsSameFile(const char *file)
  1380 {
  1381 	/* :TODO: this could be better, but no one uses this API anyway. */
  1382 	return strcmp(file, m_Path.c_str()) == 0;
  1383 }
  1384