Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27417

Please help me with my Downloader Project im having error

$
0
0
Hi Good Day everyone

I found a downloader project in this thread http://www.vbforums.com/showthread.p...resume-support and i made some edit but I'm having problem



Here's my Code
Code:

Imports System.IO
Imports System.Text.RegularExpressions
Public Class FormMain
    Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// The DefaultConnectionLimit is 2, which means you can normally only do two
        '// simultaneous downloads. This code allows you to change the limit.
        Net.ServicePointManager.DefaultConnectionLimit = 5
    End Sub
    Private Sub FormMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Dim wClient As DownloadFileAsyncExtended

        For i As Integer = 0 To ListViewEx.Items.Count - 1
            '// Check if the Tag isn't Nothing, because else the download has already
            '// finished or an error occurred, so it can't be cancelled.
            If ListViewEx.Items(i).Tag IsNot Nothing Then
                '// Get the DownloadFileAsyncExtended class instance from the ListViewItem Tag.
                wClient = DirectCast(ListViewEx.Items(i).Tag, DownloadFileAsyncExtended)
                '// Cancel the download if it's still busy.
                wClient.CancelAsync()
            End If
        Next
    End Sub
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub
    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MessageBox.Show("iDevice Firmware Downloader: Developed by khimwel", "iDL", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
    Private Sub btnAddNewDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewDownload.Click
        Dim strURL As String
        Dim strFileName As String
        Dim strSavePath As String
        strURL = ListBox2.Text.Trim
        strFileName = ListBox2.Text.Trim
        strSavePath = TextBrowse.Text.Trim
        '// Start the download.
        ListViewEx.StartDownload(strURL, Path.Combine(strSavePath, strFileName))
    End Sub
    Private Sub ListViewEx_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim objDrawingPoint As Point
        Dim objListViewItem As ListViewItem

        objDrawingPoint = ListViewEx.PointToClient(Cursor.Position)

        '// Check to see if an item has been selected.
        If Not IsNothing(objDrawingPoint) Then
            With objDrawingPoint
                objListViewItem = ListViewEx.GetItemAt(.X, .Y)
            End With

            '// If an item has been selected, then enable toolstrip buttons.
            If Not IsNothing(objListViewItem) Then
                btnResume.Enabled = True
                btnPause.Enabled = True
                btnRemove.Enabled = True
            Else '// Else disable them.
                btnResume.Enabled = False
                btnPause.Enabled = False
                btnRemove.Enabled = False
            End If
        End If
    End Sub

    Private Sub btnResume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResume.Click
        Dim wClient As DownloadFileAsyncExtended
        For i As Integer = 0 To ListViewEx.SelectedItems.Count - 1
            If ListViewEx.SelectedItems(i).Tag IsNot Nothing Then
                wClient = DirectCast(ListViewEx.SelectedItems(i).Tag, DownloadFileAsyncExtended)
                '// Make sure you check if the download is not
                '// already busy or an exception will be thrown.
                If wClient.IsBusy = False Then
                    wClient.ResumeAsync()
                End If
            End If
        Next
    End Sub
    Private Sub btnResumeAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResumeAll.Click
        Dim wClient As DownloadFileAsyncExtended

        For i As Integer = 0 To ListViewEx.Items.Count - 1
            If ListViewEx.Items(i).Tag IsNot Nothing Then
                wClient = DirectCast(ListViewEx.Items(i).Tag, DownloadFileAsyncExtended)
                '// Make sure you check if the download is not
                '// already busy or an exception will be thrown.
                If wClient.IsBusy = False Then
                    wClient.ResumeAsync()
                End If
            End If
        Next
    End Sub
    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Dim wClient As DownloadFileAsyncExtended

        For i As Integer = 0 To ListViewEx.SelectedItems.Count - 1
            If ListViewEx.SelectedItems(i).Tag IsNot Nothing Then
                wClient = DirectCast(ListViewEx.SelectedItems(i).Tag, DownloadFileAsyncExtended)
                '// Pause the download.
                wClient.CancelAsync()
            End If
        Next
    End Sub
    Private Sub btnPauseAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPauseAll.Click
        Dim wClient As DownloadFileAsyncExtended

        For i As Integer = 0 To ListViewEx.Items.Count - 1
            If ListViewEx.Items(i).Tag IsNot Nothing Then
                wClient = DirectCast(ListViewEx.Items(i).Tag, DownloadFileAsyncExtended)
                '// Pause the download.
                wClient.CancelAsync()
            End If
        Next
    End Sub
    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        Dim wClient As DownloadFileAsyncExtended

        '// Always loop backwards when removing items from the list,
        '// because the index gets updated when an item is removed.
        '// This can result in certain items not getting removed.
        For i As Integer = ListViewEx.SelectedItems.Count - 1 To 0 Step -1
            If ListViewEx.SelectedItems(i).Tag IsNot Nothing Then
                '// Get the DownloadFileAsyncExtended class instance from the ListViewItem Tag.
                wClient = DirectCast(ListViewEx.SelectedItems(i).Tag, DownloadFileAsyncExtended)
                '// Pause (cancel) the download and remove it from the list.
                wClient.CancelAsync()
                ListViewEx.SelectedItems(i).Tag = Nothing
                ListViewEx.SelectedItems(i).Remove()
            Else
                '// There's nothing to cancel, because the
                '// download has finished or caused an error.
                '// Just remove the item from the list.
                ListViewEx.SelectedItems(i).Remove()
            End If
        Next
    End Sub
    Private Sub btnRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveAll.Click
        Dim wClient As DownloadFileAsyncExtended

        '// Always loop backwards when removing items from the list,
        '// because the index gets updated when an item is removed.
        '// This can result in certain items not getting removed.
        For i As Integer = ListViewEx.Items.Count - 1 To 0 Step -1
            If ListViewEx.Items(i).Tag IsNot Nothing Then
                '// Get the DownloadFileAsyncExtended class instance from the ListViewItem Tag.
                wClient = DirectCast(ListViewEx.Items(i).Tag, DownloadFileAsyncExtended)
                '// Pause (cancel) the download and remove it from the list.
                wClient.CancelAsync()
                ListViewEx.Items(i).Tag = Nothing
                ListViewEx.Items(i).Remove()
            Else
                '// There's nothing to cancel, because the
                '// download has finished or caused an error.
                '// Just remove the item from the list.
                ListViewEx.Items(i).Remove()
            End If
        Next
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
 Dim u As New List(Of UrlItem)
        If ListBox1.Text = "iPhone 5 Global" Then
            ListBox2.Items.Clear()
            u.Add(New UrlItem("iPhone5,2_6.1.4_10B350_Restore.ipsw", "http://appldnld.apple.com/iOS6.1/091-3423.20130502.Tr3Lz/iPhone5,2_6.1.4_10B350_Restore.ipsw"))
          ListBox2.DisplayMember = "Name"
            ListBox2.ValueMember = "Url"
            ListBox2.DataSource = u
        End If
    End Sub
    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseaa.Click
        '// Select a new download folder
        FBDialog.Description = "Select download folder:"
        FBDialog.ShowDialog()
        If FBDialog.SelectedPath <> String.Empty Then
            TextBrowse.Text = FBDialog.SelectedPath & If(FBDialog.SelectedPath.EndsWith("\"), "", "\")
        End If
    End Sub
    Private Sub ListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox3.SelectedIndexChanged
        If ListBox3.Text = "iPhone" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("iPhone 5 Global")
            ListBox1.Items.Add("iPhone 5 Gsm")
            ListBox1.Items.Add("iPhone 4s ")
            ListBox1.Items.Add("iPhone 4 CDMA")
            ListBox1.Items.Add("iPhone 4 New Model")
            ListBox1.Items.Add("iPhone 4 Gsm")
            ListBox1.Items.Add("iPhone 3Gs")
            ListBox1.Items.Add("iPhone 3G")
            ListBox1.Items.Add("iPhone")
        ElseIf ListBox3.Text = "iPad" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("iPad 4 Global")
            ListBox1.Items.Add("iPad 4 Gsm")
            ListBox1.Items.Add("iPad 4 Wi-Fi")
            ListBox1.Items.Add("iPad 3 Global")
            ListBox1.Items.Add("iPad 3 CDMA")
            ListBox1.Items.Add("iPad 3 Wi-Fi")
            ListBox1.Items.Add("iPad 2 Wi-Fi Rev A")
            ListBox1.Items.Add("iPad 2 CDMA")
            ListBox1.Items.Add("iPad 2 Gsm")
            ListBox1.Items.Add("iPad 2 Wi-Fi")
            ListBox1.Items.Add("iPad")
            ListBox1.Items.Add("iPad Mini Global")
            ListBox1.Items.Add("iPad Mini Gsm")
            ListBox1.Items.Add("iPad Mini Wifi")
        End If
    End Sub
    Private Function ExtractFileNameFromURL(ByVal URL As String) As String
        Try
            Dim FixedURL As String = Regex.Replace(URL.Substring(URL.LastIndexOf("/") + 1), "[^a-zA-Z0-9!@$%^&*()_+=[\]{}';,.-]", String.Empty)
            Return FixedURL
        Catch ex As Exception
            Return String.Empty
        End Try
    End Function
    Private Sub FormAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// Set initial download folder to the 'Application StartupPath' folder
        TextBrowse.Text = Application.StartupPath & If(Application.StartupPath.EndsWith("\"), "", "\")
        '// See if there's an URL loaded in the clipboard and show it.
        If Clipboard.ContainsText = False Then Return
        Try
            Dim fileUri As New Uri(Clipboard.GetText)
            If fileUri.Scheme = Uri.UriSchemeHttp Or fileUri.Scheme = Uri.UriSchemeHttps Then
                ListBox2.Text = Clipboard.GetText
                ListBox2.Text = ExtractFileNameFromURL(Clipboard.GetText)
            End If
        Catch
        End Try
    End Sub
End Class
Public Class UrlItem
    Private n As String
    Private u As String

    Property Name() As String
        Get
            Name = n
        End Get
        Set(ByVal value As String)
            n = value
        End Set
    End Property

    Property Url() As String
        Get
            Url = u
        End Get
        Set(ByVal value As String)
            u = value
        End Set
    End Property

    Sub New(ByVal Name As String, ByVal Url As String)
        n = Name
        u = Url
    End Sub

End Class


Heres my project


http://www.4shared.com/zip/tVGXtQiV/SampleProject.html
Attached Images
  

Viewing all articles
Browse latest Browse all 27417

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>