diff options
| author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-02 16:59:52 +0000 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-01-02 16:59:52 +0000 | 
| commit | 43d4be36dd06b69f8ac126c7dcc8c259b0544f7b (patch) | |
| tree | 71baa5a3169dedc54ce4e4e9e45e78be6803105c /hardinfo2 | |
| parent | 4e082dd27545c503e6ee1440e45032f93216631a (diff) | |
Add module dependency checking.
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/callbacks.c | 4 | ||||
| -rw-r--r-- | hardinfo2/computer.c | 2 | ||||
| -rw-r--r-- | hardinfo2/devices.c | 2 | ||||
| -rw-r--r-- | hardinfo2/hardinfo.h | 1 | ||||
| -rw-r--r-- | hardinfo2/iconcache.c | 4 | ||||
| -rw-r--r-- | hardinfo2/util.c | 119 | 
6 files changed, 123 insertions, 9 deletions
| diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index e4d0f61d..5ee34fa4 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -1,6 +1,6 @@  /*   *    HardInfo - Displays System Information - *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>   *   *    This program is free software; you can redistribute it and/or modify   *    it under the terms of the GNU General Public License as published by @@ -146,7 +146,7 @@ void cb_about()      gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "HardInfo");      gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), VERSION);      gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), -				   "Copyright \302\251 2003-2006 "  +				   "Copyright \302\251 2003-2007 "   				   "Leandro A. F. Pereira");      gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about),  				  "System information and benchmark tool"); diff --git a/hardinfo2/computer.c b/hardinfo2/computer.c index 8499bb20..aebff09b 100644 --- a/hardinfo2/computer.c +++ b/hardinfo2/computer.c @@ -1,6 +1,6 @@  /*   *    HardInfo - Displays System Information - *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>   *   *    This program is free software; you can redistribute it and/or modify   *    it under the terms of the GNU General Public License as published by diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index a88f8e2b..9e6d15be 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -1,6 +1,6 @@  /*   *    HardInfo - Displays System Information - *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>   *   *    This program is free software; you can redistribute it and/or modify   *    it under the terms of the GNU General Public License as published by diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index eb78d99a..36013060 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -31,6 +31,7 @@ struct _ProgramParameters {    gboolean show_version;    gboolean gui_running;    gboolean list_modules; +  gboolean autoload_deps;    gint     report_format; diff --git a/hardinfo2/iconcache.c b/hardinfo2/iconcache.c index 69e411e5..868185e5 100644 --- a/hardinfo2/iconcache.c +++ b/hardinfo2/iconcache.c @@ -44,6 +44,8 @@ GdkPixbuf *icon_cache_get_pixbuf(const gchar *file)          g_free(tmp);      } +    g_object_ref(icon); +          return icon;  } @@ -72,6 +74,8 @@ GdkPixbuf *icon_cache_get_pixbuf_at_size(const gchar *file, gint wid, gint hei)          g_free(tmp);      } +    g_object_ref(icon); +          return icon;  } diff --git a/hardinfo2/util.c b/hardinfo2/util.c index d95770ff..d47bb289 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -1,6 +1,6 @@  /*   *    HardInfo - Displays System Information - *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + *    Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>   *   *    This program is free software; you can redistribute it and/or modify   *    it under the terms of the GNU General Public License as published by @@ -261,6 +261,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)      static gboolean  create_report = FALSE;      static gboolean  show_version  = FALSE;      static gboolean  list_modules  = FALSE; +    static gboolean  autoload_deps = FALSE;      static gchar    *report_format = NULL;      static gchar   **use_modules   = NULL; @@ -294,6 +295,13 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)  	 .description = "specify module to load"          },  	{ +	 .long_name   = "autoload-deps", +	 .short_name  = 'a', +	 .arg         = G_OPTION_ARG_NONE, +	 .arg_data    = &autoload_deps, +	 .description = "automatically load module dependencies" +        }, +	{  	 .long_name   = "version",  	 .short_name  = 'v',  	 .arg         = G_OPTION_ARG_NONE, @@ -318,6 +326,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)      param->show_version  = show_version;      param->list_modules  = list_modules;      param->use_modules   = use_modules; +    param->autoload_deps = autoload_deps;      if (report_format && g_str_equal(report_format, "html"))          param->report_format = REPORT_FORMAT_HTML; @@ -420,15 +429,18 @@ static ShellModule *module_load(gchar *filename)      module = g_new0(ShellModule, 1);      if (params.gui_running) { -        gchar *dot = g_strrstr(filename, "." G_MODULE_SUFFIX); +        gchar *tmpicon; +         +        tmpicon = g_strdup(filename); +        gchar *dot = g_strrstr(tmpicon, "." G_MODULE_SUFFIX);          *dot = '\0'; -        tmp = g_strdup_printf("%s.png", filename); +        tmp = g_strdup_printf("%s.png", tmpicon);          module->icon = icon_cache_get_pixbuf(tmp); -        g_free(tmp); -        *dot = '.'; +        g_free(tmp); +        g_free(tmpicon);      }      tmp = g_build_filename(params.path_lib, "modules", filename, NULL); @@ -514,6 +526,101 @@ static gint module_cmp(gconstpointer m1, gconstpointer m2)      return a->weight - b->weight;  } +static void module_entry_free(gpointer data, gpointer user_data) +{ +    ShellModuleEntry *entry = (ShellModuleEntry *)data; + +    g_free(entry->name); +    g_object_unref(entry->icon); + +    g_free(entry); +} + +static void module_free(ShellModule *module) +{ +    g_free(module->name); +    g_object_unref(module->icon); +    /*g_module_close(module->dll);*/ + +    g_slist_foreach(module->entries, (GFunc)module_entry_free, NULL); +    g_slist_free(module->entries); + +    g_free(module); +} + +static GSList *modules_check_deps(GSList *modules) +{ +    GSList      *mm; +    ShellModule *module; +     +    for (mm = modules; mm; mm = mm->next) { +        gchar    **(*get_deps)(void); +        gchar    **deps; +        gint 	 i; + +        module = (ShellModule *) mm->data; +         +        if (g_module_symbol(module->dll, "hi_module_depends_on", +                            (gpointer) & get_deps)) { +            for (i = 0, deps = get_deps(); deps[i]; i++) { +                GSList      *l; +                ShellModule *m; +                gboolean    found = FALSE; +                 +                for (l = modules; l; l = l->next) { +                    m = (ShellModule *)l->data; +                    gchar *name = g_path_get_basename(g_module_name(m->dll)); +                     +                    if (g_str_equal(name, deps[i]))  { +                        found = TRUE; +                        break; +                    } +                 +                    g_free(name); +                } +                 +                if (!found) { +                    if (params.autoload_deps) { +                        modules = g_slist_append(modules, module_load(deps[i])); +                        modules = modules_check_deps(modules);	/* re-check dependencies */ +                     +                        break; +                    } + +                    if (params.gui_running) { +                        GtkWidget *dialog; +                         +                        dialog = gtk_message_dialog_new(NULL, +                                                        GTK_DIALOG_DESTROY_WITH_PARENT, +                                                        GTK_MESSAGE_QUESTION, +                                                        GTK_BUTTONS_NONE, +                                                        "Module \"%s\" depends on module \"%s\", load it?", +                                                        module->name, deps[i]); +                        gtk_dialog_add_buttons(GTK_DIALOG(dialog), +                                               GTK_STOCK_NO, GTK_RESPONSE_REJECT, +                                               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, +                                               NULL); +                                                +                        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { +                            modules = g_slist_append(modules, module_load(deps[i])); +                            modules = modules_check_deps(modules);	/* re-check dependencies */ +                        } else { +                            modules = g_slist_remove(modules, module); +                            module_free(module); +                        } + +                        gtk_widget_destroy(dialog); +                    } else { +                        g_error("Module \"%s\" depends on module \"%s\".", module->name, deps[i]); +                    } +                } +            } +        } +    } +     +    return modules; +} +  static GSList *modules_load(gchar **module_list)  {      GDir *dir; @@ -537,6 +644,8 @@ static GSList *modules_load(gchar **module_list)          g_dir_close(dir);      } +    modules = modules_check_deps(modules); +      if (g_slist_length(modules) == 0) {          if (params.use_modules == NULL) {      	    g_error("No module could be loaded. Check permissions on \"%s\" and try again.", | 
