home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD13434152001.psc / frmDownload.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  2001-01-05  |  8.5 KB  |  236 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
  4. Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
  5. Begin VB.Form frmDownload 
  6.    BorderStyle     =   3  'Fixed Dialog
  7.    ClientHeight    =   3540
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   5520
  11.    FontTransparent =   0   'False
  12.    HasDC           =   0   'False
  13.    Icon            =   "frmDownload.frx":0000
  14.    KeyPreview      =   -1  'True
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    ScaleHeight     =   3540
  18.    ScaleWidth      =   5520
  19.    Begin InetCtlsObjects.Inet Inet1 
  20.       Left            =   0
  21.       Top             =   2880
  22.       _ExtentX        =   1005
  23.       _ExtentY        =   1005
  24.       _Version        =   393216
  25.    End
  26.    Begin MSComctlLib.ProgressBar ProgressBar 
  27.       Height          =   225
  28.       Left            =   120
  29.       TabIndex        =   4
  30.       Top             =   1485
  31.       Width           =   5235
  32.       _ExtentX        =   9234
  33.       _ExtentY        =   397
  34.       _Version        =   393216
  35.       Appearance      =   1
  36.    End
  37.    Begin MSComCtl2.Animation Animation1 
  38.       Height          =   615
  39.       Left            =   120
  40.       TabIndex        =   3
  41.       TabStop         =   0   'False
  42.       Top             =   0
  43.       Width           =   4695
  44.       _ExtentX        =   8281
  45.       _ExtentY        =   1085
  46.       _Version        =   393216
  47.       FullWidth       =   313
  48.       FullHeight      =   41
  49.    End
  50.    Begin VB.CommandButton CancelButton 
  51.       Cancel          =   -1  'True
  52.       Caption         =   "Cancel"
  53.       CausesValidation=   0   'False
  54.       Default         =   -1  'True
  55.       Height          =   375
  56.       Left            =   2197
  57.       TabIndex        =   0
  58.       Top             =   3050
  59.       Width           =   1215
  60.    End
  61.    Begin VB.Label RateLabel 
  62.       Caption         =   "RateLabel"
  63.       Height          =   255
  64.       Left            =   1560
  65.       TabIndex        =   10
  66.       Top             =   2400
  67.       Width           =   3765
  68.    End
  69.    Begin VB.Label TransferRate 
  70.       Caption         =   "Transfer rate:"
  71.       Height          =   255
  72.       Left            =   120
  73.       TabIndex        =   9
  74.       Top             =   2400
  75.       Width           =   1575
  76.    End
  77.    Begin VB.Label ToLabel 
  78.       Caption         =   "ToLabel"
  79.       Height          =   195
  80.       Left            =   1560
  81.       TabIndex        =   8
  82.       Top             =   2100
  83.       Width           =   3765
  84.    End
  85.    Begin VB.Label DownloadTo 
  86.       Caption         =   "Download to:"
  87.       Height          =   255
  88.       Left            =   120
  89.       TabIndex        =   7
  90.       Top             =   2100
  91.       Width           =   1575
  92.    End
  93.    Begin VB.Label TimeLabel 
  94.       Caption         =   "TimeLabel"
  95.       Height          =   255
  96.       Left            =   1560
  97.       TabIndex        =   6
  98.       Top             =   1800
  99.       Width           =   3765
  100.    End
  101.    Begin VB.Label SourceLabel 
  102.       Caption         =   "SourceLabel"
  103.       Height          =   195
  104.       Left            =   120
  105.       TabIndex        =   5
  106.       Top             =   1200
  107.       Width           =   5250
  108.    End
  109.    Begin VB.Label EstimatedTimeLeft 
  110.       Caption         =   "Estimated time left:"
  111.       Height          =   255
  112.       Left            =   120
  113.       TabIndex        =   2
  114.       Top             =   1800
  115.       Width           =   1455
  116.    End
  117.    Begin VB.Label StatusLabel 
  118.       Caption         =   "StatusLabel"
  119.       Height          =   195
  120.       Left            =   120
  121.       TabIndex        =   1
  122.       Top             =   915
  123.       Width           =   5235
  124.    End
  125. Attribute VB_Name = "frmDownload"
  126. Attribute VB_GlobalNameSpace = False
  127. Attribute VB_Creatable = False
  128. Attribute VB_PredeclaredId = True
  129. Attribute VB_Exposed = False
  130. Private CancelSearch As Boolean
  131. Public Function DownloadFile(strURL As String, _
  132.                              strDestination As String, _
  133.                              Optional UserName As String = Empty, _
  134.                              Optional Password As String = Empty) _
  135.                              As Boolean
  136. ' Funtion DownloadFile: Download a file via HTTP
  137. ' Author:   Jeff Cockayne
  138. ' Inputs:   strURL String; the source URL of the file
  139. '           strDestination; valid Win95/NT path to where you want it
  140. '           (i.e. "C:\Program Files\My Stuff\Purina.pdf")
  141. ' Returns:  Boolean; Was the download successful?
  142. Const CHUNK_SIZE As Long = 1024 ' Download chunk size
  143. Const ROLLBACK As Long = 4096   ' Bytes to roll back on resume
  144.                                 ' You can be less conservative,
  145.                                 ' and roll back less, but I
  146.                                 ' don't recommend it.
  147. Dim bData() As Byte             ' Data var
  148. Dim blnResume As Boolean        ' True if resuming download
  149. Dim intFile As Integer          ' FreeFile var
  150. Dim lngBytesReceived As Long    ' Bytes received so far
  151. Dim lngFileLength As Long       ' Total length of file in bytes
  152. Dim lngX                        ' Temp long var
  153. Dim sglLastTime As Single          ' Time last chunk received
  154. Dim sglRate As Single           ' Var to hold transfer rate
  155. Dim sglTime As Single           ' Var to hold time remaining
  156. Dim strFile As String           ' Temp filename var
  157. Dim strHeader As String         ' HTTP header store
  158. Dim strHost As String           ' HTTP Host
  159. On Local Error GoTo InternetErrorHandler
  160. ' Start with Cancel flag = False
  161. CancelSearch = False
  162. ' Get just filename (without dirs) for display
  163. strFile = ReturnFileOrFolder(strDestination, True)
  164. strHost = ReturnFileOrFolder(strURL, True, True)
  165.               
  166. SourceLabel = Empty
  167. TimeLabel = Empty
  168. ToLabel = Empty
  169. RateLabel = Empty
  170. ' Pre-open the AVI
  171. With Animation1
  172.     .AutoPlay = True
  173.     .Open App.Path & "\DOWNLD2.AVI"
  174. End With
  175. ' Show the download status form
  176. ' Move form into view
  177. Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
  178. StartDownload:
  179. If blnResume Then
  180.     StatusLabel = "Resuming download..."
  181.     lngBytesReceived = lngBytesReceived - ROLLBACK
  182.     If lngBytesReceived < 0 Then lngBytesReceived = 0
  183.     StatusLabel = "Getting file information..."
  184. End If
  185. ' Give the system time to update the form gracefully
  186. DoEvents
  187. ' Download file
  188. With Inet1
  189.     .URL = strURL
  190.     .UserName = UserName
  191.     .Password = Password
  192.     ' GET file, sending the magic resume input header...
  193.     .Execute , "GET", , "Range: bytes=" & CStr(lngBytesReceived) & "-" & vbCrLf
  194.     ' While initiating connection, yield CPU to Windows
  195.     While .StillExecuting
  196.         DoEvents
  197.         ' If user pressed Cancel button on StatusForm
  198.         ' then fail, cancel, and exit this download
  199.         If CancelSearch Then GoTo ExitDownload
  200.     Wend
  201.     StatusLabel = "Saving:"
  202.     SourceLabel = FitText(SourceLabel, strHost & " from " & .RemoteHost)
  203.     ToLabel = FitText(ToLabel, strDestination)
  204.     ' Get first header ("HTTP/X.X XXX ...")
  205.     strHeader = .GetHeader
  206. End With
  207. ' Trap common HTTP response codes
  208. Select Case Mid(strHeader, 10, 3)
  209.     Case "200"  ' OK
  210.         ' If resuming, however, this is a failure
  211.         If blnResume Then
  212.             ' Delete partially downloaded file
  213.             Kill strDestination
  214.             ' Prompt
  215.             If MsgBox("The server is unable to resume this download." & _
  216.                       vbCr & vbCr & _
  217.                       "Do you want to continue anyway?", _
  218.                       vbExclamation + vbYesNo, _
  219.                       "Unable to Resume Download") = vbYes Then
  220.                     ' Yes - continue anyway:
  221.                     ' Set resume flag to False
  222.                     blnResume = False
  223.                 Else
  224.                     ' No - cancel
  225.                     CancelSearch = FC-0000F8754 No - cancedownlu.UlateLNo, _
  226.  vbYes ThenSApg3 server is OamMd") = vbYes Then
  227. t reeceiver"a\s Then
  228.     lset Theur             "Do you 1oweUsDonti      BytesRecl      vbb0) = vbYes EWbYesc Then
  229.  baderueicaYes Ther
  230.     CarnSApg3 aYes ssword As r.a you     Heaa
  231. En=   e   
  232. 'ownyaaswor        ecnIrRecl      vbb0) = vbYes EWbYesc Then
  233. '           (i.e. "C:\Program Files\My Stuff\Purina.pdf")
  234. Ysfeicaes\MyE   (i.e. "C:\Program Files\My Stuff\PuriypMyE   (i.e.  npissssssss    a yoaData ram E;G", _
  235.  sssss    a yoaData ram E;G", _ss  syV    
  236.