Implemented amb286 - .smx extension no longer required with "sm plugins load"
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40800
This commit is contained in:
parent
a0486eea8c
commit
515be43896
@ -322,3 +322,23 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...)
|
||||
|
||||
return mylen;
|
||||
}
|
||||
|
||||
const char *LibrarySystem::GetFileExtension(const char *filename)
|
||||
{
|
||||
size_t len = strlen(filename);
|
||||
|
||||
for (size_t i = len - 1; i >= 0; i--)
|
||||
{
|
||||
if (filename[i] == PLATFORM_SEP_CHAR || filename[i] == PLATFORM_SEP_ALTCHAR)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (filename[i] == '.' && i != len - 1)
|
||||
{
|
||||
return &filename[++i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ public:
|
||||
bool IsPathDirectory(const char *path);
|
||||
void GetPlatformError(char *error, size_t maxlength);
|
||||
size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
|
||||
const char *GetFileExtension(const char *filename);
|
||||
};
|
||||
|
||||
extern LibrarySystem g_LibSys;
|
||||
|
@ -1661,19 +1661,24 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
|
||||
char error[128];
|
||||
bool wasloaded;
|
||||
const char *filename = g_RootMenu.GetArgument(3);
|
||||
IPlugin *pl = LoadPlugin(filename, false, PluginType_MapUpdated, error, sizeof(error), &wasloaded);
|
||||
|
||||
char pluginfile[256];
|
||||
const char *ext = g_LibSys.GetFileExtension(filename) ? "" : ".smx";
|
||||
UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", filename, ext);
|
||||
|
||||
IPlugin *pl = LoadPlugin(pluginfile, false, PluginType_MapUpdated, error, sizeof(error), &wasloaded);
|
||||
|
||||
if (wasloaded)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("[SM] Plugin %s is already loaded.", filename);
|
||||
g_RootMenu.ConsolePrint("[SM] Plugin %s is already loaded.", pluginfile);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("[SM] Loaded plugin %s successfully.", filename);
|
||||
g_RootMenu.ConsolePrint("[SM] Loaded plugin %s successfully.", pluginfile);
|
||||
} else {
|
||||
g_RootMenu.ConsolePrint("[SM] Plugin %s failed to load: %s.", filename, error);
|
||||
g_RootMenu.ConsolePrint("[SM] Plugin %s failed to load: %s.", pluginfile, error);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -29,7 +29,7 @@
|
||||
namespace SourceMod
|
||||
{
|
||||
#define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys"
|
||||
#define SMINTERFACE_LIBRARYSYS_VERSION 1
|
||||
#define SMINTERFACE_LIBRARYSYS_VERSION 2
|
||||
|
||||
class ILibrary
|
||||
{
|
||||
@ -173,6 +173,14 @@ namespace SourceMod
|
||||
* @param ... Format string arguments.
|
||||
*/
|
||||
virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a pointer to the extension in a filename.
|
||||
*
|
||||
* @param filename Name of file from which the extension should be extracted.
|
||||
* @return Pointer to file extension.
|
||||
*/
|
||||
virtual const char *GetFileExtension(const char *filename) =0;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user