Form1.vb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 
  2. Imports System.Net
  3. Imports System.Text
  4. Imports System.Reflection
  5. Imports Ionic.Zip
  6. Public Class Form1
  7. Private WithEvents client As New Net.WebClient
  8. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9. readTxt()
  10. DownLoadFiles()
  11. 'zipExeAllDeComp("./Debug.zip", "./")
  12. End Sub
  13. Private Sub DownLoadFiles()
  14. 'For Each p As Process In Process.GetProcesses
  15. ' If p.ProcessName = "intelligent-medicine-abinet" Then 'If you don't kNow what your program's process name is,simply run your program,run windows task manager,select 'processes' tab,scroll down untill you find your programs name.
  16. 'p.Kill()
  17. ' End If
  18. 'Next
  19. 'IO.File.Delete("intelligent-medicine-abinet.exe")
  20. client.DownloadFileAsync(New Uri(updateUrl), "Update.zip")
  21. 'client.DownloadFile("https://ehr.yihu.com/hlwyy/zjxl/healthMonitoring/demo/intelligent-medicine-abinet.exe", "intelligent-medicine-abinet_update.exe")
  22. client.Dispose()
  23. End Sub
  24. Private Sub webClient_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles client.DownloadProgressChanged
  25. ProgressBar1.Value = e.ProgressPercentage
  26. 'TextBox1.Text = e.ProgressPercentage.ToString() + "%"
  27. TextBox2.Text = String.Format("正在下载文件,完成进度{0}/{1}(KB)", e.BytesReceived / 1024, e.TotalBytesToReceive / 1024)
  28. End Sub
  29. Private Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles client.DownloadFileCompleted
  30. 'MessageBox.Show("下载程序成功!", "提示", MessageBoxButtons.OK)
  31. If e.Error Is Nothing Then
  32. 'MessageBox.Show("下载程序成功!", "提示", MessageBoxButtons.OK)
  33. Else
  34. MessageBox.Show("下载程序失败!", "提示", MessageBoxButtons.OK)
  35. Application.Exit()
  36. Return
  37. End If
  38. If e.Cancelled = True Then
  39. MessageBox.Show("下载程序取消!", "提示", MessageBoxButtons.OK)
  40. Else
  41. For Each p As Process In Process.GetProcesses
  42. If p.ProcessName = "intelligent-medicine-abinet" Then 'If you don't kNow what your program's process name is,simply run your program,run windows task manager,select 'processes' tab,scroll down untill you find your programs name.
  43. p.Kill()
  44. End If
  45. Next
  46. Threading.Thread.Sleep(5000)
  47. zipExeAllDeComp(AssemPath & "/Update.zip", AssemPath)
  48. 'IO.File.Delete("intelligent-medicine-abinet.exe")
  49. 'IO.File.Move("intelligent-medicine-abinet_update.exe", "intelligent-medicine-abinet.exe")
  50. MessageBox.Show("更新程序成功,请启动程序!", "提示", MessageBoxButtons.OK)
  51. End If
  52. Application.Exit()
  53. End Sub
  54. Private Sub Button1_Click(sender As Object, e As EventArgs)
  55. DownLoadFiles()
  56. End Sub
  57. Public Sub zipExeAllDeComp(ByVal zipFpn As String, DeCompPath As String)
  58. Dim Roptions As ReadOptions = New ReadOptions()
  59. Roptions.Encoding = Encoding.Default '解决zip 解压中文名乱码
  60. Using zip As ZipFile = ZipFile.Read(zipFpn, Roptions)
  61. 'zip.Password = "123456"
  62. Dim fs As Object
  63. fs = CreateObject("Scripting.FileSystemObject")
  64. For Each entry As ZipEntry In zip
  65. Debug.Print("文件名:" & entry.FileName)
  66. If entry.IsDirectory Then
  67. Dim fpath As String = AssemPath & "\" & entry.FileName.Replace("/", "")
  68. If IO.Directory.Exists(fpath) Then
  69. fs.deletefolder(fpath)
  70. End If
  71. 'fs.deletefolder(AssemPath & "\" & entry.FileName.Replace("/", ""))
  72. 'IO.Directory.Delete(entry.FileName)
  73. Else
  74. IO.File.Delete(entry.FileName)
  75. End If
  76. entry.Extract(DeCompPath)
  77. Next
  78. End Using
  79. End Sub
  80. End Class
  81. Module TxtRead
  82. Public updateUrl As String
  83. Public equNumFilePath As String
  84. Public password As String
  85. Public equNum As String
  86. Public app As String = Assembly.GetAssembly(GetType(Form1)).Location
  87. Public AssemPath As String = System.IO.Path.GetDirectoryName(app)
  88. Public Function readTxt()
  89. 'Dim app As String = Assembly.GetAssembly(GetType(Form1)).Location
  90. 'Dim AssemPath As String = System.IO.Path.GetDirectoryName(app)
  91. Debug.Print("1111111:" & AssemPath)
  92. Dim arr
  93. Dim str
  94. Dim i As Long
  95. arr = Split(CreateObject("scripting.filesystemobject").opentextfile(AssemPath & "\Uconfig.txt").readall, vbNewLine)
  96. For i = 0 To UBound(arr)
  97. str = Split(arr(i), "=")
  98. If str(0) = "updateUrl" Then
  99. updateUrl = str(1)
  100. End If
  101. Next
  102. Debug.Print(updateUrl)
  103. End Function
  104. End Module