Article View: borland.public.cppbuilder.nativeapi
Article #9713Re: CopyFileEx - CopyProgressRoutine - devision by zero
From: Tommy
Date: Fri, 18 Jun 2004 21:03
Date: Fri, 18 Jun 2004 21:03
131 lines
5755 bytes
5755 bytes
hi,
i did some tests, but i wont work. before the copy process starts i call
GetSystemTimeAsFileTime(&start);
and this here is my copyprogresssroutine:
DWORD WINAPI MyCopyProgressRoutine(LARGE_INTEGER TotalFileSize,LARGE_INTEGER
TotalBytesTransferred,LARGE_INTEGER StreamSize,LARGE_INTEGER
StreamBytesTransferred,DWORD dwStreamNumber,DWORD dwCallbackReason,HANDLE
hSourceFile,HANDLE hDestinationFile,LPVOID lpData)
{
TForm1 *pForm = (TForm1*) lpData;
if (TotalFileSize.QuadPart > 0)
{
// actuel file status
unsigned __int64 Percent = (((unsigned
__int64)TotalBytesTransferred.QuadPart)*100) / ((unsigned
__int64)TotalFileSize.QuadPart);
pForm->CGauge1->Progress = Percent;
// actual status of all files
pForm->tmp = (unsigned __int64)TotalBytesTransferred.QuadPart;
Percent = ((unsigned
__int64)((pForm->already_copied+pForm->tmp)*100))/(unsigned
__int64)(pForm->size);
pForm->CGauge2->Progress = Percent;
}
// calculate still needed seconds
GetSystemTimeAsFileTime(&pForm->now);
int ElapsedSeconds = (pForm->now-pForm->start);
pForm->LRestdauer->Caption = ElapsedSeconds;
//TDateTime DT1 = SystemTimeToDateTime(pForm->now);
//TDateTime DT2 = SystemTimeToDateTime(pForm->start);
//int DaysDifference = DT2 - DT1;
//pForm->LRestdauer->Caption = IntToStr(DaysDifference);
// Update
pForm->Update();
Application->ProcessMessages();
return PROGRESS_CONTINUE;
}
This wont work because i cant subtract 2 FILETIME. Another problem ist that
i cannot follow your idea how to solve. i understand that it is not good to
divide so often a value by 10million. i do not understand how to come by
your idea to the seconds which will be need till the process is finished.
can you explain me a bite more how to do.
tommy
"Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag
news:8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com...
> Tommy wrote:
>
> >1. completly size of all bytes which need to be copy (size)
> >2. size of already copied bytes (already_copied)
> >3. percent of already copied size (CGauge2->Progress)
> >
> >QueryPerformanceCounter(&start_ticks);
> >QueryPerformanceFrequency(&frequenz);
> >dir_create(ESource->Text,ETarget->Text);
> >
> >Now I have a Timer in my applcation which clocks echt second.
> >
> >void __fastcall TForm1::Timer1Timer(TObject *Sender)
> >{
> > rest = size-already_copied;
> > QueryPerformanceCounter(&ende_ticks);
> > tick_diff = ((double) ende_ticks.QuadPart - (double)
> >start_ticks.QuadPart) frequenz.QuadPart;
> > if (already_copied > 0)
>
> > LRestdauer->Caption = int(double((double)rest/(double)already_copied)
*
> >(double)tick_diff) + " s";
>
> TIP: When writing math fomulas with a lot of casting, it's often
> prudent to add a coment showing the math without all the fluff.
> So:
> (Remaining / Copied) * Elapsed
> Yep, that's the math, all right.
> But, you can do it with integers if you rearange things:
> (Remaining * Elapsed) / Copied
> Added benefit, if Elpased is in 1/1000's second, RemainingTime will be
> also. So you can define your precision by how precise ElapsedTime is.
>
>
> >Any Idea why this to not works. Is there perhabs a better way to get the
> >seconds which are need till the process is finished?
>
> Way too complicated.
> Aren't you using CopyFileEx() ? The Callback happens fairly often
> (more than once per second on my system), so no Timer needed.
> And the Performance Counter isn't needed either. You aren't doing
> multimedia or guideance systems. System Time is accurate enough for
> this job.
>
> Use GetSystemTimeAsFileTime()
> The 64bit result is 10 million per second, so divide by 10 million to
> get seconds:
>
> GetSystemTimeAsFileTime( &ftNow );
> ElapsedSeconds = ( ftNow - ftStart ) / 10000000uint64;
> You have to do some fiddling to get the FILETIMEs into UINT64s so you
> can subtract them
>
> Now, I wanted to use FILETIME to figure out how many
> hours:minutes:seconds were left, so I didn't divide Elapsed by 10
> million. But, it doesn't take too many Gigs on a slow connection to
> overflow when you are multiplying by 10 million per second.
> Talking Gigs * 10millions, it will take a total of
> 4Gigs * 400(10millions) to overflow the uint64.
> To avoid Overflow, I ballparked a figure of 10,000 which gives me
> 400Gigs remaining after 40,000 seconds, and still leaves me with
> elapsed acuracy of 1/1000 second (important in the early stages of the
> copy)
> ( (Remaining * (Elapsed/10000)) / Copied )*10000
> FileTimeToSystemTime( &ftRemaining, &SystemTime );
> Display SystemTime as Hours:Minutes:Seconds
>
Technical Details
Message-ID:
<40d3589b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40ce2e93@newsgroups.borland.com> <crtsc0pp05ki34cqsvkgsj721eei6g7obh@4ax.com> <40cef067$1@newsgroups.borland.com> <8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9a3709a4832c0e51 X-Google-Attributes: gid10cc67,public From: "Tommy" <tommyw@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40ce2e93@newsgroups.borland.com> <crtsc0pp05ki34cqsvkgsj721eei6g7obh@4ax.com> <40cef067$1@newsgroups.borland.com> <8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com> Subject: Re: CopyFileEx - CopyProgressRoutine - devision by zero Date: Fri, 18 Jun 2004 23:03:14 +0200 Lines: 133 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 84.129.28.227 Message-ID: <40d3589b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1087592603 84.129.28.227 (18 Jun 2004 14:03:23 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail