/** * \return none * \brief This function parses a directory for files of SP_MODULE_EXTENSION * type and loads them. * \param dirname The directory that should be searched for modules * * Here is just a basic function that moves through a directory. It looks at every entry, and * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called * with their filenames. */ static void build_module_from_dir(gchar const *dirname) { if (!dirname) { g_warning("%s", _("Null external module directory name. Modules will not be loaded.")); return; } if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) { return; } //# Hopefully doing this the Glib way is portable GError *err; GDir *directory = g_dir_open(dirname, 0, &err); if (!directory) { gchar *safeDir = Inkscape::IO::sanitizeString(dirname); g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir); g_free(safeDir); return; } gchar *filename; while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) { if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) { continue; } if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) { continue; } gchar *pathname = g_build_filename(dirname, filename, (char *) NULL); build_from_file(pathname); g_free(pathname); } g_dir_close(directory); return; }
void read(generic_file &f) { build_from_file(f); };