Hallo,
Ich programmiere einen Launcher für mein Spiel.
Wenn man auf Update klickt lädt er das Spiel herunter und soll es in der Appdata in dem Spiele Ordner speichern. Der Fortschritt wird in einer Progress Bar angezeigt aber nach dem Download kommt 1. nicht die MsgBox "Update erfolgreich" und 2. Die Datei ist nicht im Ordner wo sie eigentlich sein sollte.
kann mir einer bitte helfen?
Quelltext der Launcher Form:
Quelltext der Updater Form:
Ich programmiere einen Launcher für mein Spiel.
Wenn man auf Update klickt lädt er das Spiel herunter und soll es in der Appdata in dem Spiele Ordner speichern. Der Fortschritt wird in einer Progress Bar angezeigt aber nach dem Download kommt 1. nicht die MsgBox "Update erfolgreich" und 2. Die Datei ist nicht im Ordner wo sie eigentlich sein sollte.
kann mir einer bitte helfen?
Quelltext der Launcher Form:
VB.NET-Quellcode
- Public Class Form1
- Private WithEvents downloader As Net.WebClient
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim Pfad As String
- Pfad = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
- Process.Start(Pfad + "\SpielOrdner\SpielName\main.exe")
- Me.Close()
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- PictureBox2.Parent = Me
- PictureBox2.BackColor = Color.Transparent
- End Sub
- Private Sub PictureBox2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
- Application.Exit()
- End Sub
- Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
- Me.WindowState = FormWindowState.Minimized
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Form2.Show()
- Me.Enabled = False
- End Sub
- End Class
Quelltext der Updater Form:
VB.NET-Quellcode
- Imports Ionic.Zip
- Imports System.Net
- Public Class Form2
- Private WithEvents httpclient As WebClient
- Dim Pfad As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
- Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
- Form1.Enabled = True
- End Sub
- Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Try
- Dim Pfad As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
- Dim EndPfad As String = Pfad + "/Spielname/Update/"
- httpclient = New WebClient
- Dim URL As String = "http://Die Seite zum download"
- httpclient.DownloadDataAsync(New Uri(URL), "EndPfad")
- Catch ex As Exception
- MsgBox("Fehler bein Update! Kontkatieren sie Mich über diesen Fehler.", MsgBoxStyle.Critical, "Fehler")
- Me.Close()
- End Try
- End Sub
- Private Sub Installieren_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Installieren.Click
- Using zip As ZipFile = ZipFile.Read(Pfad + "/Spielname/Update/Update.zip")
- Dim Entry As ZipEntry
- For Each Entry In zip
- Entry.Extract(Pfad + "/Spielname/SpielOrdner/", ExtractExistingFileAction.OverwriteSilently)
- Next
- End Using
- End Sub
- Private Sub httpclient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles httpclient.DownloadFileCompleted
- MsgBox("Update Erfolgreich!", MsgBoxStyle.Information, "Erfolgreich!")
- End Sub
- Private Sub httpclient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
- Me.ProgressBar1.Value = e.ProgressPercentage
- Dim totalBites As Double = e.TotalBytesToReceive / 1024
- Dim bytes As Double = e.BytesReceived / 1024
- Me.Label1.Text = bytes & " KB von " & totalBites & " KB"
- End Sub
- End Class