Progress bars were not being updated correctly with script sizes. Here are a
couple of patches that resolve this issue.
The one issue that still remains is that rc is still returning _1_ from
run_script even if the script explicitly exits with 0. To get around this I
just stopped testing for it - I don't think it will be a problem to increment
the progress bar even if the script failed.
This first patch fixes copy.c. First of all it passes in the correct size and
progress (I made the progress be size/2 just so that it looks like it is working
on something) into the update function.
The next fix is to first allow it to add bytes to installed_bytes (by removing
the test on rc) and next to actually add the right number of bytes (before it
was using sz which for me = "10M" and NOT the number of bytes).
Here is the first diff:
--- copy.c.old 2004-04-30 21:53:10.000000000 -0600
+++ copy.c 2004-06-29 08:41:37.000000000 -0600
@@ -753,7 +753,7 @@
}
if ( update ) {
if (msg != NULL)
- rc = update(info, msg, 0, 0, current_option_txt);
+ rc = update(info, msg, size_node(info, node)/2,
size_node(info, node), current_option_txt);
else
rc = update(info, _("Running script"), 0, 0,
current_option_txt);
if ( !rc )
@@ -862,9 +862,9 @@
rc = copy_script(info, node,
xmlNodeListGetString(info->config,
node->childs, 1),
path, update, from_cdrom, msg);
- if (rc == 0 && sz) {
- info->installed_bytes += atoi(sz);
- size += atoi(sz);
+ if (size_node(info, node)) {
+ info->installed_bytes += size_node(info,
node);
+ size += size_node(info, node);
}
xmlFree(sz); xmlFree(msg);
#####################
Next up is a patch to gtk_ui.c
First of all I create a new static variable: last_installed_bytes. This
variable holds the amount of bytes that were installed on the last pass through
(much like last_update). This variable is necessary because there is actually a
bug in this function that if two different installed files report the same
progress one right after another - the GUI won't be updated. I ran into this
because I had 2 scripts of the same size right after eachother - and it wasn't
updating the GUI.
The rest of the new pieces should be self explanatory - and all deal with this
new variable.
--- gtk_ui.c.old 2004-05-11 19:45:22.000000000 -0600
+++ gtk_ui.c 2004-06-29 07:57:27.000000000 -0600
@@ -1747,6 +1747,7 @@
static int gtkui_update(install_info *info, const char *path, size_t progress,
size_t size, const char *current)
{
static gfloat last_update = -1;
+ static gdouble last_installed_bytes = -1;
GtkWidget *widget;
int textlen;
const char *text;
@@ -1762,7 +1763,7 @@
} else { /* "Running script" */
new_update = 1.0;
}
- if ( (int)(new_update*100) != (int)(last_update*100) ) {
+ if ( ( (int)(new_update*100) != (int)(last_update*100) ) || (
last_installed_bytes != (gdouble)info->installed_bytes ) ) {
if ( new_update == 1.0 ) {
last_update = 0.0;
} else {
@@ -1789,6 +1790,7 @@
widget = glade_xml_get_widget(setup_glade, "current_file_progress");
gtk_progress_bar_update(GTK_PROGRESS_BAR(widget), new_update);
new_update = (gdouble)info->installed_bytes / (gdouble)info->install_size;
+ last_installed_bytes=(gdouble)info->installed_bytes;
if (new_update > 1.0) {
new_update = 1.0;
}
Let me know if you have any problems with these.
Derek
One more thing.... Because of this change - the status of the commandline
installation isn't updated properly.. Here is my dialog_update from dialog_ui.c
that fixes this problem (sorry for no diff - my dialog_ui.c is so hacked up
right now that I couldn't get a good diff out of it - but the function is small
enough it shouldn't be a problem)....
static
int dialog_update(install_info *info, const char *path, size_t progress,
size_t size, const char *current)
{
char buf[PATH_MAX];
static char previous[200] = "";
int percent=-1;
if(strcmp(previous, current)){
strncpy(previous,current, sizeof(previous));
/* FIXME: Anything useful to be done here? */
}
if(size) {
percent = (int) (((float)progress/(float)size)*100.0);
} else {
percent=100;
}
if ( progress && size && !path ) {
snprintf(buf, sizeof(buf), _("Installing %s ..."), current);
dialog_gauge_update(_("Installing..."), buf, percent);
} else { /* Script */
dialog_gauge_update(_("Installing..."), path, percent);
}
return 1;
}
And personally I think that the progress bar should be updated with something
closer to (in dialog_ui.c):
percent = (int) (((float)(info->installed_bytes) /
(float)(info->install_size))*100);
I would just rather see total install progress instead of single file - but
maybe that's just me.
Derek
Only problem with your patches is the abuse of size_node() which can be a very costly operation if the
size tag is not present. I'll fix this as I merge them though.
Also I agree we should show the global progress bar in the dialog UI, so I'll do that too. ;-)
Created attachment 421 [details] Fixes copy.c Patch for copy.c - incase it got garbled in my bug report
Created attachment 422 [details] Fixes gtk_ui.c Just in case the gtk_ui.c patch got garbled.