Author: MarkieB
Date: Mon Aug 31 06:55:05 2009
New Revision: 9521
URL:
http://source.netsurf-browser.org?rev=9521&view=rev
Log:
improve accuracy of time estimates, including for larger files
Modified:
branches/MarkieB/windows/windows/download.c
branches/MarkieB/windows/windows/download.h
Modified: branches/MarkieB/windows/windows/download.c
URL:
http://source.netsurf-browser.org/branches/MarkieB/windows/windows/downlo...
==============================================================================
--- branches/MarkieB/windows/windows/download.c (original)
+++ branches/MarkieB/windows/windows/download.c Mon Aug 31 06:55:05 2009
@@ -186,30 +186,40 @@
char *size = human_friendly_bytesize(w->downloaded);
int i = 0, temp = w->time_remaining;
if (temp == -1) {
- w->time_left = strdup("unknown");
- i = SLEN("unknown");
+ w->time_left = strdup(messages_get("UnknownSize"));
+ i = strlen(w->time_left);
} else {
do {
temp = temp / 10;
i++;
} while (temp > 2);
w->time_left = malloc(i + SLEN(" s") + 1);
- if (w->time_left != NULL)
- sprintf(w->time_left, "%d s", w->time_remaining);
+ if (w->time_left != NULL) {
+ if (w->time_remaining > 3600)
+ sprintf(w->time_left, "%d h",
+ w->time_remaining / 3600);
+ else if (w->time_remaining > 60)
+ sprintf(w->time_left, "%d m",
+ w->time_remaining / 60);
+ else
+ sprintf(w->time_left, "%d s",
+ w->time_remaining);
+ }
}
char label[strlen(w->title) + strlen(size) + strlen(w->total_size) +
+ strlen(w->domain) + strlen(w->filename) +
SLEN("download from to \n[\t/\t]\n estimate of time"
" remaining ") + i + 1];
- sprintf(label, "download %s from %s to %s\n[%s\t/\t%s]\n estimate of "
- "time remaining %s", w->title, w->domain, w->filename,
- size, w->total_size, w->time_left);
+ sprintf(label, "download %s from %s to %s\n[%s\t/\t%s] [%d%%]\n"
+ "estimate of time remaining %s", w->title, w->domain,
+ w->filename, size, w->total_size, w->progress / 100,
+ w->time_left);
if (w->time_left != NULL) {
free(w->time_left);
w->time_left = NULL;
}
SendMessage(sub, WM_SETTEXT, (WPARAM)0, (LPARAM)label);
- if (w->progress < 100)
+ if (w->progress < 10000)
schedule(50, nsws_download_update_label, p);
}
@@ -221,8 +231,8 @@
return;
}
HWND sub = GetDlgItem(w->hwnd, NSWS_ID_DOWNLOAD_PROGRESS);
- SendMessage(sub, PBM_SETPOS, (WPARAM)w->progress, 0);
- if (w->progress < 100)
+ SendMessage(sub, PBM_SETPOS, (WPARAM)(w->progress / 100), 0);
+ if (w->progress < 10000)
schedule(50, nsws_download_update_progress, p);
}
@@ -258,11 +268,12 @@
if (res != size)
LOG(("file write error %d of %d", size - res, size));
w->downloaded += res;
- w->progress = (w->downloaded * 100) / w->size;
+ w->progress = (unsigned int)(((long long)(w->downloaded) * 10000)
+ / w->size);
gettimeofday(&val, NULL);
w->time_remaining = (w->progress == 0) ? -1 :
- (val.tv_sec - w->start_time.tv_sec) *
- (100 - w->progress) / w->progress;
+ (int)((val.tv_sec - w->start_time.tv_sec) *
+ (10000 - w->progress) / w->progress);
}
void gui_download_window_error(struct gui_download_window *w,
Modified: branches/MarkieB/windows/windows/download.h
URL:
http://source.netsurf-browser.org/branches/MarkieB/windows/windows/downlo...
==============================================================================
--- branches/MarkieB/windows/windows/download.h (original)
+++ branches/MarkieB/windows/windows/download.h Mon Aug 31 06:55:05 2009
@@ -33,7 +33,7 @@
char *original_total_size;
int size;
int downloaded;
- int progress;
+ unsigned int progress;
int time_remaining;
struct timeval start_time;
int speed;