core/systems/ExtensionSys.cpp
changeset 310 1efceafbda26
parent 305 59ef1afbe958
child 311 31192ed0fe13
     1.1 --- a/core/systems/ExtensionSys.cpp	Wed Jan 17 18:22:00 2007 +0000
     1.2 +++ b/core/systems/ExtensionSys.cpp	Thu Jan 18 00:17:36 2007 +0000
     1.3 @@ -4,6 +4,7 @@
     1.4  #include "CLogger.h"
     1.5  #include "sourcemm_api.h"
     1.6  #include "PluginSys.h"
     1.7 +#include "sm_srvcmds.h"
     1.8  
     1.9  CExtensionManager g_Extensions;
    1.10  IdentityType_t g_ExtType;
    1.11 @@ -209,10 +210,12 @@
    1.12  {
    1.13  	g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
    1.14  	g_PluginSys.AddPluginsListener(this);
    1.15 +	g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
    1.16  }
    1.17  
    1.18  void CExtensionManager::OnSourceModShutdown()
    1.19  {
    1.20 +	g_RootMenu.RemoveRootConsoleCommand("exts", this);
    1.21  	g_PluginSys.RemovePluginsListener(this);
    1.22  	g_ShareSys.DestroyIdentType(g_ExtType);
    1.23  }
    1.24 @@ -418,3 +421,113 @@
    1.25  
    1.26  	return true;
    1.27  }
    1.28 +
    1.29 +void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
    1.30 +{
    1.31 +	if (argcount >= 3)
    1.32 +	{
    1.33 +		const char *cmd = g_RootMenu.GetArgument(2);
    1.34 +		if (strcmp(cmd, "list") == 0)
    1.35 +		{
    1.36 +			List<CExtension *>::iterator iter;
    1.37 +			CExtension *pExt;
    1.38 +			unsigned int num = 1;
    1.39 +			switch (m_Libs.size())
    1.40 +			{
    1.41 +			case 1:
    1.42 +				{
    1.43 +					g_RootMenu.ConsolePrint("[SM] Displaying 1 extension:");
    1.44 +					break;
    1.45 +				}
    1.46 +			case 0:
    1.47 +				{
    1.48 +					g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
    1.49 +					break;
    1.50 +				}
    1.51 +			default:
    1.52 +				{
    1.53 +					g_RootMenu.ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
    1.54 +					break;
    1.55 +				}
    1.56 +			}
    1.57 +			for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++,num++)
    1.58 +			{
    1.59 +				pExt = (*iter);
    1.60 +				if (pExt->IsLoaded())
    1.61 +				{
    1.62 +					IExtensionInterface *pAPI = pExt->GetAPI();
    1.63 +					const char *name = pAPI->GetExtensionName();
    1.64 +					const char *version = pAPI->GetExtensionVerString();
    1.65 +					const char *descr = pAPI->GetExtensionDescription();
    1.66 +					g_RootMenu.ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
    1.67 +				} else {
    1.68 +					g_RootMenu.ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
    1.69 +				}
    1.70 +			}
    1.71 +			return;
    1.72 +		} else if (strcmp(cmd, "info") == 0) {
    1.73 +			if (argcount < 4)
    1.74 +			{
    1.75 +				g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
    1.76 +				return;
    1.77 +			}
    1.78 +
    1.79 +			const char *sId = g_RootMenu.GetArgument(3);
    1.80 +			unsigned int id = atoi(sId);
    1.81 +			if (id <= 0)
    1.82 +			{
    1.83 +				g_RootMenu.ConsolePrint("[SM] Usage: sm info <#>");
    1.84 +				return;
    1.85 +			}
    1.86 +
    1.87 +			if (m_Libs.size() == 0)
    1.88 +			{
    1.89 +				g_RootMenu.ConsolePrint("[SM] No extensions are loaded.");
    1.90 +				return;
    1.91 +			}
    1.92 +
    1.93 +			if (id > m_Libs.size())
    1.94 +			{
    1.95 +				g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
    1.96 +				return;
    1.97 +			}
    1.98 +
    1.99 +			List<CExtension *>::iterator iter = m_Libs.begin();
   1.100 +			CExtension *pExt = NULL;
   1.101 +			while (iter != m_Libs.end())
   1.102 +			{
   1.103 +				if (--id == 0)
   1.104 +				{
   1.105 +					pExt = (*iter);
   1.106 +					break;
   1.107 +				}
   1.108 +				iter++;
   1.109 +			}
   1.110 +			/* This should never happen */
   1.111 +			if (!pExt)
   1.112 +			{
   1.113 +				g_RootMenu.ConsolePrint("[SM] No extension was found with id %d.", id);
   1.114 +				return;
   1.115 +			}
   1.116 +
   1.117 +			if (!pExt->IsLoaded())
   1.118 +			{
   1.119 +				g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
   1.120 +				g_RootMenu.ConsolePrint(" Loaded: No (%s)", pExt->m_Error.c_str());
   1.121 +			} else {
   1.122 +				IExtensionInterface *pAPI = pExt->GetAPI();
   1.123 +				g_RootMenu.ConsolePrint(" File: %s", pExt->GetFilename());
   1.124 +				g_RootMenu.ConsolePrint(" Loaded: Yes (version %s)", pAPI->GetExtensionVerString());
   1.125 +				g_RootMenu.ConsolePrint(" Name: %s (%s)", pAPI->GetExtensionName(), pAPI->GetExtensionDescription());
   1.126 +				g_RootMenu.ConsolePrint(" Author: %s (%s)", pAPI->GetExtensionAuthor(), pAPI->GetExtensionURL());
   1.127 +				g_RootMenu.ConsolePrint(" Binary info: API version %d (compiled %s)", pAPI->GetExtensionVersion(), pAPI->GetExtensionDateString());
   1.128 +				g_RootMenu.ConsolePrint(" Metamod enabled: %s", pAPI->IsMetamodExtension() ? "yes" : "no");
   1.129 +			}
   1.130 +			return;
   1.131 +		}
   1.132 +	}
   1.133 +
   1.134 +	g_RootMenu.ConsolePrint("SourceMod Extensions Menu:");
   1.135 +	g_RootMenu.DrawGenericOption("info", "Extra extension information");
   1.136 +	g_RootMenu.DrawGenericOption("list", "List extensions");
   1.137 +}