Hab ma ein bisschen was gebastelt, Das Programm sucht bei google nach Bildern mit der gewählten Bildschirmauflösung und zeigt diese dann als Diashow an, Bilder, die toll sind können direkt auf den PC gespeichert (In den Benutzerordner) werden.
Unter MAC OS 10.5 ausgiebig getestet, wäre cool, wenn ihr das noch unter Win und Linux testen könntet!
-------------------EDIT---------------
im Hauptcode war noch ein Fehler, ist jetzt behoben
----------------------------------
die eingebetteten Bilder gibts hier:
http://www.momo-wagner.de/images.zip
Hauptfile:
Code: Alles auswählen
IncludeFile "http.pbi"
Global buffers.i=2 ;drawing buffers
UseJPEGImageDecoder()
UseTIFFImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UsePNGImageEncoder()
InitNetwork()
InitSprite()
InitKeyboard()
InitSprite3D()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
imagedir.s=GetHomeDirectory()+"Eigene Bilder\Imageloader"
CompilerElse
imagedir.s=GetHomeDirectory()+"Pictures/Imageloader"
CompilerEndIf
CreateDirectory(imagedir)
SetCurrentDirectory(imagedir)
Enumeration
#image_loaded
#image_load
#image_bar
#image_m0
#image_saving
#image_saved
#image_page
#image_error
EndEnumeration
Structure _settings
pause.i
resolution.s
saveall.b
searchstr.s
safesearch.s
screenx.i
screeny.i
page.i
url.s
loadurl.s
numbertodisp.i
numpics.i
*memorybuffer
lastdownload.i
errors.i
EndStructure
Procedure copysettings(*from._settings,*dest._settings)
*dest\pause=*from\pause
*dest\resolution=*from\resolution
*dest\saveall=*from\saveall
*dest\searchstr=*from\searchstr
*dest\safesearch=*from\safesearch
*dest\screenx=*from\screenx
*dest\screeny=*from\screeny
*dest\page=*from\page
*dest\url=*from\url
*dest\loadurl=*from\loadurl
*dest\numbertodisp=*from\numbertodisp
*dest\numpics=*from\numpics
*dest\memorybuffer=*from\memorybuffer
*dest\lastdownload=*from\lastdownload
*dest\errors=*from\errors
EndProcedure
Procedure settingsdialog(*settings._settings)
window=OpenWindow(#PB_Any,0,0,300,170,"Settings",#PB_Window_ScreenCentered)
AddKeyboardShortcut(window,#PB_Shortcut_Return,10)
TextGadget(#PB_Any,10,10,70,20,"Auflösung:")
combo=ComboBoxGadget(#PB_Any,80,10,180,20)
TextGadget(#PB_Any,10,35,80,25,"Suche nach:")
input=StringGadget(#PB_Any,90,35,190,20,"test")
checkbox=CheckBoxGadget(#PB_Any,10,65,150,15,"Alle Bilder speichern")
safe=CheckBoxGadget(#PB_Any,160,65,130,15,"Kinderfreundlich")
TextGadget(#PB_Any,10,85,100,20,"Verzögerung:")
delay=SpinGadget(#PB_Any,110,85,60,20,0,200,#PB_Spin_Numeric)
SetGadgetState(delay,10)
TextGadget(#PB_Any,10,115,280,30,"s um Bilder zu speichern, x zum verlassen des Programms")
ok=ButtonGadget(#PB_Any,125,150,50,15,"OK")
If ExamineScreenModes() And ExamineDesktops()
While NextScreenMode()
existing=0
For i=0 To CountGadgetItems(combo)
If GetGadgetItemText(combo, i)=Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight())
existing=1
EndIf
If GetGadgetItemText(combo,i) = Str(DesktopWidth(0))+"x"+Str(DesktopHeight(0))
SetGadgetState(combo,i)
EndIf
Next
If ScreenModeDepth()=32 And Not existing
AddGadgetItem(combo,-1,Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight()))
EndIf
Wend
EndIf
Repeat
event= WaitWindowEvent()
If (event=#PB_Event_Gadget And EventGadget()=ok) Or (event=#PB_Event_Menu And EventMenu()=10)
okay=1
*settings\resolution=GetGadgetText(combo)
*settings\screenx=Val(Mid(*settings\resolution,0,FindString(*settings\resolution,"x",0)))
*settings\screeny=Val(Mid(*settings\resolution,FindString(*settings\resolution,"x",0)+1))
*settings\searchstr=ReplaceString(GetGadgetText(Input)," ","+")
*settings\saveall=GetGadgetState(checkbox)
*settings\pause=GetGadgetState(delay)
If GetGadgetState(safe)
*settings\safesearch="active"
Else
*settings\safesearch="off"
EndIf
EndIf
Until okay
CloseWindow(window)
EndProcedure
Procedure displaysaved()
Start3D()
For x=1 To buffers
DisplaySprite3D(#image_saved,0,60,255)
FlipBuffers()
Next x
Stop3D()
EndProcedure
Procedure displaysaving()
Start3D()
For x=1 To buffers
DisplaySprite3D(#image_saving,0,0,70)
FlipBuffers()
Next x
Stop3D()
EndProcedure
Procedure savewallpaper(*settings._settings)
Static nb
If IsSprite(#image_loaded)
nb=nb+1
filename.s="Imagesaver"+FormatDate("%mm%dd%hh%ii", Date())+"_"+Str(nb)+".png"
If SaveSprite(#image_loaded,filename,#PB_ImagePlugin_PNG)
If OpenFile(0,"quellenangabe.csv")
If ReadString(0)="" Or ReadString(0)=" "
WriteStringN(0,"Imagename,Downloaded from")
EndIf
FileSeek(0,Lof(0))
WriteStringN(0,filename+","+*settings\url)
CloseFile(0)
EndIf
displaysaved()
EndIf
EndIf
EndProcedure
Procedure checkuserinputs(*settings._settings,thread=0)
Static stilltosave
ExamineKeyboard()
inkey.s=KeyboardInkey()
If FindString(inkey,"x",0)
CloseScreen()
End
EndIf
If FindString(inkey,"s",0) And Not thread
displaysaving()
Savewallpaper(*settings)
ElseIf FindString(inkey,"s",0) And thread
displaysaving()
stilltosave=1
ElseIf stilltosave And Not thread
savewallpaper(*settings)
stilltosave=0
EndIf
EndProcedure
Procedure httpgetfile_memory(*settings._settings)
myfile._PureHTTP_GET_FILE
myfile\Host = PureHTTP_SplitURL(*settings\loadurl,#PureHTTP_URL_TO_HOST)
myfile\Path = PureHTTP_SplitURL(*settings\loadurl,#PureHTTP_URL_TO_PATH)
myfile\Destbuffer = AllocateMemory(#PureHTTP_Buffersize)
Status.i = PureHTTP_Get_File(@myfile)
If Status = #PureHTTP_STATUS_FINISHED
*settings\lastdownload=1
*settings\memorybuffer=myfile\Destbuffer
Else
*settings\lastdownload=0
*settings\memorybuffer=0
EndIf
EndProcedure
Procedure displayloading(*settings._settings)
Start3D()
For x=1 To buffers
DisplaySprite3D(#image_load,*settings\screenx-300,0,100)
FlipBuffers()
Next x
Stop3D()
EndProcedure
Procedure displaypage(*settings._settings,alpha=130)
DisplaySprite3D(#image_page,0,*settings\screenY-70,alpha)
For y=1 To *settings\page
If 300+(10*y-1)< *settings\screenx-400
DisplaySprite3D(#image_bar,300+10*(y-1),*settings\screenY-70,alpha)
EndIf
Next y
EndProcedure
Procedure displayerrors(*settings._settings)
Start3D()
For x=1 To buffers
If *settings\errors=1
DisplaySprite3D(#image_error,*settings\screenx-400,*settings\screeny-70,150)
EndIf
DisplaySprite3D(#image_bar,*settings\screenx-100+10*(*settings\errors-1),*settings\screeny-70,150)
FlipBuffers()
Next
Stop3D()
EndProcedure
Procedure displaystart(*settings._settings)
If *settings\screenX>*settings\screenY
m0size=*settings\screenY/2
Else
m0size=*settings\screenX/2
EndIf
Start3D()
For i=1 To 100
If i=99
alpha=255
Else
alpha=i*2
EndIf
Delay(2)
For x=1 To buffers
ZoomSprite3D(#image_m0,(1.182*m0size/100)*i,(m0size/100)*i)
DisplaySprite3D(#image_m0,*settings\screenX/2-1.182*m0size/2,*settings\screenY/2-m0size/2,alpha)
FlipBuffers()
Next
Next i
Stop3D()
displayloading(*settings)
EndProcedure
Procedure.s getnextimageurl(*searcherg.s)
imagepath.s=""
one=FindString(*searcherg,"<img src=http://",0)
If one
two=FindString(*searcherg,"images?q=",one)
If two
three=FindString(*searcherg,"http://",two)
If three
four=FindString(*searcherg," ",three)
imagepath.s=Mid(*searcherg,three,four-three)
*searcherg.s=Mid(*searcherg,four)
EndIf
EndIf
EndIf
ProcedureReturn imagepath
EndProcedure
Procedure fadesprite(*settings._settings)
For i=1 To 100 Step 2
If i=98
i=255
EndIf
Delay(10)
Start3D()
For x=1 To buffers
DisplaySprite3D(#image_loaded,0,0,i)
DisplaySprite3D(#image_page,0,*settings\screenY-70,1)
displaypage(*settings,i/2)
FlipBuffers()
Next x
Stop3D()
checkuserinputs(*settings)
Next i
EndProcedure
settings._settings
settings_thread._settings
settings\page=1
settings\numbertodisp=21
settings\numpics=1
settingsdialog(@settings)
OpenScreen(settings\screenX,settings\screenY,32,"imageloader")
CatchSprite(#image_load,?load,#PB_Sprite_Texture)
TransparentSpriteColor(#image_load, RGB(255,0,255))
CreateSprite3D(#image_load,#image_load)
CatchSprite(#image_bar,?i,#PB_Sprite_Texture)
TransparentSpriteColor(#image_bar, RGB(255,0,255))
CreateSprite3D(#image_bar,#image_bar)
CatchSprite(#image_m0,?m0,#PB_Sprite_Texture)
TransparentSpriteColor(#image_m0, RGB(255,0,255))
CreateSprite3D(#image_m0,#image_m0)
CatchSprite(#image_saving,?saving,#PB_Sprite_Texture)
TransparentSpriteColor(#image_saving, RGB(255,0,255))
CreateSprite3D(#image_saving,#image_saving)
CatchSprite(#image_saved,?saved,#PB_Sprite_Texture)
TransparentSpriteColor(#image_saved, RGB(255,0,255))
CreateSprite3D(#image_saved,#image_saved)
CatchSprite(#image_page,?page,#PB_Sprite_Texture)
TransparentSpriteColor(#image_page, RGB(255,0,255))
CreateSprite3D(#image_page,#image_page)
CatchSprite(#image_error,?error,#PB_Sprite_Texture)
TransparentSpriteColor(#image_error, RGB(255,0,255))
CreateSprite3D(#image_error,#image_error)
displaystart(@settings)
While settings\numpics > 0
searcherg.s=""
settings\loadurl = URLEncoder("http://images.google.de/images?as_st=y&hl=de&safe="+settings\safesearch+"&um=1&q="+settings\searchstr+"+imagesize:"+settings\resolution+"&sa=N&start="+Str((settings\page-1)*settings\numbertodisp)+"&ndsp="+Str(settings\numbertodisp))
If settings\memorybuffer
FreeMemory(settings\memorybuffer)
EndIf
download=CreateThread(@httpgetfile_memory(),@settings)
While IsThread(download)
Delay(10)
FlipBuffers()
checkuserinputs(@settings,1)
Wend
checkuserinputs(@settings)
settings\numpics=0
searcherg.s=PeekS(settings\memorybuffer)
numpics=0
While settings\loadurl
checkuserinputs(@settings)
settings\loadurl=getnextimageurl(@searcherg)
If settings\loadurl
If settings\memorybuffer
FreeMemory(settings\memorybuffer)
EndIf
download=CreateThread(@httpgetfile_memory(),@settings)
While IsThread(download)
Delay(10)
FlipBuffers()
checkuserinputs(@settings,1)
Wend
checkuserinputs(@settings)
If settings\lastdownload
If CatchSprite(#image_loaded,settings\memorybuffer,#PB_Sprite_Texture)
settings\url=settings\loadurl
TransparentSpriteColor(#image_loaded, RGB(255,0,255))
CreateSprite3D(#image_loaded,#image_loaded)
settings\errors=0
fadesprite(@settings)
settings\numpics=settings\numpics+1
If settings\saveall
savewallpaper(@settings)
EndIf
For i=0 To settings\pause
Delay(10)
checkuserinputs(@settings)
Next
displayloading(@settings)
Else
settings\errors=settings\errors+1
displayerrors(@settings)
EndIf
Else
settings\errors=settings\errors+1
displayerrors(@settings)
EndIf
EndIf
Wend
settings\page=settings\page+1
Wend
CloseScreen()
End
load: IncludeBinary "load.bmp"
i: IncludeBinary "i.bmp"
m0: IncludeBinary "m0.bmp"
saving: IncludeBinary "saving.bmp"
saved: IncludeBinary "saved.bmp"
page: IncludeBinary "page.bmp"
error: IncludeBinary "error.bmp"
Code: Alles auswählen
; PureHTTP Include - Version: 0.45b
; OS: Linux / Windows / AmigaOS / MacOSX
; Author: Marius Eckardt (Thalius)
; a lil lib for HTTP ( for now just Downloading ;)
; Last Changes: 24.12.2008
;
; PureHTTP is aimed to be a HTTP 1.0-Compatible Crossplatform Library for use in your Projects.
; This code is PublicDomain - Credits apprechiated if you use it tho ;)
;
; Thx go to mp303 who brought me on the Idea initially with some Networkquestions in the Bugsection. :)
;
; Note: This Code is supposed to be fast but not super optimized. Basically ok for the Job - if you do optimizations
; / improvements you feel the Community could benefit from feel free to post them. :)
;
; Features:
; - HTTP Download to File with :
; - HTTP HEADER Info
; - HTTP Error Handling
; - HTTP Redirect support ( should work now! )
; - Connection Timeout Handling
; - Callback Support
; - Download Timer
; - KB/s o Meter
; - Limit Download Speed
;
; Changes:
; 0.2b:
; - Added Callback Function Support
; 0.3b:
; - lil Optimization
; 0.4b:
; - more Optimizations
; - Fixed Speedlimit To a per Kb/s Value
; - Added PureHTTP_SplitURL(url.s, type.i) - Splits an URL to Host/Path/Filename
; - Extended Example a little
; 0.41 - 0.45b:
; - small Optimizations
; - Added Redirect Support
; - Download to Memory ( Weee ! ;)
; - Added fixes by "moogle"
; - Added fix by oryaaaaa
; - Modified for PB 4.30 / 64 Bit compatibility ( if you need it for an older version simply replace all .i with .l ;))
;
; ToDo:
; - Bugfixes ?
; - Extend HTTP Header Structure to support more of HTTP/1.0
; - HTTP Resume Support
; - GUI with Callback Example
; - HTTP POST Functionality
; - Manual
;- Konstants
; Network
#PureHTTP_Name = "PureHTTP" ; UserAgent Name
#PureHTTP_Defaultfile = "index.html" ; Default for index Files ( used to parse URLs )
#PureHTTP_Buffersize = 4096 ; Chunk-/Buffersize (This Value is balanced ok for average usage. There might be a speedgain on large files increasing this, but slowdown for smaller files)
#PureHTTP_Timeout = 10000 ; Network Timeout in ms
; Status
Enumeration
#PureHTTP_STATUS_CONNECTING ; Connecting
#PureHTTP_STATUS_CONNECTED ; Connected
#PureHTTP_STATUS_GOTHEADER ; Got Header info Filesize / Content-Type
#PureHTTP_STATUS_RECEIVE ; Receiving...
#PureHTTP_STATUS_REDIRECT ; HTTP Redirect
#PureHTTP_STATUS_IDLE ; Idle, Waiting for Data...
#PureHTTP_STATUS_FINISHED ; Download Finished
#PureHTTP_STATUS_TIMEOUT ; Timeout
#PureHTTP_STATUS_HTTPERROR ; HTTP Error / Return
#PureHTTP_STATUS_FILEERROR ; Can't create file
#PureHTTP_STATUS_ABORT ; Download Aborted
EndEnumeration
; HTTP URL Related
#PureHTTP_URL_Protocol = "http://"
; URL Return-Selection Konstants
Enumeration
#PureHTTP_URL_TO_HOST ; Host
#PureHTTP_URL_TO_PATH ; Path
#PureHTTP_URL_TO_FILE ; Filename
EndEnumeration
; HTTP Protocol Related
#HTTP_Port = 80
#HTTP_Protocol10 = "HTTP/1.0"
#HTTP_Protocol11 = "HTTP/1.1"
#HTTP_ContentLength = "Content-Length:"
#HTTP_ContentType = "Content-Type:"
; HTTP Retruncodes
#HTTP_CODE_OK = 200 ; OK
#HTTP_CODE_REDIRECT = 301 ; Redirect
#HTTP_CODE_TREDIRECT = 307 ; Transparent Redirect
;- Structures
; HTTP Header Struct
Structure _PureHTTP_HEADER
Returncode.i ; HTTP Return Code -> 200 = OK -> 404 = File Not Found
ContentLength.i ; Reported Content-Size
ContentType.s ; Reported Content-Type
HTTPReturnString.s ; HTTP Retrunstring -> "HTTP ERROR 404 Not Found"
EndStructure
; File Struct
Structure _PureHTTP_GET_FILE
; File
id.i ; FileIDThread ( in case we download multiple files at once )
*Callback ; Callback Function
ConID.i ; ConnectionID
Host.s ; Host to Connect to
Path.s ; Path to File on Host
outputfile.s ; Path to local Filetarget
*DestBuffer ; Pointer to Destination Memory Buffer ( Alternative to File Download )
Status.i ; Download Status
; HTTP Header Meta Info
Header._PureHTTP_HEADER
; Network
*Buffer ; Pointer to our Paketbuffer
Totalbytes.i ; Holds actual Total bytes received from this File
StartTimer.i ; Start Timer in ms
Timer.i ; Current Our Timer in ms
Totaltime.i ; Total DownloadTime
limitspeed.i ; Limit Downloadspeed in Kb/s
kbps.f ; KB/s
EndStructure
;- Procs
; -- Semi Internal Functions
; Builds GET HTTP Header, kinda interna therefor in CAPS
; Returns HTTP HeaderString
Procedure.s PureHTTP_BUILDHEADER_HTTP_GET(*this._PureHTTP_GET_FILE)
Protected extras.s
If Len(*this\Path) <= 1
*this\Path = "/"
EndIf
; Add more Checks & stuff here...
extras.s = Chr(13) + Chr(10) + "User-Agent: " + #PureHTTP_Name
ProcedureReturn "GET " + *this\Path + " " + #HTTP_Protocol10 + Chr(13) + Chr(10) + "host: "+ *this\Host + Chr(13) + Chr(10) +"Connection: Close" + extras.s + Chr(13) + Chr(10) + Chr(13) + Chr(10)
EndProcedure
; Set Download Status
; kinda Interna-helper function
; Can be used to send an event to thread
; for ex: PureHTTP_SET_STATUS(@mydownload, #PureHTTP_STATUS_ABORT )
; Aborts download.
Procedure PureHTTP_SET_STATUS(*this._PureHTTP_GET_FILE, Status.i)
;// Set Status
*this\Status = Status.i
;// Call Callback
If *this\Callback <> 0
CallFunctionFast(*this\Callback,*this)
EndIf
EndProcedure
; -- User Functions
; Func: PureHTTP_SplitURL(url.s, [ #Pure_HTTP_URL_* ])
; Desc: Little Helper Function to Extract Host/Path/Filename out of an URL
; Returns: String: Hostname, Path, Filename
; See Types:
; #PureHTTP_URL_HOST ; Host
; #PureHTTP_URL_PATH ; Path
; #PureHTTP_URL_FILE ; Filename
;
; Example: Debug PureHTTP_SplitURL("http://www.wavemage.com/edscore/5-EndTitle.mp3",#PureHTTP_URL_FILE)
; See example below for more...
Procedure.s PureHTTP_SplitURL(URL.s, type.i = #PureHTTP_URL_TO_HOST)
Protected i.i, a.i
Result.s = ""
;// Do we have a http:// ?
a.i = FindString(URL.s,#PureHTTP_URL_Protocol,0)
If a.i
URL.s = Right(URL.s,Len(URL.s) - Len(#PureHTTP_URL_Protocol))
If type.i >= #PureHTTP_URL_TO_HOST And type.i <= #PureHTTP_URL_TO_FILE
;// Host
Result.s = StringField(URL.s,0,"/")
If type.i = #PureHTTP_URL_TO_FILE
;// Filename
;// Find File
num_slash=CountString(URL.s, "/")
Result.s=StringField(URL.s, num_slash+1, "/")
;// Sure we got a File ?
If FindString(Result.s,".",0) = 0 Or Result.s = StringField(URL.s,0,"/")
;// No ? Assuming its an index HTML
Result.s = #PureHTTP_Defaultfile
EndIf
EndIf
;// Path
If type.i = #PureHTTP_URL_TO_PATH
Result.s = Right(URL.s,Len(URL.s)-Len(Result.s))
EndIf
EndIf
EndIf
ProcedureReturn Result.s
EndProcedure
; Func: PureHTTP_Get_File(@myfile)
; Returns: Statuscode See: #PureHTTP_STATUS_*
; Desc: Downloads File
Procedure PureHTTP_Get_File(*this._PureHTTP_GET_FILE)
Protected offset.i, eoffset.i, cloffset.i, ctoffset.i, solocoffset.i, eolocoffset.i, Bytes.i, PaketCounter.i, *SEvent, *outfile
Protected m_mul.i, redirection.i = 0, dest_buffersize.i, tmp_redir_url.s
;// Set Status
PureHTTP_SET_STATUS(*this, #PureHTTP_STATUS_CONNECTING)
*this\ConID = OpenNetworkConnection( *this\Host , #HTTP_Port )
If *this\ConID
;// Set Status
PureHTTP_SET_STATUS(*this, #PureHTTP_STATUS_CONNECTED)
;// Allocate Receivebuffer
*this\Buffer = AllocateMemory(#PureHTTP_Buffersize)
;// Init Timer
*this\StartTimer = ElapsedMilliseconds()
*this\Timer = *this\StartTimer
;// Send HTTP Request
SendNetworkString(*this\ConID,PureHTTP_BUILDHEADER_HTTP_GET(*this))
;// Wait for incoming Data ...
Repeat
*SEvent = NetworkClientEvent(*this\ConID)
Select *SEvent
;// We received Data!
Case #PB_NetworkEvent_Data
;// Now go Fetch!
Repeat
Bytes.i = ReceiveNetworkData(*this\ConID, *this\Buffer, #PureHTTP_Buffersize)
;// Is this the first Paket containing the Header ?
If PaketCounter.i = 0
; PrintN(PeekS(*this\Buffer,#PureHTTP_Buffersize)) ;<- lil Debug For the header
;// Basic Process Header - Get DataOffsets
eoffset.i = FindString(PeekS(*this\Buffer, 200), #HTTP_Protocol10, 0) + Len(#HTTP_Protocol10)
If eoffset.i = Len(#HTTP_Protocol10) ;// We got a HTTP1.1 response, find new offset.
eoffset.i = FindString(PeekS(*this\Buffer, 200), #HTTP_Protocol11, 0) + Len(#HTTP_Protocol11)
EndIf
;// We sure in for a right Response now ?
If eoffset.i = Len(#HTTP_Protocol10) ; no .. still no offset
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_HTTPERROR)
Else ; Yeah baby!
cloffset.i = FindString(PeekS(*this\Buffer, #PureHTTP_Buffersize), #HTTP_ContentLength, eoffset.i) + Len(#HTTP_ContentLength)
ctoffset.i = FindString(PeekS(*this\Buffer, #PureHTTP_Buffersize), #HTTP_ContentType, eoffset.i) + Len(#HTTP_ContentType)
offset.i = FindString(PeekS(*this\Buffer, #PureHTTP_Buffersize),Chr(13) + Chr(10) + Chr(13) + Chr(10),eoffset.i) + 3
;// Do we have a Content-Length Info? if so, set Size
If cloffset.i <> Len(#HTTP_ContentLength)
*this\Header\ContentLength = Val(LTrim(RTrim(PeekS(*this\Buffer+cloffset.i,FindString(PeekS(*this\Buffer+cloffset.i,#PureHTTP_Buffersize-cloffset.i),Chr(13) + Chr(10),0)))))
EndIf
;// Set Content-Type
If ctoffset.i <> Len(#HTTP_ContentType)
*this\Header\ContentType = LTrim(RTrim(PeekS(*this\Buffer+ctoffset.i,FindString(PeekS(*this\Buffer+ctoffset.i,#PureHTTP_Buffersize-ctoffset.i),Chr(13) + Chr(10),0))))
EndIf
;// Select Header Response
*this\Header\Returncode = Val(PeekS(*this\Buffer+eoffset.i, 3))
Select *this\Header\Returncode
Case #HTTP_CODE_OK
;// Create File
If Len(*this\outputfile) > 0
*outfile = CreateFile(#PB_Any,*this\outputfile+".part")
EndIf
;//Set status
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_GOTHEADER)
;// Write first bytes to File
If *outfile
*this\Totalbytes = Bytes.i - offset.i
WriteData(*outfile, *this\Buffer + offset.i, Bytes.i - offset.i)
Else
;// Check if Download to Memory & Set Status
If Not *this\Destbuffer
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_FILEERROR)
EndIf
EndIf
; -- Add
;// Check if Memory Reserved.
If *this\Destbuffer
dest_buffersize.i = MemorySize(*this\Destbuffer)
;// Check if Buffer is Big enough for first data...
If #PureHTTP_Buffersize > dest_buffersize.i
;// Reallocate Memory to Rec-Buffersize
*this\Destbuffer = ReAllocateMemory(*this\Destbuffer,#PureHTTP_Buffersize)
EndIf
;// Download first Data to Memory Buffer
CopyMemory(*this\Buffer + offset.i,*this\Destbuffer,Bytes.i - offset.i)
*this\Totalbytes + ( Bytes.i - offset.i)
EndIf
;// Process HTTP REDIRECT
Case #HTTP_CODE_REDIRECT To #HTTP_CODE_TREDIRECT
;// Set Status
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_GOTHEADER)
;// Handle Redirection - Find new Location
solocoffset.i = FindString(PeekS(*this\Buffer),"Location:",eoffset.i) + 10
eolocoffset.i = FindString(PeekS(*this\Buffer),Chr(13) + Chr(10),solocoffset.i)
tmp_redir_url.s = Mid(PeekS(*this\Buffer), solocoffset, eolocoffset - solocoffset)
;// Got Location ? Rewrite URL !
If solocoffset.i
*this\Host = PureHTTP_SplitURL(tmp_redir_url.s,#PureHTTP_URL_TO_HOST)
*this\Path = PureHTTP_SplitURL(tmp_redir_url.s,#PureHTTP_URL_TO_PATH)
redirection.i = 1
;// Set status
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_REDIRECT)
EndIf
Default ; Unknown Error Code
;// Set Status
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_HTTPERROR)
*this\Header\HTTPReturnString = PeekS(*this\Buffer+eoffset.i,FindString(PeekS(*this\Buffer+eoffset.i,200),Chr(13) + Chr(10),0))
EndSelect
EndIf
Else ;// Download Finished ?
If Bytes.i = 0
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_FINISHED)
Else ;// No? ok then write some ...
*this\Totalbytes + Bytes.i
;// Set Status
PureHTTP_SET_STATUS(*this, #PureHTTP_STATUS_RECEIVE)
;// write Data To File
If *outfile
WriteData(*outfile,*this\Buffer,Bytes.i)
Else
;// Set Status
If Not *this\Destbuffer
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_FILEERROR)
EndIf
EndIf
;// Download to Memory: Check if Memory Reserved.
If *this\Destbuffer
dest_buffersize.i = MemorySize(*this\Destbuffer)
;// Check if Buffer is Big enough for coming data...
If *this\Totalbytes > dest_buffersize.i
;// Reallocate Memory to Fit
m_mul.i = Round(*this\Totalbytes / #PureHTTP_Buffersize,1) + 1
*this\Destbuffer = ReAllocateMemory(*this\Destbuffer,(#PureHTTP_Buffersize * m_mul.i))
EndIf
;// Download first Data to Memory Buffer
CopyMemory(*this\Buffer,*this\Destbuffer + *this\Totalbytes - Bytes.i,Bytes.i)
EndIf
;// Update KB/s
*this\kbps = (*this\Totalbytes / ((ElapsedMilliseconds()-*this\StartTimer)/1000)) / 1024
;// Update Timer
*this\Timer = ElapsedMilliseconds()
EndIf
EndIf
PaketCounter.i + 1
;// Limit Speed to
If *this\limitspeed <> 0
While *this\kbps > *this\limitspeed
;// Update KB/s & wait out our Limit...
*this\kbps = (*this\Totalbytes / ((ElapsedMilliseconds()-*this\StartTimer)/1000)) / 1024
Delay(10)
Wend
EndIf
Until *this\Status >= #PureHTTP_STATUS_FINISHED
;// Close File
If *outfile
CloseFile(*outfile)
CopyFile(*this\outputfile+".part",*this\outputfile)
DeleteFile(*this\outputfile+".part")
EndIf
Default
;// Set Status
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_IDLE)
EndSelect
;// Check Timeout
If ElapsedMilliseconds() - *this\Timer > #PureHTTP_Timeout
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_TIMEOUT)
EndIf
;// Don't burn CPU while waiting...
Delay(10)
Until *this\Status >= #PureHTTP_STATUS_FINISHED
;// Free Memory
If *this\Buffer
FreeMemory(*this\Buffer)
EndIf
*this\Totaltime = ElapsedMilliseconds() - *this\StartTimer
If *this\ConID
CloseNetworkConnection(*this\ConID)
EndIf
Else
;// Connection Timeout
PureHTTP_SET_STATUS(*this,#PureHTTP_STATUS_TIMEOUT)
EndIf
If redirection.i = 1
PureHTTP_Get_File(*this._PureHTTP_GET_FILE)
EndIf
ProcedureReturn *this\Status
EndProcedure
; **** END OF INCLUDE ****
;// !!! Debug Download to Memory Buffer
m0