0

好的,我从http://tech.reboot.pro/showthread.php?tid=2982从 Gemster 获得了这段代码。所以我只是寻找一些东西来插入我的系统,因为它需要尽快完成。所以我复制并粘贴。不过,我确实明白发生了什么。唯一的问题是它跳过了一段重要的代码,我不知道为什么。所以就在这里。

 Dim CurrentVersion As String = My.Application.Info.Version.ToString '--- Change this to Current version, needs changing on every update
    Dim ProgramName As String = My.Application.Info.AssemblyName '--- Change this to Your Program Name
    Dim SiteName As String = "http://somewebsite.com/UpdateVersion.html" '--- Change this to Your Update page
    Dim VersionCHK As String = ""
    Dim GetVer As String = ""
    Dim GetVerLink As String = ""
    Dim GetUpd As Integer

    'Web Request
    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 & "=(\d+).(\d+)=(.*?).zip")
    Dim matches As MatchCollection = Regex.Matches(ReadSource)

这是它为每个语句跳过“拆分字符串”的部分

    'Split String
    For Each match As Match In matches
        Dim RegSplit() As String = Split(Match.ToString, "=")
        GetVer = RegSplit(1)
        GetVerLink = RegSplit(2)
    Next

这是它恢复的地方。

    'Check Verison
    If GetVer > CurrentVersion Then
        GetUpd = MsgBox(ProgramName & " is an old version." & vbCrLf & "New Update is available" & _
        vbCrLf & "Current version: " & CurrentVersion & vbCrLf & "Version Avalible: " & _
        GetVer & vbCrLf & vbCrLf & "Update Now?", vbYesNo, "Update")

        If GetUpd = vbYes Then
            Dim sfd As New SaveFileDialog
            sfd.FileName = IO.Path.GetFileName(GetVerLink)
            If sfd.ShowDialog = DialogResult.OK Then
                My.Computer.Network.DownloadFile(GetVerLink, sfd.FileName)
            End If
        End If
    Else
        MsgBox(ProgramName & " is upto date." & vbCrLf & "Current version: " & CurrentVersion, 0, "Update")
    End If
    Return vbNull

任何想法为什么?提前致谢。

4

1 回答 1

1

正则表达式很可能不正确,因此匹配项为空。

我建议使用 xml 文件,而不是尝试使用正则表达式解析 html:

服务器上的 XML:

            <VersionHistory>
                <CurrentVersion>
                    <VersionNumber>
                        1.0.0.2
                    </VersionNumber>
                    <DownloadLink>
                        http://www.mysite.com/downloads/myapp_1.0.0.2.zip
                    </DownloadLink>
                </CurrentVersion>
                <LegacyVersions>
                    <VersionNumber>
                        1.0.0.1
                    </VersionNumber>
                    <DownloadLink>
                        http://www.mysite.com/downloads/myapp_1.0.0.1.zip
                    </DownloadLink>
                </LegacyVersions>
            </VersionHistory>

编码:

    Dim localVersion As String = My.Application.Info.Version.ToString
    Dim wc As New Net.WebClient
    wc.Proxy = Nothing

    Dim source As String = String.Empty

    Try
        source = wc.DownloadString("http://www.mysite.com/versions.xml")
    Catch ex As Net.WebException
        'handle accordingly
    End Try

    Dim xm As New Xml.XmlDocument
    xm.LoadXml(source)

    Dim currentVersion As String = xm.SelectSingleNode("//CurrentVersion").ChildNodes(0).InnerText.Trim
    Dim currentLink As String = xm.SelectSingleNode("//CurrentVersion").ChildNodes(1).InnerText.Trim

    If localVersion = currentVersion Then
        MessageBox.Show("Up to Date")
    Else
        'run update routine, use currentLink to download latest version
    End If
于 2012-12-14T07:51:47.570 回答