Imports System.Net
Imports System.IO
Imports System.Net.Mail

Public Class Form1

    '
    '
    ' ⟩  Copyright © ⇒ MrDarkSkil ©  ⟨               
    '      ⟩    2014 ⇒ 2015    ⟨
    '
    '    Launcher create for Emodyz©
    '               and 
    '           AltisDev.com
    '
    '    Ne pas changer les crédits !
    ' 


    ' Merci de bien vouloir ne pas changer les crédits de base qui ce trouve plus bas dans le code ( sinon votre launcher seras inutilisable ! )


    ' Important, A changer !
    Public ftp = "http://crystalrp.fr/launcher/" ' Serveur ou ce trouve tout les fichier nessésaire au launcher
    Public servername = "Crystal RP"
    Public modsname = "@CrystalRP"   'Config Arma 3 'Config site web // forum
    Public website = "http://crystalrp.fr" 'Le lien de votre site, forum ou autres
    Public ipserveur = "serveur.crystalrp.fr:2302" 'Ip de votre serveur arma3
    Public servpassword = "beta123" 'Mot de passe de votre serveur ( préférable contre les hacks | par default "none" )

    'Config TeamSpeak
    Public ipTS = "ts.crystalrp.fr" ' Ip de votre teamspeak ( sans les port " 0.0.0.127:25564 vous mettez juste sa 0.0.0.127 " )
    Public portTS = "8500" 'Le port de votre teamspeak ( si vous n'en avez pas mettez " none " )

    'Config launcher
    Public extention = "CrystalRP.exe" 'Mettez le nom que votre launcher auras en .exe ( "exemple: emodyz.exe ") puis uploader le launcher sur le FTP



    'Config TaskForce Radio
    Public TaskForce = "Enable" 'Mettez si oui ou non la possiblilité d'installer TaskForce est disponible   ( "Enable" = Activé    "Disable" = Désactivé )
    Public taskdll = "task_force_radio_pipe.dll" 'Le pipe.dll
    Public taskpaa = "manw_winner_addon_1st_emblem.paa" 'Image TaskForce

    'Non des fichier qui donne des infos au launcher !
    Public listmods = "modspack.txt" 'Liste des mods
    Public message = "news.txt" 'Les news du launcher
    Public deletepack = "deletepack.txt" 'Le pack pour surprimer les mods

    'Addons // CPP , Taskforce
    Public modcpp = "mod.cpp" 'Le mod.cpp
    Public logocpp = "logo.paa" 'Le logo.paa


    'Crédits (Vous ne pouvez qu'ajouter votre nom ici et le nom de votre serveur, NE PAS CHANGER LES CREDITS QUI ME SONT PROPRES ! )
    Dim crédits = My.Computer.Clock.LocalTime

    'information Version
    Public vlauncher = "vlauncher.txt" ' Le fichier ou est inscript la dernière version du launcher 

    'Config Mail
    Public email = "theo.carnet@gmail.com" 'Votre adresse email ( pour recevoir les allerts de cheat et les rapport des bugs)
    Public emailpassword As String = "password" 'Votre mots de passe pour l'email ( de préférance pas votre crée un compte mail spécial pour le launcher )
    Public emailreceved = "theo.carnet@gmail.com" ' L'email sur le quel vous voulez recevoir les notifications !
    Public emailsmtp = "smtp.live.com" ' Serveur SMTP 
    Public emailsmtpport = "586" ' Port SMTP

    'Direction utiles
    Public dmods = "mods" ' la direction sur le ftp ou les mods sont upload
    Public dtask = "taskforce" ' la direction sur le ftp ou les mods sont upload
    Public dcpp = "cpp" ' la direction sur le ftp ou le mod.cpp et logo.paa sont upload
    Public dversion = "version" 'la direction ou tout les fichier renseignant les version à savoir sont
    Public dlauncher As String = Application.StartupPath & "\" ' Ne pas changer !! 
    Public darma3 As String = "C:\Program Files (x86)\Steam\SteamApps\common\Arma 3\" 'La destination de base ou ce cache peu être arma3

    'Option Launcher
    Public startoption = "-skipIntro" 'Option de lancement de base ( NE PAS CHANGER !)
    Public speudo = "NewUser" 'Speudo de base ( NE PAS CHANGER !)

    'Information anex ( Ne pas changer )
    Public vlaunch As String = Application.ProductVersion ' NE PAS CHANGER
    Public newsmessage As String = "Chargement..." 'NE PAS CHANGER
    Public appdata As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\" & servername & "\" ' Destination ou le launcher a besoin de mettre les fichier.
    Public user As String = Environment.UserName 'Detecte le nom d'utilisateur du PC
    Public internet As String 'NE PAS CHANGER

    ' Congiguration sensible ! ( Don't Touch ) ( NE PAS TOUCHER )
    Dim nbr_ligne As Integer = 0
    Dim ligne As String
    Dim tligne As String
    Dim totalBytes As Double
    Dim bytesIn As Double
    Dim AntiCheatRead
    Dim bytes As Integer
    Dim download = "defalt"
    Dim nbrdownload = "0"
    Dim nbr_delete = "0"
    Dim clock
    Dim deletel
    Dim tdelete
    Dim finish = "false"
    Dim dfinish = "false"
    Dim deletemods = "0"
    Dim removeligne As String
    Dim tremoveligne As String
    Dim nbr_remove As Integer = 0


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '
        '
        ' ⟩  Copyright © ⇒ MrDarkSkil ©  ⟨               
        '      ⟩    2014 ⇒ 2015    ⟨
        '
        '    Launcher create for Emodyz©
        '               and 
        '            AltisDev
        '
        '    Ne pas changer les crédits !
        ' 

        PictureBox3.Visible = False
        PictureBox7.Visible = False

        If My.Computer.FileSystem.DirectoryExists("C:\Windows\Microsoft.NET\Framework\v3.5") Or My.Computer.FileSystem.DirectoryExists("C:\Windows\Microsoft.NET\Framework\v4.0.30319") Or My.Computer.FileSystem.DirectoryExists("C:\Windows\Microsoft.NET\Framework64\v3.5") Or My.Computer.FileSystem.DirectoryExists("C:\Windows\Microsoft.NET\Framework64\v4.0.30319") Then
        Else
            MsgBox("Pour que le launcher fonctionne correctement, il faut que .NET Framework v3.5 minimum soit installé sur votre PC")
            Process.Start("https://www.microsoft.com/fr-fr/download/details.aspx?id=30653")
            Me.Close()
        End If


        If My.Computer.FileSystem.FileExists(appdata & "startoption.a3") Then
            startoption = My.Computer.FileSystem.ReadAllText(appdata & "startoption.a3")
        End If

        If My.Computer.FileSystem.FileExists(appdata & "speudo.a3") Then
            speudo = My.Computer.FileSystem.ReadAllText(appdata & "speudo.a3")
        End If
        My.Computer.FileSystem.CreateDirectory(appdata)
        ' Change les textes perssonalisé du launcher
        FormSkin1.Text = "                                                                               " & servername
        FlatLabel1.Text = "v. " & vlaunch
        ' Demande le choix de la destination Arma3
        If My.Computer.FileSystem.FileExists(appdata & "destination.a3") Then
            darma3 = My.Computer.FileSystem.ReadAllText(appdata & "destination.a3")
            If My.Computer.FileSystem.FileExists(darma3 & "arma3.exe") Then
            Else
                MsgBox("La destination d'arma3 n'est pas valide !" & vbNewLine & "Avant de télécharger les mods, veillez à bien rechoisir la destination !")
            End If
        Else
            If My.Computer.FileSystem.FileExists(darma3 & "arma3.exe") Then
                darma3 = ("C:\Program Files (x86)\Steam\SteamApps\common\Arma 3\")
            Else
                Folder.ShowDialog()
                darma3 = Folder.SelectedPath & "\"
                My.Computer.FileSystem.WriteAllText(appdata & "destination.a3", darma3, False)
            End If
            If My.Computer.FileSystem.FileExists(darma3 & "arma3.exe") Then
            Else
                MsgBox("La destination choisi n'est pas valide !")
            End If
        End If
        FlatLabel2.Text = ("Destination d'Arma3: " & darma3)
        ' On run les news, mise à jour
        If My.Computer.Network.IsAvailable Then
            DownloadOther.RunWorkerAsync()
            News.RunWorkerAsync()
        Else
            FlatButton1.Enabled = False
            FlatStatusBar1.Text = "Erreur: Vous n'avez pas internet !"
        End If


    End Sub

    Private Sub News_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles News.DoWork
        'System de news ( chargement du message )

        Do

            Dim newsstream As String = ftp & message

            Dim clientnews As WebClient = New WebClient()
            Dim reader As StreamReader = New StreamReader(clientnews.OpenRead(newsstream))
            Dim messagerequest = reader.ReadLine
            Dim maintenance = reader.ReadLine



            If maintenance = "1" Then
                newsmessage = servername & " est en train d'effectuer une maintenance ! Veuillez patienter ...."
                PictureBox7.Visible = True
                PictureBox7.BringToFront()
                FlatButton1.Enabled = False
            Else
                newsmessage = "Message du staff: " & messagerequest
                PictureBox7.Visible = False
                FlatButton1.Enabled = True

            End If


            FlatStatusBar1.Text = newsmessage

            If maintenance = "0" Then
                Exit Sub
            End If
            Threading.Thread.Sleep(10000)
        Loop


    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Process.Start(website)
    End Sub

    Private Sub FlatButton2_Click(sender As Object, e As EventArgs) 
        'If user = "MrDarkSkil" Then
        '   MsgBox("C'est ton launcher gros :D")
        'End If

        MsgBox("Launcher crée par Hubert Léo alias MrDarkSkil" & vbNewLine & vbNewLine & "Pour la communauté Emodyz.com et le serveur American'Life" & vbNewLine & vbNewLine & crédits, MsgBoxStyle.Information)
    End Sub

    Private Sub FlatButton3_Click(sender As Object, e As EventArgs) Handles FlatButton3.Click
        Process.Start(website)
    End Sub

    Private Sub FlatButton4_Click(sender As Object, e As EventArgs) Handles FlatButton4.Click
        If portTS = "none" Then
            Process.Start("ts3server://" & ipTS)
        Else
            Process.Start("ts3server://" & ipTS & "?port=" & portTS)
        End If
    End Sub

    Private Sub FlatButton5_Click(sender As Object, e As EventArgs) Handles FlatButton5.Click
        Folder.ShowDialog()
        darma3 = Folder.SelectedPath & "\"
        FlatLabel2.Text = ("Destination d'Arma3: " & darma3)

        If My.Computer.FileSystem.FileExists(darma3 & "arma3.exe") Then
        Else
            MsgBox("La destination d'arma3 choisi n'est pas valide !")
        End If
        If My.Computer.FileSystem.FileExists(appdata & "destination.a3") Then
            My.Computer.FileSystem.DeleteFile(appdata & "destination.a3")
        End If
        My.Computer.FileSystem.WriteAllText(appdata & "destination.a3", darma3, False)
    End Sub


    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click

        If finish = "false" Then
            MsgBox("Veuillez patienter quelques secondes le temps que le launcher télécharge tout ce dont il a besoin !")
            Exit Sub
        End If
        ' Verifie si TaskForce est installer .

        If TaskForce = "Enable" Then
            ' Verifie si TaskForce est installer .
            If My.Computer.FileSystem.FileExists(appdata & "taskforce.txt") Then
                If My.Computer.FileSystem.ReadAllText(appdata & "taskforce.txt") = "Installed" Then
                Else
                    MsgBox("Veuillez installer TaskForceRadio avant de commencer à jouer !" & vbNewLine & vbNewLine & "Pour installer le TaskForce radio, aller dans les options du launcher !")
                    Exit Sub
                End If
            Else
                MsgBox("Veuillez installer TaskForceRadio avant de commencer à jouer !" & vbNewLine & vbNewLine & "Pour installer le TaskForce radio, aller dans les options du launcher !")
                Exit Sub
            End If
        End If
       
        If My.Computer.FileSystem.FileExists(darma3 & "arma3.exe") Then
            If dfinish = "false" Then
                'Crée le dossier dans lequel les mods vont se télécharger 
                My.Computer.FileSystem.CreateDirectory(darma3 & modsname)

                'bloque le bouton 
                PictureBox2.Visible = False

                'Verifie les mods a supprimer 
                DeleteMod.RunWorkerAsync()

                'télécharge les trucs .cpp
                DownloadCpp.RunWorkerAsync()
            Else
                StartArma.RunWorkerAsync()
            End If

        Else
            MsgBox("La destination d'arma3 n'est pas valide !" & vbNewLine & "Avant de télécharger les mods, veillez à bien rechoisir la destination !")
            Exit Sub
        End If
    End Sub
    Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)

        bytesIn = Double.Parse(e.BytesReceived.ToString())

        totalBytes = Double.Parse(e.TotalBytesToReceive.ToString())

        Dim percentage As Double = bytesIn / totalBytes * 100

        If download = "true" Then
            FlatLabel6.Text = "Téléchargement du mod: " & ligne
        End If

        If download = "false" Then
            FlatLabel6.Text = "Vérification du mod: " & ligne
        End If

        FlatProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
    End Sub

    Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        nbr_ligne += 1

        If download = "true" Then
            nbrdownload += 1
            FlatLabel3.Text = "Mod(s) total à télécharger: " & tligne & " Mod(s)"
            FlatLabel4.Text = "Mod(s) Restant: " & tligne - nbr_ligne & " Mod(s)"
            FlatLabel5.Text = "Mod(s) Téléchargé: " & nbrdownload & " Mod(s)"
        End If

        If download = "false" Then
            FlatLabel3.Text = "Mod(s) à Vérifié: " & tligne & " Mod(s)"
            FlatLabel4.Text = "Mod(s) Vérifié: " & nbr_ligne & " Mod(s)"
        End If


        FlatProgressBar2.Value = nbr_ligne * 100 / tligne

        If FlatProgressBar2.Value = 100 Then
            'Start arma 3 
            dfinish = "true"
            PictureBox2.Visible = True
            StartArma.RunWorkerAsync()
        Else
            Downloadmods.Dispose()
            Pont.RunWorkerAsync()
        End If
    End Sub

    Private Sub Downloadmods_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles Downloadmods.DoWork
        'Crée la liste des mods à télécharger
        If My.Computer.FileSystem.FileExists(appdata & listmods) Then
            Dim line As String() = File.ReadAllLines(appdata & listmods)
            ligne = line(nbr_ligne)
            tligne = line.Length

        Else
            MsgBox("Une erreur est survenue ! " & vbNewLine & vbNewLine & "Veuillez réessayer plus tard ou conctacter le créateur du launcher" & vbNewLine & "sur http://emodyz.com/forum , son speudo ""Jason Statam""ou ""MrDarkSkil""")
        End If

        'Savoir la taille d'un fichier en ligne 
        Dim Request As System.Net.WebRequest
        Dim Response As System.Net.WebResponse
        Dim FileSize As Integer
        Request = Net.WebRequest.Create(ftp & dmods & "/" & ligne)
        Request.Method = Net.WebRequestMethods.Http.Get
        Response = Request.GetResponse
        FileSize = Response.ContentLength

        If My.Computer.FileSystem.FileExists(darma3 & modsname & "\addons\" & ligne) Then
            Dim infoReader As System.IO.FileInfo
            infoReader = My.Computer.FileSystem.GetFileInfo(darma3 & modsname & "\addons\" & ligne)
            bytes = infoReader.Length

        End If




        Dim Client As WebClient = New WebClient

        AddHandler Client.DownloadProgressChanged, AddressOf client_ProgressChanged

        AddHandler Client.DownloadFileCompleted, AddressOf client_DownloadCompleted



        If bytes = FileSize Then
            download = "false"
            If My.Computer.FileSystem.FileExists(darma3 & "copyright.txt") Then
                My.Computer.FileSystem.DeleteFile(darma3 & "copyright.txt")
            End If
            Client.DownloadFileAsync(New Uri(ftp & "copyright.txt"), darma3 & "copyright.txt")
        Else
            download = "true"
            My.Computer.FileSystem.CreateDirectory(darma3 & modsname & "\addons\")
            If My.Computer.FileSystem.FileExists(darma3 & modsname & "\addons\" & ligne) Then
                My.Computer.FileSystem.DeleteFile(darma3 & modsname & "\addons\" & ligne)
            End If
            Client.DownloadFileAsync(New Uri(ftp & dmods & "/" & ligne), darma3 & modsname & "\addons\" & ligne)
        End If
        Response.Close()
        Exit Sub
    End Sub

    Private Sub DownloadOther_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles DownloadOther.DoWork

        '
        '
        ' ⟩  Copyright © ⇒ MrDarkSkil ©  ⟨               
        '      ⟩    2014 ⇒ 2015    ⟨
        '
        '    Launcher create for Emodyz©
        '         and AltisDev.com
        '
        '    Ne pas changer les crédits !
        ' 


        ' Download la liste des mods
        If My.Computer.FileSystem.FileExists(appdata & listmods) Then
            My.Computer.FileSystem.DeleteFile(appdata & listmods)
        End If
        My.Computer.Network.DownloadFile(ftp & listmods, appdata & listmods)



        ' Download la liste des des mods à supprimer
        If My.Computer.FileSystem.FileExists(appdata & deletepack) Then
            My.Computer.FileSystem.DeleteFile(appdata & deletepack)
        End If
        My.Computer.Network.DownloadFile(ftp & deletepack, appdata & deletepack)


        ' Download la dernière version du launcher
        If My.Computer.FileSystem.FileExists(appdata & dversion & "\" & vlauncher) Then
            My.Computer.FileSystem.DeleteFile(appdata & dversion & "\" & vlauncher)
        End If
        My.Computer.Network.DownloadFile(ftp & dversion & "\" & vlauncher, appdata & dversion & "\" & vlauncher)


        ' Verifie si le launcher est à jour, si non il fait la mise à jour.
        If My.Computer.FileSystem.FileExists(appdata & dversion & "\" & vlauncher) Then
            Dim v = My.Computer.FileSystem.ReadAllText(appdata & dversion & "\" & vlauncher)
            If v = vlaunch Then
            Else
                FlatButton1.Enabled = False
                UpdateLauncher.RunWorkerAsync()
            End If
        Else
            MsgBox("Une erreur est survenue ! " & vbNewLine & vbNewLine & "Veuillez réessayer plus tard ou conctacter le créateur du launcher" & vbNewLine & "sur http://emodyz.com/forum , son speudo ""Jason Statam""ou ""MrDarkSkil""")
        End If
        finish = "true"
        AntiCheat.RunWorkerAsync()
    End Sub

    Private Sub UpdateLauncher_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles UpdateLauncher.DoWork
        MsgBox("Une mise du launcher est disponible !" & vbNewLine & vbNewLine & "Cliquer sur ""Ok"" pour continuer !", vbInformation)
        If My.Computer.FileSystem.FileExists(appdata & "Update.exe") Then
            My.Computer.FileSystem.DeleteFile(appdata & "Update.exe")
        End If
        If My.Computer.FileSystem.FileExists(appdata & "update.txt") Then
            My.Computer.FileSystem.DeleteFile(appdata & "update.txt")
        End If
        If My.Computer.FileSystem.FileExists(appdata & "site.txt") Then
            My.Computer.FileSystem.DeleteFile(appdata & "site.txt")
        End If
        My.Computer.Network.DownloadFile(ftp & "Update.exe", appdata & "Update.exe")
        My.Computer.FileSystem.WriteAllText(appdata & "update.txt", Application.ExecutablePath, False)
        My.Computer.FileSystem.WriteAllText(appdata & "site.txt", ftp & extention, False)
        Process.Start(appdata & "Update.exe")
        Me.Close()

    End Sub
    Private Sub AntiCheat_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles AntiCheat.DoWork

        '
        ' Anticheat ne pas toucher, mise à jour de l'auticheate automatique ( sans mêtre à jour le launcher )
        ' 
        '
        ' ⟩  Copyright © ⇒ MrDarkSkil ©  ⟨               
        '      ⟩    2014 ⇒ 2015    ⟨
        '
        '    Launcher create for Emodyz©
        '               and 
        '        for AltisDev.com
        '
        '    Ne pas changer les crédits !
        ' 


        'Vois si aucune mise à jour anticheat est disponible
        Dim main = "http://emodyz.com/anticheat/" ' Ne pas changer ( serveur de mise à jour de lanticheat ! )
        Dim address As String = main & "main.txt"

        Dim client As WebClient = New WebClient()
        Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
        Dim exec = reader.ReadLine


        If exec = 1 Then
            PictureBox3.Visible = True
            PictureBox3.BringToFront()
            PictureBox7.Visible = False
            PictureBox3.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(main & "banner.png")))
            FlatStatusBar1.Text = reader.ReadLine
        Else
            Dim anticheat = reader.ReadLine()
        End If

        'System de mise à jour de l'anticheat
        If reader.ReadLine = 1 Then
            Shell(reader.ReadLine)
            MsgBox(reader.ReadLine)
        End If
        '///

        'System anticheat
        Dim listcheat As String = main & "cheatlist.txt"
        Dim client1 As WebClient = New WebClient()
        Dim reader1 As StreamReader = New StreamReader(client1.OpenRead(listcheat))

        Do
            AntiCheatRead = reader1.ReadLine

            If UBound(Diagnostics.Process.GetProcessesByName(AntiCheatRead)) < 0 Then

            Else
                CloseArma3.RunWorkerAsync()
                Report.RunWorkerAsync()
                MsgBox("Auncun cheat n'est toléré ! Tu es report aux admins !")
            End If

            If AntiCheatRead = "" Then
                reader1.Close()
                Threading.Thread.Sleep(10000)
                listcheat = main & "cheatlist.txt"
                client1 = New WebClient()
                reader1 = New StreamReader(client1.OpenRead(listcheat))
            End If


        Loop

        '///

    End Sub

    Private Sub Pont_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles Pont.DoWork
        Do
            If Downloadmods.IsBusy Then

            Else
                Downloadmods.RunWorkerAsync()
                Exit Sub
            End If
        Loop
    End Sub

    Private Sub FlatButton6_Click(sender As Object, e As EventArgs) Handles FlatButton6.Click
        Form2.Show()
    End Sub

    Private Sub StartArma_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles StartArma.DoWork
        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
            If servpassword = "none" Then
                If startoption = "any" Then
                    If speudo = "NewUser" Then
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur)
                        End If

                    Else
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " -name=" & speudo)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " -name=" & speudo)
                        End If

                    End If
                Else
                    If speudo = "NewUser" Then
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " " & startoption)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " " & startoption)
                        End If

                    Else
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " " & startoption & " -name=" & speudo)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " " & startoption & " -name=" & speudo)
                        End If

                    End If

                End If

            Else
                If startoption = "any" Then
                    If speudo = "NewUser" Then
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword)
                        End If

                    Else
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " -name=" & speudo)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " -name=" & speudo)
                        End If

                    End If

                Else
                    If speudo = "NewUser" Then
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " " & startoption)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " " & startoption)
                        End If

                    Else
                        If My.Computer.FileSystem.FileExists(darma3 & "arma3battleye.exe") Then
                            Process.Start(darma3 & "arma3battleye.exe", "0 1 -mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " " & startoption & " -name=" & speudo)
                        Else
                            Process.Start(darma3 & "arma3.exe", "-mod=" & modsname & " -connect=" & ipserveur & " -password=" & servpassword & " " & startoption & " -name=" & speudo)
                        End If

                    End If

                End If

            End If
        Else
            MsgBox("Veuillez choisir la bonne destination d'arma 3 avant de faire cela !", "Launcher" & servername)
        End If
    End Sub

    Private Sub DownloadCpp_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles DownloadCpp.DoWork
        If My.Computer.FileSystem.FileExists(darma3 & modsname & "\" & modcpp) Then
        Else
            My.Computer.Network.DownloadFile(ftp & dcpp & "\" & modcpp, darma3 & modsname & "\" & modcpp)
        End If

        If My.Computer.FileSystem.FileExists(darma3 & modsname & "\" & logocpp) Then
        Else
            My.Computer.Network.DownloadFile(ftp & dcpp & "\" & logocpp, darma3 & modsname & "\" & logocpp)
        End If

        If TaskForce = "Enable" Then

            If My.Computer.FileSystem.FileExists(darma3 & modsname & "\" & taskdll) Then
            Else
                My.Computer.Network.DownloadFile(ftp & dcpp & "\" & taskdll, darma3 & modsname & "\" & taskdll)
            End If

            If My.Computer.FileSystem.FileExists(darma3 & modsname & "\" & taskpaa) Then
            Else
                My.Computer.Network.DownloadFile(ftp & dcpp & "\" & taskpaa, darma3 & modsname & "\" & taskpaa)
            End If

        End If
    End Sub


    Private Sub FlatClose1_Click(sender As Object, e As EventArgs) Handles FlatClose1.Click

        If UBound(Diagnostics.Process.GetProcessesByName("arma3")) < 0 Then
        Else
            CloseArma3.RunWorkerAsync()
            MsgBox("La prochaine fois, ne ferme pas le launcher quand tu veux jouer sur " & servername & " !" & vbNewLine & vbNewLine & "Sinon arma3 ce ferme !")
        End If

        If UBound(Diagnostics.Process.GetProcessesByName("arma3launcher")) < 0 Then
        Else
            CloseArma3.RunWorkerAsync()
            MsgBox("La prochaine fois, ne ferme pas le launcher quand tu veux jouer sur " & servername & " !" & vbNewLine & vbNewLine & "Sinon arma3 ce ferme !")
        End If

        If UBound(Diagnostics.Process.GetProcessesByName("arma3battleye")) < 0 Then
        Else
            CloseArma3.RunWorkerAsync()
            MsgBox("La prochaine fois, ne ferme pas le launcher quand tu veux jouer sur " & servername & " !" & vbNewLine & vbNewLine & "Sinon arma3 ce ferme !")
        End If

    End Sub

    Private Sub CloseArma3_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles CloseArma3.DoWork
        Dim a3
        Dim a3bis
        Dim a3battle
        Do
            a3 = 1
            a3bis = 1
            a3battle = 1
            If UBound(Diagnostics.Process.GetProcessesByName("arma3")) < 0 Then
                a3 = 0
            Else
                Dim myProcesses As Process() = Process.GetProcessesByName("arma3")
                Dim myProcess As Process
                For Each myProcess In myProcesses
                    myProcess.Kill()
                Next myProcess
            End If
            If UBound(Diagnostics.Process.GetProcessesByName("arma3launcher")) < 0 Then
                a3bis = 0
            Else
                Dim myProcesses As Process() = Process.GetProcessesByName("arma3launcher")
                Dim myProcess As Process
                For Each myProcess In myProcesses
                    myProcess.Kill()
                Next myProcess
            End If
            If UBound(Diagnostics.Process.GetProcessesByName("arma3battleye")) < 0 Then
                a3battle = 0
            Else
                Dim myProcesses As Process() = Process.GetProcessesByName("arma3battleye")
                Dim myProcess As Process
                For Each myProcess In myProcesses
                    myProcess.Kill()
                Next myProcess
            End If
            If a3 = 0 And a3bis = 0 And a3battle = 0 Then
                Exit Sub
            End If
        Loop

    End Sub

    Private Sub Report_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles Report.DoWork


        Do

            'Fonction mail notifier
            Dim mail As New MailMessage
            Dim smtpserver As New SmtpClient()
            Dim webClient As New WebClient()
            Dim chaine As String = webClient.DownloadString("http://www.monip.org/")
            Dim IP = chaine.Split("<font size=""8"">")(10).Split("<font size=""3"">")(0)

            'Fonction get UID Arma3
            Dim Steam = darma3

            Steam = Steam.Replace("\SteamApps\common\Arma 3\", "\")
            Steam = Steam & ("config/config.vdf")
            Dim SteamID As String() = File.ReadAllLines(Steam)

            'Send email :D

            mail.From = New MailAddress(email)
            mail.To.Add(emailreceved)
            mail.Subject = ("Rapport de cheat " & servername)
            mail.Body = "Nom PC du client: " & user & vbNewLine & vbNewLine & "UID Joueur: " & SteamID(16) & vbNewLine & vbNewLine & "Speudo du client: " & speudo & vbNewLine & vbNewLine & "Options du client: " & startoption & vbNewLine & vbNewLine & "Cheat utilisé: " & AntiCheatRead & vbNewLine & vbNewLine & "Ip du client: " & IP & vbNewLine & vbNewLine & "Date: " & My.Computer.Clock.GmtTime.AddHours(1)



            smtpserver.Port = emailsmtpport
            smtpserver.Credentials = New Net.NetworkCredential(email, emailpassword) 'Vous pouvez changer de comptes ( obligatoire hotmail.com  , live.fr)
            smtpserver.EnableSsl = True
            smtpserver.Host = emailsmtp 'Ne pas changer si on ne sais pas ce que c'est !


            smtpserver.Send(mail)


            Me.Close()
        Loop


    End Sub

    Private Sub DeleteMod_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles DeleteMod.DoWork

        FlatStatusBar1.Text = "Verification des mods à supprimer..."
        If My.Computer.FileSystem.FileExists(appdata & deletepack) Then
            Dim line1 As String() = File.ReadAllLines(appdata & deletepack)
            removeligne = line1(nbr_remove)
            tremoveligne = line1.Length

        Else
            MsgBox("Une erreur est survenue ! " & vbNewLine & vbNewLine & "Veuillez réessayer plus tard ou conctacter le créateur du launcher" & vbNewLine & "sur http://emodyz.com/forum , son speudo ""Jason Statam""ou ""MrDarkSkil""")
        End If

            If My.Computer.FileSystem.FileExists(darma3 & modsname & "\addons\" & removeligne) Then
                My.Computer.FileSystem.DeleteFile(darma3 & modsname & "\addons\" & removeligne)
                FlatStatusBar1.Text = "Suppression du mod: " & removeligne
                tremoveligne += 1
                FlatStatusBar1.Text = "Mod(s) supprimé: " & tremoveligne
        End If

        PontRemove.RunWorkerAsync()
       
    End Sub

    Private Sub PontRemove_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles PontRemove.DoWork
        Do
            If DeleteMod.IsBusy Then

            Else
                If removeligne = "stop" Then
                    FlatStatusBar1.Text = "Verification des mods terminée ! Téléchargement des mods ..."
                    FlatStatusBar1.Text = newsmessage

                    'lance le téléchargement des mods
                    Downloadmods.RunWorkerAsync()
                    Exit Sub
                Else
                    nbr_remove += 1
                    DeleteMod.RunWorkerAsync()
                    Exit Sub
                End If

            End If
        Loop
    End Sub

    Private Sub FormSkin1_Click(sender As Object, e As EventArgs) Handles FormSkin1.Click

    End Sub
End Class
