Pad plugin ID based on the total plugin count (#1027)

Closes #994
This commit is contained in:
MartLegion 2019-06-16 21:06:03 -03:00 committed by Asher Baker
parent 14227c04b8
commit e47c1a840a

View File

@ -1701,6 +1701,9 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
char buffer[256]; char buffer[256];
unsigned int id = 1; unsigned int id = 1;
int plnum = GetPluginCount(); int plnum = GetPluginCount();
char plstr[10];
ke::SafeSprintf(plstr, sizeof(plstr), "%d", plnum);
int plpadding = strlen(plstr);
if (!plnum) if (!plnum)
{ {
@ -1709,7 +1712,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
} }
else else
{ {
rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", GetPluginCount(), (plnum > 1) ? "s" : ""); rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", plnum, (plnum > 1) ? "s" : "");
} }
ke::LinkedList<CPlugin *> fail_list; ke::LinkedList<CPlugin *> fail_list;
@ -1721,14 +1724,14 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
const sm_plugininfo_t *info = pl->GetPublicInfo(); const sm_plugininfo_t *info = pl->GetPublicInfo();
if (pl->GetStatus() != Plugin_Running && !pl->IsSilentlyFailed()) if (pl->GetStatus() != Plugin_Running && !pl->IsSilentlyFailed())
{ {
len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d <%s>", id, GetStatusText(pl->GetDisplayStatus())); len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d <%s>", plpadding, id, GetStatusText(pl->GetDisplayStatus()));
/* Plugin has failed to load. */ /* Plugin has failed to load. */
fail_list.append(pl); fail_list.append(pl);
} }
else else
{ {
len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d", id); len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d", plpadding, id);
} }
if (pl->GetStatus() < Plugin_Created || pl->GetStatus() == Plugin_Evicted) if (pl->GetStatus() < Plugin_Created || pl->GetStatus() == Plugin_Evicted)
{ {
@ -1958,11 +1961,11 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
if (IPluginRuntime *runtime = pl->GetRuntime()) { if (IPluginRuntime *runtime = pl->GetRuntime()) {
unsigned char *pCodeHash = runtime->GetCodeHash(); unsigned char *pCodeHash = runtime->GetCodeHash();
unsigned char *pDataHash = runtime->GetDataHash(); unsigned char *pDataHash = runtime->GetDataHash();
char combinedHash[33]; char combinedHash[33];
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]); ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]);
rootmenu->ConsolePrint(" Hash: %s", combinedHash); rootmenu->ConsolePrint(" Hash: %s", combinedHash);
} }
} else { } else {
@ -2090,7 +2093,7 @@ void CPluginManager::ReloadPluginImpl(int id, const char filename[], PluginType
char error[128]; char error[128];
bool wasloaded; bool wasloaded;
IPlugin *newpl = LoadPlugin(filename, true, ptype, error, sizeof(error), &wasloaded); IPlugin *newpl = LoadPlugin(filename, true, ptype, error, sizeof(error), &wasloaded);
if (!newpl) if (!newpl)
{ {
rootmenu->ConsolePrint("[SM] Plugin %s failed to reload: %s.", filename, error); rootmenu->ConsolePrint("[SM] Plugin %s failed to reload: %s.", filename, error);
return; return;