Form6.vb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. Imports System.Net
  2. Imports System
  3. Imports System.IO
  4. Public Class Form6
  5. Dim WithEvents WC As New WebClient
  6. Dim appPath As String = Application.StartupPath()
  7. Dim up As String
  8. Private IsFormBeingDragged As Boolean = False
  9. Private MouseDownX As Integer
  10. Dim file As System.IO.FileStream
  11. Private MouseDownY As Integer
  12. Dim downweb As String
  13. Dim z As String
  14. Dim road As String
  15. Private Sub Form6_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  16. For counter = 10 To 90 Step +20
  17. Me.Opacity = counter / 100
  18. Me.Refresh()
  19. Threading.Thread.Sleep(50)
  20. Next
  21. Me.Opacity = 100
  22. For Each Dir As String In Directory.GetDirectories(appPath & "\system\minecraft")
  23. Dim filePath As String = Dir
  24. Dim split As String() = filePath.Split("\")
  25. Dim parentFolder As String = split(split.Length - 1)
  26. ListBox2.Items.Add(parentFolder)
  27. Next
  28. If My.Computer.FileSystem.FileExists(appPath & "\system\update.wtc") Then
  29. Try
  30. My.Computer.FileSystem.DeleteFile(appPath & "\system\update.wtc")
  31. Label1.Text = "正在刪除舊資料…"
  32. Catch ex As Exception
  33. End Try
  34. End If
  35. Label1.Text = "正連接伺服器取得最新更新列表"
  36. WC.DownloadFileAsync(New Uri("http://hkwtc.no-ip.org:8080/hkwtcbs/DreamMelody/Download/update.txt"), appPath & "\system\update.wtc")
  37. End Sub
  38. Private Sub Form6_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
  39. If e.Button = MouseButtons.Left Then
  40. IsFormBeingDragged = True
  41. MouseDownX = e.X
  42. MouseDownY = e.Y
  43. End If
  44. End Sub
  45. Private Sub Form6_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
  46. If e.Button = MouseButtons.Left Then
  47. IsFormBeingDragged = False
  48. End If
  49. End Sub
  50. Private Sub Form6_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
  51. If IsFormBeingDragged Then
  52. Dim temp As Point = New Point()
  53. temp.X = Me.Location.X + (e.X - MouseDownX)
  54. temp.Y = Me.Location.Y + (e.Y - MouseDownY)
  55. Me.Location = temp
  56. temp = Nothing
  57. End If
  58. End Sub
  59. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  60. If My.Computer.FileSystem.FileExists(appPath & "\system\update.wtc") Then
  61. Try
  62. up = My.Computer.FileSystem.ReadAllText(appPath & "\system\update.wtc")
  63. Timer1.Enabled = False
  64. 'Display
  65. Dim theObjContents As New ArrayList
  66. Using objReader As New IO.StreamReader(appPath & "\system\update.wtc")
  67. While objReader.EndOfStream = False
  68. ListBox1.Items.Add(objReader.ReadLine)
  69. Label1.Text = "已下載最新列表"
  70. End While
  71. End Using
  72. Catch ex As Exception
  73. Label1.Text = ex.Message
  74. End Try
  75. Else
  76. Label1.Text = "出現了錯誤,請檢查網絡"
  77. End If
  78. End Sub
  79. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  80. Dim iCount As Integer
  81. For iCount = 90 To 10 Step -10
  82. Me.Opacity = iCount / 100
  83. Threading.Thread.Sleep(50)
  84. Next
  85. Me.Close()
  86. End Sub
  87. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  88. End Sub
  89. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  90. Timer2.Enabled = True
  91. downweb = ListBox1.SelectedItem
  92. downweb = Replace(downweb, vbCrLf, "")
  93. downweb = Replace(downweb, vbNewLine, "")
  94. If ListBox1.SelectedItem = "" Then
  95. Label1.Text = "請選擇更新版本"
  96. Else
  97. If My.Computer.FileSystem.FileExists(appPath & "\system\data\download.wtc") Then
  98. My.Computer.FileSystem.DeleteFile(appPath & "\system\data\download.wtc")
  99. End If
  100. If My.Computer.FileSystem.DirectoryExists(appPath & "\system\minecraft\" & downweb) = True Then
  101. Label1.Text = "這版本已經存在,請先刪除舊版本再重新安裝。"
  102. ElseIf My.Computer.FileSystem.DirectoryExists(appPath & "\system\minecraft\" & downweb) = False Then
  103. Try
  104. file = System.IO.File.Create(appPath & "\system\data\download.wtc")
  105. file.Dispose()
  106. Dim sb As New System.Text.StringBuilder
  107. sb.AppendLine(downweb)
  108. IO.File.WriteAllText((appPath & "\system\data\download.wtc"), sb.ToString(), System.Text.Encoding.GetEncoding(950))
  109. Threading.Thread.Sleep(100)
  110. Form7.Show()
  111. Catch ex As Exception
  112. End Try
  113. Else
  114. Label1.Text = "出現錯誤了"
  115. End If
  116. End If
  117. End Sub
  118. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  119. If My.Computer.FileSystem.DirectoryExists(appPath & "\system\minecraft") Then
  120. Try
  121. System.IO.Directory.Delete(appPath & "\system\minecraft\", FileIO.DeleteDirectoryOption.DeleteAllContents)
  122. Catch ex As Exception
  123. MsgBox(ex.Message)
  124. End Try
  125. Threading.Thread.Sleep(50)
  126. ListBox2.Items.Clear()
  127. Try
  128. For Each Dir As String In Directory.GetDirectories(appPath & "\system\minecraft")
  129. Dim filePath As String = Dir
  130. Dim split As String() = filePath.Split("\")
  131. Dim parentFolder As String = split(split.Length - 1)
  132. ListBox2.Items.Add(parentFolder)
  133. Next
  134. Catch ex As Exception
  135. End Try
  136. If My.Computer.FileSystem.DirectoryExists(appPath & "\system\minecraft") = False Then
  137. My.Computer.FileSystem.CreateDirectory(appPath & "\system\minecraft")
  138. End If
  139. End If
  140. End Sub
  141. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  142. If My.Computer.FileSystem.DirectoryExists(appPath & "\system\minecraft") Then
  143. Try
  144. System.IO.Directory.Delete(appPath & "\system\minecraft\" & ListBox2.SelectedItem, True)
  145. Catch ex As Exception
  146. MsgBox(ex.Message)
  147. End Try
  148. Threading.Thread.Sleep(50)
  149. ListBox2.Items.Clear()
  150. For Each Dir As String In Directory.GetDirectories(appPath & "\system\minecraft")
  151. Dim filePath As String = Dir
  152. Dim split As String() = filePath.Split("\")
  153. Dim parentFolder As String = split(split.Length - 1)
  154. ListBox2.Items.Add(parentFolder)
  155. Timer2.Enabled = False
  156. Next
  157. End If
  158. End Sub
  159. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  160. If My.Computer.FileSystem.FileExists(appPath & "\system\data\download.wtc") = False Then
  161. ListBox2.Items.Clear()
  162. For Each Dir As String In Directory.GetDirectories(appPath & "\system\minecraft")
  163. Dim filePath As String = Dir
  164. Dim split As String() = filePath.Split("\")
  165. Dim parentFolder As String = split(split.Length - 1)
  166. ListBox2.Items.Add(parentFolder)
  167. Timer2.Enabled = False
  168. Next
  169. End If
  170. End Sub
  171. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  172. Dim fd As OpenFileDialog = New OpenFileDialog()
  173. Dim strFileName As String
  174. Try
  175. fd.Title = "請選擇匯入的安裝檔"
  176. fd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
  177. fd.Filter = "夢裡的音符安裝檔|*.nar"
  178. fd.FilterIndex = 2
  179. fd.RestoreDirectory = True
  180. Catch ex As Exception
  181. End Try
  182. If fd.ShowDialog() = DialogResult.OK Then
  183. strFileName = fd.FileName
  184. TextBox1.Text = strFileName
  185. Threading.Thread.Sleep(50)
  186. If My.Computer.FileSystem.FileExists(appPath & "\system\data\install.exe") Then
  187. My.Computer.FileSystem.DeleteFile(appPath & "\system\data\install.exe")
  188. End If
  189. Threading.Thread.Sleep(200)
  190. My.Computer.FileSystem.CopyFile(TextBox1.Text, appPath & "\system\data\install.exe")
  191. Shell(appPath & "\system\data\install.exe")
  192. Threading.Thread.Sleep(50)
  193. Dim filePath As String = TextBox1.Text
  194. Dim split As String() = filePath.Split(".")
  195. Dim parentFolder As String = split(split.Length - 2)
  196. Threading.Thread.Sleep(200)
  197. Do Until My.Computer.FileSystem.FileExists(appPath & "\info.txt")
  198. Label1.Text = "載入匯入安裝檔資訊…"
  199. Loop
  200. Do Until My.Computer.FileSystem.FileExists(appPath & "\info.txt") = False
  201. Try
  202. road = My.Computer.FileSystem.ReadAllText(appPath & "\info.txt")
  203. Threading.Thread.Sleep(200)
  204. Try
  205. Do While My.Computer.FileSystem.FileExists(appPath & "\info.txt") = True
  206. Try
  207. My.Computer.FileSystem.CopyDirectory(appPath & "\" & road, appPath & "\system\minecraft\" & road)
  208. My.Computer.FileSystem.DeleteDirectory(appPath & "\" & road, FileIO.DeleteDirectoryOption.DeleteAllContents)
  209. Timer2.Enabled = True
  210. Catch ex As Exception
  211. End Try
  212. If My.Computer.FileSystem.FileExists(appPath & "\info.txt") Then
  213. My.Computer.FileSystem.DeleteFile(appPath & "\info.txt")
  214. End If
  215. Loop
  216. Catch ex As Exception
  217. End Try
  218. Catch ex As Exception
  219. End Try
  220. Loop
  221. End If
  222. End Sub
  223. End Class