Form2.vb 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. 
  2. Imports Microsoft.Win32
  3. Imports System.IO
  4. Imports System.Net
  5. Imports System.CodeDom.Compiler
  6. Imports fLaSh.Dissembler
  7. Public Class form2
  8. Dim wheretosave As String
  9. Dim uriSource As Uri
  10. Dim downloading As New Net.WebClient
  11. Dim timerID As IntPtr = 0
  12. Dim downloadSpeed As Integer = 0
  13. Dim currBytes As Long
  14. Dim prevBytes As Long
  15. Dim startTime As Long
  16. Dim elapsedTime As TimeSpan
  17. Dim downloadStarted As Boolean = False
  18. Sub setupEventHandlers()
  19. Try
  20. AddHandler downloading.DownloadProgressChanged, AddressOf getDownloadProgress
  21. AddHandler downloading.DownloadFileCompleted, AddressOf downloadHasEnded
  22. AddHandler SystemEvents.TimerElapsed, AddressOf downloadUpdating
  23. Catch exc As Exception
  24. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  25. MessageBoxIcon.Information)
  26. End Try
  27. End Sub
  28. Sub downloadUpdating(ByVal sender As Object, ByVal e As Microsoft.Win32.TimerElapsedEventArgs)
  29. Try
  30. elapsedTime = TimeSpan.FromTicks((Now.Ticks - startTime))
  31. lblElapsedTime.Text = "Elapsed Time: " & String.Format("{0:00}:{1:00}:{2:00}", _
  32. elapsedTime.TotalHours, elapsedTime.Minutes, elapsedTime.Seconds)
  33. downloadSpeed = (currBytes - prevBytes)
  34. lblSpeedKbytes.Text = "Speed: " & FormatNumber(downloadSpeed / 1000, 2).ToString & " KB/s"
  35. prevBytes = currBytes
  36. Catch exc As Exception
  37. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  38. MessageBoxIcon.Information)
  39. End Try
  40. End Sub
  41. Sub doDownload()
  42. Try
  43. downloading.DownloadFileAsync(uriSource, Label1.Text)
  44. downloadStarted = True
  45. btnCancel.Enabled = True
  46. Catch exc As Exception
  47. downloadStarted = False
  48. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  49. MessageBoxIcon.Information)
  50. End Try
  51. End Sub
  52. Sub downloadHasEnded(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
  53. Try
  54. If e.Cancelled Then
  55. LblStatus.Text = "Status: Canceled"
  56. Else
  57. LblStatus.Text = "Status: Finished!"
  58. End If
  59. btnCancel.Enabled = False
  60. If timerID.ToInt32 > 0 Then
  61. SystemEvents.KillTimer(timerID)
  62. timerID = Nothing
  63. End If
  64. Catch exc As Exception
  65. MessageBox.Show(e.Error.Message, " Info!", MessageBoxButtons.OK, _
  66. MessageBoxIcon.Information)
  67. End Try
  68. End Sub
  69. Sub getDownloadProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
  70. Try
  71. pbDownloadProgress.Value = e.ProgressPercentage
  72. lblProgress.Text = "Progress: " & e.ProgressPercentage.ToString & "%"
  73. lblDownloadBytes.Text = "Downloaded: " & FormatNumber(e.BytesReceived / 1000, 2).ToString & " KB"
  74. lblDownloadSize.Text = "Download Size: " & FormatNumber(e.TotalBytesToReceive / 1000, 2).ToString & " KB"
  75. currBytes = e.BytesReceived
  76. Catch exc As Exception
  77. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  78. MessageBoxIcon.Information)
  79. End Try
  80. End Sub
  81. Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  82. End Sub
  83. Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  84. Try
  85. If timerID.ToInt32 > 0 Then
  86. SystemEvents.KillTimer(timerID)
  87. timerID = Nothing
  88. End If
  89. downloading.CancelAsync()
  90. Catch exc As Exception
  91. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  92. MessageBoxIcon.Information)
  93. End Try
  94. End Sub
  95. Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  96. End Sub
  97. Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  98. MessageBox.Show("Attention ! Ne choisis pas la nouvelle version de minecraft mais le launcher ! C'est très important !!!", "Warning - Minecraft AutoUpdater", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  99. Dim ofd As New OpenFileDialog
  100. ofd.FilterIndex = 1
  101. ofd.Filter = "Exe (*.exe)|*.exe"
  102. ofd.ShowDialog()
  103. TextBox1.Text = ofd.FileName
  104. Try
  105. SaveProperties(TextBox1.Text)
  106. Catch ex As Exception
  107. MessageBox.Show(ex.Message)
  108. End Try
  109. End Sub
  110. Private Sub SaveProperties(ByVal sPath As String)
  111. Dim web As New WebClient
  112. Dim checkversion As String = web.DownloadString("http://pulsor.fileave.com/Version.txt")
  113. Try
  114. If Not File.Exists(sPath) Then
  115. Throw New Exception("Exe not found!")
  116. End If
  117. Cursor.Current = Cursors.WaitCursor
  118. Application.DoEvents()
  119. Dim oVersionResource As New VersionResource()
  120. oVersionResource.LoadFrom(sPath)
  121. '
  122. oVersionResource.ProductVersion = checkversion
  123. '
  124. Dim oStringFileInfo As StringFileInfo = DirectCast(oVersionResource("StringFileInfo"), StringFileInfo)
  125. oStringFileInfo("ProductVersion") = String.Format("{0}" & vbNullChar, oVersionResource.ProductVersion)
  126. oStringFileInfo("Assembly Version") = String.Format("{0}" & vbNullChar, oVersionResource.ProductVersion)
  127. oVersionResource.SaveTo(sPath)
  128. MessageBox.Show("Done!")
  129. Catch ex As Exception
  130. MessageBox.Show(ex.Message)
  131. Finally
  132. Cursor.Current = Cursors.Default
  133. End Try
  134. End Sub
  135. Private Sub Getlinkdownload()
  136. Dim web As New WebClient
  137. Dim getver As String = web.DownloadString("http://pulsor.fileave.com/DownloadAddress.txt")
  138. txtDownloadAddress.Text = getver
  139. End Sub
  140. Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  141. form2.CheckForIllegalCrossThreadCalls = False
  142. Dim thread As New System.Threading.Thread(AddressOf Getlinkdownload)
  143. thread.Start()
  144. System.Threading.Thread.Sleep(1000)
  145. Try
  146. setupEventHandlers()
  147. Catch exc As Exception
  148. MessageBox.Show(exc.Message, " Info!", MessageBoxButtons.OK, _
  149. MessageBoxIcon.Information)
  150. End Try
  151. Try
  152. Dim saveDLG As New SaveFileDialog
  153. Dim ext As String = "|Exe(*.exe)|*.exe"
  154. saveDLG.Filter = "All Files (*.*)|*.*" & ext '"Exe (*.exe)|*.exe"
  155. saveDLG.Title = "ClanLSE - Minecraft Launcher"
  156. If saveDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
  157. Label1.Text = saveDLG.FileName
  158. End If
  159. uriSource = New Uri(txtDownloadAddress.Text)
  160. timerID = SystemEvents.CreateTimer((1000))
  161. doDownload()
  162. startTime = Now.Ticks
  163. currBytes = 0
  164. prevBytes = 0
  165. downloadSpeed = 0
  166. pbDownloadProgress.Value = 0
  167. LblStatus.Text = "Status: Started"
  168. Catch exc As Exception
  169. MessageBox.Show(exc.Message, " Download Button!", MessageBoxButtons.OK, _
  170. MessageBoxIcon.Information)
  171. End Try
  172. End Sub
  173. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
  174. End Sub
  175. Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
  176. End Sub
  177. End Class