Advertisement
Guest User

Launcher code

a guest
Dec 22nd, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.87 KB | None | 0 0
  1. Imports System
  2. Imports System.IO
  3. Imports System.ComponentModel
  4. Imports Microsoft.Win32
  5. Imports System.Diagnostics
  6. Imports System.IO.PathTooLongException
  7.  
  8. Public Class Form1
  9.     Dim tRestant As Integer
  10.     Dim tEcoule As Integer
  11.     Dim TailleFichier As Integer = 0
  12.     Dim TailleFichier2 As Integer = 0
  13.     Dim seconde As Boolean = True
  14.     Dim min As Integer = 0
  15.     Dim max As Integer = 1
  16.     Dim pbarvalue As Integer = 0
  17.     Dim directory As String = "nochange"
  18.     Dim file As String
  19.     Private Sub UnRar(ByVal filepath As String, ByVal WorkingDirectory As String)
  20.  
  21.         Dim objRegKey As RegistryKey
  22.         objRegKey = Registry.ClassesRoot.OpenSubKey("WinRAR\Shell\Open\Command")
  23.  
  24.         Dim obj As Object = objRegKey.GetValue("")
  25.  
  26.         Dim objRarPath As String = obj.ToString()
  27.         objRarPath = objRarPath.Substring(1, objRarPath.Length - 7)
  28.  
  29.         objRegKey.Close()
  30.  
  31.         Dim objArguments As String
  32.         objArguments = " X " & " " & filepath & " " + " " + WorkingDirectory
  33.  
  34.         Dim objStartInfo As New ProcessStartInfo()
  35.         objStartInfo.UseShellExecute = False
  36.         objStartInfo.FileName = objRarPath
  37.         objStartInfo.Arguments = objArguments
  38.         objStartInfo.WindowStyle = ProcessWindowStyle.Hidden
  39.         objStartInfo.WorkingDirectory = WorkingDirectory & ""
  40.  
  41.         Dim objProcess As New Process()
  42.         objProcess.StartInfo = objStartInfo
  43.         objProcess.Start()
  44.  
  45.     End Sub
  46.     Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
  47.         FolderBrowserDialog1.ShowDialog()
  48.         directory = FolderBrowserDialog1.SelectedPath
  49.         My.Computer.FileSystem.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma")
  50.         My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\directory.a3", directory, False)
  51.     End Sub
  52.  
  53.     Private Sub FlatButton5_Click(sender As Object, e As EventArgs) Handles FlatButton5.Click
  54.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\directory.a3") Then
  55.             file = My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\directory.a3") & "\arma3.exe"
  56.             Process.Start(file)
  57.         Else
  58.             MsgBox("Veuillez spécifier le chemin de votre dossier ArmA III !", MsgBoxStyle.Critical, "Erreur")
  59.         End If
  60.  
  61.     End Sub
  62.     Private Sub FlatButton2_Click(sender As Object, e As EventArgs) Handles FlatButton2.Click
  63.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\size.txt") Or My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar") Then
  64.             MsgBox("Vous avez déjà téléchargé le mod ! Vérifiez si une mise à jour est disponible", MsgBoxStyle.Exclamation, "Erreur")
  65.         Else
  66.             If directory = "nochange" Then
  67.                 MsgBox("Veuillez sélectionner le répertoire d'Arma 3 !", MsgBoxStyle.Critical, "Erreur")
  68.             Else
  69.                 tEcoule = 0
  70.                 PictureBox1.Visible = False
  71.                 FlatProgressBar1.Visible = True
  72.                 FlatLabel1.Visible = True
  73.                 FlatLabel2.Visible = True
  74.                 FlatLabel3.Visible = True
  75.                 Timer2.Start()
  76.                 BackgroundWorker1.RunWorkerAsync()
  77.             End If
  78.         End If
  79.     End Sub
  80.  
  81.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  82.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\directory.a3") Then
  83.             directory = My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\directory.a3")
  84.         Else
  85.             MsgBox("Veuillez sélectionner votre répertoire d'Arma 3 avant tout !", MsgBoxStyle.Information, "Priorité")
  86.         End If
  87.     End Sub
  88.  
  89.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  90.         Dim FichierInfo As System.IO.FileInfo = New System.IO.FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar")
  91.         Dim TailleFichier As Integer = FichierInfo.Length
  92.         Dim size As Integer = My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\size.txt")
  93.         pbarvalue = TailleFichier / size * 100
  94.         FlatProgressBar1.Value = pbarvalue
  95.         If pbarvalue = 100 Then
  96.             FlatButton6.Visible = True
  97.             Timer3.Stop()
  98.             Timer1.Stop()
  99.             MsgBox("Les Addons ont finit d'être téléchargé !", MsgBoxStyle.Information, "Terminé")
  100.  
  101.         End If
  102.     End Sub
  103.  
  104.     Private Sub FlatButton4_Click(sender As Object, e As EventArgs) Handles FlatButton4.Click
  105.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt") Then
  106.             My.Computer.Network.DownloadFile("ftp://user:motdepasse@85.214.88.140/maj.txt", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt")
  107.             If My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt") = My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt") Then
  108.                 My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt")
  109.                 MsgBox("Il n'y a pas de nouvelle mise à jour disponible !", MsgBoxStyle.Information, "Addons à jour")
  110.             ElseIf My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt") <> My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt") Then
  111.                 My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt")
  112.                 My.Computer.FileSystem.RenameFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt", "maj-OLD.txt")
  113.                 My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\size.txt")
  114.                 My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar")
  115.                 tEcoule = 0
  116.                 PictureBox1.Visible = False
  117.                 FlatProgressBar1.Visible = True
  118.                 FlatLabel1.Visible = True
  119.                 FlatLabel2.Visible = True
  120.                 FlatLabel3.Visible = True
  121.                 Timer2.Start()
  122.                 BackgroundWorker1.RunWorkerAsync()
  123.             End If
  124.         Else
  125.             MsgBox("Veuillez d'abords télécharger les Mods !", MsgBoxStyle.Exclamation, "Erreur")
  126.         End If
  127.     End Sub
  128.  
  129.     Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
  130.         Timer1.Start()
  131.         Timer3.Start()
  132.         Timer2.Stop()
  133.     End Sub
  134.  
  135.     Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  136.         My.Computer.Network.DownloadFile("ftp://user:motdepasse@85.214.88.140/size.txt", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\size.txt")
  137.         My.Computer.Network.DownloadFile("ftp://user:motdepasse@85.214.88.140/Addon.rar", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar")
  138.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt") Then
  139.             My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj.txt")
  140.         ElseIf My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt") Then
  141.             My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt")
  142.         End If
  143.         My.Computer.Network.DownloadFile("ftp://user:motdepasse@85.214.88.140/maj.txt", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\maj-OLD.txt")
  144.     End Sub
  145.  
  146.     Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
  147.         Dim size As Integer = My.Computer.FileSystem.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\size.txt")
  148.         tEcoule += 1
  149.         FlatLabel1.Text = "Temps écoulé : " & tEcoule
  150.         If seconde = True Then
  151.             Dim FichierInfo As System.IO.FileInfo = New System.IO.FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar")
  152.             TailleFichier = FichierInfo.Length
  153.             FlatLabel3.Text = "Vitesse de télechargement : " & (TailleFichier - TailleFichier2) / 1000 & " Ko/s"
  154.             tRestant = (size - TailleFichier) / (TailleFichier - TailleFichier2)
  155.             seconde = False
  156.         ElseIf seconde = False Then
  157.             Dim FichierInfo As System.IO.FileInfo = New System.IO.FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar")
  158.             TailleFichier2 = FichierInfo.Length
  159.             FlatLabel3.Text = "Vitesse de télechargement : " & (TailleFichier2 - TailleFichier) / 1000 & " Ko/s"
  160.             seconde = True
  161.             tRestant = (size - TailleFichier) / (TailleFichier2 - TailleFichier)
  162.         End If
  163.         FlatLabel2.Text = "Temps restant : " & tRestant
  164.     End Sub
  165.  
  166.     Private Sub FlatButton6_Click(sender As Object, e As EventArgs) Handles FlatButton6.Click
  167.         If My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\LauncherArma") Then
  168.             My.Computer.FileSystem.DeleteDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\LauncherArma", FileIO.DeleteDirectoryOption.DeleteAllContents)
  169.         End If
  170.         If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\modsname.txt") Then
  171.             My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\modsname.txt")
  172.         End If
  173.         My.Computer.FileSystem.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\LauncherArma")
  174.         UnRar(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Addon.rar", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\LauncherArma")
  175.         Dim ligne As String
  176.         My.Computer.Network.DownloadFile("ftp://user:motdepasse@85.214.88.140/modsname.txt", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\modsname.txt")
  177.         Dim sr As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\LauncherArma\modsname.txt")
  178.         While sr.Peek <> -1
  179.             ligne = sr.ReadLine()
  180.             My.Computer.FileSystem.CopyDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\LauncherArma\" & ligne, directory & "\" & ligne, True)
  181.         End While
  182.         PictureBox1.Visible = True
  183.         FlatButton6.Visible = False
  184.         FlatProgressBar1.Visible = False
  185.         FlatLabel1.Visible = False
  186.         FlatLabel2.Visible = False
  187.         FlatLabel3.Visible = False
  188.     End Sub
  189. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement