void PluginSet::load(FileXML *file, uint32_t load_flags) { int result = 0; // Current plugin being amended Plugin *plugin = (Plugin*)first; int64_t startproject = 0; record = file->tag.get_property("RECORD", record); do{ result = file->read_tag(); if(!result) { if(file->tag.title_is("/PLUGINSET")) { result = 1; } else if(file->tag.title_is("PLUGIN")) { int64_t length = file->tag.get_property("LENGTH", (int64_t)0); loaded_length += length; int plugin_type = file->tag.get_property("TYPE", 1); char title[BCTEXTLEN]; title[0] = 0; file->tag.get_property("TITLE", title); SharedLocation shared_location; shared_location.load(file); if(load_flags & LOAD_EDITS) { plugin = insert_plugin(title, startproject, length, plugin_type, &shared_location, 0, 0); plugin->load(file); startproject += length; } else if(load_flags & LOAD_AUTOMATION) { if(plugin) { plugin->load(file); plugin = (Plugin*)plugin->next; } } } } }while(!result); optimize(); }
static void insert_plugin(plugins *p, const char *file_name, const char *plugin_name, void *handle, int type,int num) { if (p->next) insert_plugin(p->next, file_name, plugin_name, handle, type, (p->type == type) ? num+1 : num); else { p->next = (plugins*)malloc(sizeof(plugins)); p->next->type = type; p->next->handle = handle; p->next->file_name = (char*)malloc(strlen(file_name)+1); strcpy(p->next->file_name, file_name); p->next->plugin_name = (char*)malloc(strlen(plugin_name)+7); sprintf(p->next->plugin_name, "%d - %s", num+((p->type == type) ? 2 : 1), plugin_name); p->next->next=NULL; } }
void plugin_scan_directory(const char *directory) { DIR *dir; char cwd[1024]; struct dirent *entry; liste_plugins = (plugins*)malloc(sizeof(plugins)); liste_plugins->type = -1; liste_plugins->next = NULL; strcpy(cwd, directory); strcat(cwd, "plugins"); dir = opendir(cwd); while((entry = readdir(dir)) != NULL) { void *handle; char *name; if (strcmp(entry->d_name + strlen(entry->d_name) - 3, ".so")) continue; name = malloc(strlen(cwd)+1+strlen(entry->d_name)+1); strcpy(name, cwd); strcat(name, "/"); strcat(name, entry->d_name); handle = dlopen(name, RTLD_NOW); if (handle) { PLUGIN_INFO PluginInfo; getDllInfo = dlsym(handle, "GetDllInfo"); if (getDllInfo) { getDllInfo(&PluginInfo); insert_plugin(liste_plugins, name, PluginInfo.Name, handle, PluginInfo.Type, 0); } } else printf("Couldn't load plugin '%s': %s\n", name, dlerror()); } current = liste_plugins; }