Results 1 to 12 of 12

Thread: Another Auto-Downloader

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Another Auto-Downloader

    K, first off most of this IS NOT my code. I modified it so that it was an auto-updater instead of just a downloader. Ive fixed numerous bugs and stuff...All you need is an inet1, listbox called lststat, label called lblstatus,command button called cmdcancel

    VB Code:
    1. -------------------------------------------------
    2.  
    3. Private m_GettingFileSize     As Boolean
    4. Private m_DownloadingFile     As Boolean
    5. Private m_DownloadingFileSize As Long
    6. Private m_LocalSaveFile       As String
    7. Private m_FileSize As String
    8. Private FirstResponse As Boolean
    9. Dim ff As Integer
    10. Dim exe As String
    11. dim filesize as string
    12.  
    13. Private Sub cmdCancel_Click()
    14. 'On Error Resume Next
    15. Inet1.Cancel
    16.     Unload Me
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. filesize = # ' Okay this is how i do it, make filesize a number, compile your program and upload it. Then see how big it is on the ftp.  Type the number in the filesize re-compile and upload. Then it will have the correct filesize.
    21. If App.PrevInstance Then
    22. End
    23. End If
    24.  
    25. Dim RemoteFileToGet As String
    26. 'Name of the updated exe
    27. RemoteFileToGet = "www.bazooka.com" 'THIS IS THE DOWNLOAD
    28.  
    29. FirstResponse = False
    30. m_FileSize = GetHTTPFileSize(RemoteFileToGet)
    31. lstStat.AddItem "Establishing file size & location..."
    32. lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 ' \/
    33. If Int(m_FileSize) \ 1024 <> filesize Then  'shows in kb instead of other stuff
    34. MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
    35. m_LocalSaveFile = App.Path & "\rarfile or zip.rar"
    36. Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\name of .exe" & Chr(34)
    37. Else
    38. MsgBox "Your exe is updated as can be :) "
    39. lstStat.AddItem "Done."
    40. lblStatus.Caption = "0/0"
    41. End If
    42. End Sub
    43.  
    44. Private Function GetHTTPFileSize(strHTTPFile As String) As Long
    45. On Error GoTo ErrorHandler
    46.     Dim GetValue As String
    47.     Dim GetSize  As Long
    48.    
    49.     m_GettingFileSize = True
    50.    
    51.     Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
    52.  
    53.     Do Until Inet1.StillExecuting = False
    54.         DoEvents
    55.     Loop
    56.  
    57.     GetValue = Inet1.GetHeader("Content-length")
    58.    
    59.     Do Until Inet1.StillExecuting = False
    60.         DoEvents
    61.     Loop
    62.    
    63.     If IsNumeric(GetValue) = True Then
    64.         GetSize = CLng(GetValue)
    65.     Else
    66.         GetSize = -1
    67.     End If
    68.  
    69.     If GetSize <= 0 Then GetSize = -1
    70.  
    71.     m_GettingFileSize = False
    72.     GetHTTPFileSize = GetSize
    73. Exit Function
    74.  
    75. ErrorHandler:
    76.     m_GettingFileSize = False
    77.     GetHTTPFileSize = -1
    78.    ' MsgBox err.Number & err.Description
    79. End Function
    80.  
    81. Private Sub Inet1_StateChanged(ByVal State As Integer)
    82.  
    83. Dim vtData()  As Byte
    84. Dim FreeNr    As Integer
    85. Dim SizeDone  As Long
    86. Dim bDone     As Boolean
    87. Dim GetPerc   As Integer
    88.  
    89. Select Case State
    90.    
    91.      Case 1
    92.         lstStat.AddItem "Trying to find file..."
    93.     Case 2
    94.         lstStat.AddItem "File found"
    95.     Case 3
    96.         lstStat.AddItem "Asking for approval..."
    97.     Case 4
    98.         lstStat.AddItem "Accepted"
    99.     Case 5
    100.         lstStat.AddItem "Requesting file..."
    101.     Case 6
    102.         lstStat.AddItem "Request sent"
    103.     Case 7
    104.     If FirstResponse = False Then
    105.         lstStat.AddItem "Receiving response..."
    106.         FirstResponse = True
    107.         End If
    108.        
    109.     Case 8
    110.     If FirstResponse = False Then
    111.         lstStat.AddItem "Response received"
    112.         FirstResponse = True
    113.         End If
    114.        
    115.     Case 9
    116.         lstStat.AddItem "Disconnecting..."
    117.     Case 10
    118.         lstStat.AddItem "Disconnected"
    119.    
    120.     Case 11
    121.         lstStat.AddItem "Error downloading file"
    122.         Call cmdCancel_Click
    123.  
    124.     Case 12
    125.    
    126.     If m_GettingFileSize = True Then
    127.     Exit Sub
    128.     End If
    129.    
    130.     FreeNr = FreeFile
    131.    
    132.     Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr
    133.                
    134.     'this shows the status in real time
    135.     'kinda fancy
    136.    
    137.                 Do While Not bDone
    138.                     vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
    139.                    
    140.                     SizeDone = SizeDone + UBound(vtData)
    141.                    
    142.                     lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb" 'lets it be shown in kb instead of bytes
    143.                    
    144.                     GetPerc = (SizeDone / m_FileSize) * 100
    145.                     If GetPerc > 100 Then GetPerc = 100
    146.                     If GetPerc < 0 Then GetPerc = 0
    147.                    
    148.                     Me.Caption = "AutoUpdater - " & GetPerc & "%"
    149.                                        
    150.                     Put #FreeNr, , vtData()           'chunk wegschrijven naar bestand
    151.                     If UBound(vtData) = -1 Then
    152.                         bDone = True  'Er zijn geen chunks meer, KLAAR DUS
    153.                     Else
    154.                         DoEvents      'Yield to other processes
    155.                     End If
    156.                 Loop
    157.                
    158.                 Close FreeNr
    159.    
    160. End Select
    161. lstStat.ListIndex = lstStat.ListCount - 1
    162.  
    163. If GetPerc = 100 Then
    164. Call cmdCancel_Click
    165. End If
    166.  
    167. '    If Len(err.Description) & Len(err.Source) = 0 Then
    168.     'Print vbNullString
    169.    ' Else
    170.     ' MsgBox err.Description & " Source : " & err.Source
    171.     ' End If
    172. End Sub

  2. #2

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Another Auto-Downloader

    ive thought of a 100x better way to do it:

    VB Code:
    1. Private m_GettingFileSize     As Boolean
    2. Private m_DownloadingFile     As Boolean
    3. Private m_DownloadingFileSize As Long
    4. Private m_LocalSaveFile       As String
    5. Private m_FileSize As String
    6. Private FirstResponse As Boolean
    7. Dim ff As Integer
    8. Dim exe As String
    9. Dim filesize As String
    10. Dim x As String
    11.  
    12. Private Sub cmdCancel_Click()
    13. 'On Error Resume Next
    14. Inet1.Cancel
    15.     Unload Me
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19. If Dir$(App.Path & "/version.txt") <> "" Then  'put inside the version your up to
    20.     Open App.Path & "/version.txt" For Input As #ff
    21.     Do Until EOF(ff)
    22.        Line Input #ff, version
    23.     Loop
    24.     Close #ff
    25. Else
    26.     MsgBox "You deleted version.txt!!It is needed!"
    27. End If
    28. If App.PrevInstance Then
    29. End
    30. End If
    31. x = Inet1.OpenURL("website.com/version.txt", icString) ' this should be the same number as version.txt, until you update.  When you update put a new number and include the new version.txt
    32. Dim RemoteFileToGet As String
    33. 'Name of the updated exe
    34. RemoteFileToGet = "www.site.rar" 'THIS IS THE DOWNLOAD
    35. FirstResponse = False
    36. m_FileSize = GetHTTPFileSize(RemoteFileToGet)
    37. lstStat.AddItem "Establishing file size & location..."
    38. lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 'shows whole numbers
    39. If x <> version Then
    40. MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
    41. m_LocalSaveFile = App.Path & "\site.rar" 'whatevr you wanna save the file as
    42. Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\yay.exe" & Chr(34) 'just leave this
    43. Else
    44. MsgBox "Your as updated as can be :) "
    45. lstStat.AddItem "Done."
    46. lblStatus.Caption = "0/0"
    47. End If
    48. 'error1:
    49.   ' If err.Number = 0 Then
    50.        ' MsgBox "Your missing updater.dll and cserver.dll"
    51. 'End If
    52. End Sub
    53.  
    54. Private Function GetHTTPFileSize(strHTTPFile As String) As Long
    55. On Error GoTo ErrorHandler
    56.     Dim GetValue As String
    57.     Dim GetSize  As Long
    58.    
    59.     m_GettingFileSize = True
    60.    
    61.     Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
    62.  
    63.     Do Until Inet1.StillExecuting = False
    64.         DoEvents
    65.     Loop
    66.  
    67.     GetValue = Inet1.GetHeader("Content-length")
    68.    
    69.     Do Until Inet1.StillExecuting = False
    70.         DoEvents
    71.     Loop
    72.    
    73.     If IsNumeric(GetValue) = True Then
    74.         GetSize = CLng(GetValue)
    75.     Else
    76.         GetSize = -1
    77.     End If
    78.  
    79.     If GetSize <= 0 Then GetSize = -1
    80.  
    81.     m_GettingFileSize = False
    82.     GetHTTPFileSize = GetSize
    83. Exit Function
    84.  
    85. ErrorHandler:
    86.     m_GettingFileSize = False
    87.     GetHTTPFileSize = -1
    88.    ' MsgBox err.Number & err.Description
    89. End Function
    90.  
    91. Private Sub Inet1_StateChanged(ByVal State As Integer)
    92. 'On Error g
    93.  
    94. Dim vtData()  As Byte
    95. Dim FreeNr    As Integer
    96. Dim SizeDone  As Long
    97. Dim bDone     As Boolean
    98. Dim GetPerc   As Integer
    99.  
    100. Select Case State
    101.    
    102.      Case 1
    103.         lstStat.AddItem "Trying to find file..."
    104.     Case 2
    105.         lstStat.AddItem "File found"
    106.     Case 3
    107.         lstStat.AddItem "Asking for approval..."
    108.     Case 4
    109.         lstStat.AddItem "Accepted"
    110.     Case 5
    111.         lstStat.AddItem "Requesting file..."
    112.     Case 6
    113.         lstStat.AddItem "Request sent"
    114.     Case 7
    115.     If FirstResponse = False Then
    116.         lstStat.AddItem "Receiving response..."
    117.         FirstResponse = True
    118.         End If
    119.        
    120.     Case 8
    121.     If FirstResponse = False Then
    122.         lstStat.AddItem "Response received"
    123.         FirstResponse = True
    124.         End If
    125.        
    126.     Case 9
    127.         lstStat.AddItem "Disconnecting..."
    128.     Case 10
    129.         lstStat.AddItem "Disconnected"
    130.    
    131.     Case 11
    132.         lstStat.AddItem "Error downloading file"
    133.         Call cmdCancel_Click
    134.  
    135.     Case 12
    136.    
    137.     If m_GettingFileSize = True Then
    138.     Exit Sub
    139.     End If
    140.    
    141.     FreeNr = FreeFile
    142.    
    143.     Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr 'file downloading above
    144.                
    145.     'this shows the status in real time
    146.     'kinda fancy
    147.    
    148.                 Do While Not bDone
    149.                     vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
    150.                    
    151.                     SizeDone = SizeDone + UBound(vtData)
    152.                    
    153.                     lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb"
    154.                    
    155.                     GetPerc = (SizeDone / m_FileSize) * 100
    156.                     If GetPerc > 100 Then GetPerc = 100
    157.                     If GetPerc < 0 Then GetPerc = 0
    158.                    
    159.                     Me.Caption = "AutoUpdater - " & GetPerc & "%"
    160.                                        
    161.                     Put #FreeNr, , vtData()           'chunk wegschrijven naar bestand
    162.                     If UBound(vtData) = -1 Then
    163.                         bDone = True  'Er zijn geen chunks meer, KLAAR DUS
    164.                     Else
    165.                         DoEvents      'Yield to other processes
    166.                     End If
    167.                 Loop
    168.                
    169.                 Close FreeNr
    170.    
    171. End Select
    172. lstStat.ListIndex = lstStat.ListCount - 1
    173.  
    174. If GetPerc = 100 Then
    175. Call cmdCancel_Click
    176. End If
    177.  
    178. '    If Len(err.Description) & Len(err.Source) = 0 Then
    179.     'Print vbNullString
    180.    ' Else
    181.     ' MsgBox err.Description & " Source : " & err.Source
    182.     ' End If
    183. End Sub

  3. #3
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Another Auto-Downloader

    Quote Originally Posted by |2eM!x
    K, first off most of this IS NOT my code. I modified it so that it was an auto-updater instead of just a downloader. Ive fixed numerous bugs and stuff...All you need is an inet1, listbox called lststat, label called lblstatus,command button called cmdcancel

    VB Code:
    1. -------------------------------------------------
    2.  
    3. Private m_GettingFileSize     As Boolean
    4. Private m_DownloadingFile     As Boolean
    5. Private m_DownloadingFileSize As Long
    6. Private m_LocalSaveFile       As String
    7. Private m_FileSize As String
    8. Private FirstResponse As Boolean
    9. Dim ff As Integer
    10. Dim exe As String
    11. dim filesize as string
    12.  
    13. Private Sub cmdCancel_Click()
    14. 'On Error Resume Next
    15. Inet1.Cancel
    16.     Unload Me
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. filesize = # ' Okay this is how i do it, make filesize a number, compile your program and upload it. Then see how big it is on the ftp.  Type the number in the filesize re-compile and upload. Then it will have the correct filesize.
    21. If App.PrevInstance Then
    22. End
    23. End If
    24.  
    25. Dim RemoteFileToGet As String
    26. 'Name of the updated exe
    27. RemoteFileToGet = "www.bazooka.com" 'THIS IS THE DOWNLOAD
    28.  
    29. FirstResponse = False
    30. m_FileSize = GetHTTPFileSize(RemoteFileToGet)
    31. lstStat.AddItem "Establishing file size & location..."
    32. lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 ' \/
    33. If Int(m_FileSize) \ 1024 <> filesize Then  'shows in kb instead of other stuff
    34. MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
    35. m_LocalSaveFile = App.Path & "\rarfile or zip.rar"
    36. Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\name of .exe" & Chr(34)
    37. Else
    38. MsgBox "Your exe is updated as can be :) "
    39. lstStat.AddItem "Done."
    40. lblStatus.Caption = "0/0"
    41. End If
    42. End Sub
    43.  
    44. Private Function GetHTTPFileSize(strHTTPFile As String) As Long
    45. On Error GoTo ErrorHandler
    46.     Dim GetValue As String
    47.     Dim GetSize  As Long
    48.    
    49.     m_GettingFileSize = True
    50.    
    51.     Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
    52.  
    53.     Do Until Inet1.StillExecuting = False
    54.         DoEvents
    55.     Loop
    56.  
    57.     GetValue = Inet1.GetHeader("Content-length")
    58.    
    59.     Do Until Inet1.StillExecuting = False
    60.         DoEvents
    61.     Loop
    62.    
    63.     If IsNumeric(GetValue) = True Then
    64.         GetSize = CLng(GetValue)
    65.     Else
    66.         GetSize = -1
    67.     End If
    68.  
    69.     If GetSize <= 0 Then GetSize = -1
    70.  
    71.     m_GettingFileSize = False
    72.     GetHTTPFileSize = GetSize
    73. Exit Function
    74.  
    75. ErrorHandler:
    76.     m_GettingFileSize = False
    77.     GetHTTPFileSize = -1
    78.    ' MsgBox err.Number & err.Description
    79. End Function
    80.  
    81. Private Sub Inet1_StateChanged(ByVal State As Integer)
    82.  
    83. Dim vtData()  As Byte
    84. Dim FreeNr    As Integer
    85. Dim SizeDone  As Long
    86. Dim bDone     As Boolean
    87. Dim GetPerc   As Integer
    88.  
    89. Select Case State
    90.    
    91.      Case 1
    92.         lstStat.AddItem "Trying to find file..."
    93.     Case 2
    94.         lstStat.AddItem "File found"
    95.     Case 3
    96.         lstStat.AddItem "Asking for approval..."
    97.     Case 4
    98.         lstStat.AddItem "Accepted"
    99.     Case 5
    100.         lstStat.AddItem "Requesting file..."
    101.     Case 6
    102.         lstStat.AddItem "Request sent"
    103.     Case 7
    104.     If FirstResponse = False Then
    105.         lstStat.AddItem "Receiving response..."
    106.         FirstResponse = True
    107.         End If
    108.        
    109.     Case 8
    110.     If FirstResponse = False Then
    111.         lstStat.AddItem "Response received"
    112.         FirstResponse = True
    113.         End If
    114.        
    115.     Case 9
    116.         lstStat.AddItem "Disconnecting..."
    117.     Case 10
    118.         lstStat.AddItem "Disconnected"
    119.    
    120.     Case 11
    121.         lstStat.AddItem "Error downloading file"
    122.         Call cmdCancel_Click
    123.  
    124.     Case 12
    125.    
    126.     If m_GettingFileSize = True Then
    127.     Exit Sub
    128.     End If
    129.    
    130.     FreeNr = FreeFile
    131.    
    132.     Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr
    133.                
    134.     'this shows the status in real time
    135.     'kinda fancy
    136.    
    137.                 Do While Not bDone
    138.                     vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
    139.                    
    140.                     SizeDone = SizeDone + UBound(vtData)
    141.                    
    142.                     lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb" 'lets it be shown in kb instead of bytes
    143.                    
    144.                     GetPerc = (SizeDone / m_FileSize) * 100
    145.                     If GetPerc > 100 Then GetPerc = 100
    146.                     If GetPerc < 0 Then GetPerc = 0
    147.                    
    148.                     Me.Caption = "AutoUpdater - " & GetPerc & "%"
    149.                                        
    150.                     Put #FreeNr, , vtData()           'chunk wegschrijven naar bestand
    151.                     If UBound(vtData) = -1 Then
    152.                         bDone = True  'Er zijn geen chunks meer, KLAAR DUS
    153.                     Else
    154.                         DoEvents      'Yield to other processes
    155.                     End If
    156.                 Loop
    157.                
    158.                 Close FreeNr
    159.    
    160. End Select
    161. lstStat.ListIndex = lstStat.ListCount - 1
    162.  
    163. If GetPerc = 100 Then
    164. Call cmdCancel_Click
    165. End If
    166.  
    167. '    If Len(err.Description) & Len(err.Source) = 0 Then
    168.     'Print vbNullString
    169.    ' Else
    170.     ' MsgBox err.Description & " Source : " & err.Source
    171.     ' End If
    172. End Sub
    Run-time error '6':
    Overflow

    VB Code:
    1. GetPerc = (SizeDone / m_FileSize) * 100

  4. #4
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Another Auto-Downloader

    Quote Originally Posted by |2eM!x
    ive thought of a 100x better way to do it:

    VB Code:
    1. Private m_GettingFileSize     As Boolean
    2. Private m_DownloadingFile     As Boolean
    3. Private m_DownloadingFileSize As Long
    4. Private m_LocalSaveFile       As String
    5. Private m_FileSize As String
    6. Private FirstResponse As Boolean
    7. Dim ff As Integer
    8. Dim exe As String
    9. Dim filesize As String
    10. Dim x As String
    11.  
    12. Private Sub cmdCancel_Click()
    13. 'On Error Resume Next
    14. Inet1.Cancel
    15.     Unload Me
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19. If Dir$(App.Path & "/version.txt") <> "" Then  'put inside the version your up to
    20.     Open App.Path & "/version.txt" For Input As #ff
    21.     Do Until EOF(ff)
    22.        Line Input #ff, version
    23.     Loop
    24.     Close #ff
    25. Else
    26.     MsgBox "You deleted version.txt!!It is needed!"
    27. End If
    28. If App.PrevInstance Then
    29. End
    30. End If
    31. x = Inet1.OpenURL("website.com/version.txt", icString) ' this should be the same number as version.txt, until you update.  When you update put a new number and include the new version.txt
    32. Dim RemoteFileToGet As String
    33. 'Name of the updated exe
    34. RemoteFileToGet = "www.site.rar" 'THIS IS THE DOWNLOAD
    35. FirstResponse = False
    36. m_FileSize = GetHTTPFileSize(RemoteFileToGet)
    37. lstStat.AddItem "Establishing file size & location..."
    38. lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 'shows whole numbers
    39. If x <> version Then
    40. MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
    41. m_LocalSaveFile = App.Path & "\site.rar" 'whatevr you wanna save the file as
    42. Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\yay.exe" & Chr(34) 'just leave this
    43. Else
    44. MsgBox "Your as updated as can be :) "
    45. lstStat.AddItem "Done."
    46. lblStatus.Caption = "0/0"
    47. End If
    48. 'error1:
    49.   ' If err.Number = 0 Then
    50.        ' MsgBox "Your missing updater.dll and cserver.dll"
    51. 'End If
    52. End Sub
    53.  
    54. Private Function GetHTTPFileSize(strHTTPFile As String) As Long
    55. On Error GoTo ErrorHandler
    56.     Dim GetValue As String
    57.     Dim GetSize  As Long
    58.    
    59.     m_GettingFileSize = True
    60.    
    61.     Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
    62.  
    63.     Do Until Inet1.StillExecuting = False
    64.         DoEvents
    65.     Loop
    66.  
    67.     GetValue = Inet1.GetHeader("Content-length")
    68.    
    69.     Do Until Inet1.StillExecuting = False
    70.         DoEvents
    71.     Loop
    72.    
    73.     If IsNumeric(GetValue) = True Then
    74.         GetSize = CLng(GetValue)
    75.     Else
    76.         GetSize = -1
    77.     End If
    78.  
    79.     If GetSize <= 0 Then GetSize = -1
    80.  
    81.     m_GettingFileSize = False
    82.     GetHTTPFileSize = GetSize
    83. Exit Function
    84.  
    85. ErrorHandler:
    86.     m_GettingFileSize = False
    87.     GetHTTPFileSize = -1
    88.    ' MsgBox err.Number & err.Description
    89. End Function
    90.  
    91. Private Sub Inet1_StateChanged(ByVal State As Integer)
    92. 'On Error g
    93.  
    94. Dim vtData()  As Byte
    95. Dim FreeNr    As Integer
    96. Dim SizeDone  As Long
    97. Dim bDone     As Boolean
    98. Dim GetPerc   As Integer
    99.  
    100. Select Case State
    101.    
    102.      Case 1
    103.         lstStat.AddItem "Trying to find file..."
    104.     Case 2
    105.         lstStat.AddItem "File found"
    106.     Case 3
    107.         lstStat.AddItem "Asking for approval..."
    108.     Case 4
    109.         lstStat.AddItem "Accepted"
    110.     Case 5
    111.         lstStat.AddItem "Requesting file..."
    112.     Case 6
    113.         lstStat.AddItem "Request sent"
    114.     Case 7
    115.     If FirstResponse = False Then
    116.         lstStat.AddItem "Receiving response..."
    117.         FirstResponse = True
    118.         End If
    119.        
    120.     Case 8
    121.     If FirstResponse = False Then
    122.         lstStat.AddItem "Response received"
    123.         FirstResponse = True
    124.         End If
    125.        
    126.     Case 9
    127.         lstStat.AddItem "Disconnecting..."
    128.     Case 10
    129.         lstStat.AddItem "Disconnected"
    130.    
    131.     Case 11
    132.         lstStat.AddItem "Error downloading file"
    133.         Call cmdCancel_Click
    134.  
    135.     Case 12
    136.    
    137.     If m_GettingFileSize = True Then
    138.     Exit Sub
    139.     End If
    140.    
    141.     FreeNr = FreeFile
    142.    
    143.     Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr 'file downloading above
    144.                
    145.     'this shows the status in real time
    146.     'kinda fancy
    147.    
    148.                 Do While Not bDone
    149.                     vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
    150.                    
    151.                     SizeDone = SizeDone + UBound(vtData)
    152.                    
    153.                     lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb"
    154.                    
    155.                     GetPerc = (SizeDone / m_FileSize) * 100
    156.                     If GetPerc > 100 Then GetPerc = 100
    157.                     If GetPerc < 0 Then GetPerc = 0
    158.                    
    159.                     Me.Caption = "AutoUpdater - " & GetPerc & "%"
    160.                                        
    161.                     Put #FreeNr, , vtData()           'chunk wegschrijven naar bestand
    162.                     If UBound(vtData) = -1 Then
    163.                         bDone = True  'Er zijn geen chunks meer, KLAAR DUS
    164.                     Else
    165.                         DoEvents      'Yield to other processes
    166.                     End If
    167.                 Loop
    168.                
    169.                 Close FreeNr
    170.    
    171. End Select
    172. lstStat.ListIndex = lstStat.ListCount - 1
    173.  
    174. If GetPerc = 100 Then
    175. Call cmdCancel_Click
    176. End If
    177.  
    178. '    If Len(err.Description) & Len(err.Source) = 0 Then
    179.     'Print vbNullString
    180.    ' Else
    181.     ' MsgBox err.Description & " Source : " & err.Source
    182.     ' End If
    183. End Sub
    Run-time error '52':
    Bad file name or number

    VB Code:
    1. Open App.Path & "\version.txt" For Input As #ff

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Another Auto-Downloader

    and at the request of brailleschool, a multifile downloader..with alot cleaner code
    Attached Files Attached Files

  6. #6
    Lively Member
    Join Date
    May 2005
    Location
    Norway
    Posts
    71

    Re: Another Auto-Downloader

    Will this code execute the file after download?
    Is it a way to get around the filesize being typed?
    How hard is it to add execution of the file after download?

    Thx

  7. #7

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Another Auto-Downloader

    no, but use shell app.path & "\" & filename

    to open after downloading..
    to take out the amount being downloaded is easy...if you look thru the code you will see, if not post back

  8. #8
    Member Birth's Avatar
    Join Date
    Jan 2003
    Location
    Montreal
    Posts
    57

    Re: Another Auto-Downloader

    Hello,

    I'm using pretty much the same code as the in "autod.rar" except that instead of using HTTP I want to use FTP because I need to put the files being downloaded by the users in a private directory with an encrypted password on the server. And of course, I need the Progress Bar.

    The problem is that using FTP, it seems that the GetChunk thing looks pretty much useless. With the UBound(vtData) Function, for example, I get -1 and the file as already been downloaded using the .Execute "GET" Operation in one chunk.

    I've tried everything (I think!), is there any way around this? Can a password be used using HTTP???

    I'm stuck!

    ~~~~~~~~~~~~~~~~~~~~
    There's always something
    ~~~~~~~~~~~~~~~~~~~~
    <Any link censored by moderator>

  9. #9

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Another Auto-Downloader

    Im sorry birth, but i have no clue how to send a password over HTTP. Sorry

  10. #10
    Junior Member
    Join Date
    Jul 2005
    Posts
    28

    Re: Another Auto-Downloader

    This code is almost what I'm looking for, I would like this to display the time taken to download all the files, this way I can test my internet connection, is there a way the time taken can be added to this code please, also a progress bar would be nice

    Chetty

  11. #11

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Another Auto-Downloader

    To get the time taken, just use gettickcount and use it before downloading, and while downloading.

    To use the progressbar, use GetPerc on it

  12. #12
    Junior Member
    Join Date
    Jul 2005
    Posts
    28

    Re: Another Auto-Downloader

    Thanks for the reply but I wish I was clever enough to understand what you are taking about, could you post an example please

    Chetty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width