🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: CopyFileEx - CopyProgressRoutine - devision by zero

#9607
From: Tommy
Date: Tue, 22 Jun 2004 22:31
148 lines
5497 bytes
Hi Bob,

I tried to implement your ideas but i will still have some problems:

In the my header i put following code:

typedef union uFT264{
FILETIME ft;
DWORDLONG i64;
}FT264;

FT264 StartTime;
FT264 now;
FT264 remaining;
FT264 elapsed;


In my main code, i first give StartTime a value when i start my prozess:

GetSystemTimeAsFileTime(&StartTime.ft);


And here is my CopyRoutine:

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)
   {
      // Aktuellen Dateistatus ermitteln
      unsigned __int64 Percent = (((unsigned
__int64)TotalBytesTransferred.QuadPart)*100) / ((unsigned
__int64)TotalFileSize.QuadPart);
      pForm->CGauge1->Progress = Percent;

      // Aktuellen Status aller Dateien ermitteln
      pForm->tmp = (unsigned __int64)TotalBytesTransferred.QuadPart;
      Percent = ((unsigned
__int64)((pForm->already_copied+pForm->tmp)*100))/(unsigned
__int64)(pForm->size);
      pForm->CGauge2->Progress = Percent;
   }

   pForm->now.i64 = 0;
   pForm->remaining.i64 = 0;
   pForm->elapsed.i64 = 0;

   unsigned __int64 BytesRemaining = pForm->size - pForm->already_copied;

   SYSTEMTIME SystemTime;
   GetLocalTime(&SystemTime);
   SystemTimeToFileTime(&SystemTime, &pForm->now.ft);
   pForm->elapsed.i64 = pForm->now.i64 - pForm->StartTime.i64;
   FileTimeToSystemTime(&pForm->elapsed.ft, &SystemTime);
   FormatTime(&SystemTime, szCM_U_TIMECOPIED);

   pForm->remaining.i64 = ((BytesRemaining * (pForm->elapsed.i64/10000U)) /
(pForm->already_copied+1))*10000U;
   FileTimeToSystemTime(&pForm->remaining.ft, &SystemTime);
   FormatTime(&SystemTime, szCM_U_TIMEREMAINING);

   // Updaten
   pForm->Update();
   Application->ProcessMessages();

   return PROGRESS_CONTINUE;
}


When I compile I get errors that FormatTime is undefined. i could not find
anywhere. furthermore szCM_U_TIMECOPIED and szCM_U_TIMEREMAINING are also
undefined.

Is the last value save in SystemTime the time which is still need until the
prozess is finished or do i need any more calculations?

Tommy






"Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag
news:2bj7d0dc8b89se5ibtdm7nntbvsrga2lrt@4ax.com...
> Tommy wrote:
>
> >i did some tests, but i wont work. before the copy process starts i call
>
> How does it "won't work"?
> Does it compile?
> Does it run?
> Does it give larger values than you expect?
> Smaller?
> Sorry, but my mind reading machine is broken.
>
>
> >
> >This wont work because i cant subtract 2 FILETIME.
>
> Yeah, I mentioned that you needed to mess with getting a FT into a
> int64.  I'm not too proud of the way I did it, but..
> typedef union uFT264{
> FILETIME ft;
> DWORDLONG i64;
> }FT264;
> static FT264 StartTime;
> void updatetime()
> { FT264 now;
> FT264 remaining;
> FT264 elapsed;
> SYSTEMTIME SystemTime;
> GetLocalTime( &SystemTime );
> SystemTimeToFileTime( &SystemTime, &now.ft );
> elapsed.i64 = now.i64 - StartTime.i64;
> FileTimeToSystemTime( &elapsed.ft, &SystemTime );
> FormatTime( &SystemTime, szCM_U_TIMECOPIED );
>
> remaining.i64 = ((BytesRemaining * (elapsed.i64/10000U)) /
> (BytesSoFar+1))*10000U;
> FileTimeToSystemTime( &remaining.ft, &SystemTime );
> FormatTime( &SystemTime, szCM_U_TIMEREMAINING );
>
>
> > 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.
>
> What I really think isn't so good, is converting to floating point
> when there's no need.
>
> If you keep everything in FILETIME accuracy, then you don't need to
> divide my 10 million. Just use FileTimeToSystemTime to convert to
> hours:minutes:seconds.  But, if you keep everything at FILETIME
> accuracy, there's a decent chance the multiply will overflow.
> So, dividing the elapsed time by 10,000 reduces the chance of overflow
> while still keeping a time accuracy of 1/1000th second. After the
> calculation, you need to re-multiply by the same 10,000 to return the
> FILETIME to it's original "accuracy" so that FileTimeToSystemTime can
> decode it properly.
>
>
>
Technical Details
Message-ID: <40d8b34c$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> <40cef067$1@newsgroups.borland.com> <8hauc01e3dsrlu787m5s8jo10rpu0k3duq@4ax.com> <40d3589b@newsgroups.borland.com> <2bj7d0dc8b89se5ibtdm7nntbvsrga2lrt@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> <40d3589b@newsgroups.borland.com> <2bj7d0dc8b89se5ibtdm7nntbvsrga2lrt@4ax.com>
Subject: Re: CopyFileEx - CopyProgressRoutine - devision by zero
Date: Wed, 23 Jun 2004 00:31:37 +0200
Lines: 150
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.31.75
Message-ID: <40d8b34c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1087943500 84.129.31.75 (22 Jun 2004 15:31:40 -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