IExtension *CExtensionManager::LoadAutoExtension(const char *path) { /* Remove platform extension if it's there. Compat hack. */ const char *ext = libsys->GetFileExtension(path); if (strcmp(ext, PLATFORM_LIB_EXT) == 0) { char path2[PLATFORM_MAX_PATH]; smcore.Format(path2, sizeof(path2), "%s", path); path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0'; return LoadAutoExtension(path2); } IExtension *pAlready; if ((pAlready=FindExtensionByFile(path)) != NULL) { return pAlready; } char error[256]; CExtension *p = new CLocalExtension(path); /* We put us in the list beforehand so extensions that check for each other * won't recursively load each other. */ m_Libs.push_back(p); if (!p->Load(error, sizeof(error)) || !p->IsLoaded()) { smcore.LogError("[SM] Unable to load extension \"%s\": %s", path, error); p->SetError(error); } return p; }
IExtension *CExtensionManager::LoadAutoExtension(const char *path) { if (!strstr(path, "." PLATFORM_LIB_EXT)) { char newpath[PLATFORM_MAX_PATH]; g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT); return LoadAutoExtension(newpath); } IExtension *pAlready; if ((pAlready=FindExtensionByFile(path)) != NULL) { return pAlready; } char error[256]; CExtension *p = new CLocalExtension(path); /* We put us in the list beforehand so extensions that check for each other * won't recursively load each other. */ m_Libs.push_back(p); if (!p->Load(error, sizeof(error)) || !p->IsLoaded()) { g_Logger.LogError("[SM] Unable to load extension \"%s\": %s", path, error); p->SetError(error); } return p; }
void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload) { /* This function doesn't really need to do anything now. We make sure the * other extension is loaded, but handling of dependencies is really done * by the interface fetcher. */ if (required || autoload) { LoadAutoExtension(file); } }
void CExtensionManager::TryAutoload() { char path[PLATFORM_MAX_PATH]; g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions"); IDirectory *pDir = libsys->OpenDirectory(path); if (!pDir) { return; } const char *lfile; size_t len; while (pDir->MoreFiles()) { if (pDir->IsEntryDirectory()) { pDir->NextEntry(); continue; } lfile = pDir->GetEntryName(); len = strlen(lfile); if (len <= 9) /* size of ".autoload" */ { pDir->NextEntry(); continue; } if (strcmp(&lfile[len - 9], ".autoload") != 0) { pDir->NextEntry(); continue; } char file[PLATFORM_MAX_PATH]; len = smcore.Format(file, sizeof(file), "%s", lfile); strcpy(&file[len - 9], ".ext"); LoadAutoExtension(file); pDir->NextEntry(); } }