Imports System.Text.RegularExpressions
Imports System.IO
Public Class Form1
Dim CurrentVersion As String = "v1.0" '--- Change this to Current version, needs changing on every update
Dim ProgramName As String = "MyProgram" '--- Change this to Your Progran Name
Dim SiteName As String = "http://localhost/UpdateCHK.php" '--- Change this to Your Update page
Dim VersionCHK, GetVer, GetVerLink As String
Dim GetUpd As Integer
Public Sub AutoUpdate()
Dim WebRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(SiteName)
Dim WebResponse As System.Net.HttpWebResponse = WebRequest.GetResponse
Dim STR As System.IO.StreamReader = New System.IO.StreamReader(WebResponse.GetResponseStream())
Dim ReadSource As String = STR.ReadToEnd
Dim Regex As New System.Text.RegularExpressions.Regex(ProgramName & "=v(\d+).(\d+)=(.*?).zip")
Dim matches As MatchCollection = Regex.Matches(ReadSource)
For Each match As Match In matches
Dim RegSplit() As String = Split(match.ToString, "=")
GetVer = RegSplit(1)
GetVerLink = RegSplit(2)
Next
If GetVer > CurrentVersion Then
GetUpd = MsgBox(ProgramName & " เป็นเวอร์ชั่นเก่า." & vbCrLf & "มีอัพเดตใหม่" & _
vbCrLf & "เวอร์ชั่นของคุณคือ: " & CurrentVersion & vbCrLf & "เวอร์ชั่นใหม่คือ: " & _
GetVer & vbCrLf & vbCrLf & "อัพเดตเดี๋ยวนี้?", vbYesNo, "Update")
If GetUpd = vbYes Then
System.IO.File.Delete("c:\ชื่อไฟล์เดิม")
My.Computer.Network.DownloadFile(GetVerLink, "c:\ชื่อไฟล์ใหม่")
End If
Else
MsgBox(ProgramName & " เวอร์ชั่นนี้" & vbCrLf & "เป็นเวอร์ชั่นล่าสุดแล้ว " & vbCrLf & "This Patch is " & CurrentVersion, 0, "Update")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AutoUpdate()
End Sub
End Class