core/systems/PluginSys.cpp
changeset 1252 00865e7118b6
parent 1232 9f123e1a6c28
child 1330 ab94316bb52b
     1.1 --- a/core/systems/PluginSys.cpp	Thu Aug 02 17:33:10 2007 +0000
     1.2 +++ b/core/systems/PluginSys.cpp	Thu Aug 02 17:41:59 2007 +0000
     1.3 @@ -2002,22 +2002,34 @@
     1.4  		} else if (strcmp(cmd, "unload") == 0) {
     1.5  			if (argcount < 4)
     1.6  			{
     1.7 -				g_RootMenu.ConsolePrint("[SM] Usage: sm plugins unload <#>");
     1.8 +				g_RootMenu.ConsolePrint("[SM] Usage: sm plugins unload <#|file>");
     1.9  				return;
    1.10  			}
    1.11  
    1.12 -			int id = 1;
    1.13 -			int num = atoi(g_RootMenu.GetArgument(3));
    1.14 -			if (num < 1 || num > (int)GetPluginCount())
    1.15 +			CPlugin *pl;
    1.16 +			char *end;
    1.17 +			const char *arg = g_RootMenu.GetArgument(3);
    1.18 +			int id = strtol(arg, &end, 10);
    1.19 +
    1.20 +			if (*end == '\0')
    1.21  			{
    1.22 -				g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", num);
    1.23 -				return;
    1.24 -			}
    1.25 +				pl = GetPluginByOrder(id);
    1.26 +				if (!pl)
    1.27 +				{
    1.28 +					g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
    1.29 +					return;
    1.30 +				}
    1.31 +			} else {
    1.32 +				char pluginfile[256];
    1.33 +				const char *ext = g_LibSys.GetFileExtension(arg) ? "" : ".smx";
    1.34 +				UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", arg, ext);
    1.35  
    1.36 -			IPluginIterator *iter = GetPluginIterator();
    1.37 -			for (; iter->MorePlugins() && id<num; iter->NextPlugin(), id++)
    1.38 -				;
    1.39 -			IPlugin *pl = iter->GetPlugin();
    1.40 +				if (!sm_trie_retrieve(m_LoadLookup, pluginfile, (void **)&pl))
    1.41 +				{
    1.42 +					g_RootMenu.ConsolePrint("[SM] Plugin %s is not loaded.", pluginfile);
    1.43 +					return;
    1.44 +				}
    1.45 +			}
    1.46  
    1.47  			char name[PLATFORM_MAX_PATH];
    1.48  			const sm_plugininfo_t *info = pl->GetPublicInfo();
    1.49 @@ -2030,7 +2042,6 @@
    1.50  				g_RootMenu.ConsolePrint("[SM] Failed to unload plugin %s.", name);
    1.51  			}
    1.52  
    1.53 -			iter->Release();
    1.54  			return;
    1.55  		} else if (strcmp(cmd, "info") == 0) {
    1.56  			if (argcount < 4)