Guest User

Untitled

a guest
Feb 23rd, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Net
  3. Imports Ionic.Zip
  4.  
  5. Public Class Form1
  6. Dim ver As String
  7. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8. Dim client As WebClient = New WebClient()
  9. Dim localver
  10. ver = client.DownloadString("http://skymoders.pl/api/verlauncher.txt")
  11. If My.Computer.FileSystem.FileExists("C:\skymoders\launcher\verl.txt") Then
  12. Dim sr As StreamReader = New StreamReader("C:\skymoders\launcher\verl.txt")
  13. localver = sr.ReadToEnd
  14. End If
  15.  
  16.  
  17. Dim client1 As WebClient = New WebClient()
  18. AddHandler client1.DownloadProgressChanged, AddressOf client1_ProgressChanged
  19. AddHandler client1.DownloadFileCompleted, AddressOf client1_DownloadCompleted
  20.  
  21. If localver = ver Then
  22. Process.Start("C:\skymoders\launcher\SkyModers.exe")
  23. Me.Close()
  24. Else
  25. My.Computer.FileSystem.CreateDirectory("C:\skymoders\launcher")
  26. Try
  27. client1.DownloadFileTaskAsync(New Uri("http://skymoders.pl/api/Launcher.zip"), "C:\skymoders\launcher.zip")
  28. Catch
  29. MsgBox("Błąd połączenia, sprawdz połączenie internetowe")
  30. End Try
  31. End If
  32. End Sub
  33. Private Sub client1_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
  34. Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
  35. Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
  36. Dim percentage As Double = bytesIn / totalBytes * 100
  37. ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
  38. End Sub
  39. Private Sub client1_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
  40. Try
  41. Console.WriteLine("C:\skymoders\launcher.zip")
  42. Dim MCLibFile = "C:\skymoders\launcher.zip"
  43. Dim ZipToUnpack As String = MCLibFile
  44. Dim UnpackDirectory As String = "C:\skymoders\launcher"
  45. Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
  46. Dim eb As ZipEntry
  47. ' here, we extract every entry, but we could extract conditionally,
  48. ' based on entry name, size, date, checkbox status, etc.
  49. For Each eb In zip1
  50. eb.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
  51. Next
  52. End Using
  53. Catch
  54.  
  55. End Try
  56. File.WriteAllText("C:\skymoders\launcher\verl.txt", ver)
  57. Process.Start("C:\skymoders\launcher\SkyModers.exe")
  58. Me.Close()
  59. End Sub
  60. End Class
Advertisement
Add Comment
Please, Sign In to add comment