RSBasic Backup Desktop download tool
Posted: Sun Aug 23, 2015 11:25 pm
Hi to All With permission from RSBasic today here is a Desktop tool to download from his repository. RSBasic requests that the following code is not altered and used in anyway to download multiple files or the whole of the repository. The code may be used under the above conditions with the following repository "http://www.rsbasic.de/backups/".
Compile Options: Create ThreadSafe Executable !!!!
Require`s Droopy Lib else Code in 2nd Post to Fangbeast include Droopy`s Procedure.
Clicking on the ListIconGadget column headers sorts the name or date fields, LMD click on an element downloads the selected file to the current users selected download folder.
Zebuddi.
Compile Options: Create ThreadSafe Executable !!!!
Require`s Droopy Lib else Code in 2nd Post to Fangbeast include Droopy`s Procedure.
Clicking on the ListIconGadget column headers sorts the name or date fields, LMD click on an element downloads the selected file to the current users selected download folder.
Zebuddi.

Code: Select all
EnableExplicit
CompilerIf Not #PB_Compiler_Thread
MessageRequester("Hint", "Enable threadsafe!")
End
CompilerEndIf
InitNetwork()
Global Window_0
Global StatusBar_Window_0
Global Window_0_ListIcon
Structure dat
name.s
size.s
date.s
rdate.i
dwll.s
EndStructure
Global NewList dat.dat()
Global gThread.i, gThread2.i, gDownloadFinished.b, gBackup_Url$ = "http://www.rsbasic.de/backups/"
Define Event.i, url$, UserDownLoadFolder$
Procedure OnListIconCLick(WindowID, message, wParam, lParam)
Protected Result, *nmITEM.NMITEMACTIVATE
Result = #PB_ProcessPureBasicEvents
Select message
Case #WM_NOTIFY
*nmITEM.NMITEMACTIVATE = lParam
Select *nmITEM\hdr\code
Case #LVN_COLUMNCLICK ;/ HeaderClick
If *nmITEM\hdr\hwndFrom = GadgetID(Window_0_ListIcon) ;/ ListIconGadget
With dat()
If gDownloadFinished = 1
If *nmITEM\iSubItem = 0
SortStructuredList(dat(),#PB_Sort_Ascending, OffsetOf(dat\name), TypeOf(dat\name))
ClearGadgetItems(Window_0_ListIcon)
ForEach dat()
AddGadgetItem(Window_0_ListIcon, -1, \name+Chr(10)+\date+Chr(10)+\dwll)
Next
ElseIf *nmITEM\iSubItem = 1
SortStructuredList(dat(), #PB_Sort_Descending, OffsetOf(dat\rdate) ,TypeOf(dat\rdate))
ClearGadgetItems(Window_0_ListIcon)
ForEach dat()
AddGadgetItem(Window_0_ListIcon, -1, \name+Chr(10)+\date+Chr(10)+\dwll)
Next
EndIf
EndIf
EndWith
EndIf
Result = #True
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
Procedure DownloadFileUpdater(dummy.i)
Protected i, dot$, t$ = "|,/,-,\,|,/,-,\,", c
Repeat
c+1
dot$ = StringField(t$, c, ",")
SetWindowTitle(Window_0, "Downloading File "+dot$)
Delay(60)
If c=8 : c=0 : EndIf
Until gDownloadFinished = 1
EndProcedure
Procedure ProcessFile(dummy.i)
Protected rsb$=GetTemporaryDirectory()+"rsb.txt" ; tempory copy of the download url$ source
Protected ThisLine$, nbr.i, i.i, p.i
If ReceiveHTTPFile(gBackup_Url$, rsb$)
Protected regex_all.i = CreateRegularExpression(#PB_Any, "<td>.*?a></td>")
Protected regex_list.i = CreateRegularExpression(#PB_Any, "<td>.*?</td>")
Protected regex_dlink.i = CreateRegularExpression(#PB_Any, Chr(34) + ".*" + Chr(34))
Protected Dim t$(0)
Protected Dim l$(0)
Protected Dim dlink$(0)
SetWindowTitle(Window_0, "Downloading File")
If ReadFile(0,rsb$)
While Not Eof(0)
ThisLine$ + ReadString(0, ReadStringFormat(0))
Wend
CloseFile(0)
nbr = ExtractRegularExpression(regex_all, ThisLine$, t$())
EndIf
gDownloadFinished = 1
SetWindowTitle(Window_0, "Processing Downloaded File")
With dat()
For i=0 To nbr-1
ExtractRegularExpression(regex_list, t$(i), l$())
AddElement(dat())
For p = 0 To 3
l$(p) = RemoveString(l$(p), "<td>")
l$(p) = RemoveString(l$(p), "</td>")
Next
\name = l$(0)
\size = l$(1)
\date = l$(2)
\rdate = Date( Val(StringField(\date, 3, ".")), Val(StringField(\date, 2 ,".")),Val(StringField(\date, 1 , ".")), 0, 0, 0)
ExtractRegularExpression(regex_dlink, l$(3),dlink$())
\dwll = dlink$(0)
Next
SortStructuredList(dat(), #PB_Sort_Descending, OffsetOf(dat\rdate) ,TypeOf(dat\rdate))
ForEach dat()
AddGadgetItem(Window_0_ListIcon, -1, \name+Chr(10)+\date+Chr(10)+\dwll)
Next
StatusBarText(StatusBar_Window_0,1,Str(ListSize(dat())))
EndWith
Else
MessageRequester("Download Error", GetLastErrorAsText(GetLastError()))
End
EndIf
SetWindowTitle(Window_0, "RS BackUp Downloader Processing Complete")
FreeArray(l$())
FreeArray(t$())
FreeArray(dlink$())
FreeRegularExpression(regex_all)
FreeRegularExpression(regex_dlink)
FreeRegularExpression(regex_list)
gDownloadFinished = 1
EndProcedure
Procedure OpenWindow_Window_0()
Window_0 = OpenWindow(#PB_Any, 521, 101, 667, 400, "RS BackUp Downloader", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
If Window_0
Window_0_ListIcon = ListIconGadget(#PB_Any, 0, 0, 667, 377, "File", 200, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(Window_0_ListIcon, 1,"Date",100)
AddGadgetColumn(Window_0_ListIcon, 2,"Download Link",367)
StatusBar_Window_0 = CreateStatusBar(#PB_Any, WindowID(Window_0))
If StatusBar_Window_0
AddStatusBarField(100) : AddStatusBarField(100): AddStatusBarField(467)
StatusBarText(StatusBar_Window_0,0,"Entries: ")
EndIf
EndIf
EndProcedure
OpenWindow_Window_0()
gThread = CreateThread(@ProcessFile(),0)
gThread2 = CreateThread(@DownloadFileUpdater(),0)
SetWindowCallback(@OnListIconCLick(), Window_0)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case Window_0_ListIcon
Select EventType()
Case #PB_EventType_LeftDoubleClick
url$ = RemoveString(GetGadgetItemText(Window_0_ListIcon, GetGadgetState(Window_0_ListIcon),2),Chr(34))
UserDownLoadFolder$ = "C:\Users\"+UserName()+"\Downloads\"+GetFilePart(url$)
If ReceiveHTTPFile(url$,UserDownLoadFolder$)
StatusBarText(StatusBar_Window_0, 2, "Downloading File "+GetFilePart(url$))
Else
StatusBarText(StatusBar_Window_0, 2, "Error Downloading File "+Str(GetLastError_()))
EndIf
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Select EventWindow()
Case Window_0
CloseWindow(Window_0)
Window_0 = 0
Break
EndSelect
EndSelect
ForEver
FreeList(dat())