+int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
+ const char *plug_dir, const char *plug_path)
+{
+ char plugin_path[BCTEXTLEN];
+ sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
+ FileSystem fs;
+ fs.set_filter( "[*.plugin][*.so]" );
+ if( fs.update(plugin_path) )
+ return 1;
+
+ for( int i=0; i<fs.dir_list.total; ++i ) {
+ char fs_path[BCTEXTLEN];
+ get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
+ if( fs.is_dir(fs_path) ) {
+ get_plugin_path(plugin_path, plug_dir, fs_path);
+ if( check_plugin_index(plugins, plug_dir, plugin_path) )
+ return 1;
+ }
+ else if( !plugin_exists(fs_path, plugins) )
+ return 1;
+ }
+ return 0;
+}
+
+
+int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
+{
+ if( !plugindb )
+ plugindb = new ArrayList<PluginServer*>;
+ init_ffmpeg();
+ char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
+ create_defaults_path(index_path, PLUGIN_FILE);
+ char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
+ strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
+ if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
+ printf("init plugin index: %s\n", plugin_path);
+ FILE *fp = fopen(index_path,"w");
+ if( !fp ) {
+ fprintf(stderr,_("MWindow::init_plugins: "
+ "can't create plugin index: %s\n"), index_path);
+ return 1;
+ }
+ fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
+ fprintf(fp, "%s\n", plugin_path);
+ init_plugin_index(mwindow, preferences, fp, plugin_path);
+ init_ffmpeg_index(mwindow, preferences, fp);
+ fclose(fp);
+ return load_plugin_index(mwindow, index_path, plugin_path);
+}
+
+int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
+{
+ char *path = getenv("LADSPA_PATH");
+ char ladspa_path[BCTEXTLEN];
+ if( !path ) {
+ get_exe_path(ladspa_path);
+ strcat(ladspa_path, "/ladspa");
+ path = ladspa_path;
+ }
+ for( int len=0; *path; path+=len ) {
+ char *cp = strchr(path,':');
+ len = !cp ? strlen(path) : cp-path;
+ char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
+ memcpy(plugin_path, path, len); plugin_path[len] = 0;
+ char *plugin_dir = FileSystem::basepath(plugin_path);
+ strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
+ create_defaults_path(index_path, LADSPA_FILE);
+ cp = index_path + strlen(index_path);
+ for( char *bp=plugin_path; *bp!=0; ++bp )
+ *cp++ = *bp=='/' ? '_' : *bp;
+ *cp = 0;
+ if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
+ if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
+ load_plugin_index(mwindow, index_path, plugin_path);
+ }
+ return 1;
+}
+
+void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
+ FILE *fp, const char *plugin_dir)
+{
+ int idx = PLUGIN_IDS;
+ if( plugindb ) {
+ for( int i=0; i<plugindb->size(); ++i ) {
+ PluginServer *server = plugindb->get(i);
+ if( server->dir_idx >= idx )
+ idx = server->dir_idx+1;
+ }
+ }
+ scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
+}
+
+int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
+ const char *index_path, const char *plugin_dir)
+{
+ char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
+ strcpy(plugin_path, path); delete [] path;
+ printf("init ladspa index: %s\n", plugin_dir);
+ FILE *fp = fopen(index_path,"w");
+ if( !fp ) {
+ fprintf(stderr,_("MWindow::init_ladspa_index: "
+ "can't create plugin index: %s\n"), index_path);
+ return 1;
+ }
+ fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
+ fprintf(fp, "%s\n", plugin_dir);
+ init_plugin_index(mwindow, preferences, fp, plugin_path);
+ fclose(fp);
+ return 0;
+}
+
+void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,