Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1239,74 +1239,66 @@ guint wb_project_get_bookmarks_count(WB_PROJECT *prj) | |
**/ | ||
gboolean wb_project_save(WB_PROJECT *prj, GError **error) | ||
{ | ||
GKeyFile *kf; | ||
guint index; | ||
gchar *contents; | ||
gsize length, boomarks_size; | ||
gboolean success = FALSE; | ||
WB_PROJECT_ON_SAVE_USER_DATA tmp; | ||
|
||
if (prj != NULL) | ||
g_return_val_if_fail(prj, FALSE); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lpaulsen93
Author
Contributor
|
||
|
||
/* Load existing data into GKeyFile */ | ||
kf = g_key_file_new (); | ||
if (!g_key_file_load_from_file(kf, prj->filename, G_KEY_FILE_NONE, error)) | ||
{ | ||
GKeyFile *kf; | ||
guint index; | ||
gchar *contents; | ||
gsize length, boomarks_size; | ||
return FALSE; | ||
} | ||
|
||
/* Load existing data into GKeyFile */ | ||
kf = g_key_file_new (); | ||
if (!g_key_file_load_from_file(kf, prj->filename, G_KEY_FILE_NONE, error)) | ||
{ | ||
return FALSE; | ||
} | ||
/* Remove existing, old data from our plugin */ | ||
g_key_file_remove_group (kf, "Workbench", NULL); | ||
|
||
/* Remove existing, old data from our plugin */ | ||
g_key_file_remove_group (kf, "Workbench", NULL); | ||
/* Save Project bookmarks as string list */ | ||
boomarks_size = wb_project_get_bookmarks_count(prj); | ||
if (boomarks_size > 0) | ||
{ | ||
gchar **bookmarks_strings, *file, *rel_path; | ||
|
||
/* Save Project bookmarks as string list */ | ||
boomarks_size = wb_project_get_bookmarks_count(prj); | ||
if (boomarks_size > 0) | ||
bookmarks_strings = g_new0(gchar *, boomarks_size+1); | ||
for (index = 0 ; index < boomarks_size ; index++ ) | ||
{ | ||
gchar **bookmarks_strings, *file, *rel_path; | ||
file = wb_project_get_bookmark_at_index(prj, index); | ||
rel_path = get_any_relative_path(prj->filename, file); | ||
|
||
bookmarks_strings = g_new0(gchar *, boomarks_size+1); | ||
for (index = 0 ; index < boomarks_size ; index++ ) | ||
{ | ||
file = wb_project_get_bookmark_at_index(prj, index); | ||
rel_path = get_any_relative_path(prj->filename, file); | ||
|
||
bookmarks_strings[index] = rel_path; | ||
} | ||
g_key_file_set_string_list | ||
(kf, "Workbench", "Bookmarks", (const gchar **)bookmarks_strings, boomarks_size); | ||
for (index = 0 ; index < boomarks_size ; index++ ) | ||
{ | ||
g_free (bookmarks_strings[index]); | ||
} | ||
g_free(bookmarks_strings); | ||
bookmarks_strings[index] = rel_path; | ||
} | ||
g_key_file_set_string_list | ||
(kf, "Workbench", "Bookmarks", (const gchar **)bookmarks_strings, boomarks_size); | ||
for (index = 0 ; index < boomarks_size ; index++ ) | ||
{ | ||
g_free (bookmarks_strings[index]); | ||
} | ||
g_free(bookmarks_strings); | ||
} | ||
|
||
/* Init tmp data */ | ||
tmp.kf = kf; | ||
tmp.dir_count = 1; | ||
/* Init tmp data */ | ||
tmp.kf = kf; | ||
tmp.dir_count = 1; | ||
|
||
/* Store our directories */ | ||
g_slist_foreach(prj->directories, (GFunc)wb_project_save_directories, &tmp); | ||
/* Store our directories */ | ||
g_slist_foreach(prj->directories, (GFunc)wb_project_save_directories, &tmp); | ||
|
||
/* Get data as string */ | ||
contents = g_key_file_to_data (kf, &length, error); | ||
g_key_file_free(kf); | ||
/* Get data as string */ | ||
contents = g_key_file_to_data (kf, &length, error); | ||
g_key_file_free(kf); | ||
|
||
/* Save to file */ | ||
success = g_file_set_contents (prj->filename, contents, length, error); | ||
if (success) | ||
{ | ||
prj->modified = FALSE; | ||
} | ||
g_free (contents); | ||
} | ||
else if (error != NULL) | ||
/* Save to file */ | ||
success = g_file_set_contents (prj->filename, contents, length, error); | ||
if (success) | ||
{ | ||
g_set_error (error, 0, 0, | ||
"Internal error: param missing (file: %s, line %d)", | ||
__FILE__, __LINE__); | ||
prj->modified = FALSE; | ||
} | ||
g_free (contents); | ||
|
||
return success; | ||
} | ||
|
@@ -1325,118 +1317,110 @@ gboolean wb_project_save(WB_PROJECT *prj, GError **error) | |
**/ | ||
gboolean wb_project_load(WB_PROJECT *prj, gchar *filename, GError **error) | ||
{ | ||
GKeyFile *kf; | ||
guint index; | ||
gchar *contents; | ||
gchar key[100]; | ||
gsize length; | ||
gboolean success = FALSE; | ||
|
||
if (prj != NULL) | ||
g_return_val_if_fail(prj, FALSE); | ||
|
||
if (!g_file_get_contents (filename, &contents, &length, error)) | ||
{ | ||
GKeyFile *kf; | ||
guint index; | ||
gchar *contents; | ||
gchar key[100]; | ||
gsize length; | ||
return FALSE; | ||
} | ||
|
||
if (!g_file_get_contents (filename, &contents, &length, error)) | ||
{ | ||
return FALSE; | ||
} | ||
kf = g_key_file_new (); | ||
|
||
kf = g_key_file_new (); | ||
if (!g_key_file_load_from_data (kf, contents, length, | ||
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, | ||
error)) | ||
{ | ||
g_key_file_free (kf); | ||
g_free (contents); | ||
return FALSE; | ||
} | ||
|
||
if (!g_key_file_load_from_data (kf, contents, length, | ||
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, | ||
error)) | ||
{ | ||
g_key_file_free (kf); | ||
g_free (contents); | ||
return FALSE; | ||
} | ||
if (g_key_file_has_group (kf, "Workbench")) | ||
{ | ||
WB_PROJECT_DIR *new_dir; | ||
gchar *str; | ||
gchar **splitv, **bookmarks_strings; | ||
|
||
if (g_key_file_has_group (kf, "Workbench")) | ||
/* Load project bookmarks from string list */ | ||
bookmarks_strings = g_key_file_get_string_list (kf, "Workbench", "Bookmarks", NULL, error); | ||
if (bookmarks_strings != NULL) | ||
{ | ||
WB_PROJECT_DIR *new_dir; | ||
gchar *str; | ||
gchar **splitv, **bookmarks_strings; | ||
gchar **file, *abs_path; | ||
|
||
/* Load project bookmarks from string list */ | ||
bookmarks_strings = g_key_file_get_string_list (kf, "Workbench", "Bookmarks", NULL, error); | ||
if (bookmarks_strings != NULL) | ||
file = bookmarks_strings; | ||
while (*file != NULL) | ||
{ | ||
gchar **file, *abs_path; | ||
|
||
file = bookmarks_strings; | ||
while (*file != NULL) | ||
abs_path = get_combined_path(prj->filename, *file); | ||
if (abs_path != NULL) | ||
{ | ||
abs_path = get_combined_path(prj->filename, *file); | ||
if (abs_path != NULL) | ||
{ | ||
wb_project_add_bookmark_int(prj, abs_path); | ||
g_free(abs_path); | ||
} | ||
file++; | ||
wb_project_add_bookmark_int(prj, abs_path); | ||
g_free(abs_path); | ||
} | ||
g_strfreev(bookmarks_strings); | ||
file++; | ||
} | ||
g_strfreev(bookmarks_strings); | ||
} | ||
|
||
/* Load project dirs */ | ||
for (index = 1 ; index < 1025 ; index++) | ||
/* Load project dirs */ | ||
for (index = 1 ; index < 1025 ; index++) | ||
{ | ||
g_snprintf(key, sizeof(key), "Dir%u-BaseDir", index); | ||
if (!g_key_file_has_key (kf, "Workbench", key, NULL)) | ||
{ | ||
g_snprintf(key, sizeof(key), "Dir%u-BaseDir", index); | ||
if (!g_key_file_has_key (kf, "Workbench", key, NULL)) | ||
{ | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str == NULL) | ||
{ | ||
break; | ||
} | ||
new_dir = wb_project_add_directory_int(prj, str, FALSE); | ||
if (new_dir == NULL) | ||
{ | ||
break; | ||
} | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str == NULL) | ||
{ | ||
break; | ||
} | ||
new_dir = wb_project_add_directory_int(prj, str, FALSE); | ||
if (new_dir == NULL) | ||
{ | ||
break; | ||
} | ||
|
||
g_snprintf(key, sizeof(key), "Dir%u-FilePatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_file_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
g_snprintf(key, sizeof(key), "Dir%u-FilePatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_file_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
|
||
g_snprintf(key, sizeof(key), "Dir%u-IgnoredDirsPatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_ignored_dirs_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
g_snprintf(key, sizeof(key), "Dir%u-IgnoredDirsPatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_ignored_dirs_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
|
||
g_snprintf(key, sizeof(key), "Dir%u-IgnoredFilePatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_ignored_file_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
g_snprintf(key, sizeof(key), "Dir%u-IgnoredFilePatterns", index); | ||
str = g_key_file_get_string(kf, "Workbench", key, NULL); | ||
if (str != NULL) | ||
{ | ||
splitv = g_strsplit (str, ";", -1); | ||
wb_project_dir_set_ignored_file_patterns(new_dir, splitv); | ||
} | ||
g_free(str); | ||
} | ||
|
||
g_key_file_free(kf); | ||
g_free (contents); | ||
success = TRUE; | ||
} | ||
else if (error != NULL) | ||
{ | ||
g_set_error (error, 0, 0, | ||
"Internal error: param missing (file: %s, line %d)", | ||
__FILE__, __LINE__); | ||
} | ||
|
||
g_key_file_free(kf); | ||
g_free (contents); | ||
success = TRUE; | ||
|
||
return success; | ||
} | ||
|
||
|
Are you aware that its possible for distributions or others to build with G_DISABLE_CHECKS and the
g_return_val_if_failed
will be removed, so the function will crash on some poor user if their actions happen to result in the function being called with a NULL?Your documentation for the function doesn't disallow NULL, so you always need to reject it. Probably better to use an if and
g_warning
or g_critical` for the message, which can be made to crash for easier debugging by setting G_DEBUG.There have been some spirited Geany discussions about the "right" way to use these Glib debugging macros (IMHO there is none if the macro can be compiled out, unless you can prove by analysis or exhaustive testing that the failure cannot occur to the above mentioned innocent user, but if you can do that you don't need the test in the first place). Its certainly the case that Geany itself is still subject to the problem referred to above.