summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2017-07-02 14:47:03 +0000
committerMartin Owens <doctormo@gmail.com>2017-07-02 14:47:03 +0000
commit7dc5626af3eb924fa381c46491cd49178a78cd73 (patch)
treee50a3b98ce1393b7a06efbd11425f8c458b0cbbb /src/extension
parentpyc files are generated when testing modules, ignore them (diff)
downloadinkscape-7dc5626af3eb924fa381c46491cd49178a78cd73.tar.gz
inkscape-7dc5626af3eb924fa381c46491cd49178a78cd73.zip
Move directory scanners to new get_filenames(...) calls
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/dependency.cpp12
-rw-r--r--src/extension/extension.cpp1
-rw-r--r--src/extension/extension.h1
-rw-r--r--src/extension/implementation/script.cpp22
-rw-r--r--src/extension/implementation/xslt.cpp22
-rw-r--r--src/extension/init.cpp66
6 files changed, 16 insertions, 108 deletions
diff --git a/src/extension/dependency.cpp b/src/extension/dependency.cpp
index 837520381..827475011 100644
--- a/src/extension/dependency.cpp
+++ b/src/extension/dependency.cpp
@@ -18,6 +18,7 @@
#include "dependency.h"
#include "db.h"
#include "extension.h"
+#include "io/resource.h"
namespace Inkscape {
namespace Extension {
@@ -151,12 +152,11 @@ bool Dependency::check (void) const
Glib::ustring location(_string);
switch (_location) {
case LOCATION_EXTENSIONS: {
- for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
- std::string temploc = Glib::build_filename(Inkscape::Extension::Extension::search_path[i], location);
- if (Glib::file_test(temploc, filetest)) {
- location = temploc;
- break;
- }
+ using namespace Inkscape::IO::Resource;
+ Glib::ustring temploc = get_filename(EXTENSIONS, location.c_str());
+ if(Glib::file_test(temploc, filetest)) {
+ location = temploc;
+ break;
}
} /* PASS THROUGH!!! */
case LOCATION_ABSOLUTE: {
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp
index 9c0221521..f1b328f05 100644
--- a/src/extension/extension.cpp
+++ b/src/extension/extension.cpp
@@ -40,7 +40,6 @@ namespace Extension {
/* Inkscape::Extension::Extension */
-std::vector<const gchar *> Extension::search_path;
std::ofstream Extension::error_file;
/**
diff --git a/src/extension/extension.h b/src/extension/extension.h
index bbd6d068b..962c3c8a7 100644
--- a/src/extension/extension.h
+++ b/src/extension/extension.h
@@ -95,7 +95,6 @@ public:
STATE_UNLOADED, /**< The extension has not been loaded */
STATE_DEACTIVATED /**< The extension is missing something which makes it unusable */
} state_t;
- static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
private:
gchar *id; /**< The unique identifier for the Extension */
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index b1058d415..8da56fecd 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -33,6 +33,7 @@
#include "extension/db.h"
#include "inkscape.h"
#include "io/sys.h"
+#include "io/resource.h"
#include "preferences.h"
#include "script.h"
#include "selection.h"
@@ -184,25 +185,8 @@ std::string Script::solve_reldir(Inkscape::XML::Node *reprin) {
Glib::ustring str = reprin->firstChild()->content();
return str;
}
-
- Glib::ustring reldir = s;
- for (unsigned int i=0;
- i < Inkscape::Extension::Extension::search_path.size();
- i++) {
-
- gchar * fname = g_build_filename(
- Inkscape::Extension::Extension::search_path[i],
- reprin->firstChild()->content(),
- NULL);
- Glib::ustring filename = fname;
- g_free(fname);
- //printf("Filename: %s\n", filename.c_str());
- if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) ) {
- return Glib::filename_from_utf8(filename);
- }
- }
-
- return "";
+ using namespace Inkscape::IO::Resource;
+ return get_filename(EXTENSIONS, reprin->firstChild()->content());
}
diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp
index 373378d97..94852a98e 100644
--- a/src/extension/implementation/xslt.cpp
+++ b/src/extension/implementation/xslt.cpp
@@ -23,6 +23,7 @@
#include "extension/input.h"
#include "io/sys.h"
+#include "io/resource.h"
#include <unistd.h>
#include <cstring>
#include "document.h"
@@ -62,30 +63,13 @@ Glib::ustring XSLT::solve_reldir(Inkscape::XML::Node *reprin) {
}
Glib::ustring reldir = s;
-
if (reldir == "extensions") {
-
- for (unsigned int i=0;
- i < Inkscape::Extension::Extension::search_path.size();
- i++) {
-
- gchar * fname = g_build_filename(
- Inkscape::Extension::Extension::search_path[i],
- reprin->firstChild()->content(),
- NULL);
- Glib::ustring filename = fname;
- g_free(fname);
-
- if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) )
- return filename;
-
- }
+ using namespace Inkscape::IO::Resource;
+ return get_filename(EXTENSIONS, reprin->firstChild()->content());
} else {
Glib::ustring str = reprin->firstChild()->content();
return str;
}
-
- return "";
}
bool XSLT::check(Inkscape::Extension::Extension *module)
diff --git a/src/extension/init.cpp b/src/extension/init.cpp
index a40196a74..9830b0176 100644
--- a/src/extension/init.cpp
+++ b/src/extension/init.cpp
@@ -117,7 +117,6 @@ namespace Extension {
the extension directory and parsed */
#define SP_MODULE_EXTENSION "inx"
-static void build_module_from_domain(Domain domain);
static void check_extensions();
/**
@@ -154,8 +153,7 @@ update_pref(Glib::ustring const &pref_path,
* Invokes the init routines for internal modules.
*
* This should be a list of all the internal modules that need to initialized. This is just a
- * convinent place to put them. Also, this function calls build_module_from_domain to parse the
- * Inkscape extensions directory.
+ * convinent place to put them.
*/
void
init()
@@ -246,8 +244,9 @@ init()
Internal::Filter::Filter::filters_all();
- build_module_from_domain(USER);
- build_module_from_domain(SYSTEM);
+ for(auto &filename: get_filenames(EXTENSIONS, {SP_MODULE_EXTENSION})) {
+ build_from_file(filename.c_str());
+ }
/* this is at the very end because it has several catch-alls
* that are possibly over-ridden by other extensions (such as
@@ -267,63 +266,6 @@ init()
);
}
-/**
- * \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_domain(Domain domain)
-{
- char const *dirname = get_path(domain, EXTENSIONS);
-
- 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;
- }
-
- // TODO: We may have to get to why this is needed, since it seems redundent.
- Inkscape::Extension::Extension::search_path.push_back(dirname);
-
- 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;
-}
-
-
static void
check_extensions_internal(Extension *in_plug, gpointer in_data)
{