[VB08/10]Updater problem.

12/30/2010 16:12 Headshot94#1
Hi leute also ich hab mit einem neuen Updater Experimentiert das mir der alte nicht mehr gut genug war. mein problem ist nun wenn ich ihn starte sagt er mir das ein 404 fehler vom server her komme hier mal der teil code irgentwas darin macht nen fehler und ich finde ihn nicht.

PHP Code:
    Dim MyVersion As Integer Form12.Label1.Text ' Die aktuelle Version des Programmes
    Dim CurrentVersion As Integer = 2.0 ' 
Die neue Version aus dem Internet
    Dim UpdateFile 
As String 'Falls es ein neues Update gibt wird hier die datei reingeladen
    Dim FileSize As Integer = 388.096
    Dim SFD As New SaveFileDialog
    Dim Sekunden As Integer = 4
    Dim Value As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://downloadwebseite.co.de/version.txt"), HttpWebRequest)
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Dim reader As StreamReader = New StreamReader(response.GetResponseStream(), System.Text.Encoding.Default)
            CurrentVersion = reader.ReadToEnd()
            If Not response Is Nothing Then response.Close()
        Catch
        End Try

        '
Überprüfe ob aktuelle Version neuer ist
        Label1
.Text "Fortschritt: Suche nach Updates"
        
If CurrentVersion MyVersion Then
            
If MsgBox("Es wurde ein Update gefunden!" Chr(13) & _
                      
"Möchten Sie es Runterladen?"MsgBoxStyle.Question MsgBoxStyle.YesNo_
                      
MsgBoxResult.Yes Then
                Label1
.Text "Fortschritt: Lade Update Runter"
                '? Lade Aktuelles Update runter
                Try
                    Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://headshot94.funpic.de/down/Multi%20Tool%20V1.exe" & CurrentVersion.ToString), HttpWebRequest)
                    Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
                    Dim reader As StreamReader = New StreamReader(response.GetResponseStream(), System.Text.Encoding.Default)
                    UpdateFile = reader.ReadToEnd()
                    Label1.Text = "Fortschritt: Update heruntergeladen"
                    If Not response Is Nothing Then response.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try



                '
Legt den Dateinamenfilter des SFD fest
                SFD
.Filter "Ausführbare Dateien(*.exe)|*.exe"

                '? Wenn im Speicherdialog ok geclickt wurde
                If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                    '
erstelle Neuen BinaryWriter
                    Dim BWriter 
As New BinaryWriter(SFD.OpenFileSystem.Text.Encoding.Default)

                    
'? Starte Schleife für das schreiben der datei
                    For i = 0 To FileSize - 1
                        BWriter.Write(UpdateFile.Chars(i))
                        Value += 1 / 100
                    Next
                    '
Schliese den BWriter damit auf die datei zugegriffen werden kann
                    BWriter
.Close()
                
End If
            
End If
            
Label1.Text "Fortschritt: Fertig mit dem Update Schließe Anwendung in 5"
            
Timer1.Start()
        Else
            
Label1.Text "Keine Updates gefunden"
            
MsgBox("Keine Updates gefunden"MsgBoxStyle.Information"Keine Updates verfügbar")
        
End If
    
End Sub 
hoffe ihr könnt mir dabei helfen
12/30/2010 17:08 Secredo#2
Höchstwahrscheinlich ist eine URL falsch eingegeben, da ein 404 Error immer darauf hinweist, dass iwas nicht gefunden wurden.

Noch ein Tipp: Mit einem WebClient (System.Net.WebClient) kannst du Dateien viel einfacher herunterladen. Dort musst du auch nichts in einer Textdatei zwischenspeichern oder ähnliches. ;D

MfG Secredo
12/30/2010 17:49 Demon-777#3
Well try this one out:

Code:
Imports System.Net

Public Class Updater

    Dim WithEvents client As New WebClient()

    Private Sub btnStart_Click(
                ByVal sender As Object,
                ByVal e As System.EventArgs) Handles btnStart.Click

        Dim version = My.Application.Info.Version

        Try
            Dim updated = New Version(
                client.DownloadString("http://downloadwebseite.co.de/version.txt")
            )

            If (updated > version) Then

                Dim result =
                    MessageBox.Show("Es wurde ein Update gefunden!" + Chr(13) + "Möchten Sie es runterladen?", "Update",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question)

                If (result = Windows.Forms.DialogResult.Yes) Then

                    Dim dialog = New SaveFileDialog() With {
                        .Filter = "Ausführbare Dateien (*.exe)|*.exe",
                        .OverwritePrompt = True,
                        .CheckPathExists = True
                    }

                    If (dialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
                        client.DownloadFile(
                            New Uri("http://headshot94.funpic.de/down/Multi%20Tool%20V1.exe"), dialog.FileName)
                    End If

                End If
            Else
                MessageBox.Show(
                    "Es wurden keine Updates gefunden!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        Catch exceptionWeb As WebException
            ' TODO: Handle web exception here.
        End Try

    End Sub

    Private Sub client_DownloadFileCompleted(
                ByVal sender As Object,
                ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles client.DownloadFileCompleted

        ' TODO: Implement downloadcomplete event.

    End Sub

    Private Sub client_DownloadProgressChanged(
                ByVal sender As Object,
                ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles client.DownloadProgressChanged

        ' TODO: Track download status here.

    End Sub

End Class
Don't expect much becouse it was a work of 1 min.
You can handle all download information stuff in webclient events and yeah! it works for me lol :P
12/30/2010 17:55 Headshot94#4
danke für eure hilfe werde den code mal test hoffe das es dann geht.

Noch mal an Secredo
in der text datei ist die version des programms sonst nix.
12/30/2010 19:34 Secredo#5
Entschuldigung, meinte natürlich, dass du es nicht in einem String zwischenspeichern musst, das erledigt der Webclient für dich. ;D