Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS CURL Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/CURLS resume download
This example is the version from Wed, 14th Jul 2015.
Project "CURLS resume download.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
w=new WorkThread
w.url = url.Text
w.Resume=false
w.run
End EventHandler
End Control
Control URL Inherits TextField
ControlInstance URL Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control ResultText Inherits Label
ControlInstance ResultText Inherits Label
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
w.d.cancel=true
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
w=new WorkThread
w.Resume=true
w.run
End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if w<>Nil then
dim s as string = w.GetMessage
if s<>"" then
listbox1.AddRow s
end if
end if
End EventHandler
End Control
Property w As WorkThread
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class DownloadCURL Inherits CURLSMBS
EventHandler Function Progress(dltotal as Int64, dlnow as Int64, ultotal as Int64, ulnow as Int64) As boolean
if dltotal=0 then
message = "Downloading..."
else
// add the existing bytes so users are not confused.
// The values are normally relative to a download!
dlnow=dlnow+offset
dltotal=dltotal+offset
message = "Downloading "+Format(dlnow/dltotal,"0%")+" "+Format(dlnow/1024,"0")+" of "+Format(dltotal/1024,"0")+" KB"
end if
End EventHandler
EventHandler Function Write(data as string, dataSize as Integer) As integer
b.Write data
Return lenb(Data)
End EventHandler
Property Message As string
Property b As BinaryStream
Property offset As int64
End Class
Class WorkThread Inherits Thread
EventHandler Sub Run()
dim e as integer
dim u as string = url
dim filename as string = NthField(u,"/",CountFields(u,"/"))
dim file as FolderItem = SpecialFolder.Desktop.Child(filename)
dim b as BinaryStream
if resume then
b = BinaryStream.Open(file, true)
else
b = BinaryStream.Create(file)
end if
d=new DownloadCURL
d.OptionURL=u
d.YieldTime=true
d.b=b
if resume then
d.offset=b.Length
d.OptionResumeFromLarge=b.Length
b.Position=b.Length
end if
e=d.Perform
b=nil
if e=42 then
d.message = "Result: "+str(e)+" (download stopped)"
elseif e=0 then
d.message = "Result: "+str(e)+" (download is complete)"
else
d.message = "Result: "+str(e)+" (download failed)"
end if
End EventHandler
Function GetMessage() As string
dim s as string = d.message
d.message = ""
if s<>"" then
Return s
end if
End Function
Property Resume As Boolean
Property d As DownloadCURL
Property url As string
End Class
End Project
See also:
- /CURL/CURLS Amazon S3 download
- /CURL/CURLS Amazon S3 upload
- /CURL/CURLS LDAP Query
- /CURL/CURLS Low Level Sockets
- /CURL/CURLS post form values/CURLS post form values old
- /CURL/CURLS preemptive threaded download
- /CURL/CURLS preemptive threaded upload
- /CURL/CURLS SSL verification/CURLS SSL verification
- /CURL/CURLS text download
- /CURL/CURLS threaded download
The items on this page are in the following plugins: MBS CURL Plugin.