-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMinecraftUpdate.vb
More file actions
116 lines (97 loc) · 5.5 KB
/
MinecraftUpdate.vb
File metadata and controls
116 lines (97 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Imports System.Net
Imports System.IO
Imports System.Threading
Imports System.xml
Public Class MinecraftUpdate
Dim DownThread As Thread
Private Delegate Sub voidDelegate(ByRef totalDownloadedByte As Long, totalBytes As Long)
Private Sub MinecraftUpdate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MetroLabel.Left = (Me.Width - MetroLabel.Width) \ 2
MetroProgressBar.Left = (Me.Width - MetroProgressBar.Width) \ 2
MetroProgressBarAll.Left = (Me.Width - MetroProgressBar.Width) \ 2
Control.CheckForIllegalCrossThreadCalls = False
DownThread = New Thread(New ThreadStart(AddressOf Update))
DownThread.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
' Update()
End Sub
Private Sub Update()
Try
Dim Myrq As HttpWebRequest = HttpWebRequest.Create(PeoLeser.Minecraft.CoreClass.GetINI("Launcher", "UpdateXML", "", Application.StartupPath + "\LightMCLauncher\launcher.ini"))
Dim myrp As HttpWebResponse = Myrq.GetResponse
Dim st As Stream = myrp.GetResponseStream
Dim so As Stream = New FileStream(Application.StartupPath + "\LightMCLauncher\" + "update.xml", FileMode.Create)
Dim by(1024) As Byte
Dim osize As Integer = st.Read(by, 0, by.Length)
While osize > 0
Application.DoEvents()
so.Write(by, 0, osize)
osize = st.Read(by, 0, by.LongLength)
End While
so.Close()
st.Close()
Dim xmlDoc As New XmlDocument
xmlDoc.Load(Application.StartupPath + "\LightMCLauncher\" + "update.xml")
Dim UpdateLine As TextReader = File.OpenText(Application.StartupPath + "\LightMCLauncher\" + "update.xml")
Dim UpdateLineAll As String = UpdateLine.ReadToEnd, LineCount As Int16 = 0
LineCount = (UBound(Split(UpdateLineAll, vbCrLf)) - 2) / 6
UpdateLine.Close()
MetroProgressBarAll.Maximum = LineCount
Dim UpdateInfo(LineCount, 3) As String
For i = 1 To LineCount
Try
UpdateInfo(i, 0) = xmlDoc.SelectSingleNode("update").SelectSingleNode("file" + i.ToString).SelectSingleNode("action").InnerText
UpdateInfo(i, 1) = xmlDoc.SelectSingleNode("update").SelectSingleNode("file" + i.ToString).SelectSingleNode("path").InnerText
UpdateInfo(i, 2) = xmlDoc.SelectSingleNode("update").SelectSingleNode("file" + i.ToString).SelectSingleNode("version").InnerText
UpdateInfo(i, 3) = xmlDoc.SelectSingleNode("update").SelectSingleNode("file" + i.ToString).SelectSingleNode("url").InnerText
Catch ex As System.NullReferenceException
End Try
Next
For i = 1 To LineCount
Select Case UpdateInfo(i, 0)
Case "Creat"
If UpdateInfo(i, 2) <> PeoLeser.Minecraft.CoreClass.getMd5Hash(Application.StartupPath + "/" + UpdateInfo(i, 1)) Then
Dim Myrq2 As HttpWebRequest = HttpWebRequest.Create(PeoLeser.Minecraft.CoreClass.GetINI("Launcher", "UpdateURL", "", Application.StartupPath + "\LightMCLauncher\launcher.ini") + UpdateInfo(i, 3))
Dim myrp2 As HttpWebResponse = Myrq2.GetResponse
Dim totalBytes As Long = myrp2.ContentLength
Dim st2 As Stream = myrp2.GetResponseStream
Try
line1: Dim so2 As Stream = New FileStream(Application.StartupPath + "\" + UpdateInfo(i, 1), FileMode.Create)
Dim totalDownloadedByte As Long = 0
Dim by2(1024) As Byte
Dim osize2 As Integer = st2.Read(by2, 0, by2.Length)
While osize2 > 0
totalDownloadedByte = osize2 + totalDownloadedByte
Application.DoEvents()
so2.Write(by2, 0, osize2)
Me.Invoke(New voidDelegate(AddressOf UpdateUI), totalDownloadedByte, totalBytes)
osize2 = st2.Read(by2, 0, by2.LongLength)
End While
so2.Close()
st2.Close()
Catch ex As DirectoryNotFoundException
'MsgBox(UpdateInfo(i, 1))
Directory.CreateDirectory(Strings.Left(UpdateInfo(i, 1), UpdateInfo(i, 1).LastIndexOf("\")))
GoTo line1
End Try
End If
Case "Delete"
Try
File.Delete(Application.StartupPath + "\" + UpdateInfo(i, 1))
Catch ex As Exception
End Try
End Select
MetroProgressBarAll.Value = i
Next
Catch ex As Exception
End Try
MetroProgressBarAll.Value = MetroProgressBarAll.Maximum
MetroProgressBar.Value = MetroProgressBar.Maximum
Me.Close()
End Sub
Private Sub UpdateUI(ByRef totalDownloadedByte As Long, totalBytes As Long)
MetroProgressBar.Maximum = totalBytes
MetroProgressBar.Value = totalDownloadedByte
End Sub
End Class