Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports ICSharpCode.SharpZipLib.Zip
- Imports System.IO
- Imports System.Drawing.Drawing2D
- Public Class Form1
- Dim Temp As String = System.IO.Path.GetTempPath
- Dim Appdata As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
- Dim KillMC As String
- Sub SelectFiles()
- Dim Selecter As New OpenFileDialog
- With Selecter
- .Title = "Select the bin.zip file you would like to load."
- .FileName = ""
- .InitialDirectory = Application.StartupPath
- .Filter = ".zip | *.zip"
- End With
- If Selecter.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = Selecter.FileName
- End Sub
- Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
- Dim Redo As Integer = 1
- Dim MyZipInputStream As ZipInputStream
- Dim MyFileStream As FileStream
- MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
- Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
- Directory.CreateDirectory(ExtractDir)
- While Not MyZipEntry Is Nothing
- If (MyZipEntry.IsDirectory) Then
- Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
- Else
- If Not Directory.Exists(ExtractDir & "\" & _
- Path.GetDirectoryName(MyZipEntry.Name)) Then
- Directory.CreateDirectory(ExtractDir & "\" & _
- Path.GetDirectoryName(MyZipEntry.Name))
- End If
- MyFileStream = New FileStream(ExtractDir & "\" & _
- MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
- Dim count As Integer
- Dim buffer(4096) As Byte
- count = MyZipInputStream.Read(buffer, 0, 4096)
- While count > 0
- MyFileStream.Write(buffer, 0, count)
- count = MyZipInputStream.Read(buffer, 0, 4096)
- End While
- MyFileStream.Close()
- End If
- Try
- MyZipEntry = MyZipInputStream.GetNextEntry
- Catch ex As Exception
- MyZipEntry = Nothing
- End Try
- End While
- If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
- If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
- End Sub
- Function JavaChecker()
- Dim JavaCheck As System.Diagnostics.Process
- For Each JavaCheck In System.Diagnostics.Process.GetProcesses()
- If JavaCheck.ProcessName.Contains("javaw5") Then
- 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")
- Select Case KillMC
- Case vbYes
- Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("javaw")
- For Each p As Process In pProcess
- p.Kill()
- Next
- System.Threading.Thread.Sleep(300)
- Return True
- Case vbNo
- Return False
- MsgBox("Patch aborted.", 0 + 64, "Notice")
- End
- End Select
- End If
- Next
- Return True
- End Function
- Sub ClearBin()
- Dim dir As New IO.DirectoryInfo(Appdata & "\.minecraft\bin")
- Dim filetypes As IO.FileInfo() = dir.GetFiles("*.*")
- Dim file As IO.FileInfo
- For Each file In filetypes
- If Not file.Name = "version" Then
- file.Delete()
- End If
- Next
- Directory.Delete(Appdata & "\.minecraft\bin\natives", True)
- End Sub
- Sub TheEvent()
- If JavaChecker() = False Then Exit Sub
- Timer1.Start()
- If Directory.Exists(Temp & "\bin.zip") Then Directory.Delete(Temp & "\bin.zip")
- File.Delete(Temp & "\verison")
- If CheckBox1.Checked = True Then
- ClearBin()
- ExtractArchive(TextBox1.Text, Appdata & "\.minecraft\bin")
- End If
- If CheckBox1.Checked = False Then
- If Label2.Text.Contains("1.3_01") Then
- ClearBin()
- Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
- TheWriter.Write(My.Resources._1_3_01, 0, My.Resources._1_3_01.Length)
- TheWriter.Close()
- ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
- End If
- If Label2.Text.Contains("1.4") Then
- ClearBin()
- Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
- TheWriter.Write(My.Resources._1_4, 0, My.Resources._1_4.Length)
- TheWriter.Close()
- ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
- End If
- If Label2.Text.Contains("1.2_01") Then
- ClearBin()
- Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
- TheWriter.Write(My.Resources._1_2_01, 0, My.Resources._1_2_01.Length)
- TheWriter.Close()
- ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
- End If
- If Label2.Text.Contains("1.1_02") Then
- ClearBin()
- Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
- TheWriter.Write(My.Resources._1_1_02, 0, My.Resources._1_1_02.Length)
- TheWriter.Close()
- ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
- End If
- If Label2.Text.Contains("1.2_02") Then
- ClearBin()
- Dim TheWriter As System.IO.FileStream = IO.File.Create(Temp & "\bin.zip")
- TheWriter.Write(My.Resources._1_2_02, 0, My.Resources._1_2_02.Length)
- TheWriter.Close()
- ExtractArchive(Temp & "\bin.zip", Appdata & "\.minecraft\bin")
- End If
- End If
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
- If Label2.Text = "" And TextBox1.Text = "" Then
- 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")
- Exit Sub
- End If
- '//Make the form look like it's getting shit done.
- FButton1.Text = "Patching..."
- FButton1.Enabled = False
- ListBox1.Enabled = False
- TextBox1.Enabled = False
- FButton2.Enabled = False
- CheckBox1.Enabled = False
- '//Do the work.
- TheEvent()
- End Sub
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- End
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Label2.Select()
- End Sub
- Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
- If CheckBox1.Checked = True Then
- TextBox1.Enabled = True
- FButton2.Enabled = True
- ListBox1.Enabled = False
- Label2.Text = ""
- Label2.Hide()
- For ListBoxSelectedItemID As Int32 = 0 To ListBox1.Items.Count - 1
- ListBox1.SetSelected(ListBoxSelectedItemID, False)
- Next
- Else
- TextBox1.Enabled = False
- FButton2.Enabled = False
- ListBox1.Enabled = True
- Label2.Text = ""
- Label2.Show()
- End If
- End Sub
- Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
- On Error Resume Next
- If ListBox1.SelectedItems(0).ToString.Contains("1.4") Then
- Label2.Text = "Version 1.4"
- End If
- If ListBox1.SelectedItems(0).ToString.Contains("1.3_01") Then
- Label2.Text = "Version 1.3_01"
- End If
- If ListBox1.SelectedItems(0).ToString.Contains("1.2_01") Then
- Label2.Text = "Version 1.2_01"
- End If
- If ListBox1.SelectedItems(0).ToString.Contains("1.1_02") Then
- Label2.Text = "Version 1.1_02"
- End If
- If ListBox1.SelectedItems(0).ToString.Contains("1.2_02") Then
- Label2.Text = "Version 1.2_02"
- End If
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- If FProgressBar1.Progress >= 99 Then
- FProgressBar1.Progress = 100
- Timer1.Stop()
- Timer1.Enabled = False
- FButton1.Text = "Patch Client"
- FButton1.Enabled = True
- ListBox1.Enabled = True
- TextBox1.Enabled = True
- FButton2.Enabled = True
- CheckBox1.Enabled = True
- CheckBox1.Checked = False
- TextBox1.Text = Nothing
- MsgBox("The requested operation has been compeleted sucessfully; your minecraft is now " & Label2.Text & ".")
- For ListBoxSelectedItemID As Int32 = 0 To ListBox1.Items.Count - 1
- ListBox1.SetSelected(ListBoxSelectedItemID, False)
- Next
- Label2.Text = Nothing
- FProgressBar1.Progress = 0
- Exit Sub
- End If
- FProgressBar1.Progress += 1
- End Sub
- Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
- Process.Start("http://www.minecraftforum.net/viewtopic.php?f=1025&t=110985")
- End Sub
- Private Sub FButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
- If Label2.Text = "" And TextBox1.Text = "" Then
- 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")
- Exit Sub
- End If
- '//Make the form look like it's getting shit done.
- FButton1.Text = "Patching..."
- FButton1.Enabled = False
- ListBox1.Enabled = False
- TextBox1.Enabled = False
- FButton2.Enabled = False
- CheckBox1.Enabled = False
- '//Do the work.
- TheEvent()
- End Sub
- Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End
- End Sub
- Private Sub PictureBox2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
- Me.Cursor = Cursors.Hand
- End Sub
- Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
- Me.Cursor = Cursors.Arrow
- End Sub
- Private Sub FButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton2.Click
- SelectFiles()
- End Sub
- Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
- End
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement