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
00038 g_return_val_if_fail(filename != NULL, FALSE);
00039 g_return_val_if_fail(main_window != NULL, FALSE);
00040
00041 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00042 stat(filename, stat_buf);
00043
00044 log_message(main_window, G_LOG_LEVEL_DEBUG, "filename to load : %s", filename);
00045
00046 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00047 {
00048
00049 heraia_hex_document_new(main_window, filename);
00050
00051 gtk_box_pack_start(GTK_BOX(heraia_get_widget(main_window->xmls->main, "vbox1")),
00052 main_window->current_DW->current_hexwidget, TRUE, TRUE, 0);
00053
00054 gtk_widget_show(main_window->current_DW->current_hexwidget);
00055
00056 log_message(main_window, G_LOG_LEVEL_DEBUG, "Hexwidget : %p", main_window->current_DW->current_hexwidget);
00057
00058 success = TRUE;
00059
00060 if (main_window->filename != filename)
00061 {
00062 if (main_window->filename != NULL)
00063 {
00064 g_free(main_window->filename);
00065 }
00066 main_window->filename = g_strdup_printf("%s", filename);
00067 }
00068
00069
00070 update_main_window_name(main_window);
00071
00072 log_message(main_window, G_LOG_LEVEL_DEBUG, "file %s loaded !", main_window->filename);
00073
00074 }
00075 else
00076 {
00077 if (S_ISREG(stat_buf->st_mode))
00078 {
00079 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s is empty !\n", filename);
00080 }
00081 else
00082 {
00083 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s does not exist !\n", filename);
00084 }
00085 success = FALSE;
00086 }
00087
00088 g_free(stat_buf);
00089
00090 return success;
00091 }
00092
00093
00098 static GladeXML *load_glade_xml_if_it_exists(gchar *file_to_load)
00099 {
00100 struct stat *stat_buf;
00101 GladeXML *xml = NULL;
00102
00103 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00104
00105 stat(file_to_load, stat_buf);
00106 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00107 {
00108 xml = glade_xml_new(file_to_load, NULL, NULL);
00109 }
00110 else
00111 {
00112 xml = NULL;
00113 }
00114
00115 g_free(stat_buf);
00116
00117 return xml;
00118 }
00119
00120
00121
00122
00123
00124 GladeXML *load_glade_xml_file(GList *location_list, gchar *filename)
00125 {
00126 gchar *file_to_load = NULL;
00127 GList *list = g_list_first(location_list);
00128 GladeXML *xml = NULL;
00129
00130 while (list != NULL && xml == NULL)
00131 {
00132 file_to_load = g_build_filename((gchar *) list->data, filename, NULL);
00133
00134 xml = load_glade_xml_if_it_exists(file_to_load);
00135
00136 if (xml == NULL)
00137 {
00138 list = list->next;
00139 }
00140 g_free(file_to_load);
00141 }
00142
00143 return xml;
00144 }