This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vanilla.vb
72 lines (63 loc) · 3.07 KB
/
Vanilla.vb
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
Imports System.IO
Imports Newtonsoft.Json.Linq
Public Class Vanilla
'Création du Dictionnaire contenant la liste des versions et leurs liens
Public Versions As New Dictionary(Of String, String)
Private Sub Vanilla_Load(sender As Object, e As EventArgs) Handles MyBase.Load
UpdateVersionList()
End Sub
Private Sub UpdateVersionList()
If CheckInternet() Then
If File.Exists(Informations.VanillaManifestDownloadPath) Then
File.Delete(Informations.VanillaManifestDownloadPath)
End If
Try
My.Computer.Network.DownloadFile(Informations.VanillaManifestURL, Informations.VanillaManifestDownloadPath)
#Disable Warning CA1031 ' Do not catch general exception types
Catch ex As Exception
MsgBox("Une erreur est survenue lors de l'obtention de la liste des versions :" + vbNewLine + ex.Message, vbOKOnly + vbCritical + 4096, "Erreur")
#Enable Warning CA1031 ' Do not catch general exception types
End Try
Dim VersionManifestJSON As String = File.ReadAllText(Informations.VanillaManifestDownloadPath)
Dim obj As JObject = JObject.Parse(VersionManifestJSON)
VersionsList.BeginUpdate()
Dim VersionsJSON = obj("versions").ToList()
For Each VersionJSON As JToken In VersionsJSON
Dim VersionObj As JObject = JObject.Parse(VersionJSON.ToString())
Dim versionInfo As New ListViewItem
Dim VersionName As String
Dim VersionLink As String
For Each version As JProperty In VersionObj.Children()
version.CreateReader()
Select Case version.Name
Case "id"
versionInfo.Text = version.Value
VersionName = version.Value
Case "type"
versionInfo.SubItems.Add(version.Value)
Case "url"
VersionLink = version.Value
End Select
Next
VersionsList.Items.Add(versionInfo)
#Disable Warning BC42104 ' La variable est utilisée avant de se voir attribuer une valeur
Versions.Add(VersionName, VersionLink)
#Enable Warning BC42104 ' La variable est utilisée avant de se voir attribuer une valeur
Next
VersionsList.EndUpdate()
VersionsList.Update()
Else
MsgBox("Pas d'accès internet !", vbOKOnly + vbCritical + 4096, "Erreur")
End If
End Sub
Private Sub VersionsList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles VersionsList.SelectedIndexChanged
If VersionsList.SelectedItems.Count = 1 Then
NextBtn.Enabled = True
Else
NextBtn.Enabled = False
End If
End Sub
Private Sub NextBtn_Click(sender As Object, e As EventArgs) Handles NextBtn.Click
Downloader.DownloadVanillaServer(VersionsList.SelectedItems.Item(0).Text, Me, Eula)
End Sub
End Class