Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

bool Inkscape::Extension::Dependency::check ( void   )  const

Check if the dependency passes.

Returns:
Whether or not the dependency passes.
This function depends largely on all of the enums. The first level that is evaluted is the _type.

If the type is TYPE_EXTENSION then the id for the extension is looked up in the database. If the extension is found, and it is not deactivated, the dependency passes.

If the type is TYPE_PLUGIN then the path for the plugin is found using the Glib::Module routines. When the path is found, then there is a check to see if the file exists using the file_test function.

If the type is TYPE_EXECUTABLE or TYPE_FILE things are getting even more interesting because now the _location variable is also taken into account. First, the difference between the two is that the file test for TYPE_EXECUTABLE also tests to make sure the file is executable, besides checking that it exists.

If the _location is LOCATION_EXTENSIONS then the INKSCAPE_EXTENSIONDIR is put on the front of the string with build_filename. Then the appopriate filetest is run.

If the _location is LOCATION_ABSOLUTE then the file test is run directly on the string.

If the _location is LOCATION_PATH or not specified then the path is used to find the file. Each entry in the path is stepped through, attached to the string, and then tested. If the file is found then a TRUE is returned. If we get all the way through the path then a FALSE is returned, the command could not be found.

Definition at line 128 of file dependency.cpp.

References _location, _string, _type, LOCATION_ABSOLUTE, LOCATION_EXTENSIONS, LOCATION_PATH, Inkscape::Extension::Extension::search_path, TYPE_EXECUTABLE, TYPE_EXTENSION, TYPE_FILE, and TYPE_PLUGIN.

{
    // std::cout << "Checking: " << *this << std::endl;

    if (_string == NULL) return FALSE;

    switch (_type) {
        case TYPE_EXTENSION: {
            Extension * myext = db.get(_string);
            if (myext == NULL) return FALSE;
            if (myext->deactivated()) return FALSE;
            break;
        }
        case TYPE_PLUGIN: {
            if (!Glib::Module::get_supported()) {
                return FALSE;
            }

            std::string path = Glib::Module::build_path(INKSCAPE_PLUGINDIR, _string);
            if (!Glib::file_test(path, Glib::FILE_TEST_EXISTS))
                return FALSE;
            break;
        }
        case TYPE_EXECUTABLE:
        case TYPE_FILE: {
            Glib::FileTest filetest = Glib::FILE_TEST_EXISTS;
            if (_type == TYPE_EXECUTABLE) {
                filetest |= Glib::FILE_TEST_IS_EXECUTABLE;
            }

            std::string 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;
                        }
                    }
                } /* PASS THROUGH!!! */
                case LOCATION_ABSOLUTE: {
                    if (!Glib::file_test(location, filetest)) {
                        // std::cout << "Failing on location: " << location << std::endl;
                        return FALSE;
                    }
                    break;
                }
                /* The default case is to look in the path */
                case LOCATION_PATH:
                default: {
                    gchar * path = g_strdup(g_getenv("PATH"));

                    if (path == NULL) {
                        /* There is no `PATH' in the environment.
                           The default search path is the current directory */
                        path = g_strdup(G_SEARCHPATH_SEPARATOR_S);
                    }

                    gchar * orig_path = path;

                    for (; path != NULL;) {
                        gchar * local_path;
                        gchar * final_name;

                        local_path = path;
                        path = g_utf8_strchr(path, -1, G_SEARCHPATH_SEPARATOR);
                        /* Not sure whether this is UTF8 happy, but it would seem
                           like it considering that I'm searching (and finding)
                           the ':' character */
                        if (path != local_path && path != NULL) {
                            path[0] = '\0';
                            path++;
                        } else {
                            path = NULL;
                        }

                        if (local_path == '\0') {
                            final_name = g_strdup(_string);
                        } else {
                            final_name = g_build_filename(local_path, _string, NULL);
                        }

                        if (Glib::file_test(final_name, filetest)) {
                            g_free(final_name);
                            g_free(orig_path);
                            return TRUE;
                        }
                        // give it a 2nd try with ".exe" added
                        gchar * final_name_exe = g_strdup_printf ("%s.exe", final_name);                        
                        if (Glib::file_test(final_name_exe, filetest)) {
                            g_free(final_name);
                            g_free(final_name_exe);
                            g_free(orig_path);
                            return TRUE;
                        }

                        g_free(final_name);
                        g_free(final_name_exe);
                    }

                    g_free(orig_path);
                    return FALSE; /* Reverse logic in this one */
                    break;
                }
            } /* switch _location */
            break;
        } /* TYPE_FILE, TYPE_EXECUTABLE */
        default:
            return FALSE;
    } /* switch _type */

    return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index