Move CPlugin compilation into its own function.
This commit is contained in:
parent
d9216cc599
commit
3807edbeb8
@ -205,7 +205,7 @@ void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPlugin::UpdateInfo()
|
bool CPlugin::ReadInfo()
|
||||||
{
|
{
|
||||||
/* Now grab the info */
|
/* Now grab the info */
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
@ -436,6 +436,30 @@ void *CPlugin::GetPluginStructure()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only called during plugin construction.
|
||||||
|
bool CPlugin::TryCompile(char *error, size_t maxlength)
|
||||||
|
{
|
||||||
|
char fullpath[PLATFORM_MAX_PATH];
|
||||||
|
g_pSM->BuildPath(Path_SM, fullpath, sizeof(fullpath), "plugins/%s", m_filename);
|
||||||
|
|
||||||
|
char loadmsg[255];
|
||||||
|
m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
|
||||||
|
if (!m_pRuntime) {
|
||||||
|
ke::SafeSprintf(error, maxlength, "Unable to load plugin (%s)", loadmsg);
|
||||||
|
m_status = Plugin_BadLoad;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadInfo() sets its own error state.
|
||||||
|
if (!ReadInfo()) {
|
||||||
|
ke::SafeSprintf(error, maxlength, "%s", m_errormsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_status = Plugin_Created;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
IPluginContext *CPlugin::GetBaseContext()
|
IPluginContext *CPlugin::GetBaseContext()
|
||||||
{
|
{
|
||||||
if (m_pRuntime == NULL)
|
if (m_pRuntime == NULL)
|
||||||
@ -903,25 +927,8 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
|
|||||||
pPlugin = CPlugin::CreatePlugin(path, error, maxlength);
|
pPlugin = CPlugin::CreatePlugin(path, error, maxlength);
|
||||||
assert(pPlugin != NULL);
|
assert(pPlugin != NULL);
|
||||||
|
|
||||||
if (pPlugin->m_status == Plugin_Uncompiled)
|
if (pPlugin->m_status == Plugin_Uncompiled) {
|
||||||
{
|
pPlugin->TryCompile(error, maxlength);
|
||||||
char fullpath[PLATFORM_MAX_PATH];
|
|
||||||
g_pSM->BuildPath(Path_SM, fullpath, sizeof(fullpath), "plugins/%s", pPlugin->m_filename);
|
|
||||||
|
|
||||||
char loadmsg[255];
|
|
||||||
pPlugin->m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg));
|
|
||||||
if (!pPlugin->m_pRuntime) {
|
|
||||||
if (error)
|
|
||||||
ke::SafeSprintf(error, maxlength, "Unable to load plugin (%s)", loadmsg);
|
|
||||||
pPlugin->m_status = Plugin_BadLoad;
|
|
||||||
} else {
|
|
||||||
if (pPlugin->UpdateInfo()) {
|
|
||||||
pPlugin->m_status = Plugin_Created;
|
|
||||||
} else {
|
|
||||||
if (error)
|
|
||||||
ke::SafeSprintf(error, maxlength, "%s", pPlugin->m_errormsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pPlugin->GetStatus() == Plugin_Created)
|
if (pPlugin->GetStatus() == Plugin_Created)
|
||||||
|
@ -249,11 +249,14 @@ public:
|
|||||||
}
|
}
|
||||||
void LibraryActions(LibraryAction action);
|
void LibraryActions(LibraryAction action);
|
||||||
void SyncMaxClients(int max_clients);
|
void SyncMaxClients(int max_clients);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool UpdateInfo();
|
bool ReadInfo();
|
||||||
void SetTimeStamp(time_t t);
|
void SetTimeStamp(time_t t);
|
||||||
void DependencyDropped(CPlugin *pOwner);
|
void DependencyDropped(CPlugin *pOwner);
|
||||||
|
|
||||||
|
bool TryCompile(char *error, size_t maxlength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This information is static for the lifetime of the plugin.
|
// This information is static for the lifetime of the plugin.
|
||||||
char m_filename[PLATFORM_MAX_PATH];
|
char m_filename[PLATFORM_MAX_PATH];
|
||||||
|
Loading…
Reference in New Issue
Block a user