Page 1 of 1

Download Progress

PostPosted: Tue Sep 27, 2005 8:57 am
by domino
My Pub features an update procedure which downloads and replaces a .dbf file with a more up to date version. (plus a few other bits and bobs)

Once the new .dbf has been downloaded the Pub needs to do s few things prior to shut down and restart (which to my surprise I was able to do via close app delay... open app at the end of the update procedure)

However my question concerns the download progress... I need to ensure that the new files have been downloaded before proceeding onto the next stage of the process. If I use the [DownloadProgress] variable it reports 100% in a fraction of a second, even if the variable has been reset to zero first... I'm lucky enough to have a fast broadband connection but others won`t.

How do I halt the execution of code until the download process has finished?

Cheers
Dave

PS.. Not NeoBook but is this for real?
http://www.atomchip.com/

PostPosted: Tue Sep 27, 2005 10:31 am
by Gaev
dave:

Assuming that the previous version of the .dbf file has been erased/renamed before you issue the DownloadFile command, it might be the old "cache" problem with the IE/Browser component.

So if erasing/renaming prior to download does not do the trick, try ...

a) Downloading to a uniquely new filename first e.g. instead of ABC.dbf, use ABC_ccyymmdd_hhmmss.dbf ... then, rename it to ABC.dbf

b) If that does not work, do a InternetFileSize command first, then before initiating the DownloadFile command, start a Timer that checks the FileSize of the downloaded file.

PostPosted: Tue Sep 27, 2005 4:11 pm
by domino
Gaev

b) If that does not work, do a InternetFileSize command first, then before initiating the DownloadFile command, start a Timer that checks the FileSize of the downloaded file.


I'm reasonably certain that a) isn`t the problem, but b) looks a good idea but I`m not sure how to make it work using the timer... a snippet of pseudo code would be useful

Cheers
Dave

PostPosted: Tue Sep 27, 2005 5:13 pm
by Gaev
Dave:
I'm reasonably certain that a) isn`t the problem
... ok but at least erase the file before you reference it in a DownloadFile.
... I`m not sure how to make it work using the timer... a snippet of pseudo code would be useful
... lets say that your current script set is ...
Code: Select all
DownloadFile "[sourceUrl]" "[destination]" ""
... other commands once the download is complete
... you could change it to ...
Code: Select all
InternetFileSize "[sourceUrl]" "[UrlSize]"
FileErase "[destination]"
TimerStart "Timer1" "1000"
DownloadFile "[sourceUrl]" "[destination]" "HideProgress"
Return
... and the TimerInterval script could be something like ...
Code: Select all
FileExists "[destination]" "[FileStatus]"
If "[FileStatus]" "<>" "True"
   Return
Else
   GoSub "GetFileSize"
   Math "[FileSize]/[UrlSize]" "5" "[PercentDownloaded]"
   If "[PercentDownloaded]" "<" "0.98"
      Return
   Else
      TimerStop "Timer1"
      ... other commands once the download is complete
   Endif   
Endif
Note:
a) For the subroutine "GetFileSize", use your favourite method (i.e. Run Dir command to file, HPW/Sam's newLisp or other 3rd party plug-in)
b) You may have to play a bit with the method of determining if Download is complete ... I have shown a method that looks for 98% completion ... you might choose to use a difference (in bytes) ... the reason you can not depend on an exact match is that different platforms use different block sizes on disk and so can report slightly different values.

I would still try out the anti-caching workaround first ... haven't tried it myself, but you might even try specifying the url with dummy additional parameters ... like abc.ext?version=ccyymmdd_hhmmss ... if you choose this method, note that it only works with http:// protocols (not file:// ones).

PostPosted: Wed Sep 28, 2005 4:10 am
by domino
Gaev

First things first.. The timer routine works like a charm. Thanks very much. (And thanks to rlFunctions for the file size function)

I'm reasonably certain that a) isn`t the problem
... ok but at least erase the file before you reference it in a DownloadFile.


I made sure the file was erased and replaced the original .dbf with a an update with some extra entries to verify the process was working. Obviously I'll need to check on some other PC's in due course.


... I have shown a method that looks for 98% completion ... you might choose to use a difference (in bytes) ... the reason you can not depend on an exact match is that different platforms use different block sizes on disk and so can report slightly different values.


On my PC the files sizes have proved to be identical, but I`ve left it at 98% for the time being.. Again we'll see what happens on some other PC's.

Just as a matter of interest on my system the entire process of closing/deleting/downloading/replacing/comparing/restarting the db and pub + updating version number text files...is less than 15 seconds.. admittedly the dbf is only 22kb.. but fast nevertheless.

(also the replacement db is in an .htaccess protected folder so the new [HTTPUserID] and [HTTPUserPassword] global variables have been useful)

Cheers
Dave