123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
-
- Imports System.Net
- Imports System.Text
- Imports System.Reflection
- Imports Ionic.Zip
- Public Class Form1
- Private WithEvents client As New Net.WebClient
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- readTxt()
- DownLoadFiles()
- 'zipExeAllDeComp("./Debug.zip", "./")
- End Sub
- Private Sub DownLoadFiles()
- 'For Each p As Process In Process.GetProcesses
- ' 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.
- 'p.Kill()
- ' End If
- 'Next
- 'IO.File.Delete("intelligent-medicine-abinet.exe")
- client.DownloadFileAsync(New Uri(updateUrl), "Update.zip")
- 'client.DownloadFile("https://ehr.yihu.com/hlwyy/zjxl/healthMonitoring/demo/intelligent-medicine-abinet.exe", "intelligent-medicine-abinet_update.exe")
- client.Dispose()
- End Sub
- Private Sub webClient_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles client.DownloadProgressChanged
- ProgressBar1.Value = e.ProgressPercentage
- 'TextBox1.Text = e.ProgressPercentage.ToString() + "%"
- TextBox2.Text = String.Format("正在下载文件,完成进度{0}/{1}(KB)", e.BytesReceived / 1024, e.TotalBytesToReceive / 1024)
- End Sub
- Private Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles client.DownloadFileCompleted
- 'MessageBox.Show("下载程序成功!", "提示", MessageBoxButtons.OK)
- If e.Error Is Nothing Then
- 'MessageBox.Show("下载程序成功!", "提示", MessageBoxButtons.OK)
- Else
- MessageBox.Show("下载程序失败!", "提示", MessageBoxButtons.OK)
- Application.Exit()
- Return
- End If
- If e.Cancelled = True Then
- MessageBox.Show("下载程序取消!", "提示", MessageBoxButtons.OK)
- Else
- For Each p As Process In Process.GetProcesses
- 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.
- p.Kill()
- End If
- Next
- Threading.Thread.Sleep(5000)
- zipExeAllDeComp(AssemPath & "/Update.zip", AssemPath)
- 'IO.File.Delete("intelligent-medicine-abinet.exe")
- 'IO.File.Move("intelligent-medicine-abinet_update.exe", "intelligent-medicine-abinet.exe")
- MessageBox.Show("更新程序成功,请启动程序!", "提示", MessageBoxButtons.OK)
- End If
- Application.Exit()
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs)
- DownLoadFiles()
- End Sub
- Public Sub zipExeAllDeComp(ByVal zipFpn As String, DeCompPath As String)
- Dim Roptions As ReadOptions = New ReadOptions()
- Roptions.Encoding = Encoding.Default '解决zip 解压中文名乱码
- Using zip As ZipFile = ZipFile.Read(zipFpn, Roptions)
- 'zip.Password = "123456"
- Dim fs As Object
- fs = CreateObject("Scripting.FileSystemObject")
- For Each entry As ZipEntry In zip
- Debug.Print("文件名:" & entry.FileName)
- If entry.IsDirectory Then
- Dim fpath As String = AssemPath & "\" & entry.FileName.Replace("/", "")
- If IO.Directory.Exists(fpath) Then
- fs.deletefolder(fpath)
- End If
- 'fs.deletefolder(AssemPath & "\" & entry.FileName.Replace("/", ""))
- 'IO.Directory.Delete(entry.FileName)
- Else
- IO.File.Delete(entry.FileName)
- End If
- entry.Extract(DeCompPath)
- Next
- End Using
- End Sub
- End Class
- Module TxtRead
- Public updateUrl As String
- Public equNumFilePath As String
- Public password As String
- Public equNum As String
- Public app As String = Assembly.GetAssembly(GetType(Form1)).Location
- Public AssemPath As String = System.IO.Path.GetDirectoryName(app)
- Public Function readTxt()
- 'Dim app As String = Assembly.GetAssembly(GetType(Form1)).Location
- 'Dim AssemPath As String = System.IO.Path.GetDirectoryName(app)
- Debug.Print("1111111:" & AssemPath)
- Dim arr
- Dim str
- Dim i As Long
- arr = Split(CreateObject("scripting.filesystemobject").opentextfile(AssemPath & "\Uconfig.txt").readall, vbNewLine)
- For i = 0 To UBound(arr)
- str = Split(arr(i), "=")
- If str(0) = "updateUrl" Then
- updateUrl = str(1)
- End If
- Next
- Debug.Print(updateUrl)
- End Function
- End Module
|