Skip to content

Commit e47c1a8

Browse files
Mart-Userasherkin
authored andcommitted
Pad plugin ID based on the total plugin count (#1027)
Closes #994
1 parent 14227c0 commit e47c1a8

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

core/logic/PluginSys.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,9 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
17011701
char buffer[256];
17021702
unsigned int id = 1;
17031703
int plnum = GetPluginCount();
1704+
char plstr[10];
1705+
ke::SafeSprintf(plstr, sizeof(plstr), "%d", plnum);
1706+
int plpadding = strlen(plstr);
17041707

17051708
if (!plnum)
17061709
{
@@ -1709,7 +1712,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
17091712
}
17101713
else
17111714
{
1712-
rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", GetPluginCount(), (plnum > 1) ? "s" : "");
1715+
rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", plnum, (plnum > 1) ? "s" : "");
17131716
}
17141717

17151718
ke::LinkedList<CPlugin *> fail_list;
@@ -1721,14 +1724,14 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
17211724
const sm_plugininfo_t *info = pl->GetPublicInfo();
17221725
if (pl->GetStatus() != Plugin_Running && !pl->IsSilentlyFailed())
17231726
{
1724-
len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d <%s>", id, GetStatusText(pl->GetDisplayStatus()));
1727+
len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d <%s>", plpadding, id, GetStatusText(pl->GetDisplayStatus()));
17251728

17261729
/* Plugin has failed to load. */
17271730
fail_list.append(pl);
17281731
}
17291732
else
17301733
{
1731-
len += ke::SafeSprintf(buffer, sizeof(buffer), " %02d", id);
1734+
len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d", plpadding, id);
17321735
}
17331736
if (pl->GetStatus() < Plugin_Created || pl->GetStatus() == Plugin_Evicted)
17341737
{
@@ -1958,11 +1961,11 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
19581961
if (IPluginRuntime *runtime = pl->GetRuntime()) {
19591962
unsigned char *pCodeHash = runtime->GetCodeHash();
19601963
unsigned char *pDataHash = runtime->GetDataHash();
1961-
1964+
19621965
char combinedHash[33];
19631966
for (int i = 0; i < 16; i++)
19641967
ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]);
1965-
1968+
19661969
rootmenu->ConsolePrint(" Hash: %s", combinedHash);
19671970
}
19681971
} else {
@@ -2090,7 +2093,7 @@ void CPluginManager::ReloadPluginImpl(int id, const char filename[], PluginType
20902093
char error[128];
20912094
bool wasloaded;
20922095
IPlugin *newpl = LoadPlugin(filename, true, ptype, error, sizeof(error), &wasloaded);
2093-
if (!newpl)
2096+
if (!newpl)
20942097
{
20952098
rootmenu->ConsolePrint("[SM] Plugin %s failed to reload: %s.", filename, error);
20962099
return;

0 commit comments

Comments
 (0)