home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
- Begin VB.Form frmDownload
- BorderStyle = 3 'Fixed Dialog
- ClientHeight = 3540
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 5520
- FontTransparent = 0 'False
- HasDC = 0 'False
- Icon = "frmDownload.frx":0000
- KeyPreview = -1 'True
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 3540
- ScaleWidth = 5520
- Begin InetCtlsObjects.Inet Inet1
- Left = 0
- Top = 2880
- _ExtentX = 1005
- _ExtentY = 1005
- _Version = 393216
- End
- Begin MSComctlLib.ProgressBar ProgressBar
- Height = 225
- Left = 120
- TabIndex = 4
- Top = 1485
- Width = 5235
- _ExtentX = 9234
- _ExtentY = 397
- _Version = 393216
- Appearance = 1
- End
- Begin MSComCtl2.Animation Animation1
- Height = 615
- Left = 120
- TabIndex = 3
- TabStop = 0 'False
- Top = 0
- Width = 4695
- _ExtentX = 8281
- _ExtentY = 1085
- _Version = 393216
- FullWidth = 313
- FullHeight = 41
- End
- Begin VB.CommandButton CancelButton
- Cancel = -1 'True
- Caption = "Cancel"
- CausesValidation= 0 'False
- Default = -1 'True
- Height = 375
- Left = 2197
- TabIndex = 0
- Top = 3050
- Width = 1215
- End
- Begin VB.Label RateLabel
- Caption = "RateLabel"
- Height = 255
- Left = 1560
- TabIndex = 10
- Top = 2400
- Width = 3765
- End
- Begin VB.Label TransferRate
- Caption = "Transfer rate:"
- Height = 255
- Left = 120
- TabIndex = 9
- Top = 2400
- Width = 1575
- End
- Begin VB.Label ToLabel
- Caption = "ToLabel"
- Height = 195
- Left = 1560
- TabIndex = 8
- Top = 2100
- Width = 3765
- End
- Begin VB.Label DownloadTo
- Caption = "Download to:"
- Height = 255
- Left = 120
- TabIndex = 7
- Top = 2100
- Width = 1575
- End
- Begin VB.Label TimeLabel
- Caption = "TimeLabel"
- Height = 255
- Left = 1560
- TabIndex = 6
- Top = 1800
- Width = 3765
- End
- Begin VB.Label SourceLabel
- Caption = "SourceLabel"
- Height = 195
- Left = 120
- TabIndex = 5
- Top = 1200
- Width = 5250
- End
- Begin VB.Label EstimatedTimeLeft
- Caption = "Estimated time left:"
- Height = 255
- Left = 120
- TabIndex = 2
- Top = 1800
- Width = 1455
- End
- Begin VB.Label StatusLabel
- Caption = "StatusLabel"
- Height = 195
- Left = 120
- TabIndex = 1
- Top = 915
- Width = 5235
- End
- Attribute VB_Name = "frmDownload"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private CancelSearch As Boolean
- Public Function DownloadFile(strURL As String, _
- strDestination As String, _
- Optional UserName As String = Empty, _
- Optional Password As String = Empty) _
- As Boolean
- ' Funtion DownloadFile: Download a file via HTTP
- ' Author: Jeff Cockayne
- ' Inputs: strURL String; the source URL of the file
- ' strDestination; valid Win95/NT path to where you want it
- ' (i.e. "C:\Program Files\My Stuff\Purina.pdf")
- ' Returns: Boolean; Was the download successful?
- Const CHUNK_SIZE As Long = 1024 ' Download chunk size
- Const ROLLBACK As Long = 4096 ' Bytes to roll back on resume
- ' You can be less conservative,
- ' and roll back less, but I
- ' don't recommend it.
- Dim bData() As Byte ' Data var
- Dim blnResume As Boolean ' True if resuming download
- Dim intFile As Integer ' FreeFile var
- Dim lngBytesReceived As Long ' Bytes received so far
- Dim lngFileLength As Long ' Total length of file in bytes
- Dim lngX ' Temp long var
- Dim sglLastTime As Single ' Time last chunk received
- Dim sglRate As Single ' Var to hold transfer rate
- Dim sglTime As Single ' Var to hold time remaining
- Dim strFile As String ' Temp filename var
- Dim strHeader As String ' HTTP header store
- Dim strHost As String ' HTTP Host
- On Local Error GoTo InternetErrorHandler
- ' Start with Cancel flag = False
- CancelSearch = False
- ' Get just filename (without dirs) for display
- strFile = ReturnFileOrFolder(strDestination, True)
- strHost = ReturnFileOrFolder(strURL, True, True)
-
- SourceLabel = Empty
- TimeLabel = Empty
- ToLabel = Empty
- RateLabel = Empty
- ' Pre-open the AVI
- With Animation1
- .AutoPlay = True
- .Open App.Path & "\DOWNLD2.AVI"
- End With
- ' Show the download status form
- ' Move form into view
- Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
- StartDownload:
- If blnResume Then
- StatusLabel = "Resuming download..."
- lngBytesReceived = lngBytesReceived - ROLLBACK
- If lngBytesReceived < 0 Then lngBytesReceived = 0
- StatusLabel = "Getting file information..."
- End If
- ' Give the system time to update the form gracefully
- DoEvents
- ' Download file
- With Inet1
- .URL = strURL
- .UserName = UserName
- .Password = Password
- ' GET file, sending the magic resume input header...
- .Execute , "GET", , "Range: bytes=" & CStr(lngBytesReceived) & "-" & vbCrLf
- ' While initiating connection, yield CPU to Windows
- While .StillExecuting
- DoEvents
- ' If user pressed Cancel button on StatusForm
- ' then fail, cancel, and exit this download
- If CancelSearch Then GoTo ExitDownload
- Wend
- StatusLabel = "Saving:"
- SourceLabel = FitText(SourceLabel, strHost & " from " & .RemoteHost)
- ToLabel = FitText(ToLabel, strDestination)
- ' Get first header ("HTTP/X.X XXX ...")
- strHeader = .GetHeader
- End With
- ' Trap common HTTP response codes
- Select Case Mid(strHeader, 10, 3)
- Case "200" ' OK
- ' If resuming, however, this is a failure
- If blnResume Then
- ' Delete partially downloaded file
- Kill strDestination
- ' Prompt
- If MsgBox("The server is unable to resume this download." & _
- vbCr & vbCr & _
- "Do you want to continue anyway?", _
- vbExclamation + vbYesNo, _
- "Unable to Resume Download") = vbYes Then
- ' Yes - continue anyway:
- ' Set resume flag to False
- blnResume = False
- Else
- ' No - cancel
- CancelSearch = FC-0000F8754 No - cancedownlu.UlateLNo, _
- vbYes ThenSApg3 server is OamMd") = vbYes Then
- t reeceiver"a\s Then
- lset Theur "Do you 1oweUsDonti BytesRecl vbb0) = vbYes EWbYesc Then
- baderueicaYes Ther
- CarnSApg3 aYes ssword As r.a you Heaa
- En= e
- 'ownyaaswor ecnIrRecl vbb0) = vbYes EWbYesc Then
- ' (i.e. "C:\Program Files\My Stuff\Purina.pdf")
- Ysfeicaes\MyE (i.e. "C:\Program Files\My Stuff\PuriypMyE (i.e. npissssssss a yoaData ram E;G", _
- sssss a yoaData ram E;G", _ss syV
-