🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9774

Re: CopyFileEx - CopyProgressRoutine - devision by zero

#9774
From: Tommy
Date: Tue, 15 Jun 2004 12:49
86 lines
3969 bytes
Hi,

you was right. before i calculate i check the size of the file. so it works
fine.

in a next step, i like to display the how many seconds will still need until
the copy process is completed.

ich have following information.

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)

My Idea: Each time, when the timer clocks, i determine the time differenz
from the start of the process to now. and with the bytes which still have to
be copied and the bytes which are already copied, i can calculate the
seconds still needed.

When I start my copy process, i call QueryPerformanceCounter and
QueryPerformanceFrequency before.

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";
   Application->ProcessMessages();
}

But my code does not show the still needed seconds, it only shows mysterious
symbols.

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?

tommy


"Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag
news:crtsc0pp05ki34cqsvkgsj721eei6g7obh@4ax.com...
> Tommy wrote:
>
> >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)
> >{
>
> >   unsigned __int64 Percent = (((unsigned
> >__int64)TotalBytesTransferred.QuadPart)*100) / ((unsigned
> >__int64)TotalFileSize.QuadPart);
>
> Are you sure you aren't copying any zero-size files?
>
> >   pForm->tmp = (unsigned __int64)TotalBytesTransferred.QuadPart;
> >   Percent = ((unsigned
> >__int64)((pForm->already_copied+pForm->tmp)*100))/(unsigned
> >__int64)(pForm->size);
>
> You don't show where pForm->size is set or calculated.
> But the problem if most likely the first one (zero size files)
>
> >In my copyprogressroutine, i have some source to calcuale how man percent
> >have already copied of that file and of the hole process. As i work with
big
> >files i use unsigned __int64. but when i run my appliaction i always get
> >after a short time the message "devision by zero" and the application
stops.
> >when i comment the calculation of the percent, the application run fine.
> >what is wrong with my calcution. what to change that is calculate the
copied
> >bytes of the file and of the hole process?
>
>
Technical Details
Message-ID: <40cef067$1@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-mail
References: <40ce2e93@newsgroups.borland.com> <crtsc0pp05ki34cqsvkgsj721eei6g7obh@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>
Subject: Re: CopyFileEx - CopyProgressRoutine - devision by zero
Date: Tue, 15 Jun 2004 14:49:38 +0200
Lines: 88
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: 217.88.158.162
Message-ID: <40cef067$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1087303783 217.88.158.162 (15 Jun 2004 05:49:43 -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