Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Net
- Imports System.ComponentModel
- Imports System.Xml.Serialization
- Imports System
- Imports WMPLib
- Public Class MainForm
- 'Version Launcher
- Dim latestversion As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://tavianalife.com/launcher/version.txt")
- Dim response As System.Net.HttpWebResponse = latestversion.GetResponse()
- Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
- Dim newestversion As String = sr.ReadToEnd()
- 'Version Launcher Client
- Dim file4 As String = Application.ProductVersion
- 'AppData
- Public appdata As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\TavianaLife\"
- #Region " Attributs "
- Private webClient As WebClient
- Private player As WindowsMediaPlayer = New WindowsMediaPlayer
- Private aInfoFichierServeur As Entites.FichierXml
- Private aListeInfoFichierLocal As List(Of Entites.Fichier)
- Private aListeFichierDownload As List(Of Entites.Fichier)
- Private sounds As List(Of String)
- Private playing As Boolean = True
- Private activeSound As Integer = 0
- Private activedwl As Integer = 0
- Private dwlBytes As Long = 0
- Private totalBytes As Long = 0
- #End Region
- #Region " Propriétés "
- ''' <summary>
- ''' Information des fichiers sur le serveur
- ''' </summary>
- Private Property InfoFichierServeur() As Entites.FichierXml
- Get
- If aInfoFichierServeur Is Nothing Then
- aInfoFichierServeur = New Entites.FichierXml
- End If
- Return aInfoFichierServeur
- End Get
- Set(ByVal value As Entites.FichierXml)
- aInfoFichierServeur = value
- End Set
- End Property
- ''' <summary>
- ''' Liste d'information des fichiers local
- ''' </summary>
- Private Property ListeInfoFichierLocal() As List(Of Entites.Fichier)
- Get
- If aListeInfoFichierLocal Is Nothing Then
- aListeInfoFichierLocal = New List(Of Entites.Fichier)
- End If
- Return aListeInfoFichierLocal
- End Get
- Set(ByVal value As List(Of Entites.Fichier))
- aListeInfoFichierLocal = value
- End Set
- End Property
- ''' <summary>
- ''' Liste d'information des fichiers local
- ''' </summary>
- Private Property ListeFichierDownload() As List(Of Entites.Fichier)
- Get
- If aListeFichierDownload Is Nothing Then
- aListeFichierDownload = New List(Of Entites.Fichier)
- End If
- Return aListeFichierDownload
- End Get
- Set(ByVal value As List(Of Entites.Fichier))
- aListeFichierDownload = value
- End Set
- End Property
- #End Region
- #Region " Launching "
- Private Sub Set_Sounds()
- sounds = New List(Of String)
- Try
- ObtenirInfoFichierServeur(My.Settings.InfosSound)
- For Each sound In InfoFichierServeur.ListeFichier
- sounds.Add(sound.Path)
- Next
- Catch ex As Exception
- MsgBox("Erreur de connexion au serveur distant. Contacter un administrateur.", MsgBoxStyle.Information, "Taviana Life France")
- End Try
- InfoFichierServeur = Nothing
- End Sub
- Private Sub MainForm_load(sender As Object, e As EventArgs) Handles MyBase.Load
- If My.Computer.FileSystem.FileExists(appdata & "dmod.a3") Then
- My.Settings.GameEXEPath = My.Computer.FileSystem.ReadAllText(appdata & "dmod.a3")
- End If
- pathTB.Text = ("Destination Arma 3: " & My.Settings.GameEXEPath)
- If newestversion.Contains(file4) Then
- ITalk_Label6.ForeColor = Color.Green
- ITalk_Label6.Text = file4
- Else
- ITalk_Label6.ForeColor = Color.Red
- ITalk_Label6.Text = file4
- End If
- Set_Sounds()
- If sounds.Count > 0 Then
- player.URL = My.Settings.ServerIp & sounds(0)
- player.settings.setMode("Loop", False)
- player.controls.play()
- playBtn.Refresh()
- CheckUpdate()
- Else
- Close()
- End If
- End Sub
- #End Region
- Private Sub OKToPlay()
- playBtn.Visible = False
- Close()
- End Sub
- #Region " Validation "
- Private Function CheckUpdate() As Boolean
- playBtn.Text = "Recherche de Mise à jour..."
- playBtn.Visible = True
- Try
- 'Mauvais Path
- If Not File.Exists(My.Settings.GameEXEPath) Then
- playBtn.Text = "Veuillez indiquer le chemin d'accès au fichier " & My.Settings.GameEXE
- Return False
- End If
- pathTB.Text = My.Settings.GameEXEPath
- My.Settings.GameFolderPath = Path.GetDirectoryName(My.Settings.GameEXEPath)
- Try
- ObtenirInfoFichierServeur(My.Settings.InfosMod)
- ValidateFiles()
- Return False
- Catch ex As Exception
- playBtn.Text = "Erreur de connexion au server #Log:" & ex.Message
- Return False
- End Try
- Catch ex As Exception
- playBtn.Text = "Veuillez indiquer le chemin d'accès au fichier " & My.Settings.GameEXE
- Return False
- End Try
- End Function
- ''' <summary>
- ''' Permet d'obtenir l'information sur les fichiers sur le serveur
- ''' </summary>
- Private Sub ObtenirInfoFichierServeur(ByVal fichier As String)
- webClient = New WebClient
- Dim fichierXmlServeur() As Byte = webClient.DownloadData(My.Settings.ServerIp & fichier)
- Dim contenuXml As String = System.Text.Encoding.UTF8.GetString(fichierXmlServeur)
- Dim objStringReader As New StringReader(contenuXml)
- Dim x As New XmlSerializer(InfoFichierServeur.GetType)
- InfoFichierServeur = DirectCast(x.Deserialize(objStringReader), Entites.FichierXml)
- objStringReader.Close()
- End Sub
- ''' <summary>
- ''' Permet d'orbtenir l'information sur les fichiers localement
- ''' </summary>
- Private Sub ObtenirInfoFichierLocal()
- Dim infoFichier As FileInfo = Nothing
- Dim pathLocal As String = String.Empty
- Dim sx() As String
- If Not Directory.Exists(String.Format("{0}\{1}", My.Settings.GameFolderPath, My.Settings.ModFolderName)) Then
- Directory.CreateDirectory(String.Format("{0}\{1}", My.Settings.GameFolderPath, My.Settings.ModFolderName))
- End If
- For Each fichierTrouver In My.Computer.FileSystem.GetFiles(String.Format("{0}\{1}", My.Settings.GameFolderPath, My.Settings.ModFolderName), FileIO.SearchOption.SearchAllSubDirectories, "*")
- infoFichier = My.Computer.FileSystem.GetFileInfo(fichierTrouver)
- If fichierTrouver IsNot Nothing Then
- sx = Split(fichierTrouver, "@")
- pathLocal = "@" & sx(1)
- ListeInfoFichierLocal.Add(New Entites.Fichier With
- {.Path = pathLocal,
- .TotalBytes = infoFichier.Length})
- End If
- Next
- End Sub
- Private Sub ComparerListes()
- Dim listeDifferenceFichierLocal As IEnumerable(Of Entites.Fichier) =
- From o In InfoFichierServeur.ListeFichier
- Where Not ListeInfoFichierLocal.Exists(Function(x) x.Path.ToLower = o.Path.ToLower AndAlso
- x.TotalBytes = o.TotalBytes)
- Select o
- Dim listeDifferenceFichierServeur As IEnumerable(Of Entites.Fichier) =
- From o In ListeInfoFichierLocal
- Where Not InfoFichierServeur.ListeFichier.Exists(Function(x) x.Path.ToLower = o.Path.ToLower AndAlso
- x.TotalBytes = o.TotalBytes)
- Select o
- If Not listeDifferenceFichierServeur.Any Then
- MsgBox("Une mise à jour des addons est disponible, Appuyez sur OK..", MsgBoxStyle.Information, "Taviana Life France")
- SupprimerFichierLocal(listeDifferenceFichierServeur)
- End If
- If listeDifferenceFichierLocal.Any Then
- ListeFichierDownload = New List(Of Entites.Fichier)(listeDifferenceFichierLocal)
- End If
- PreDownload()
- End Sub
- ''' <summary>
- ''' Permet de supprimer les fichiers localement qui ne sont plus sur le serveur
- ''' </summary>
- ''' <param name="pListeDifferenceFichierServeur">Liste de différence de fichier sur le serveur</param>
- Private Sub SupprimerFichierLocal(pListeDifferenceFichierServeur As IEnumerable(Of Entites.Fichier))
- Dim pathFichier As String = String.Empty
- For Each fichierServeur In pListeDifferenceFichierServeur
- pathFichier = String.Format("{0}\{1}",
- My.Settings.GameFolderPath,
- fichierServeur.Path)
- If File.Exists(pathFichier) Then
- File.Delete(pathFichier)
- End If
- Next
- End Sub
- Private Sub ValidateFiles()
- playBtn.Enabled = False
- Try
- 'Étape 1 - Obtenir les information des fichiers localement
- ObtenirInfoFichierLocal()
- 'Étape 2 - Comparer les fichiers serveur et local pour les différences,
- ' sinon tout télécharger les fichiers du serveur si le dossier local est vide
- If ListeInfoFichierLocal IsNot Nothing AndAlso
- ListeInfoFichierLocal.Any Then
- ComparerListes()
- Else
- ListeFichierDownload = New List(Of Entites.Fichier)(InfoFichierServeur.ListeFichier)
- PreDownload()
- End If
- Catch ex As Exception
- playBtn.Text = "Erreur lors du téléchargement de fichiers... #Log: " & ex.Message
- Application.Exit()
- End Try
- End Sub
- #End Region
- #Region " Download "
- Private Sub PreDownload()
- If ListeFichierDownload.Any Then
- totalBytes = 0
- For Each fichier In ListeFichierDownload
- totalBytes += fichier.TotalBytes
- Next
- filePB.Visible = True
- globalPB.Visible = True
- DownloadFiles()
- Else
- OKToPlay()
- End If
- End Sub
- ''' <summary>
- ''' Permet d'obtenir tout les fichier sur le serveur
- ''' </summary>
- Private Sub DownloadFiles()
- webClient = New WebClient
- If ListeFichierDownload(activedwl).Path.Where(Function(x) x = "\").Count > 1 Then
- Dim segmentPath() As String = ListeFichierDownload(activedwl).Path.Split("\"c)
- Dim repertoirACreer As String = segmentPath(1)
- If Not Directory.Exists(String.Format("{0}\{1}\{2}", My.Settings.GameFolderPath, My.Settings.ModFolderName, repertoirACreer)) Then
- Directory.CreateDirectory(String.Format("{0}\{1}\{2}", My.Settings.GameFolderPath, My.Settings.ModFolderName, repertoirACreer))
- End If
- End If
- webClient.DownloadFileAsync(
- New Uri(String.Format("{0}{1}", My.Settings.ServerIp, ListeFichierDownload(activedwl).Path)), String.Format("{0}\{1}",
- My.Settings.GameFolderPath,
- ListeFichierDownload(activedwl).Path))
- AddHandler webClient.DownloadProgressChanged, AddressOf WC_DownloadProgressChanged
- AddHandler webClient.DownloadFileCompleted, AddressOf WC_DownloadFileCompleted
- End Sub
- #End Region
- #Region " Event "
- Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
- Dim now As Integer = (e.BytesReceived / 1000) / 1000
- Dim total As Integer = (e.TotalBytesToReceive / 1000) / 1000
- Dim globalPourcent = Format(((dwlBytes + e.BytesReceived) / totalBytes) * 100, "0.00")
- Dim globalNow As Integer = ((dwlBytes + e.BytesReceived) / 1000) / 1000
- Dim globalTotal As Integer = (totalBytes / 1000) / 1000
- playBtn.Text = globalPourcent & "% " & "Mis à Jour " & globalNow & "Mo de " & globalTotal & "Mo" & vbCrLf & now & "Mo de " & total & "Mo"
- globalPB.Value = globalPourcent
- filePB.Value = e.ProgressPercentage
- End Sub
- Private Sub WC_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs)
- dwlBytes += ListeFichierDownload(activedwl).TotalBytes
- activedwl += 1
- If activedwl < ListeFichierDownload.Count Then
- DownloadFiles()
- Else
- filePB.Visible = False
- globalPB.Visible = False
- My.Settings.ModVersion = InfoFichierServeur.Version
- OKToPlay()
- End If
- End Sub
- #End Region
- #Region " Gestion Btn Click "
- #Region " Main "
- Private Sub BrowseBtn_Click_1(sender As Object, e As EventArgs) Handles BrowseBtn.Click
- Dim fileDiag As OpenFileDialog
- fileDiag = New OpenFileDialog
- fileDiag.InitialDirectory = "C:\"
- fileDiag.Filter = "Exécutable Arma3|" & My.Settings.GameEXE
- If fileDiag.ShowDialog = Windows.Forms.DialogResult.OK Then
- My.Settings.GameEXEPath = fileDiag.FileName
- My.Settings.GameFolderPath = Path.GetDirectoryName(My.Settings.GameEXEPath)
- My.Settings.ModVersion = 0
- My.Computer.FileSystem.WriteAllText(appdata & "dmod.a3", My.Settings.GameEXEPath, False)
- pathTB.Text = My.Settings.GameEXEPath
- If CheckUpdate() Then
- OKToPlay()
- End If
- End If
- End Sub
- #End Region
- #Region " Sound "
- Private Function validateIndex(ByVal index As Integer) As Boolean
- Return index >= 0 AndAlso index < sounds.Count
- End Function
- Private Sub ITalk_LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles ITalk_LinkLabel1.LinkClicked
- Process.Start("http://tavianalife.com/forum/index.php?/user/1-ac1d-r41n/")
- End Sub
- Private Sub ITalk_LinkLabel1_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles ITalk_LinkLabel1.LinkClicked
- Process.Start("http://tavianalife.com/forum/index.php?/user/1-ac1d-r41n/")
- End Sub
- #End Region
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement