x BoooM x (26.08.2012)
Thema: [HowTo] Update-Funktion
-
21.08.2012, 11:36 #1
[HowTo] Update-Funktion
Hallo,
da vorher jemand gefragt hat wie man in VB.Net am besten einen Updater realisiert, habe
ich mich dazu entschlossen ein kleine Funktion dafür zu schreiben.
Funktionsweise:
Ihr habt 2 .txt's auf einem Webspace. Eine mit der aktuellen Version(text) und eine mit der
URL wo man die aktuellste Version downloaden kann.
z.B.
version.txt
Inhalt: 1.0.0
path.txt
Inhalt: http://deineUrl.de/new.exe/
Im Source müsst ihr das natürlich
auf die Variable 'version' anpassen. Falls eine neue Version verfügbar ist, wird man
gefragt ob man sie downloaden will. Wenn ja, wird ein Dialog geöffnet um den Pfad
auszusuchen und die neue Version wird heruntergeladen.
Folgende Variablen werden benötigt:
PHP-Code:Dim ofd As New FolderBrowserDialog
Dim urlVersion As String = "http://127.0.0.1/version.txt"
Dim urlPath As String = "http://127.0.0.1/path.txt"
Dim version As String = "0.0.1"
Dim nPath As String = String.Empty
Dim nVersion As String = String.Empty
Dim WithEvents wc As New WebClient
PHP-Code:Private Sub checkForUpdate()
Try
nPath = wc.DownloadString(urlPath)
nVersion = wc.DownloadString(urlVersion)
Catch ex As Exception
MessageBox.Show("Keine Verbindung!")
Exit Sub
End Try
If Not nVersion = version Then
Dim r As MsgBoxResult = MsgBox("Eine neue Version ist verfügbar! Downloaden?", MsgBoxStyle.YesNo)
If r = MsgBoxResult.Yes Then
ofd.ShowDialog()
Try
wc.DownloadFileAsync(New Uri(nPath), ofd.SelectedPath + "\Updater" & nVersion & ".exe")
Catch ex As Exception
MessageBox.Show("Keine Verbindung!")
End Try
End If
Else
MessageBox.Show("Kein Update verfügbar!")
End If
End Sub
PHP-Code:Private Sub w_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles wc.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
PHP-Code:checkForUpdate()
Bei Fragen fragen!
MfGGeändert von exception (21.08.2012 um 13:22 Uhr)
-
The Following User Says Thank You to exception For This Useful Post:
-
21.08.2012, 13:17 #2
AW: [HowTo] Update-Funktion
>>> Visual Basic .NET programming for Beginners - Try ... Catch
Wenn deine Seite mal nicht erreichbar ist schmiert das Programm ab.
-
21.08.2012, 13:22 #3
-
21.08.2012, 13:29 #4
AW: [HowTo] Update-Funktion
Habe mal meine Verbindung getrennt und bin dann auf Aktuallisierung, eine MessageBox mit "Keine Verbindung" erscheint nicht, schmiert trotzdem ab.
-
21.08.2012, 13:43 #5
AW: [HowTo] Update-Funktion
Habe schon lange VB.Net nicht mehr angepackt aber ich finde es so schöner: (mit Sicherheit Fehler drin)
PHP-Code:Dim downloadlink as String = "http://blu.bb/latest.rar"
Private Function checkForUpdate()
Dim version as String = "0.1"
Dim wc as new System.Net.Webclient
Dim checklink as String = "http://blu.bb/version.txt"
Dim update as boolean = false
Try
dim newVersion as string = wc.DownloadString(checklink)
Catch ex as Exeption
return false
End Try
if newVersion = 0.2 Then
return true
else
return false
end if
End Function
if checkForUpdate = true Then
DOWNLOAD!
end if
-
21.08.2012, 13:50 #6
-
21.08.2012, 14:02 #7
AW: [HowTo] Update-Funktion
Ich finde es sinnvoller die URL zum Download hardzucoden(gibt's das Wort? ), so spart man sich eine Abfrage
-
21.08.2012, 14:05 #8
AW: [HowTo] Update-Funktion
Geändert von exception (21.08.2012 um 14:07 Uhr)
-
21.08.2012, 14:05 #9
AW: [HowTo] Update-Funktion
Siehe mein Code:
Dim downloadlink as String = "http://blu.bb/latest.rar"
-
21.08.2012, 14:57 #10
-
The Following User Says Thank You to Diebspiel For This Useful Post:
Dbzfreak1337 (21.08.2012)
Ähnliche Themen
-
Matheaufgabe mit e - Funktion
Von !lkay im Forum BildungAntworten: 4Letzter Beitrag: 22.01.2014, 00:32 -
einfache diffen Funktion
Von yamyam87 im Forum Knuddels ProgrammierungAntworten: 2Letzter Beitrag: 25.12.2012, 17:57 -
Funktion mit 3 Parabelpunkten angeben
Von !lkay im Forum BildungAntworten: 3Letzter Beitrag: 18.09.2012, 20:18 -
Neue Funktion - NextDate!
Von Waterpolo im Forum Knuddels-NewsAntworten: 17Letzter Beitrag: 05.06.2012, 17:05 -
Geheime Funktion zum Erkennen von IPs?
Von FranzJoseph im Forum Fragen & ProblemeAntworten: 2Letzter Beitrag: 10.12.2011, 07:08
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.