Split LoadOrRequireExtensions into two distinct functions.
This commit is contained in:
parent
15f4a05122
commit
3195dec436
@ -927,7 +927,7 @@ LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool deb
|
|||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case APLRes_Success:
|
case APLRes_Success:
|
||||||
if (!LoadOrRequireExtensions(plugin, 1, error, maxlength))
|
if (!LoadExtensions(plugin, error, maxlength))
|
||||||
return LoadRes_Failure;
|
return LoadRes_Failure;
|
||||||
return LoadRes_Successful;
|
return LoadRes_Successful;
|
||||||
|
|
||||||
@ -1158,44 +1158,53 @@ bool CPlugin::ForEachExtVar(const ExtVarCallback& callback)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength)
|
bool CPluginManager::LoadExtensions(CPlugin *pPlugin, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
auto callback = [pPlugin, pass, error, maxlength]
|
auto callback = [pPlugin, error, maxlength]
|
||||||
(const sp_pubvar_t *pubvar, const CPlugin::ExtVar& ext) -> bool
|
(const sp_pubvar_t *pubvar, const CPlugin::ExtVar& ext) -> bool
|
||||||
{
|
{
|
||||||
char path[PLATFORM_MAX_PATH];
|
char path[PLATFORM_MAX_PATH];
|
||||||
if (pass == 1) {
|
/* Attempt to auto-load if necessary */
|
||||||
/* Attempt to auto-load if necessary */
|
if (ext.autoload) {
|
||||||
if (ext.autoload) {
|
libsys->PathFormat(path, PLATFORM_MAX_PATH, "%s", ext.file);
|
||||||
libsys->PathFormat(path, PLATFORM_MAX_PATH, "%s", ext.file);
|
g_Extensions.LoadAutoExtension(path, ext.required);
|
||||||
g_Extensions.LoadAutoExtension(path, ext.required);
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return pPlugin->ForEachExtVar(ke::Move(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CPluginManager::RequireExtensions(CPlugin *pPlugin, char *error, size_t maxlength)
|
||||||
|
{
|
||||||
|
auto callback = [pPlugin, error, maxlength]
|
||||||
|
(const sp_pubvar_t *pubvar, const CPlugin::ExtVar& ext) -> bool
|
||||||
|
{
|
||||||
|
/* Is this required? */
|
||||||
|
if (ext.required) {
|
||||||
|
char path[PLATFORM_MAX_PATH];
|
||||||
|
libsys->PathFormat(path, PLATFORM_MAX_PATH, "%s", ext.file);
|
||||||
|
IExtension *pExt = g_Extensions.FindExtensionByFile(path);
|
||||||
|
if (!pExt)
|
||||||
|
pExt = g_Extensions.FindExtensionByName(ext.name);
|
||||||
|
|
||||||
|
if (!pExt || !pExt->IsRunning(nullptr, 0)) {
|
||||||
|
ke::SafeSprintf(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", ext.name, ext.file);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else if (pass == 2) {
|
g_Extensions.BindChildPlugin(pExt, pPlugin);
|
||||||
/* Is this required? */
|
} else {
|
||||||
if (ext.required) {
|
char buffer[64];
|
||||||
libsys->PathFormat(path, PLATFORM_MAX_PATH, "%s", ext.file);
|
ke::SafeSprintf(buffer, sizeof(buffer), "__ext_%s_SetNTVOptional", &pubvar->name[6]);
|
||||||
IExtension *pExt = g_Extensions.FindExtensionByFile(path);
|
|
||||||
if (!pExt)
|
|
||||||
pExt = g_Extensions.FindExtensionByName(ext.name);
|
|
||||||
|
|
||||||
if (!pExt || !pExt->IsRunning(nullptr, 0)) {
|
if (IPluginFunction *pFunc = pPlugin->GetBaseContext()->GetFunctionByName(buffer)) {
|
||||||
ke::SafeSprintf(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", ext.name, ext.file);
|
cell_t res;
|
||||||
|
if (pFunc->Execute(&res) != SP_ERROR_NONE) {
|
||||||
|
ke::SafeSprintf(error, maxlength, "Fatal error during plugin initialization (ext req)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_Extensions.BindChildPlugin(pExt, pPlugin);
|
|
||||||
} else {
|
|
||||||
char buffer[64];
|
|
||||||
ke::SafeSprintf(buffer, sizeof(buffer), "__ext_%s_SetNTVOptional", &pubvar->name[6]);
|
|
||||||
|
|
||||||
if (IPluginFunction *pFunc = pPlugin->GetBaseContext()->GetFunctionByName(buffer)) {
|
|
||||||
cell_t res;
|
|
||||||
if (pFunc->Execute(&res) != SP_ERROR_NONE) {
|
|
||||||
ke::SafeSprintf(error, maxlength, "Fatal error during plugin initialization (ext req)");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
return pPlugin->ForEachExtVar(ke::Move(callback));
|
return pPlugin->ForEachExtVar(ke::Move(callback));
|
||||||
@ -1257,15 +1266,11 @@ bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin, char *error, size_t maxl
|
|||||||
bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength)
|
bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
/* Second pass for extension requirements */
|
/* Second pass for extension requirements */
|
||||||
if (!LoadOrRequireExtensions(pPlugin, 2, error, maxlength))
|
if (!RequireExtensions(pPlugin, error, maxlength))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!FindOrRequirePluginDeps(pPlugin, error, maxlength))
|
if (!FindOrRequirePluginDeps(pPlugin, error, maxlength))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
/* Run another binding pass */
|
/* Run another binding pass */
|
||||||
g_ShareSys.BindNativesToPlugin(pPlugin, false);
|
g_ShareSys.BindNativesToPlugin(pPlugin, false);
|
||||||
|
@ -485,7 +485,8 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Runs an extension pass on a plugin.
|
* Runs an extension pass on a plugin.
|
||||||
*/
|
*/
|
||||||
bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
|
bool LoadExtensions(CPlugin *pPlugin, char *error, size_t maxlength);
|
||||||
|
bool RequireExtensions(CPlugin *pPlugin, char *error, size_t maxlength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages required natives.
|
* Manages required natives.
|
||||||
|
Loading…
Reference in New Issue
Block a user