Advertisement
Guest User

Minecraft Update Controller Source By Vaquxine

a guest
Mar 31st, 2011
3,609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports ICSharpCode.SharpZipLib.Zip
  2. Imports System.IO
  3. Imports System.Drawing.Drawing2D
  4.  
  5. Public Class Form1
  6.     Dim Temp As String = System.IO.Path.GetTempPath
  7.     Dim Appdata As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
  8.     Dim KillMC As String
  9.     Sub SelectFiles()
  10.         Dim Selecter As New OpenFileDialog
  11.         With Selecter
  12.             .Title = "Select the bin.zip file you would like to load."
  13.             .FileName = ""
  14.             .InitialDirectory = Application.StartupPath
  15.             .Filter = ".zip | *.zip"
  16.         End With
  17.  
  18.         If Selecter.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = Selecter.FileName
  19.     End Sub
  20.     Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
  21.         Dim Redo As Integer = 1
  22.         Dim MyZipInputStream As ZipInputStream
  23.         Dim MyFileStream As FileStream
  24.         MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
  25.         Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
  26.         Directory.CreateDirectory(ExtractDir)
  27.         While Not MyZipEntry Is Nothing
  28.             If (MyZipEntry.IsDirectory) Then
  29.                 Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
  30.             Else
  31.                 If Not Directory.Exists(ExtractDir & "\" & _
  32.                 Path.GetDirectoryName(MyZipEntry.Name)) Then
  33.                     Directory.CreateDirectory(ExtractDir & "\" & _
  34.                     Path.GetDirectoryName(MyZipEntry.Name))
  35.                 End If
  36.                 MyFileStream = New FileStream(ExtractDir & "\" & _
  37.                   MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
  38.                 Dim count As Integer
  39.                 Dim buffer(4096) As Byte
  40.                 count = MyZipInputStream.Read(buffer, 0, 4096)
  41.                 While count > 0
  42.                     MyFileStream.Write(buffer, 0, count)
  43.                     count = MyZipInputStream.Read(buffer, 0, 4096)
  44.                 End While
  45.                 MyFileStream.Close()
  46.             End If
  47.             Try
  48.                 MyZipEntry = MyZipInputStream.GetNextEntry
  49.             Catch ex As Exception
  50.                 MyZipEntry = Nothing
  51.             End Try
  52.         End While
  53.         If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
  54.         If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
  55.     End Sub
  56.     Function JavaChecker()
  57.         Dim JavaCheck As System.Diagnostics.Process
  58.         For Each JavaCheck In System.Diagnostics.Process.GetProcesses()
  59.             If JavaCheck.ProcessName.Contains("javaw5") Then
  60.                 KillMC = MsgBox("It would appear minecraft is currently running, it needs to be closed for this program to work; would you like us to close it?", 4 + 48, "Warning")
  61.  
  62.                 Select Case KillMC
  63.                     Case vbYes
  64.                         Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("javaw")
  65.                         For Each p As Process In pProcess
  66.                             p.Kill()
  67.                         Next
  68.                         System.Threading.Thread.Sleep(300)
  69.                         Return True
  70.                     Case vbNo
  71.                         Return False
  72.                         MsgBox("Patch aborted.", 0 + 64, "Notice")
  73.                         End
  74.                 End Select
  75.  
  76.             End If
  77.         Next
  78.         Return True
  79.     End Function
  80.     Sub ClearBin()
  81.         Dim dir As New IO.DirectoryInfo(Appdata & "\.minecraft\bin")
  82.         Dim filetypes As IO.FileInfo() = dir.GetFiles("*.*")
  83.         Dim file As IO.FileInfo
  84.  
  85.         For Each file In filetypes
  86.             If Not file.Name = "version" Then
  87.                 file.Delete()
  88.             End If
  89.         Next
  90.  
  91.         Directory.Delete(Appdata & "\.minecraft\bin\natives", True)
  92.     End Sub
  93.     Sub TheEvent()
  94.         If JavaChecker() = False Then Exit Sub
  95.         Timer1.Start()
  96.  
  97.         If Directory.Exists(Temp & "\bin.zip") Then Directory.Delete(Temp & "\bin.zip")
  98.         File.Delete(Temp & "\verison")
  99.  
  100.         If CheckBox1.Checked = True Then
  101.             ClearBin()
  102.             ExtractArchive(TextBox1.Text, Appdata & "\.minecraft\bin")
  103.         End If
  104.  
  105.         If CheckBox1.Checked = False Then
  106.             If Label2.Text.Contains("1.3_01") Then
  107.                 ClearBin()
  108.  
  109.                 Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
  110.                 TheWriter.Write(My.Resources._1_3_01, 0, My.Resources._1_3_01.Length)
  111.                 TheWriter.Close()
  112.  
  113.                 ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
  114.             End If
  115.             If Label2.Text.Contains("1.4") Then
  116.                 ClearBin()
  117.  
  118.                 Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
  119.                 TheWriter.Write(My.Resources._1_4, 0, My.Resources._1_4.Length)
  120.                 TheWriter.Close()
  121.  
  122.                 ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
  123.             End If
  124.             If Label2.Text.Contains("1.2_01") Then
  125.                 ClearBin()
  126.  
  127.                 Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
  128.                 TheWriter.Write(My.Resources._1_2_01, 0, My.Resources._1_2_01.Length)
  129.                 TheWriter.Close()
  130.  
  131.                 ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
  132.             End If
  133.  
  134.             If Label2.Text.Contains("1.1_02") Then
  135.                 ClearBin()
  136.  
  137.                 Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
  138.                 TheWriter.Write(My.Resources._1_1_02, 0, My.Resources._1_1_02.Length)
  139.                 TheWriter.Close()
  140.  
  141.                 ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
  142.             End If
  143.  
  144.             If Label2.Text.Contains("1.2_02") Then
  145.                 ClearBin()
  146.  
  147.                 Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
  148.                 TheWriter.Write(My.Resources._1_2_02, 0, My.Resources._1_2_02.Length)
  149.                 TheWriter.Close()
  150.  
  151.                 ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
  152.             End If
  153.         End If
  154.     End Sub
  155.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
  156.         If Label2.Text = "" And TextBox1.Text = "" Then
  157.             MsgBox("Please either select a preloaded version from the box above, or select your own bin.zip file to load before trying to update the client!", 0 + 16, "Error")
  158.             Exit Sub
  159.         End If
  160.  
  161.         '//Make the form look like it's getting shit done.
  162.        FButton1.Text = "Patching..."
  163.         FButton1.Enabled = False
  164.         ListBox1.Enabled = False
  165.         TextBox1.Enabled = False
  166.         FButton2.Enabled = False
  167.         CheckBox1.Enabled = False
  168.  
  169.         '//Do the work.
  170.        TheEvent()
  171.     End Sub
  172.  
  173.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  174.         End
  175.     End Sub
  176.  
  177.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  178.         Label2.Select()
  179.     End Sub
  180.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  181.         If CheckBox1.Checked = True Then
  182.             TextBox1.Enabled = True
  183.             FButton2.Enabled = True
  184.             ListBox1.Enabled = False
  185.             Label2.Text = ""
  186.             Label2.Hide()
  187.  
  188.             For ListBoxSelectedItemID As Int32 = 0 To ListBox1.Items.Count - 1
  189.                 ListBox1.SetSelected(ListBoxSelectedItemID, False)
  190.             Next
  191.         Else
  192.             TextBox1.Enabled = False
  193.             FButton2.Enabled = False
  194.             ListBox1.Enabled = True
  195.             Label2.Text = ""
  196.             Label2.Show()
  197.         End If
  198.     End Sub
  199.  
  200.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  201.         On Error Resume Next
  202.         If ListBox1.SelectedItems(0).ToString.Contains("1.4") Then
  203.             Label2.Text = "Version 1.4"
  204.         End If
  205.  
  206.         If ListBox1.SelectedItems(0).ToString.Contains("1.3_01") Then
  207.             Label2.Text = "Version 1.3_01"
  208.         End If
  209.  
  210.         If ListBox1.SelectedItems(0).ToString.Contains("1.2_01") Then
  211.             Label2.Text = "Version 1.2_01"
  212.         End If
  213.  
  214.         If ListBox1.SelectedItems(0).ToString.Contains("1.1_02") Then
  215.             Label2.Text = "Version 1.1_02"
  216.         End If
  217.  
  218.         If ListBox1.SelectedItems(0).ToString.Contains("1.2_02") Then
  219.             Label2.Text = "Version 1.2_02"
  220.         End If
  221.     End Sub
  222.  
  223.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  224.         If FProgressBar1.Progress >= 99 Then
  225.             FProgressBar1.Progress = 100
  226.  
  227.             Timer1.Stop()
  228.             Timer1.Enabled = False
  229.  
  230.             FButton1.Text = "Patch Client"
  231.             FButton1.Enabled = True
  232.             ListBox1.Enabled = True
  233.             TextBox1.Enabled = True
  234.             FButton2.Enabled = True
  235.             CheckBox1.Enabled = True
  236.             CheckBox1.Checked = False
  237.             TextBox1.Text = Nothing
  238.  
  239.             MsgBox("The requested operation has been compeleted sucessfully; your minecraft is now " & Label2.Text & ".")
  240.  
  241.             For ListBoxSelectedItemID As Int32 = 0 To ListBox1.Items.Count - 1
  242.                 ListBox1.SetSelected(ListBoxSelectedItemID, False)
  243.             Next
  244.             Label2.Text = Nothing
  245.  
  246.             FProgressBar1.Progress = 0
  247.             Exit Sub
  248.         End If
  249.  
  250.         FProgressBar1.Progress += 1
  251.     End Sub
  252.  
  253.     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
  254.         Process.Start("http://www.minecraftforum.net/viewtopic.php?f=1025&t=110985")
  255.     End Sub
  256.  
  257.     Private Sub FButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
  258.         If Label2.Text = "" And TextBox1.Text = "" Then
  259.             MsgBox("Please either select a preloaded version from the box above, or select your own bin.zip file to load before trying to update the client!", 0 + 16, "Error")
  260.             Exit Sub
  261.         End If
  262.  
  263.         '//Make the form look like it's getting shit done.
  264.        FButton1.Text = "Patching..."
  265.         FButton1.Enabled = False
  266.         ListBox1.Enabled = False
  267.         TextBox1.Enabled = False
  268.         FButton2.Enabled = False
  269.         CheckBox1.Enabled = False
  270.  
  271.         '//Do the work.
  272.        TheEvent()
  273.     End Sub
  274.  
  275.     Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  276.         End
  277.     End Sub
  278.  
  279.     Private Sub PictureBox2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
  280.         Me.Cursor = Cursors.Hand
  281.     End Sub
  282.  
  283.     Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
  284.         Me.Cursor = Cursors.Arrow
  285.     End Sub
  286.  
  287.     Private Sub FButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton2.Click
  288.         SelectFiles()
  289.     End Sub
  290.  
  291.     Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
  292.         End
  293.     End Sub
  294. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement