Create the directory for the preferences files before writing out the
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 26 Mar 2005 01:05:29 +0000 (01:05 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 26 Mar 2005 01:05:29 +0000 (01:05 +0000)
"recent" file.

Have "write_recent()" handle putting up error windows for failed
attempts to write the "recent" file.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13909 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/main.c
gtk/recent.c
gtk/recent.h

index d833c87015b1ac116b39d55e8d1454f801a9d6e6..8afed64ac116a7617b68cd1366c89d7fd098910d 100644 (file)
@@ -864,15 +864,12 @@ main_set_for_capture_file(gboolean have_capture_file_in)
 gboolean
 main_do_quit(void)
 {
-       gchar *rec_path;
-
-
-    /* get the current geometry, before writing it to disk */
-    main_save_window_geometry(top_level);
+       /* get the current geometry, before writing it to disk */
+       main_save_window_geometry(top_level);
 
        /* write user's recent file to disk
         * It is no problem to write this file, even if we do not quit */
-       write_recent(&rec_path);
+       write_recent();
 
        /* XXX - should we check whether the capture file is an
           unsaved temporary file for a live capture and, if so,
index 2708ae7690c4075d7f8f7cfe253d6d53b193cc6b..5e200f8e961c12c35e2161799aecdf53b586496d 100644 (file)
@@ -41,6 +41,7 @@
 #include "ui_util.h"
 #include "dlg_utils.h"
 #include "cfilter_combo_utils.h"
+#include "simple_dialog.h"
 
 #define RECENT_KEY_MAIN_TOOLBAR_SHOW        "gui.toolbar_main_show"
 #define RECENT_KEY_FILTER_TOOLBAR_SHOW      "gui.filter_toolbar_show"
@@ -91,12 +92,13 @@ find_index_from_string_array(char *needle, char **haystack, int default_value)
        return default_value;
 }
 
-/* Write out "recent" to the user's recent file, and return 0.
-   If we got an error, stuff a pointer to the path of the recent file
-   into "*pf_path_return", and return the errno. */
-int
-write_recent(char **rf_path_return)
+/* Attempt to Write out "recent" to the user's recent file.
+   If we got an error report it with a dialog box and return FALSE,
+   otherwise return TRUE. */
+gboolean
+write_recent(void)
 {
+  char        *pf_dir_path;
   char        *rf_path;
   FILE        *rf;
 
@@ -106,10 +108,23 @@ write_recent(char **rf_path_return)
    *   so that duplication can be avoided with filter.c
    */
 
+  /* Create the directory that holds personal configuration files, if
+     necessary.  */
+  if (create_persconffile_dir(&pf_dir_path) == -1) {
+     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
+      strerror(errno));
+     g_free(pf_dir_path);
+     return FALSE;
+  }
+
   rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);
   if ((rf = fopen(rf_path, "w")) == NULL) {
-    *rf_path_return = rf_path;
-    return errno;
+     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+      "Can't open recent file\n\"%s\": %s.", rf_path,
+      strerror(errno));
+    g_free(rf_path);
+    return FALSE;
   }
 
   fputs("# Recent settings file for Ethereal " VERSION ".\n"
@@ -213,10 +228,10 @@ write_recent(char **rf_path_return)
   fclose(rf);
 
   /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
-     an error indication, or maybe write to a new preferences file and
+     an error indication, or maybe write to a new recent file and
      rename that file on top of the old one only if there are not I/O
      errors. */
-  return 0;
+  return TRUE;
 }
 
 
index 6307b58b1d6c645d0a9fb87f0354d1857204f1fb..f034962c35cc4d4cf6b3988ef726535fd0a1ec7f 100644 (file)
@@ -67,10 +67,9 @@ extern recent_settings_t recent;
 
 /** Write recent settings file.
  *
- * @param rf_path_return path to recent file if function failed
- * @return 0 if succeeded, errno if failed
+ * @return TRUE if succeeded, FALSE if failed
  */
-extern int write_recent(char **rf_path_return);
+extern gboolean write_recent(void);
 
 /** Read recent settings file.
  *