00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <libheraia.h>
00028
00029 static GladeXML *load_glade_xml_if_it_exists(char *file_to_load);
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 gboolean load_file_to_analyse(heraia_window_t *main_window, gchar *filename)
00041 {
00042 struct stat *stat_buf = NULL;
00043 gboolean success = FALSE;
00044 GtkWidget *notebook = NULL;
00045
00046 g_return_val_if_fail(filename != NULL, FALSE);
00047 g_return_val_if_fail(main_window != NULL, FALSE);
00048
00049 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00050 stat(filename, stat_buf);
00051
00052 log_message(main_window, G_LOG_LEVEL_DEBUG, "filename to load : %s", filename);
00053
00054 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00055 {
00056
00057 heraia_hex_document_new(main_window, filename);
00058
00059 gtk_box_pack_start(GTK_BOX(heraia_get_widget(main_window->xmls->main, "vbox1")),
00060 main_window->current_DW->current_hexwidget, TRUE, TRUE, 0);
00061
00062 gtk_widget_show(main_window->current_DW->current_hexwidget);
00063
00064 log_message(main_window, G_LOG_LEVEL_DEBUG, "Hexwidget : %p", main_window->current_DW->current_hexwidget);
00065
00066 success = TRUE;
00067
00068 if (main_window->filename != filename)
00069 {
00070 if (main_window->filename != NULL)
00071 {
00072 g_free(main_window->filename);
00073 }
00074 main_window->filename = g_strdup_printf("%s", filename);
00075 }
00076
00077
00078 update_main_window_name(main_window);
00079 set_notebook_tab_name(main_window);
00080
00081
00082 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save"), TRUE);
00083 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save_as"), TRUE);
00084 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00085 gtk_widget_show(notebook);
00086
00087 log_message(main_window, G_LOG_LEVEL_DEBUG, "file %s loaded !", main_window->filename);
00088
00089
00090 }
00091 else
00092 {
00093 if (S_ISREG(stat_buf->st_mode))
00094 {
00095 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s is empty !", filename);
00096 }
00097 else
00098 {
00099 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s does not exist !", filename);
00100 }
00101 success = FALSE;
00102 }
00103
00104 g_free(stat_buf);
00105
00106 return success;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 static GladeXML *load_glade_xml_if_it_exists(gchar *file_to_load)
00118 {
00119 struct stat *stat_buf;
00120 GladeXML *xml = NULL;
00121
00122 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00123
00124 stat(file_to_load, stat_buf);
00125 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00126 {
00127 xml = glade_xml_new(file_to_load, NULL, NULL);
00128 }
00129 else
00130 {
00131 xml = NULL;
00132 }
00133
00134 g_free(stat_buf);
00135
00136 return xml;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 GladeXML *load_glade_xml_file(GList *location_list, gchar *filename)
00149 {
00150 gchar *file_to_load = NULL;
00151 GList *list = g_list_first(location_list);
00152 GladeXML *xml = NULL;
00153
00154 while (list != NULL && xml == NULL)
00155 {
00156 file_to_load = g_build_filename((gchar *) list->data, filename, NULL);
00157
00158 xml = load_glade_xml_if_it_exists(file_to_load);
00159
00160 if (xml == NULL)
00161 {
00162 list = list->next;
00163 }
00164 g_free(file_to_load);
00165 }
00166
00167 return xml;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177 gboolean load_preference_file(heraia_window_t *main_window)
00178 {
00179 if (main_window != NULL && main_window->prefs != NULL)
00180 {
00181 return g_key_file_load_from_file(main_window->prefs->file, main_window->prefs->filename, G_KEY_FILE_KEEP_COMMENTS & G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
00182 }
00183 else
00184 {
00185 return FALSE;
00186 }
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196 gboolean save_preferences_to_file(prefs_t *prefs)
00197 {
00198 gsize length = 0;
00199 gchar *contents = NULL;
00200 gboolean result = FALSE;
00201
00202 if (prefs != NULL && prefs->file != NULL && prefs->filename != NULL)
00203 {
00204 contents = g_key_file_to_data(prefs->file, &length, NULL);
00205 result = g_file_set_contents(prefs->filename, contents, length, NULL);
00206 g_free(contents);
00207 }
00208
00209 return result;
00210 }
00211
00212
00213