Hallo VBer
Ich habe eine frage, ich habe mir ein kleinen Patcher gemacht, doch der geht recht in die systemleistung rein. kann man das ein wenig verkleinern? der soll ja nur runterladen und nicht grosse funktionen ausführen oder sonst was.
ich erstelle in mit "Optimieren"= JA und NET.Framework 4
hier der code:
Spoiler anzeigen
Und em entschuldigt, ich bin erst seit ca 1 2 wochen wirklich am lernen =)
mfg
Ich habe eine frage, ich habe mir ein kleinen Patcher gemacht, doch der geht recht in die systemleistung rein. kann man das ein wenig verkleinern? der soll ja nur runterladen und nicht grosse funktionen ausführen oder sonst was.
ich erstelle in mit "Optimieren"= JA und NET.Framework 4
hier der code:
VB.NET-Quellcode
- Imports System.IO
- Imports System.Security.Cryptography
- Public Class Form1
- Dim PATCHURL As String = "http://************.ch/refine/patcher_row/"
- Dim PATCHLIST As String = "http://************.ch/refine/patchlist.xml"
- Dim AppPath As String = My.Computer.FileSystem.CurrentDirectory
- Dim WithEvents PatchDownloader As New System.Net.WebClient
- Dim WithEvents PatchListDownloader As New System.Net.WebClient
- Dim DLURLS As New List(Of String)
- Dim ANZAHLDLS As Integer = 0
- Dim busy As Boolean = Nothing
- Public Function MD5FileHash(ByVal sFile As String) As String
- Dim MD5 As New MD5CryptoServiceProvider
- Dim Hash As Byte()
- Dim Result As String = ""
- Dim Tmp As String = ""
- Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
- MD5.ComputeHash(FN)
- FN.Close()
- Hash = MD5.Hash
- For i As Integer = 0 To Hash.Length - 1
- Tmp = Hex(Hash(i))
- If Len(Tmp) = 1 Then Tmp = "0" & Tmp
- Result += Tmp
- Next
- Return Result
- End Function
- Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
- lbl_aktuelledatei.Text = "Starte Patchvorgang.."
- BG_List.RunWorkerAsync()
- End Sub
- Private Sub BG_List_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BG_List.DoWork
- PatchListDownloader.DownloadFileAsync(New Uri(PATCHLIST), AppPath & "\patchlist.xml")
- End Sub
- Private Sub PatchListDownloader_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles PatchListDownloader.DownloadFileCompleted
- lbl_aktuelledatei.Text = "Patchlist herruntergeladen. Starte nun das Patchen."
- PB_AktuDatei.Value = 0
- PB_GSM.Value = 0
- BG_Pacher.RunWorkerAsync()
- End Sub
- Private Sub BG_Pacher_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BG_Pacher.DoWork
- If BG_Pacher.CancellationPending = True Then
- BG_Pacher.CancelAsync()
- End If
- Try
- Dim xDocument As New Xml.XmlDocument
- xDocument.Load(AppPath & "\patchlist.xml")
- lbl_aktuelledatei.Text = "Starte nun das Patchen"
- For Each node As Xml.XmlNode In xDocument.SelectNodes("Dateien/Datei")
- Dim DateiPfad As String = AppPath & "\" & node.Attributes("Dateiname").InnerText
- Dim CheckSum As String = node.Attributes("Checksum").InnerText
- Dim check As Boolean = Nothing
- lbl_aktuelledatei.Text = "Prüfe : " & node.Attributes("Dateiname").InnerText
- If File.Exists(DateiPfad) = False Then
- DLURLS.Add(PATCHURL & node.Attributes("Dateiname").InnerText.Replace("\", "/"))
- Else
- If CheckSum = MD5FileHash(DateiPfad) Then
- check = True
- Else
- DLURLS.Add(PATCHURL & node.Attributes("Dateiname").InnerText.Replace("\", "/"))
- check = False
- End If
- End If
- Next
- ANZAHLDLS = DLURLS.Count
- PB_GSM.Maximum = ANZAHLDLS
- PB_GSM.Value = 0
- Catch ex As Exception
- End Try
- Do
- Try
- If PatchDownloader.IsBusy = True Then
- busy = True
- Else
- For Each DownloadDatei In DLURLS
- If IsNothing(DownloadDatei) Then Exit Do
- Do
- If busy = False Then
- lbl_aktuelledatei.Text = "Patche : " & IO.Path.GetFileName(DownloadDatei)
- Dim SpeicherOrt As String = My.Computer.FileSystem.CurrentDirectory & "\" & DownloadDatei.Replace(PATCHURL, "").Replace("/", "\")
- Dim uri As New Uri(DownloadDatei)
- If File.Exists(SpeicherOrt) = True Then
- File.Delete(SpeicherOrt)
- End If
- PatchDownloader.DownloadFileAsync(uri, SpeicherOrt)
- busy = True
- Exit Do
- End If
- Loop
- Next
- File.Delete(AppPath & "\patchlist.xml")
- Exit Do
- End If
- Catch ex As Exception
- End Try
- Loop
- End Sub
- Private Sub PatchDownloader_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles PatchDownloader.DownloadFileCompleted
- busy = False
- If PB_GSM.Value = ANZAHLDLS Then
- Else
- PB_GSM.Value += 1
- End If
- End Sub
- Private Sub PatchDownloader_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles PatchDownloader.DownloadProgressChanged
- PB_AktuDatei.Maximum = e.TotalBytesToReceive
- PB_AktuDatei.Value = e.BytesReceived
- End Sub
- End Class
Und em entschuldigt, ich bin erst seit ca 1 2 wochen wirklich am lernen =)
mfg
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Fire88“ ()