diff options
Diffstat (limited to 'hardinfo2')
-rw-r--r-- | hardinfo2/arch/common/blowfish.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/md5.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/sha1.h | 2 | ||||
-rw-r--r-- | hardinfo2/arch/common/zlib.h | 2 | ||||
-rw-r--r-- | hardinfo2/benchmark.c | 2 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 16 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 9 | ||||
-rw-r--r-- | hardinfo2/iconcache.c | 4 | ||||
-rw-r--r-- | hardinfo2/menu.c | 2 | ||||
-rw-r--r-- | hardinfo2/report.c | 21 | ||||
-rw-r--r-- | hardinfo2/report.h | 3 | ||||
-rw-r--r-- | hardinfo2/shell.c | 32 | ||||
-rw-r--r-- | hardinfo2/util.c | 45 |
13 files changed, 80 insertions, 62 deletions
diff --git a/hardinfo2/arch/common/blowfish.h b/hardinfo2/arch/common/blowfish.h index 3a237baf..4d496553 100644 --- a/hardinfo2/arch/common/blowfish.h +++ b/hardinfo2/arch/common/blowfish.h @@ -36,7 +36,7 @@ benchmark_fish(void) gchar *bdata_path; - bdata_path = g_build_filename(path_data, "benchmark.data", NULL); + bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); return g_strdup("[Error]\n" diff --git a/hardinfo2/arch/common/md5.h b/hardinfo2/arch/common/md5.h index b539b2c7..0cf30705 100644 --- a/hardinfo2/arch/common/md5.h +++ b/hardinfo2/arch/common/md5.h @@ -33,7 +33,7 @@ benchmark_md5(void) gchar *bdata_path; - bdata_path = g_build_filename(path_data, "benchmark.data", NULL); + bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); return g_strdup("[Error]\n" diff --git a/hardinfo2/arch/common/sha1.h b/hardinfo2/arch/common/sha1.h index cbf8e2a3..2468869e 100644 --- a/hardinfo2/arch/common/sha1.h +++ b/hardinfo2/arch/common/sha1.h @@ -32,7 +32,7 @@ benchmark_sha1(void) gchar *bdata_path; - bdata_path = g_build_filename(path_data, "benchmark.data", NULL); + bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); return g_strdup("[Error]\n" diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h index 0e93be47..3f76aabb 100644 --- a/hardinfo2/arch/common/zlib.h +++ b/hardinfo2/arch/common/zlib.h @@ -53,7 +53,7 @@ benchmark_zlib(void) glong srclen = 65536; gchar *bdata_path; - bdata_path = g_build_filename(path_data, "benchmark.data", NULL); + bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { g_free(bdata_path); return g_strdup("[Error]\n" diff --git a/hardinfo2/benchmark.c b/hardinfo2/benchmark.c index 28896056..367ea592 100644 --- a/hardinfo2/benchmark.c +++ b/hardinfo2/benchmark.c @@ -45,7 +45,7 @@ benchmark_include_results(gchar *results, const gchar *benchmark) int i; conf = g_key_file_new(); - bconf_path = g_build_filename(path_data, "benchmark.conf", NULL); + bconf_path = g_build_filename(params.path_data, "benchmark.conf", NULL); g_key_file_load_from_file(conf, bconf_path, 0, NULL); machines = g_key_file_get_keys(conf, benchmark, NULL, NULL); diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 63609a3c..6619afa1 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -26,10 +26,6 @@ #include <binreloc.h> -gchar *path_data = NULL, - *path_lib = NULL; -gboolean gui_running = FALSE; - ProgramParameters params = { 0 }; int @@ -39,14 +35,20 @@ main(int argc, char **argv) parameters_init(&argc, &argv, ¶ms); + if (params.show_version) { + g_print("HardInfo version " VERSION "\n"); + g_print("Copyright (C) 2003-2006 Leandro A. F. Pereira. See COPYING for details.\n"); + return 0; + } + if (!params.create_report) { /* we only try to open the UI if the user didn't asked for a report. */ - gui_running = ui_init(&argc, &argv); + params.gui_running = ui_init(&argc, &argv); /* if GTK+ initialization failed, assume the user wants a report. */ - if (!gui_running) + if (!params.gui_running) params.create_report = TRUE; } @@ -58,7 +60,7 @@ main(int argc, char **argv) modules = modules_load(); - if (gui_running) { + if (params.gui_running) { icon_cache_init(); stock_icons_init(); diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 68c995c7..1a5a4b97 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -27,7 +27,12 @@ typedef struct _ProgramParameters ProgramParameters; struct _ProgramParameters { gboolean create_report; + gboolean show_version; + gboolean gui_running; gint report_format; + + gchar *path_lib; + gchar *path_data; }; struct _FileTypes { @@ -67,13 +72,9 @@ GSList *modules_load(void); /* BinReloc stuff */ gboolean binreloc_init(gboolean try_hardcoded); -extern gchar* path_lib; -extern gchar* path_data; - /* GTK UI stuff */ gboolean ui_init(int *argc, char ***argv); void parameters_init(int *argc, char ***argv, ProgramParameters *params); -extern gboolean gui_running; extern ProgramParameters params; #endif /* __HARDINFO_H__ */ diff --git a/hardinfo2/iconcache.c b/hardinfo2/iconcache.c index 9cb5a035..69e411e5 100644 --- a/hardinfo2/iconcache.c +++ b/hardinfo2/iconcache.c @@ -37,7 +37,7 @@ GdkPixbuf *icon_cache_get_pixbuf(const gchar *file) icon = g_hash_table_lookup(cache, file); if (!icon) { - gchar *tmp = g_build_filename(path_data, "pixmaps", file, NULL); + gchar *tmp = g_build_filename(params.path_data, "pixmaps", file, NULL); icon = gdk_pixbuf_new_from_file(tmp, NULL); g_hash_table_insert(cache, g_strdup(file), icon); @@ -64,7 +64,7 @@ GdkPixbuf *icon_cache_get_pixbuf_at_size(const gchar *file, gint wid, gint hei) icon = g_hash_table_lookup(cache, file); if (!icon) { - gchar *tmp = g_build_filename(path_data, "pixmaps", file, NULL); + gchar *tmp = g_build_filename(params.path_data, "pixmaps", file, NULL); icon = gdk_pixbuf_new_from_file_at_size(tmp, wid, hei, NULL); g_hash_table_insert(cache, g_strdup(file), icon); diff --git a/hardinfo2/menu.c b/hardinfo2/menu.c index 63b5a2b2..9a301700 100644 --- a/hardinfo2/menu.c +++ b/hardinfo2/menu.c @@ -121,7 +121,7 @@ void menu_init(Shell *shell) /* Read in the UI from our XML file */ error = NULL; - uidefs_path = g_build_filename(path_data, "uidefs.xml", NULL); + uidefs_path = g_build_filename(params.path_data, "uidefs.xml", NULL); gtk_ui_manager_add_ui_from_file(menu_manager, uidefs_path, &error); g_free(uidefs_path); diff --git a/hardinfo2/report.c b/hardinfo2/report.c index e6b3a08f..a5885b26 100644 --- a/hardinfo2/report.c +++ b/hardinfo2/report.c @@ -306,7 +306,7 @@ report_create_inner_from_module_list(ReportContext *ctx, GSList *modules) ShellModule *module = (ShellModule *) modules->data; GSList *entries; - if (!gui_running) + if (!params.gui_running) fprintf(stderr, "%s\n", module->name); report_title(ctx, module->name); @@ -314,7 +314,7 @@ report_create_inner_from_module_list(ReportContext *ctx, GSList *modules) for (entries = module->entries; entries; entries = entries->next) { ShellModuleEntry *entry = (ShellModuleEntry *) entries->data; - if (!gui_running) + if (!params.gui_running) fprintf(stderr, " * %s\n", entry->name); ctx->entry = entry; @@ -421,13 +421,18 @@ report_create_from_module_list(ReportContext *ctx, GSList *modules) gchar * report_create_from_module_list_format(GSList *modules, ReportFormat format) { - ReportContext *ctx; - gchar *retval; + ReportContext *(*create_context)(); + ReportContext *ctx; + gchar *retval; - if (format == REPORT_FORMAT_HTML) - ctx = report_context_html_new(); - else - ctx = report_context_text_new(); + if (format >= N_REPORT_FORMAT) + return NULL; + + create_context = file_types[format].data; + if (!create_context) + return NULL; + + ctx = create_context(); report_create_from_module_list(ctx, modules); retval = g_strdup(ctx->output); diff --git a/hardinfo2/report.h b/hardinfo2/report.h index faf04ac5..b7203c43 100644 --- a/hardinfo2/report.h +++ b/hardinfo2/report.h @@ -22,8 +22,9 @@ #include <shell.h> typedef enum { + REPORT_FORMAT_HTML, REPORT_FORMAT_TEXT, - REPORT_FORMAT_HTML + N_REPORT_FORMAT } ReportFormat; typedef struct _ReportDialog ReportDialog; diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index e4d1f194..9713c4fc 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -64,7 +64,7 @@ void shell_ui_manager_set_visible(const gchar *path, { GtkWidget *widget; - if (!gui_running) + if (!params.gui_running) return; widget = gtk_ui_manager_get_widget(shell->ui_manager, path); @@ -83,7 +83,7 @@ void shell_action_set_property(const gchar *action_name, { GtkAction *action; - if (!gui_running) + if (!params.gui_running) return; action = gtk_action_group_get_action(shell->action_group, action_name); @@ -103,7 +103,7 @@ void shell_action_set_enabled(const gchar *action_name, gboolean setting) { GtkAction *action; - if (!gui_running) + if (!params.gui_running) return; action = gtk_action_group_get_action(shell->action_group, action_name); @@ -116,7 +116,7 @@ gboolean shell_action_get_enabled(const gchar *action_name) { GtkAction *action; - if (!gui_running) + if (!params.gui_running) return FALSE; action = gtk_action_group_get_action(shell->action_group, action_name); @@ -129,7 +129,7 @@ gboolean shell_action_get_enabled(const gchar *action_name) void shell_set_side_pane_visible(gboolean setting) { - if (!gui_running) + if (!params.gui_running) return; if (setting) @@ -144,7 +144,7 @@ gboolean shell_action_get_active(const gchar *action_name) GSList *proxies; /* FIXME: Ugh. Are you sure there isn't any simpler way? O_o */ - if (!gui_running) + if (!params.gui_running) return FALSE; action = gtk_action_group_get_action(shell->action_group, action_name); @@ -169,7 +169,7 @@ void shell_action_set_active(const gchar *action_name, gboolean setting) GSList *proxies; /* FIXME: Ugh. Are you sure there isn't any simpler way? O_o */ - if (!gui_running) + if (!params.gui_running) return; action = gtk_action_group_get_action(shell->action_group, action_name); @@ -190,7 +190,7 @@ void shell_action_set_active(const gchar *action_name, gboolean setting) void shell_status_pulse(void) { - if (!gui_running) + if (!params.gui_running) return; if (shell->_pulses++ == 20) { @@ -207,7 +207,7 @@ shell_status_pulse(void) void shell_status_set_percentage(gint percentage) { - if (!gui_running) + if (!params.gui_running) return; gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(shell->progress), @@ -219,7 +219,7 @@ shell_status_set_percentage(gint percentage) void shell_view_set_enabled(gboolean setting) { - if (!gui_running) + if (!params.gui_running) return; if (setting) { @@ -239,7 +239,7 @@ shell_view_set_enabled(gboolean setting) void shell_status_set_enabled(gboolean setting) { - if (!gui_running) + if (!params.gui_running) return; if (setting) @@ -253,7 +253,7 @@ shell_status_set_enabled(gboolean setting) void shell_do_reload(void) { - if (!gui_running) + if (!params.gui_running) return; shell_action_set_enabled("RefreshAction", FALSE); @@ -278,7 +278,7 @@ shell_do_reload(void) void shell_status_update(const gchar *message) { - if (!gui_running) + if (!params.gui_running) return; gtk_label_set_markup(GTK_LABEL(shell->status), message); @@ -356,7 +356,7 @@ shell_tree_modules_load(ShellTree * shelltree) keyfile = g_key_file_new(); - modules_conf = g_build_filename(path_data, "modules.conf", NULL); + modules_conf = g_build_filename(params.path_data, "modules.conf", NULL); g_key_file_load_from_file(keyfile, modules_conf, 0, NULL); g_free(modules_conf); @@ -381,7 +381,7 @@ shell_tree_modules_load(ShellTree * shelltree) g_free(iname); iname = tmp; - tmp = g_build_filename(path_lib, "modules", iname, NULL); + tmp = g_build_filename(params.path_lib, "modules", iname, NULL); module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); g_free(tmp); @@ -430,7 +430,7 @@ shell_tree_modules_load(ShellTree * shelltree) g_key_file_free(keyfile); if (g_slist_length(shelltree->modules) == 0) { - g_error("No module could be loaded. Check permissions on %s and try again.", path_lib); + g_error("No module could be loaded. Check permissions on %s and try again.", params.path_lib); } } #endif diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 9ed9b8fc..49252a33 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -175,14 +175,14 @@ gboolean binreloc_init(gboolean try_hardcoded) /* If the runtime data directories we previously found, don't even try to find them again. */ - if (path_data && path_lib) { + if (params.path_data && params.path_lib) { return TRUE; } if (try_hardcoded || !gbr_init(&error)) { /* We were asked to try hardcoded paths or BinReloc failed to initialize. */ - path_data = g_strdup(PREFIX); - path_lib = g_strdup(LIBPREFIX); + params.path_data = g_strdup(PREFIX); + params.path_lib = g_strdup(LIBPREFIX); if (error) { g_error_free(error); @@ -191,23 +191,23 @@ gboolean binreloc_init(gboolean try_hardcoded) /* If we were able to initialize BinReloc, build the default data and library paths. */ tmp = gbr_find_data_dir(PREFIX); - path_data = g_build_filename(tmp, "hardinfo", NULL); + params.path_data = g_build_filename(tmp, "hardinfo", NULL); g_free(tmp); tmp = gbr_find_lib_dir(PREFIX); - path_lib = g_build_filename(tmp, "hardinfo", NULL); + params.path_lib = g_build_filename(tmp, "hardinfo", NULL); g_free(tmp); } /* Try to see if the uidefs.xml file isn't missing. This isn't the definitive test, but it should do okay for most situations. */ - tmp = g_build_filename(path_data, "uidefs.xml", NULL); + tmp = g_build_filename(params.path_data, "uidefs.xml", NULL); if (!g_file_test(tmp, G_FILE_TEST_EXISTS)) { - g_free(path_data); - g_free(path_lib); + g_free(params.path_data); + g_free(params.path_lib); g_free(tmp); - path_data = path_lib = NULL; + params.path_data = params.path_lib = NULL; if (try_hardcoded) { /* We tried the hardcoded paths, but still was unable to find the @@ -230,7 +230,7 @@ log_handler(const gchar * log_domain, GLogLevelFlags log_level, const gchar * message, gpointer user_data) { - if (!gui_running) { + if (!params.gui_running) { /* No GUI running: spit the message to the terminal */ g_print("\n\n*** %s: %s\n\n", (log_level & G_LOG_FLAG_FATAL) ? "Error" : "Warning", @@ -259,6 +259,7 @@ log_handler(const gchar * log_domain, void parameters_init(int *argc, char ***argv, ProgramParameters * param) { static gboolean create_report = FALSE; + static gboolean show_version = FALSE; static gchar *report_format = NULL; static GOptionEntry options[] = { @@ -267,16 +268,23 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) .short_name = 'r', .arg = G_OPTION_ARG_NONE, .arg_data = &create_report, - .description = "create a report and print to standard output" + .description = "creates a report and prints to standard output" }, { .long_name = "report-format", .short_name = 'f', .arg = G_OPTION_ARG_STRING, .arg_data = &report_format, - .description = "choose a report format (text, html)" + .description = "chooses a report format (text, html)" }, - { NULL } + { + .long_name = "version", + .short_name = 'v', + .arg = G_OPTION_ARG_NONE, + .arg_data = &show_version, + .description = "shows program version and quit" + }, + { NULL } }; GOptionContext *ctx; @@ -291,6 +299,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) param->create_report = create_report; param->report_format = REPORT_FORMAT_TEXT; + param->show_version = show_version; if (report_format && g_str_equal(report_format, "html")) param->report_format = REPORT_FORMAT_HTML; @@ -348,7 +357,7 @@ GSList *modules_load(void) keyfile = g_key_file_new(); - modules_conf = g_build_filename(path_data, "modules.conf", NULL); + modules_conf = g_build_filename(params.path_data, "modules.conf", NULL); g_key_file_load_from_file(keyfile, modules_conf, 0, NULL); g_free(modules_conf); @@ -365,7 +374,7 @@ GSList *modules_load(void) module->name = g_strdup(cat[i]); iname = g_key_file_get_value(keyfile, "categories", cat[i], NULL); - if (gui_running) { + if (params.gui_running) { tmp = g_strdup_printf("%s.png", iname); module->icon = icon_cache_get_pixbuf(tmp); g_free(tmp); @@ -375,7 +384,7 @@ GSList *modules_load(void) g_free(iname); iname = tmp; - tmp = g_build_filename(path_lib, "modules", iname, NULL); + tmp = g_build_filename(params.path_lib, "modules", iname, NULL); module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); g_free(tmp); @@ -393,7 +402,7 @@ GSList *modules_load(void) const gchar *(*shell_name) (gint); ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); - if (gui_running + if (params.gui_running && g_module_symbol(module->dll, "hi_icon", (gpointer) & (shell_icon))) { entry->icon = shell_icon(i); @@ -430,7 +439,7 @@ GSList *modules_load(void) if (g_slist_length(modules) == 0) { g_error ("No module could be loaded. Check permissions on %s and try again.", - path_lib); + params.path_lib); } return modules; |