1.1 --- a/core/systems/PluginSys.cpp Mon Oct 15 01:06:06 2007 +0000
1.2 +++ b/core/systems/PluginSys.cpp Mon Oct 15 04:06:57 2007 +0000
1.3 @@ -466,7 +466,7 @@
1.4 iter != m_Libraries.end();
1.5 iter++)
1.6 {
1.7 - g_PluginSys.OnLibraryAction((*iter).c_str(), dropping);
1.8 + g_PluginSys.OnLibraryAction((*iter).c_str(), true, dropping);
1.9 }
1.10 }
1.11
1.12 @@ -988,7 +988,9 @@
1.13 {
1.14 /* Autoload any modules */
1.15 LoadOrRequireExtensions(pPlugin, 1, error, maxlength);
1.16 - } else {
1.17 + }
1.18 + else
1.19 + {
1.20 pPlugin->SetErrorState(Plugin_Failed, "%s", error);
1.21 }
1.22 }
1.23 @@ -1156,12 +1158,16 @@
1.24 return false;
1.25 }
1.26 }
1.27 - } else {
1.28 + }
1.29 + else
1.30 + {
1.31 /* Check that we aren't registering the same library twice */
1.32 if (pPlugin->m_RequiredLibs.find(name) == pPlugin->m_RequiredLibs.end())
1.33 {
1.34 pPlugin->m_RequiredLibs.push_back(name);
1.35 - } else {
1.36 + }
1.37 + else
1.38 + {
1.39 continue;
1.40 }
1.41 List<CPlugin *>::iterator iter;
1.42 @@ -1237,7 +1243,9 @@
1.43 g_LibSys.PathFormat(path, PLATFORM_MAX_PATH, "%s", file);
1.44 g_Extensions.LoadAutoExtension(path);
1.45 }
1.46 - } else if (pass == 2) {
1.47 + }
1.48 + else if (pass == 2)
1.49 + {
1.50 /* Is this required? */
1.51 if (ext->required)
1.52 {
1.53 @@ -1256,10 +1264,32 @@
1.54 snprintf(error, maxlength, "Required extension \"%s\" file(\"%s\") not running", name, file);
1.55 }
1.56 return false;
1.57 - } else {
1.58 + }
1.59 + else
1.60 + {
1.61 g_Extensions.BindChildPlugin(pExt, pPlugin);
1.62 }
1.63 }
1.64 + else
1.65 + {
1.66 + IPluginFunction *pFunc;
1.67 + char buffer[64];
1.68 + UTIL_Format(buffer, sizeof(buffer), "__ext_%s_SetNTVOptional", &pubvar->name[6]);
1.69 +
1.70 + if ((pFunc = pBase->GetFunctionByName(buffer)) != NULL)
1.71 + {
1.72 + cell_t res;
1.73 + pFunc->Execute(&res);
1.74 + if (pPlugin->GetContext()->n_err != SP_ERROR_NONE)
1.75 + {
1.76 + if (error)
1.77 + {
1.78 + UTIL_Format(error, maxlength, "Fatal error during plugin initialization (ext req)");
1.79 + }
1.80 + return false;
1.81 + }
1.82 + }
1.83 + }
1.84 }
1.85 }
1.86 }
1.87 @@ -1277,13 +1307,14 @@
1.88
1.89 /* Bind all extra natives */
1.90 g_Extensions.BindAllNativesToPlugin(pPlugin);
1.91 - AddFakeNativesToPlugin(pPlugin);
1.92
1.93 if (!FindOrRequirePluginDeps(pPlugin, error, maxlength))
1.94 {
1.95 return false;
1.96 }
1.97
1.98 + AddFakeNativesToPlugin(pPlugin);
1.99 +
1.100 /* Find any unbound natives
1.101 * Right now, these are not allowed
1.102 */
1.103 @@ -1345,7 +1376,7 @@
1.104 s_iter != pPlugin->m_Libraries.end();
1.105 s_iter++)
1.106 {
1.107 - OnLibraryAction((*s_iter).c_str(), false);
1.108 + OnLibraryAction((*s_iter).c_str(), true, false);
1.109 }
1.110
1.111 return true;
1.112 @@ -1505,7 +1536,7 @@
1.113 s_iter != pPlugin->m_Libraries.end();
1.114 s_iter++)
1.115 {
1.116 - OnLibraryAction((*s_iter).c_str(), true);
1.117 + OnLibraryAction((*s_iter).c_str(), true, true);
1.118 }
1.119
1.120 /* Go through all dependent plugins and tell them this plugin is now gone */
1.121 @@ -2409,7 +2440,7 @@
1.122 return (CPlugin *)(pToken->ptr);
1.123 }
1.124
1.125 -void CPluginManager::OnLibraryAction(const char *lib, bool drop)
1.126 +void CPluginManager::OnLibraryAction(const char *lib, bool is_a_plugin, bool drop)
1.127 {
1.128 List<CPlugin *>::iterator iter;
1.129
1.130 @@ -2420,6 +2451,14 @@
1.131 cell_t required;
1.132 } *plc;
1.133
1.134 + struct _ext
1.135 + {
1.136 + cell_t name;
1.137 + cell_t file;
1.138 + cell_t autoload;
1.139 + cell_t required;
1.140 + } *ext;
1.141 +
1.142 const char *name = drop ? "OnLibraryRemoved" : "OnLibraryAdded";
1.143
1.144 for (iter=m_plugins.begin();
1.145 @@ -2445,23 +2484,38 @@
1.146 {
1.147 continue;
1.148 }
1.149 - if (strncmp(pubvar->name, "__pl_", 5) != 0)
1.150 + if (is_a_plugin && strncmp(pubvar->name, "__pl_", 5) == 0)
1.151 {
1.152 - continue;
1.153 - }
1.154 - plc = (_pl *)pubvar->offs;
1.155 - if (plc->required)
1.156 - {
1.157 - continue;
1.158 + plc = (_pl *)pubvar->offs;
1.159 + if (plc->required)
1.160 + {
1.161 + continue;
1.162 + }
1.163 + char *str;
1.164 + pContext->LocalToString(plc->name, &str);
1.165 + if (strcmp(str, lib) != 0)
1.166 + {
1.167 + continue;
1.168 + }
1.169 + pf->PushString(lib);
1.170 + pf->Execute(NULL);
1.171 }
1.172 - char *str;
1.173 - pContext->LocalToString(plc->name, &str);
1.174 - if (strcmp(str, lib) != 0)
1.175 + else if (!is_a_plugin && strncmp(pubvar->name, "__ext_", 6) == 0)
1.176 {
1.177 - continue;
1.178 + ext = (_ext *)pubvar->offs;
1.179 + if (ext->required)
1.180 + {
1.181 + continue;
1.182 + }
1.183 + char *str;
1.184 + pContext->LocalToString(ext->name, &str);
1.185 + if (strcmp(str, lib) != 0)
1.186 + {
1.187 + continue;
1.188 + }
1.189 + pf->PushString(lib);
1.190 + pf->Execute(NULL);
1.191 }
1.192 - pf->PushString(lib);
1.193 - pf->Execute(NULL);
1.194 }
1.195 }
1.196 }