2012-12-14 2 views
0

Ok이 코드를 Gemster에서 http://tech.reboot.pro/showthread.php?tid=2982으로 가져 왔습니다. 그래서 나는 이제 막 끝내야 할 필요가있는 것처럼 내 시스템에 플러그 할 무언가를 찾았습니다. 그래서 복사하고 붙여 넣었습니다. 그러나, 나는 무슨 일이 일어나고 있는지 이해합니다. 유일한 문제는 중요한 코드 섹션을 건너 뛰고 이유를 파악할 수 없다는 것입니다. 그래서 여기 있습니다. Vb.net의 자동 업데이트 기능

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 

어떤 아이디어가 있습니까? 미리 감사드립니다.

답변

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