Waiting for download to complete

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Pebah
Posts: 23
Joined: Mon Aug 01, 2011 9:35 pm

Waiting for download to complete

Post by Pebah » Wed Nov 16, 2011 1:13 am

HI,

I'm using the following script to download a file. After the download I move on to other things, How do I modify this script to force LiveCode to wait until the download is completed before doing anything else besides updating a progress bar?

Currently the program moves on to other handlers that are contingent on the download being finished, which it isn't.

Thanks!

Peter


on downloadFile
   open stack "MITA_Updater"
   
   repeat until the lockscreen is "false"
      unlock screen
   end repeat
   
   updateStatus "Downloading the update..."
   
   load URL "http://artsinteractive.org/updates/MITA-1NEW.livecode" with message "downloadDone"
   
   libURLSetStatusCallback "myProgress",the long ID of scrollbar "Progress"
end downloadFile

on myProgress theObject,theStatus
   put theStatus into theObject
end myProgress

on downloadDone pUrl, pStatus
   put theURL & "MITA-1NEW.livecode" into thisURL
   
    if pStatus = "cached" then
          put url pUrl into url ("binfile:" & thisURL)
     end if
     unload url pUrl
end downloadDone

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Waiting for download to complete

Post by Klaus » Wed Nov 16, 2011 11:36 am

Hi Peter,

you can download files either blocking or NON blocking.
Your current method "load" (like LibURLDownloadToFile etc.) are non blocking so you can display a progressbar or something.

If you use the blocking way like:
...
put URL "http://artsinteractive.org/updates/MITA-1NEW.livecode" into url("binfile:yourfilehere.livecode")
if the result <> empty then
## an error occurred
end if
...
Then the script will halt until the download is finished (or until an error occurs 8) ) but you canot have a progressbar this way.
Maybe you can show an animated GIF or something but that's all. So you have the choice :D

Another option could be to set a global variable "isloading" or whatever, but then you need to check this in every handler/action
that the user might execute while the download is happening. Know what I mean?


Best

Klaus

Pebah
Posts: 23
Joined: Mon Aug 01, 2011 9:35 pm

Re: Waiting for download to complete

Post by Pebah » Wed Nov 16, 2011 6:17 pm

Yes, I understand.

I've sort of solved the problem by using a slightly different procedure. I've made my script (a download and file updater) a two-step method: the user downloads the file by clicking a button, then clicks another button to install when the download is complete. Before it was a single-button, which I see is not possible with an active progress bar.

Thanks.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Waiting for download to complete

Post by jacque » Thu Nov 17, 2011 6:21 pm

Another way to handle it with a single button is to change your script so that nothing else is called until the download completes. You don't show the whole script so I'm not sure what your handler continues to do, but the solution is to put the remainder of the actions into the "downloadDone" handler. That way you can check to see if the download is completed, and if so, call the handler that does whatever should happen next.

Code: Select all

on downloadDone pUrl, pStatus
   put theURL & "MITA-1NEW.livecode" into thisURL
    if pStatus = "cached" then
          put url pUrl into url ("binfile:" & thisURL)
          --> DoMyNextThing HERE  <--
     end if
     unload url pUrl
end downloadDone
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply