PureLVSORT library : sorting ListIconGadgets (and more)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hello gnozal,

thank you for your interest in this new idea.

First, do you want to connect to a 'FTP' server ?

If so, do you remember the cool Zapman tool 'Drop Upload' ?

source code is provided, with a FTP include.
I'm not sure if it supports Proxi connection. But you can try.

download it here - and then update the tool (another update is available) :

http://www.purebasic.fr/english/viewtopic.php?t=12593
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:thank you for your interest in this new idea.
Moderate interest :wink:
Flype wrote:First, do you want to connect to a 'FTP' server ?
I don't have FTP access, so it has to be HTTP.
Anyway, Zapman's tool doesn't support Proxy connection.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

I guessed, that you'd find another solution.

From now on, you create *.pak files (packed with PB compression or ZIP compression) containing the LIB files and an information file. In this information file, you save some information, e. g. version number, time/date of the lib, etc.

Your updater just uses URLDownloadToFile_() then. This command, I guess, automatically uses the internet settings of Internet Explorer. So itll work! The updater just downloads a small information file and if neccessary, it notifies the user about new updates.

I don't want to visit this forum, just to lok for one of your libs (I use more than one of your libs, gnozal). Oh nooo... If there is an update I *manually* have to download and install the lib. Puhhh... Can't this be done by your auto-updater, too?

Then, we all would have always the newest update and we don't need to do anything! :D
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

lazy, lazy, sexy coders...

Does the URLDownloadToFile_() works with proxi ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:lazy, lazy, sexy coders...

Does the URLDownloadToFile_() works with proxi ?
Well, thefool's last example in thread http://www.purebasic.fr/english/viewtopic.php?t=11078 does not work (I tried wit hhttp://www.purebasic.fr/english/templates/subS ... _phpBB.gif).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Flype wrote:Does the URLDownloadToFile_() works with proxi ?
Seems so.

@ gnozal: No comment for me? :(
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Well, thefool's snippet works at home (no proxy here) with the link you provided (the GIF).

But, if you have proxy i notice this in thefools code :

the first internet access done in the code is this line :

Code: Select all

InternetOpen_("", OpenType, #Null, #Null, 0)
If we look at the associated MSDN documentation we can see that this function needs a special Flag for proxy connection : #INTERNET_OPEN_TYPE_PROXY
Use INTERNET_OPEN_TYPE_PROXY if the system on which the application is running uses one or more proxy servers to access the Internet. InternetOpen uses the proxy servers indicated by lpszProxyName and bypasses the proxy for any host names or IP addresses specified by lpszProxyBypass.
have a look here :
http://msdn.microsoft.com/library/defau ... nality.asp
http://msdn.microsoft.com/library/defau ... etopen.asp

as i have not a proxy defined at home nor at work, i can't test.
but it should not be to difficult... Let us know :wink:

here are the constants for the function :

Code: Select all

#define INTERNET_OPEN_TYPE_PRECONFIG 0 
#define INTERNET_OPEN_TYPE_DIRECT 1 
#define INTERNET_OPEN_TYPE_PROXY 3 
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 
#define PRE_CONFIG_INTERNET_ACCESS INTERNET_OPEN_TYPE_PRECONFIG
#define LOCAL_INTERNET_ACCESS INTERNET_OPEN_TYPE_DIRECT
#define CERN_PROXY_INTERNET_ACCESS INTERNET_OPEN_TYPE_PROXY
but, once again, as AND51 said, what's about the URLDownloadFile_() ? does it works for you ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

AND51 wrote:
Flype wrote:Does the URLDownloadToFile_() works with proxi ?
Seems so.

@ gnozal: No comment for me? :(
Some patience please, I am not only working for your pleasure :wink:
I tried this code from Fr34k :

Code: Select all

; ----------------------------------------------------------------------------
;
;  Asyncronous download with Callback
;
;  by Timo Harter
;
; ----------------------------------------------------------------------------
;
; Usage:
;
; DownloadFile(Url$, SaveTo$, WindowID, Callback)
;
; Url$      Source Url to download from
; SaveTo$   Target File on disk
; WindowID  ID of any window, that will stay open until the download finishes
;           (used for internal communication)
; Callback  Address of a callback function to receive status information
;
; Callback Procedure:
;
; Procedure.l DownloadCallback(Url$, Progress.l, FileSize.l, StatusCode.l, StatusMessage$)
;
;   ProcedureReturn 1
; EndProcedure
;
; Url$            Url of the current download
; Progress        Bytes downloaded
;                 If download finished successfully, #DOWNLOAD_OK is returned (-1)
;                 If download failed, or was aborted, #DOWNLOAD_FAILED is returned (-2)
; FileSize        Total size of file (may change during download)
; StatusCode      Information code on download status. For more info go here:
;                 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceurlmn/html/cerefbindstatus.asp
; StatusMessage$  Additional Information on StatusCode
;
;
; Return a nonzero value to continue the download, or zero to abort it.
;
; Note: Any number of downloads can be started simultanously, each can
; have it's own callback, or they can also use the same if you want. The Url$
; parameter can then be used to find out to which file the information belongs.
;
; ----------------------------------------------------------------------------

#DOWNLOAD_OK = -1
#DOWNLOAD_FAILED = -2

#WM_DOWNLOADPROGRESS = #WM_USER + 1
#WM_DOWNLOADEND      = #WM_USER + 2

Enumeration 1
  #BINDSTATUS_FINDINGRESOURCE
  #BINDSTATUS_CONNECTING
  #BINDSTATUS_REDIRECTING
  #BINDSTATUS_BEGINDOWNLOADDATA
  #BINDSTATUS_DOWNLOADINGDATA
  #BINDSTATUS_ENDDOWNLOADDATA
  #BINDSTATUS_BEGINDOWNLOADCOMPONENTS
  #BINDSTATUS_INSTALLINGCOMPONENTS
  #BINDSTATUS_ENDDOWNLOADCOMPONENTS
  #BINDSTATUS_USINGCACHEDCOPY
  #BINDSTATUS_SENDINGREQUEST
  #BINDSTATUS_CLASSIDAVAILABLE
  #BINDSTATUS_MIMETYPEAVAILABLE
  #BINDSTATUS_CACHEFILENAMEAVAILABLE
  #BINDSTATUS_BEGINSYNCOPERATION
  #BINDSTATUS_ENDSYNCOPERATION
  #BINDSTATUS_BEGINUPLOADDATA
  #BINDSTATUS_UPLOADINGDATA
  #BINDSTATUS_ENDUPLOADINGDATA
  #BINDSTATUS_PROTOCOLCLASSID
  #BINDSTATUS_ENCODING
  #BINDSTATUS_VERFIEDMIMETYPEAVAILABLE
  #BINDSTATUS_CLASSINSTALLLOCATION
  #BINDSTATUS_DECODING
  #BINDSTATUS_LOADINGMIMEHANDLER
  #BINDSTATUS_CONTENTDISPOSITIONATTACH
  #BINDSTATUS_FILTERREPORTMIMETYPE
  #BINDSTATUS_CLSIDCANINSTANTIATE
  #BINDSTATUS_IUNKNOWNAVAILABLE
  #BINDSTATUS_DIRECTBIND
  #BINDSTATUS_RAWMIMETYPE
  #BINDSTATUS_PROXYDETECTING
  #BINDSTATUS_ACCEPTRANGES
EndEnumeration


Structure IBindStatusCallback_Functions
  QueryInterface.l
  AddRef.l
  Release.l
  OnStartBinding.l
  GetPriority.l
  OnLowResource.l
  OnProgress.l
  OnStopBinding.l
  GetBindInfo.l
  OnDataAvailable.l
  OnObjectAvailable.l
EndStructure

Structure StatusObject
  *IBindStatusCallback.IBindStatusCallback_Functions
  
  Url.s
  SaveTo.s
  Callback.l
  CallWindow.l  
  Progress.l
  ProgressMax.l
  StatusCode.l
  *StatusText
  
  ObjectCount.l
EndStructure

Global IBindStatusCallback_Functions.IBindStatusCallback_Functions
Global NewList StatusObject.StatusObject()


Procedure.l StatusObject_QueryInterface(*THIS.StatusObject, *iid.IID, *Object.Long) 
  If CompareMemory(*iid, ?IID_IUnknown, SizeOf(IID)) Or CompareMemory(*iid, ?IID_IBindStatusCallback, SizeOf(IID))
    *Object\l = *THIS    
    ProcedureReturn #S_OK
  Else    
    *Object\l = 0
    ProcedureReturn #E_NOINTERFACE
  EndIf
EndProcedure

Procedure.l StatusObject_AddRef(*THIS.StatusObject)
  *THIS\ObjectCount + 1
  ProcedureReturn *THIS\ObjectCount
EndProcedure

Procedure.l StatusObject_Release(*THIS.StatusObject)
  *THIS\ObjectCount - 1
  ProcedureReturn *THIS\ObjectCount
EndProcedure

Procedure.l StatusObject_OnStartBinding(*THIS.StatusObject, reserved.l, *IB.IBinding)
  ProcedureReturn #S_OK
EndProcedure

Procedure.l StatusObject_GetPriority(*THIS.StatusObject, *Priority.Long) 
  ProcedureReturn #E_NOTIMPL
EndProcedure

Procedure.l StatusObject_OnLowResource(*THIS.StatusObject)
  ProcedureReturn #E_NOTIMPL
EndProcedure

Procedure.l StatusObject_OnProgress(*THIS.StatusObject, Progress.l, ProgressMax.l, StatusCode.l, szStatusText.l)
  *THIS\Progress = Progress
  *THIS\ProgressMax = ProgressMax
  *THIS\StatusCode = StatusCode
  
  length = WideCharToMultiByte_(#CP_ACP, 0, szStatusText, -1, 0, 0, 0, 0)
  *String = HeapAlloc_(GetProcessHeap_(), 0, length) 
  WideCharToMultiByte_(#CP_ACP, 0, szStatusText, -1, *String, length, 0, 0)
  
  *THIS\StatusText = *String
  
  Result = SendMessage_(*THIS\CallWindow, #WM_DOWNLOADPROGRESS, 0, *THIS)
  HeapFree_(GetProcessHeap_(), 0, *String)
  
  If Result = #False
    ProcedureReturn #E_ABORT
  Else
    ProcedureReturn #S_OK
  EndIf
EndProcedure

Procedure.l StatusObject_OnStopBinding(*THIS.StatusObject, Result.l, szError.l)
  ProcedureReturn #S_OK
EndProcedure

Procedure.l StatusObject_GetBindInfo(*THIS.StatusObject, BINDF.l, *bindinfo)
  ProcedureReturn #S_OK
EndProcedure

Procedure.l StatusObject_OnDataAvailable(*THIS.StatusObject, BSCF.l, Size.l, *formatec, *stgmed)
  ProcedureReturn #S_OK
EndProcedure

Procedure.l StatusObject_OnObjectAvailable(*THIS.StatusObject, *iid.IID, *UNK.IUnknown)
  ProcedureReturn #S_OK
EndProcedure

IBindStatusCallback_Functions\QueryInterface    = @StatusObject_QueryInterface()
IBindStatusCallback_Functions\AddRef            = @StatusObject_AddRef()
IBindStatusCallback_Functions\Release           = @StatusObject_Release()
IBindStatusCallback_Functions\OnStartBinding    = @StatusObject_OnStartBinding()
IBindStatusCallback_Functions\GetPriority       = @StatusObject_GetPriority()
IBindStatusCallback_Functions\OnLowResource     = @StatusObject_OnLowResource()
IBindStatusCallback_Functions\OnProgress        = @StatusObject_OnProgress()
IBindStatusCallback_Functions\OnStopBinding     = @StatusObject_OnStopBinding()
IBindStatusCallback_Functions\GetBindInfo       = @StatusObject_GetBindInfo()
IBindStatusCallback_Functions\OnDataAvailable   = @StatusObject_OnDataAvailable()
IBindStatusCallback_Functions\OnObjectAvailable = @StatusObject_OnObjectAvailable()

Procedure Download_Thread(*THIS.StatusObject)
  Result.l = UrlDownloadToFile_(0, *THIS\Url, *THIS\SaveTo, 0, *THIS)
  SendMessage_(*THIS\CallWindow, #WM_DOWNLOADEND, Result, *THIS)
EndProcedure

Procedure Download_WindowCallback(Window.l, message.l, wParam.l, lParam.l)
  If message = #WM_DOWNLOADPROGRESS
    *THIS.StatusObject = lParam
    ProcedureReturn CallFunctionFast(*THIS\Callback, *THIS\Url, *THIS\Progress, *THIS\ProgressMax, *THIS\StatusCode, PeekS(*THIS\StatusText))
    
  ElseIf message = #WM_DOWNLOADEND
    If wParam = #S_OK        
      *THIS.StatusObject = lParam
      CallFunctionFast(*THIS\Callback, *THIS\Url, #DOWNLOAD_OK, 0, 0, "")
    Else
      *THIS.StatusObject = lParam
      CallFunctionFast(*THIS\Callback, *THIS\Url, #DOWNLOAD_FAILED, 0, 0, "")
    EndIf
    ChangeCurrentElement(StatusObject(), *THIS)
    DeleteElement(StatusObject())    
    
  EndIf  
  
  ProcedureReturn CallWindowProc_(GetWindowLong_(Window, #GWL_USERDATA), Window, message, wParam, lParam)
EndProcedure


Procedure DownloadFile(Url.s, SaveTo.s, WindowID.l, Callback.l)
  AddElement(StatusObject())
  StatusObject()\IBindStatusCallback = IBindStatusCallback_Functions
  StatusObject()\Url = Url
  StatusObject()\SaveTo = SaveTo
  StatusObject()\CallWindow = WindowID
  StatusObject()\Callback = Callback  
  
  If GetWindowLong_(WindowID, #GWL_WNDPROC) <> @Download_WindowCallback()
    SetWindowLong_(WindowID, #GWL_USERDATA, GetWindowLong_(WindowID, #GWL_WNDPROC))
    SetWindowLong_(WindowID, #GWL_WNDPROC, @Download_WindowCallback())
  EndIf
  
  CreateThread(@Download_Thread(), @StatusObject())
EndProcedure


DataSection
IID_IUnknown:  
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
    
IID_IBindStatusCallback:  
Data.l $79EAC9C1
Data.w $BAF9, $11CE
Data.b $8C, $82, $00, $AA, $00, $4B, $A9, $0B    
EndDataSection

; ////////////////////////////////////////////////////////////


; Window Constants
;
Enumeration
  #DownloadWindow
EndEnumeration

; Gadget Constants
;
Enumeration
  #Gadget_1
  #Gadget_2
  #Gadget_Url
  #Gadget_SaveTo
  #Gadget_ChooseFile
  #Gadget_Status
  #Gadget_Progress
  #Gadget_Start
  #Gadget_Stop
  #Gadget_Close
  #Gadget_StatusText
EndEnumeration


Procedure Open_DownloadWindow()
  If OpenWindow(#DownloadWindow, 414, 385, 447, 230, "File download:",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    If CreateGadgetList(WindowID(#DownloadWindow))
      TextGadget(#Gadget_1, 5, 10, 60, 20, "Url:", #PB_Text_Right)
      TextGadget(#Gadget_2, 5, 35, 60, 20, "SaveTo:", #PB_Text_Right)
      StringGadget(#Gadget_Url, 70, 5, 320, 20, "")
      StringGadget(#Gadget_SaveTo, 70, 30, 320, 20, "")
      ButtonGadget(#Gadget_ChooseFile, 395, 30, 50, 20, "...")
      ListViewGadget(#Gadget_Status, 5, 55, 385, 120)
      ProgressBarGadget(#Gadget_Progress, 5, 180, 385, 20, 0, 100)
      ButtonGadget(#Gadget_Start, 395, 80, 50, 20, "Start")
      ButtonGadget(#Gadget_Stop, 395, 105, 50, 20, "Abort")
      ButtonGadget(#Gadget_Close, 395, 205, 50, 20, "Close")
      TextGadget(#Gadget_StatusText, 5, 205, 385, 20, "", #PB_Text_Center | #PB_Text_Border)
      
    EndIf
  EndIf
EndProcedure


; ---------------------------------------------------------

;
Global Abort.l
Declare DownloadCallback(Url$, Progress.l, FileSize.l, StatusCode.l, StatusText$)

Open_DownloadWindow()

DisableGadget(#Gadget_Stop, #True)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow: End
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Gadget_Close: End
          
        Case #Gadget_ChooseFile
          File.s = SaveFileRequester("Save File to...", GetGadgetText(#Gadget_SaveTo), "All Files|*.*", 0)
          If File <> "": SetGadgetText(#Gadget_SaveTo, File): EndIf
          
          
        Case #Gadget_Start
          Abort = #False
          DisableGadget(#Gadget_Start, #True)
          DisableGadget(#Gadget_Stop, #False)
          
          SetGadgetState(#Gadget_Progress, 0)
          ClearGadgetItemList(#Gadget_Status)
          
          Url$ = GetGadgetText(#Gadget_Url)
          SaveTo$ = GetGadgetText(#Gadget_SaveTo)
          
          DownloadFile(Url$, SaveTo$, WindowID(#DownloadWindow), @DownloadCallback()) ; download command
          
        Case #Gadget_Stop
          Abort = #True
          
      EndSelect
  EndSelect
ForEver



; download callback:
Procedure DownloadCallback(Url$, Progress.l, FileSize.l, StatusCode.l, StatusText$)
  
  If Progress = #DOWNLOAD_OK  ; download sucessfull
    
    MessageRequester("","Download complete")
    DisableGadget(#Gadget_Start, #False)
    DisableGadget(#Gadget_Stop, #True)
    
  ElseIf Progress = #DOWNLOAD_FAILED ; download failed or aborted
    
    MessageRequester("","Download failed!")
    DisableGadget(#Gadget_Start, #False)
    DisableGadget(#Gadget_Stop, #True)
    
  Else  ; download in progress...
    
    ; progress bar
    If FileSize = 0
      SetGadgetState(#Gadget_Progress, 0)
    Else
      SetGadgetState(#Gadget_Progress, (Progress*100)/FileSize)
    EndIf  
    
    ; size info
    SetGadgetText(#Gadget_StatusText, Str(Progress) + " of "+Str(FileSize) + " Bytes complete.")
    
    ; info box
    Select StatusCode
      Case #BINDSTATUS_FINDINGRESOURCE:   Text$ = "Finding "+StatusText$
      Case #BINDSTATUS_CONNECTING:        Text$ = "Connecting to "+StatusText$
      Case #BINDSTATUS_REDIRECTING:       Text$ = "Resolved to "+StatusText$
      Case #BINDSTATUS_BEGINDOWNLOADDATA: Text$ = "Downloading "+StatusText$
      Case #BINDSTATUS_ENDDOWNLOADDATA:   Text$ = "Finished downloading "+StatusText$
      Case #BINDSTATUS_USINGCACHEDCOPY:   Text$ = "Receiving file from cache."
      Case #BINDSTATUS_MIMETYPEAVAILABLE: Text$ = "MIME Type is "+StatusText$
      Case #BINDSTATUS_PROXYDETECTING:    Text$ = "A Proxy Server was detected"
      Default: Text$ = ""
    EndSelect
    If Text$ <> ""
      AddGadgetItem(#Gadget_Status, -1, Text$)
      SetGadgetState(#Gadget_Status, CountGadgetItems(#Gadget_Status)-1)
    EndIf    
    
  EndIf
  
  ; result is important!
  If Abort = #False
    ProcedureReturn #True ; continue
  Else
    ProcedureReturn #False ; stop download
  EndIf
EndProcedure
It seems to work (find proxy, connecting, downloading, finished downloading, download complete) but no file created !?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

still on windows 98 ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Flype wrote:still on windows 98 ?
Yep, but code above tested at work (NT4).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

The code from above always fails here (Windows Media Center Edition 2005 = XP Pro SP2).

I just resolves google.de's IP address, but downloading
http://www.google.de/index.htm or
http://www.google.de/
always failes.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Ok, tested UrlDownloadToFile_() alone, it fails.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Then, you MUST open a HTTP connection on your own, using the HTTP-protocol.

Just send this header to you host:

Code: Select all

GET /gnozal/PureLVSORT_.zip HTTP/1.0
User-Agent. ikickyourass
Connection: Close
You'll receive a header+the file. Afterwards, you must seperate the components and write the file from the buffer into a fle. Then open the file and work with it (or work with the file dirctely from the buffer).
PB 4.30

Code: Select all

onErrorGoto(?Fred)
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Hey! This code 100% works on my machine. It manually makes use of PB-network commands. This makes it possible to write an updater also for mac+linux, not only for windows (no API being used).

This commented code receives information about your PureLVSORT_.zip, gnozal! Try it! :wink:

Code: Select all

InitNetwork()

; We work with HTTP/1.0 instead of HTTP/1.1 this is easier;
; however, we must create a connection to the server before sending
; something each time.

host$="people.freenet.de"
purelvsort40$="/gnozal/PureLVSORT_.zip"

id=OpenNetworkConnection(host$, 80) ; Port 80 is the default HTTP-Port

; HEAD will retrieve the normale header of the file. GET would retrieve the
; normal header + the file (we just want the information "file size")
; Content-Length: This is the file size in bytes
request$="HEAD "+purelvsort40$+" HTTP/1.0"+#CRLF$ ; general information about method, requested file and used http-version
request$+"User-Agent: gnozals PB-Lib updater (testcode by AND51)"+#CRLF$ ; optional line giving the server information about your program
request$+"Connection: Close"+#CRLF$ ; closing connection ist the default in HTTP 1.0. We can also write "Keep-Alive", then the server does not close the connection (not supported by every server)
request$+#CRLF$ ; Appening an empty line marks the end of the header

SendNetworkData(id, @request$, Len(request$))

*response=AllocateMemory(1024*1024*1024) ; Creating buffer for the server's answer

Repeat : Until ReceiveNetworkData(id, *response, 1000) <> 1000 ; receiving the server's response

CloseNetworkConnection(id) ; Some servers colse connection automatically. Then executing this command leads to crash using PB 4.00 or lower

MessageRequester("testcode by AND51", PeekS(*response)) ; Display the server's answer.
; Statuscode 200: This means everything is ok. If this is not a 2xx message, there is any kind of error
; Content-Type: This is the fily type. text/html means, that the file is a HTML file. ZIp files are declared as application/zip
; Content-Length: This is the file size in bytes
; Accept-Ranges: If its value is bytes, it is possible to resume download if download was interrupted. Useful, if your updater
;                 should act like a download manager
; The other information are not very useful.
In the request, I use HEAD. Do this, to inform the user about download size BEFORE downloading the whole file!
Afterwards, you can send a second request with GET instead of HEAD. GET will receive the normal header+the whole file.

Header + file are always divided by the first empty line occuring. Do you understand?
PB 4.30

Code: Select all

onErrorGoto(?Fred)
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

I've got another idea: I write this updater.
To detect a new update, I must find out, which lib version is currently installed.

My idea: gnozal, please save a *.ini on your webspace, which I will download then. This INi should look like this (example):

Code: Select all

[PureLVSORT]
CurrentVersion = 1.2
File = /gnozal/PureLVSORT_.zip

[PureColor]
CurrentVersion = 1.5
File = /gnozal/PureCOLOR_.zip

[etc...]
my updater then will create a INI in the PB-directory (or in the programs directory) storing the last version that was installed.

But I need help: I don't know, where to install the libs. 2 possibilities:
  • if there is an update, I'll download a SFX-Archive. Then I run your SFX-Archive with the parameter /update. If you recognize, that you got the parameter /update, you hide your window and install automatically.
  • You explain to me where to install each file, because I don't know where to installl *.lib and *.* and *.h and so on......
I could imagine, that my code will run on Win, Linux and Max (because I wont use API). If you want, we can write an additional updater, working for PB 3.94 - but I recommend, to write only a updater for PB 4.00 or higher.

If you've got TeamSpeak, gnozal, we can talk about this topic instead of writing. Now I stop writing an await your answer.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply