heraia_io.c
Go to the documentation of this file.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 gboolean load_file_to_analyse(heraia_window_t *main_window, gchar *filename)
00040 {
00041 struct stat *stat_buf = NULL;
00042 gboolean success = FALSE;
00043 GtkWidget *notebook = NULL;
00044 doc_t* doc = 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 doc = heraia_hex_document_new(main_window, filename);
00058
00059 if (doc != NULL)
00060 {
00061 add_new_tab_in_main_window(main_window, doc);
00062
00063
00064
00065
00066
00067
00068
00069
00070 log_message(main_window, G_LOG_LEVEL_DEBUG, "Hexwidget : %p", doc->hex_widget);
00071
00072 success = TRUE;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 update_main_window_name(main_window);
00087 set_notebook_tab_name(main_window);
00088
00089
00090 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save"), TRUE);
00091 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save_as"), TRUE);
00092 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00093 gtk_widget_show(notebook);
00094
00095 log_message(main_window, G_LOG_LEVEL_DEBUG, "file %s loaded !", filename);
00096 }
00097 else
00098 {
00099 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while trying to load file %s", filename);
00100 success = FALSE;
00101 }
00102
00103 }
00104 else
00105 {
00106 if (S_ISREG(stat_buf->st_mode))
00107 {
00108 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s is empty !", filename);
00109 }
00110 else
00111 {
00112 log_message(main_window, G_LOG_LEVEL_WARNING, "The file %s does not exist !", filename);
00113 }
00114 success = FALSE;
00115 }
00116
00117 g_free(stat_buf);
00118
00119 return success;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 static GladeXML *load_glade_xml_if_it_exists(gchar *file_to_load)
00131 {
00132 struct stat *stat_buf;
00133 GladeXML *xml = NULL;
00134
00135 stat_buf = (struct stat *) g_malloc0 (sizeof(struct stat));
00136
00137 stat(file_to_load, stat_buf);
00138 if (S_ISREG(stat_buf->st_mode) && stat_buf->st_size>0)
00139 {
00140 xml = glade_xml_new(file_to_load, NULL, NULL);
00141 }
00142 else
00143 {
00144 xml = NULL;
00145 }
00146
00147 g_free(stat_buf);
00148
00149 return xml;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 GladeXML *load_glade_xml_file(GList *location_list, gchar *filename)
00162 {
00163 gchar *file_to_load = NULL;
00164 GList *list = g_list_first(location_list);
00165 GladeXML *xml = NULL;
00166
00167 while (list != NULL && xml == NULL)
00168 {
00169 file_to_load = g_build_filename((gchar *) list->data, filename, NULL);
00170
00171 xml = load_glade_xml_if_it_exists(file_to_load);
00172
00173 if (xml == NULL)
00174 {
00175 list = list->next;
00176 }
00177 g_free(file_to_load);
00178 }
00179
00180 return xml;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 gboolean load_preference_file(heraia_window_t *main_window)
00191 {
00192 if (main_window != NULL && main_window->prefs != NULL)
00193 {
00194 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);
00195 }
00196 else
00197 {
00198 return FALSE;
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209 gboolean save_preferences_to_file(prefs_t *prefs)
00210 {
00211 gsize length = 0;
00212 gchar *contents = NULL;
00213 gboolean result = FALSE;
00214
00215 if (prefs != NULL && prefs->file != NULL && prefs->filename != NULL)
00216 {
00217 contents = g_key_file_to_data(prefs->file, &length, NULL);
00218 result = g_file_set_contents(prefs->filename, contents, length, NULL);
00219 g_free(contents);
00220 }
00221
00222 return result;
00223 }