Change includes for getenv_utf8()
[obnox/wireshark/wip.git] / file.c
diff --git a/file.c b/file.c
index 680940a1c9febaab71ee1862a39977ed56452a9f..c69e0ea51877738d14db5580992c228454b6d727 100644 (file)
--- a/file.c
+++ b/file.c
@@ -60,6 +60,7 @@
 #include "merge.h"
 #include "alert_box.h"
 #include "simple_dialog.h"
+#include "main_statusbar.h"
 #include "progress_dlg.h"
 #include "ui_util.h"
 #include <epan/prefs.h>
@@ -473,24 +474,46 @@ static void outofmemory_cb(gpointer dialog _U_, gint btn _U_, gpointer data _U_)
     main_window_exit();
 }
 
-static float calc_progbar_val(capture_file *cf, gint64 size, gint64 file_pos){
-
+static float
+calc_progbar_val(capture_file *cf, gint64 size, gint64 file_pos, gchar *status_str, gulong status_size)
+{
   float   progbar_val;
 
   progbar_val = (gfloat) file_pos / (gfloat) size;
   if (progbar_val > 1.0) {
-    /* The file probably grew while we were reading it.
-       Update file size, and try again. */
+
+    /*  The file probably grew while we were reading it.
+     *  Update file size, and try again.
+     */
     size = wtap_file_size(cf->wth, NULL);
+
+    /*  Another possibility is that we're reading a compressed file and we've
+     *  read more (uncompressed) data from the file than exists in the
+     *  (compressed) file.  So check how much data we've actually read.
+     *
+     *  This is inside this "if val > 1.0" check to avoid the lseek() when
+     *  reading uncompressed files.  Testing has (thus far) shown no progress
+     *  bar weirdness resulting from switching from the data offset (when
+     *  reading the first part of the file) to the real file position.
+     */
+    file_pos = wtap_read_so_far(cf->wth, NULL);
+
     if (size >= 0)
       progbar_val = (gfloat) file_pos / (gfloat) size;
-    /* If it's still > 1, either "wtap_file_size()" failed (in which
-       case there's not much we can do about it), or the file
-       *shrank* (in which case there's not much we can do about
-       it); just clip the progress value at 1.0. */
+
+    /*  If it's still > 1, either "wtap_file_size()" failed (in which
+     *  case there's not much we can do about it), or the file
+     *  *shrank* (in which case there's not much we can do about
+     *  it); just clip the progress value at 1.0.
+     */
     if (progbar_val > 1.0f)
       progbar_val = 1.0f;
   }
+
+  g_snprintf(status_str, status_size,
+            "%" G_GINT64_MODIFIER "dKB of %" G_GINT64_MODIFIER "dKB",
+            file_pos / 1024, size / 1024);
+
   return progbar_val;
 }
 
@@ -571,10 +594,10 @@ cf_read(capture_file *cf, gboolean from_save)
     if (size >= 0) {
       count++;
       /* Create the progress bar if necessary.
-       * Check wether it should be created or not every MIN_NUMBER_OF_PACKET
+       * Check whether it should be created or not every MIN_NUMBER_OF_PACKET
        */
       if ((progbar == NULL) && !(count % MIN_NUMBER_OF_PACKET)){
-        progbar_val = calc_progbar_val( cf, size, data_offset);
+        progbar_val = calc_progbar_val(cf, size, data_offset, status_str, sizeof(status_str));
         if (from_save == FALSE)
           progbar = delayed_create_progress_dlg("Loading", name_ptr,
                                                 TRUE, &stop_flag, &start_time, progbar_val);
@@ -590,7 +613,7 @@ cf_read(capture_file *cf, gboolean from_save)
          that for every packet can be costly, especially on a big file. */
       if (data_offset >= progbar_nextstep) {
         if (progbar != NULL) {
-          progbar_val = calc_progbar_val( cf, size, data_offset);
+          progbar_val = calc_progbar_val(cf, size, data_offset, status_str, sizeof(status_str));
           /* update the packet lists content on the first run or frequently on very large files */
           /* (on smaller files the display update takes longer than reading the file) */
 #ifdef HAVE_LIBPCAP
@@ -611,9 +634,6 @@ cf_read(capture_file *cf, gboolean from_save)
             }
           }
 #endif /* HAVE_LIBPCAP */
-          g_snprintf(status_str, sizeof(status_str),
-                     "%" G_GINT64_MODIFIER "dKB of %" G_GINT64_MODIFIER "dKB",
-                     data_offset / 1024, size / 1024);
           update_progress_dlg(progbar, progbar_val, status_str);
         }
         progbar_nextstep += progbar_quantum;
@@ -1829,7 +1849,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
      start? */
   selected_frame = cf->current_frame;
 
-  /* Mark frane num as not found */
+  /* Mark frame num as not found */
   selected_frame_num = -1;
 
   /* Freeze the packet list while we redo it, so we don't get any
@@ -3912,12 +3932,12 @@ find_packet(capture_file *cf,
 
           if (prefs.gui_find_wrap)
           {
-              simple_status("Search reached the beginning. Continuing at end.");
+              statusbar_push_temporary_msg("Search reached the beginning. Continuing at end.");
               fdata = cf->plist_end;    /* wrap around */
           }
           else
           {
-              simple_status("Search reached the beginning.");
+              statusbar_push_temporary_msg("Search reached the beginning.");
               fdata = start_fd;        /* stay on previous packet */
           }
         }
@@ -3927,12 +3947,12 @@ find_packet(capture_file *cf,
         if (fdata == NULL) {
           if (prefs.gui_find_wrap)
           {
-              simple_status("Search reached the end. Continuing at beginning.");
+              statusbar_push_temporary_msg("Search reached the end. Continuing at beginning.");
               fdata = cf->plist_start;    /* wrap around */
           }
           else
           {
-              simple_status("Search reached the end.");
+              statusbar_push_temporary_msg("Search reached the end.");
               fdata = start_fd;     /* stay on previous packet */
           }
         }
@@ -4008,13 +4028,13 @@ cf_goto_frame(capture_file *cf, guint fnumber)
 
   if (fdata == NULL) {
     /* we didn't find a packet with that packet number */
-    simple_status("There is no packet number %u.", fnumber);
+    statusbar_push_temporary_msg("There is no packet number %u.", fnumber);
     return FALSE;   /* we failed to go to that packet */
   }
   if (!fdata->flags.passed_dfilter) {
     /* that packet currently isn't displayed */
     /* XXX - add it to the set of displayed packets? */
-    simple_status("Packet number %u isn't displayed.", fnumber);
+    statusbar_push_temporary_msg("Packet number %u isn't displayed.", fnumber);
     return FALSE;   /* we failed to go to that packet */
   }