14/07/09 7:46
GoLDBeRG
Public ferma As Int32 Public start As Int32 Public url As Uri Public num As Int16 Public Sub scarica() Dim str As Stream = File.OpenWrite("Part" & num & ".part") impo.arrfile.Add("Part" & num & ".part") Dim request As HttpWebRequest = WebRequest.Create(url) request.AddRange(start, ferma) Dim response As HttpWebResponse = request.GetResponse Dim stream As Stream = response.GetResponseStream While (True) If impo.download = False Then Exit While End If Dim by(8192) As Byte Dim int As Integer = stream.Read(by, 0, by.Length) impo.quanti += int impo.totali += int Str.Write(by, 0, by.Length) Thread.Sleep(10) If int = 0 Then Exit While End If End While str.Close() End Sub End Class
allora con questo codice scarico la singola parte di un file quindi creo il conseguente file .part numerato... quindi so come sono i file in sequenza..... poi devo ricostruire il maledetto file quindi ho questa procedura.....
Public Sub creafile() While (True) Thread.Sleep(1000) If impo.download = False Then Exit Sub End If If impo.completato Then impo.completato = False Dim stre As Stream = File.OpenWrite("Download") For Each asd As String In impo.arrfile Me.Invoke(param, "Creazione del file... " & asd) Dim cosa() As Byte = File.ReadAllBytes(asd) stre.Write(cosa, 0, cosa.Length) Next stre.Close() Exit While End If End While impo.download = False Me.Invoke(param2) End Sub
la procedura resta in circolo finche o il download non è annullato o finche non completo tutti i download.... voi penserete.... non è detto che il file part0 sia stato creato prima del file part1... e invece si quindi non è quello il problema.... il problema o sta nella ricostruzione.... o in questa altra procedura dove do i parametri di addrange ai singoli download....
Public Sub vedi() impo.download = True Dim wc As New WebClient Dim b1() As Byte = wc.Encoding.GetBytes("GET " & url & " HTTP/1.1" & vbNewLine & vbNewLine) wc.OpenWrite(min).Write(b1, 0, b1.Length) wc.OpenRead(url) For Each asd As String In wc.ResponseHeaders If IsNumeric(wc.ResponseHeaders.Item(asd)) Then filegen = wc.ResponseHeaders.Item(asd) End If Next Dim conto As Int16 = 5 While ((filegen Mod conto) <> 0) conto += 1 End While Dim parte As Long = filegen / conto For a As Integer = 0 To conto - 1 Dim f As New conn f.start = parte * a f.num = a f.ferma = f.start + parte - 1 f.url = New Uri(url) Dim g As New Thread(AddressOf f.scarica) g.Start() Thread.Sleep(50) Next Dim thr As New Thread(AddressOf creafile) thr.Start() End Sub
scervellatevi assieme a me
aaa