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
| Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Launcher"
Me.Show()
Private Sub Form1_LocationChanged(sender As System.Object, e As System.EventArgs) Handles MyBase.LocationChanged
Dim VERIF_VERSION As String = My.Computer.FileSystem.ReadAllText("version.txt")
Dim versionfile As String = "version.txt"
If My.Computer.FileSystem.FileExists(versionfile) Then
My.Computer.FileSystem.DeleteFile(versionfile)
End If
My.Computer.Network.DownloadFile(Site2 & versionfile, versionfile)
Dim LastVer As String = My.Computer.FileSystem.ReadAllText(versionfile)
Label.Visible = False
Label2.Visible = False
Label1.Visible = False
Label3.Visible = False
Label4.Visible = False
If VERIF_VERSION < LastVer Then
TabControl.SelectTab(1)
File.Delete(versionfile)
Dim t1 As String = VERIF_VERSION + 1
Dim sw As StreamWriter
sw = New StreamWriter(versionfile)
sw.WriteLine(t1)
sw.Close()
Label.Visible = True
Label.Text = (LastVer & "Mise a jour détecter ")
Label1.Visible = True
Label1.Text = ("Mise à jour " & t1 & "/" & LastVer)
My.Computer.Network.DownloadFile(Site2 & t1 & ".zip", t1 & ".zip")
Label2.Visible = True
Label2.Text = ("Décompression de l'archives")
decompression(Application.StartupPath, t1 & ".zip")
Label3.Visible = True
Label3.Text = ("Décompresion achever.")
GoTo repeat
End If
If VERIF_VERSION = LastVer Then
Label4.Visible = True
Label4.Text = ("Vous pouvez désormais jouez.")
End If
End Sub
Public Sub decompression(ByVal destinationDirectory As String, ByVal myzipfile As String)
' on cree l'entree zip
Dim zipIStream As ZipInputStream = New ZipInputStream(File.OpenRead(myzipfile))
Dim theEntry As ZipEntry
' pour toutes les entrees
Do While (1)
' recuperation de l'entree
theEntry = zipIStream.GetNextEntry()
' si l'entree vaut nothing => c'est fini
If theEntry Is Nothing Then Exit Do
' test si l'entrée est un fichier
If theEntry.IsFile Then
' definition du fichier de sortie
Dim myFile As New FileInfo(destinationDirectory & "\" & theEntry.Name)
' on crée le(s) répertoire(s) si besoin
Directory.CreateDirectory(myFile.DirectoryName)
' creation du fichier de sortie
Dim fs As FileStream = New FileStream(myFile.FullName, FileMode.Create)
Dim size As Integer = 2048
Dim data As Byte() = New Byte(size) {}
Do Until (size <= 0)
size = zipIStream.Read(data, 0, data.Length)
fs.Write(data, 0, size)
Loop
fs.Flush()
fs.Close()
End If
Loop
' on ferme le flux
zipIStream.Close()
End Sub
End class |