-- "NetOp.transaction" Parent Script (v.1) -- @version 1.0 -- @Requires: script("NetOp") property ancestor property NetID property downloadURL property LocalAddress on new (me, netAddress, alocalAddress) NetID = 0 downloadURL = netAddress LocalAddress = alocalAddress ancestor = script("NetOp").rawNew() callAncestor(#new, me) return me end on Start (me) NetID = downloadNetThing(downloadURL, LocalAddress) if NetID < 0 then put "ERROR" && downloadURL, LocalAddress end if aTimerObj = timeout().new(me.string, 100, #Timer_CheckProgress, me) return NetID end on Destroy (me) netAbort(NetID) NetID = VOID callAncestor(#Destroy, me) end on Timer_CheckProgress (me, aTimer) if voidP(NetID) then -- we have aborted the operation atimer.forget() return 0 end if finished = netDone(NetID) if finished then errorNum = netError(NetID) if stringP(errorNum) then errorNum =0 aTimer.forget() me.GenerateEventMessage(#DownloadComplete, [#LocalAddress: LocalAddress, #Error: errorNum, #remoteAddress: downloadURL]) else -- check the current status status = getStreamStatus(NetID) currentState = status.state -- before sending the status, work out the portion downloaded case (currentState) of "InProgress": if status.bytesSoFar > 0 then if status.bytesTotal > 0 then f = MIN(1.0, float(status.bytesSoFar)/status.bytesTotal ) else f = 0.50 else f = 0 end if "Complete": f = 1.00 otherwise f = 0 end case -- add the fractionDone as a property to the statusList status.addProp( #fractiondone, f ) -- inform the callback object of the current state and the % transferred me.GenerateEventMessage(#DownloadStatusUpdate, status) end if end