/* ** Print progress */ BOOL HTAlertCallback_progress( HTRequest *request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar *reply ) { if ( op == HT_PROG_READ ) { if ( !dl_is_ftp ) { Cvar_SetValue( "cl_downloadCount", ( float ) HTRequest_bytesRead( request ) ); } else { /* show_bug.cgi?id=605 */ if ( !HTNet_rawBytesCount( request->net ) ) { Com_DPrintf( "Force raw byte count on request->net %p\n", request->net ); HTFTP_setRawBytesCount( request ); } Cvar_SetValue( "cl_downloadCount", ( float ) HTFTP_getDNetRawBytesCount( request ) ); } } return YES; }
PUBLIC char * HTDialog_progressMessage (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input) { char * result = NULL; switch (op) { case HT_PROG_DNS: StrAllocMCopy(&result, "Looking up ", input ? (char *) input : "", NULL); break; case HT_PROG_CONNECT: StrAllocMCopy(&result, "Contacting ", input ? (char *) input : "", NULL); break; case HT_PROG_ACCEPT: StrAllocCopy(result, "Waiting for connection..."); break; case HT_PROG_LOGIN: StrAllocCopy(result, "Logging in..."); break; case HT_PROG_READ: if (request) { long cl = HTAnchor_length(HTRequest_anchor(request)); if (cl > 0) { long b_read = HTRequest_bodyRead(request); double pro = (double) b_read/cl*100; char buf[10]; char pct[10]; HTNumToStr((unsigned long) cl, buf, 10); sprintf(pct, "%d%%", (int) pro); StrAllocMCopy(&result, "Read (", pct, " of ", buf, ")", NULL); } else { long b_read = HTRequest_bytesRead(request); int * raw_read = input ? (int *) input : NULL; if (b_read > 0) { char buf[10]; HTNumToStr(b_read, buf, 10); StrAllocMCopy(&result, "Read ", buf, "bytes", NULL); } else if (raw_read && *raw_read>0) { char buf[10]; HTNumToStr(*raw_read, buf, 10); StrAllocMCopy(&result, "Read ", buf, "bytes", NULL); } else { StrAllocCopy(result, "Reading..."); } } } break; case HT_PROG_WRITE: if (request && HTMethod_hasEntity(HTRequest_method(request))) { HTParentAnchor *anchor=HTRequest_anchor(HTRequest_source(request)); long cl = HTAnchor_length(anchor); if (cl > 0) { long b_write = HTRequest_bodyWritten(request); double pro = (double) b_write/cl*100; char buf[10]; char pct[10]; HTNumToStr((unsigned long) cl, buf, 10); sprintf(pct, "%d%%", (int) pro); StrAllocMCopy(&result, "Writing (", pct, " of ", buf, ")", NULL); } else { long b_written = HTRequest_bytesWritten(request); int * raw_written = input ? (int *) input : NULL; if (b_written > 0) { char buf[10]; HTNumToStr(b_written>0 ? b_written : 0, buf, 10); StrAllocMCopy(&result, "Writing ", buf, "bytes", NULL); } if (raw_written && *raw_written>0) { char buf[10]; HTNumToStr(*raw_written, buf, 10); StrAllocMCopy(&result, "Writing ", buf, "bytes", NULL); } else { StrAllocCopy(result, "Writing..."); } } } break; case HT_PROG_DONE: StrAllocCopy(result, "Done!"); break; case HT_PROG_INTERRUPT: StrAllocCopy(result, "Interrupted!"); break; case HT_PROG_OTHER: StrAllocCopy(result, "Working - please wait..."); break; case HT_PROG_TIMEOUT: StrAllocCopy(result, "Request timeout - server did not respond."); break; default: StrAllocCopy(result, "UNKNOWN PROGRESS STATE"); break; } return result; }