Mercurial > pidgin.yaz
comparison libpurple/util.c @ 23473:60d3ba8c9047
propagate from branch 'im.pidgin.pidgin' (head 1d533cebad7c0dbda8ec8ebee1334d27dcae5f9c)
to branch 'im.pidgin.soc.2008.themes' (head 6108b8f480f1589e219641d557022940902871cf)
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 30 Jun 2008 23:12:54 +0000 |
parents | 276925996951 774ef2a2e7f8 |
children | 2ecd716746e6 |
comparison
equal
deleted
inserted
replaced
23398:47b709962aab | 23473:60d3ba8c9047 |
---|---|
2755 } | 2755 } |
2756 | 2756 |
2757 xmlnode * | 2757 xmlnode * |
2758 purple_util_read_xml_from_file(const char *filename, const char *description) | 2758 purple_util_read_xml_from_file(const char *filename, const char *description) |
2759 { | 2759 { |
2760 const char *user_dir = purple_user_dir(); | 2760 return xmlnode_from_file(purple_user_dir(), filename, description, "util"); |
2761 gchar *filename_full; | |
2762 GError *error = NULL; | |
2763 gchar *contents = NULL; | |
2764 gsize length; | |
2765 xmlnode *node = NULL; | |
2766 | |
2767 g_return_val_if_fail(user_dir != NULL, NULL); | |
2768 | |
2769 purple_debug_info("util", "Reading file %s from directory %s\n", | |
2770 filename, user_dir); | |
2771 | |
2772 filename_full = g_build_filename(user_dir, filename, NULL); | |
2773 | |
2774 if (!g_file_test(filename_full, G_FILE_TEST_EXISTS)) | |
2775 { | |
2776 purple_debug_info("util", "File %s does not exist (this is not " | |
2777 "necessarily an error)\n", filename_full); | |
2778 g_free(filename_full); | |
2779 return NULL; | |
2780 } | |
2781 | |
2782 if (!g_file_get_contents(filename_full, &contents, &length, &error)) | |
2783 { | |
2784 purple_debug_error("util", "Error reading file %s: %s\n", | |
2785 filename_full, error->message); | |
2786 g_error_free(error); | |
2787 } | |
2788 | |
2789 if ((contents != NULL) && (length > 0)) | |
2790 { | |
2791 node = xmlnode_from_str(contents, length); | |
2792 | |
2793 /* If we were unable to parse the file then save its contents to a backup file */ | |
2794 if (node == NULL) | |
2795 { | |
2796 gchar *filename_temp; | |
2797 | |
2798 filename_temp = g_strdup_printf("%s~", filename); | |
2799 purple_debug_error("util", "Error parsing file %s. Renaming old " | |
2800 "file to %s\n", filename_full, filename_temp); | |
2801 purple_util_write_data_to_file(filename_temp, contents, length); | |
2802 g_free(filename_temp); | |
2803 } | |
2804 | |
2805 g_free(contents); | |
2806 } | |
2807 | |
2808 /* If we could not parse the file then show the user an error message */ | |
2809 if (node == NULL) | |
2810 { | |
2811 gchar *title, *msg; | |
2812 title = g_strdup_printf(_("Error Reading %s"), filename); | |
2813 msg = g_strdup_printf(_("An error was encountered reading your " | |
2814 "%s. They have not been loaded, and the old file " | |
2815 "has been renamed to %s~."), description, filename_full); | |
2816 purple_notify_error(NULL, NULL, title, msg); | |
2817 g_free(title); | |
2818 g_free(msg); | |
2819 } | |
2820 | |
2821 g_free(filename_full); | |
2822 | |
2823 return node; | |
2824 } | 2761 } |
2825 | 2762 |
2826 /* | 2763 /* |
2827 * Like mkstemp() but returns a file pointer, uses a pre-set template, | 2764 * Like mkstemp() but returns a file pointer, uses a pre-set template, |
2828 * uses the semantics of tempnam() for the directory to use and allocates | 2765 * uses the semantics of tempnam() for the directory to use and allocates |