Viewing file: c/wget/progress.c | Back to directory listing
Author: Loren Segal | Last modified: February 20 2006 07:00 pm | Download

/* Download progress.
   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
This file is part of GNU Wget.
 
## - Edit on May 9th by Loren Segal - mIRC wget.dll
 - Butchered this file because mIRC does not have any console output.
	All progress implementations were replaced by simple a interface
	to mIRC.
##
 
GNU Wget is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
GNU Wget is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with Wget; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
In addition, as a special exception, the Free Software Foundation
gives permission to link the code of its release of Wget with the
OpenSSL project's "OpenSSL" library (or with modified versions of it
that use the same license as the "OpenSSL" library), and distribute
the linked executables.  You must obey the GNU General Public License
in all respects for all of the code used other than "OpenSSL".  If you
modify this file, you may extend this exception to your version of the
file, but you are not obligated to do so.  If you do not wish to do
so, delete this exception statement from your version.  */
 
#include <config.h>
 
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif /* HAVE_STRING_H */
#include <assert.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
 
#include "wget.h"
#include "progress.h"
#include "utils.h"
#include "retr.h"
 
/* Create a progress gauge.  INITIAL is the number of bytes the
   download starts from (zero if the download starts from scratch).
   TOTAL is the expected total number of bytes in this download.  If
   TOTAL is zero, it means that the download size is not known in
   advance.  */
 
void *
progress_create (long initial, long total)
{
	//char *filename = WGET_THREAD->filename;
	WGET_THREAD->download_info.size = initial;
	WGET_THREAD->download_info.total = total;
	WGET_THREAD->download_info.last_timer_value = 0;
	WGET_OPTIONS->dot_bytes = 0;
	WGET_OPTIONS->dot_spacing = 0;
	//if (!filename) filename = xstrdup("UNKNOWN_FILE");
	//SendCommand(mIRC_window, "%s %d %d %s", MCMD_WGET_BEGIN, WGET_THREAD_ID+1, total-initial, filename);
}
 
/* Inform the progress gauge of newly received bytes.  DLTIME is the
   time in milliseconds since the beginning of the download.  */
 
void
progress_update (void *progress, long howmuch, double dltime)
{
	struct options *opt = WGET_OPTIONS;
	pthread_t t = WGET_THREAD;
 
	t->download_info.size += howmuch;
	opt->dot_spacing += howmuch;
	opt->dot_bytes++;
	if (opt->dot_bytes >= opt->dots_in_line)
	{
		double rate, msecs = dltime - t->download_info.last_timer_value;
		char *speed = retr_rate (opt->dot_spacing, msecs, 1);
		long size = t->download_info.size;
		long total = t->download_info.total;
		int percentage = (total ? (int)(100.0 * size / total) : 0);
		if (msecs == 0) 
			msecs = wtimer_granularity();
		rate = ((double)1000 * opt->dot_spacing / msecs) / 1024.0;
 
		SIGNAL_PROGRESS(size, speed, percentage, total);
		t->download_info.percent = percentage;
		t->download_info.size = size;
		t->download_info.rate = rate;
		t->download_info.last_timer_value = dltime;
		free(speed);
 
		opt->dot_bytes = 0;
		opt->dot_spacing = 0;
	}
}
 
/* Tell the progress gauge to clean up.  Calling this will free the
   PROGRESS object, the further use of which is not allowed.  */
 
void
progress_finish (void *progress, double dltime)
{
 // SendCommand(mIRC_window, "%s %d %d %d", MCMD_WGET_COMPLETE, WGET_THREAD_ID+1, WGET_THREAD->download_info.size, WGET_THREAD->download_info.total);
}