00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "heraia_types.h"
00025
00026 static GladeXML *load_glade_xml_if_it_exists(char *file_to_load);
00027
00033 gboolean load_file_to_analyse(heraia_window_t *main_window, gchar *filename)
00034 {
00035 struct stat *stat_buf = NULL;
00036 gboolean success = FALSE;
00037 GtkWidget *notebook = NULL;
00038
00039 g_return_val_if_fail(filename != NULL, FALSE);
00040 g_return_val_if_fail(main_window != NULL, FALSE);
00041
00042 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00043 stat(filename, stat_buf);
00044
00045 log_message(main_window, G_LOG_LEVEL_DEBUG, "filename to load : %s", filename);
00046
00047 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00048 {
00049
00050 heraia_hex_document_new(main_window, filename);
00051
00052 gtk_box_pack_start(GTK_BOX(heraia_get_widget(main_window->xmls->main, "vbox1")),
00053 main_window->current_DW->current_hexwidget, TRUE, TRUE, 0);
00054
00055 gtk_widget_show(main_window->current_DW->current_hexwidget);
00056
00057 log_message(main_window, G_LOG_LEVEL_DEBUG, "Hexwidget : %p", main_window->current_DW->current_hexwidget);
00058
00059 success = TRUE;
00060
00061 if (main_window->filename != filename)
00062 {
00063 if (main_window->filename != NULL)
00064 {
00065 g_free(main_window->filename);
00066 }
00067 main_window->filename = g_strdup_printf("%s", filename);
00068 }
00069
00070
00071 update_main_window_name(main_window);
00072 set_notebook_tab_name(main_window);
00073
00074
00075 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00076 gtk_widget_show(notebook);
00077
00078 log_message(main_window, G_LOG_LEVEL_DEBUG, "file %s loaded !", main_window->filename);
00079
00080
00081 }
00082 else
00083 {
00084 if (S_ISREG(stat_buf->st_mode))
00085 {
00086 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s is empty !\n", filename);
00087 }
00088 else
00089 {
00090 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s does not exist !\n", filename);
00091 }
00092 success = FALSE;
00093 }
00094
00095 g_free(stat_buf);
00096
00097 return success;
00098 }
00099
00100
00105 static GladeXML *load_glade_xml_if_it_exists(gchar *file_to_load)
00106 {
00107 struct stat *stat_buf;
00108 GladeXML *xml = NULL;
00109
00110 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00111
00112 stat(file_to_load, stat_buf);
00113 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00114 {
00115 xml = glade_xml_new(file_to_load, NULL, NULL);
00116 }
00117 else
00118 {
00119 xml = NULL;
00120 }
00121
00122 g_free(stat_buf);
00123
00124 return xml;
00125 }
00126
00127
00128
00129
00130
00131 GladeXML *load_glade_xml_file(GList *location_list, gchar *filename)
00132 {
00133 gchar *file_to_load = NULL;
00134 GList *list = g_list_first(location_list);
00135 GladeXML *xml = NULL;
00136
00137 while (list != NULL && xml == NULL)
00138 {
00139 file_to_load = g_build_filename((gchar *) list->data, filename, NULL);
00140
00141 xml = load_glade_xml_if_it_exists(file_to_load);
00142
00143 if (xml == NULL)
00144 {
00145 list = list->next;
00146 }
00147 g_free(file_to_load);
00148 }
00149
00150 return xml;
00151 }