Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/08/2013, 17:50
vistaero
 
Fecha de Ingreso: noviembre-2009
Mensajes: 67
Antigüedad: 14 años, 6 meses
Puntos: 2
Respuesta: Descargar el archivo más reciente de un repositorio

Lo logré, pero creo que de una forma un poco chapuza, ya que tras un buen rato intentando hacer un lector de xml, no logré nada, decidí simplemente tratar el archivo xml como un archivo de texto plano en el que buscar la etiqueta correspondiente y aislar el valor, eliminando del principio y el final de la cadena la cantidad de caracteres que sé que siempre van a estar ocupando las etiquetas. Dejo aquí el código de un BackgroundWorker que hice para calcular la dirección:

Código vb:
Ver original
  1. Dim FileName
  2. Dim FileToDownload
  3. Private LatestVersionFolder As String
  4. Private LatestVersionFile As String
  5. Private UrlDownload
  6.  
  7.     Private Sub FileURLCalculator_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles FileURLCalculator.DoWork
  8.         Dim CraftBukkitUrl As String = "http://repo.bukkit.org/content/groups/public/org/bukkit/craftbukkit/"
  9.         FileToDownload = CraftBukkitUrl & "maven-metadata.xml"
  10.         FileName = "maven-metadata.xml"
  11.         wc = New System.Net.WebClient()
  12.         AddHandler wc.DownloadProgressChanged, AddressOf OnDownloadProgressChanged
  13.         AddHandler wc.DownloadFileCompleted, AddressOf OnFileDownloadCompleted
  14.         wc.DownloadFile(New Uri(FileToDownload), Application.StartupPath & "\versions\temp\" & FileName)
  15.  
  16.         Dim xmlfile As Object = System.IO.File.ReadAllLines(Application.StartupPath & "\versions\temp\" & "maven-metadata.xml")
  17.         For Each line As String In xmlfile
  18.             If line.StartsWith("    <latest>") Then
  19.                 Dim line2 As String
  20.                 Dim line2l As Integer
  21.                 line2 = line.Remove(0, 12)
  22.                 line2l = line2.Count - 9
  23.                 line2 = line2.Remove(line2l, 9)
  24.                 LatestVersionFolder = line2
  25.             End If
  26.         Next
  27.  
  28.         Dim Url1 As String = CraftBukkitUrl & "/" & LatestVersionFolder & "/" & FileName
  29.         wc.DownloadFile(New Uri(Url1), Application.StartupPath & "\versions\temp\" & FileName & "2")
  30.         wc.Dispose()
  31.         Dim xmlfile2 As Object = System.IO.File.ReadAllLines(Application.StartupPath & "\versions\temp\" & "maven-metadata.xml2")
  32.         For Each line As String In xmlfile2
  33.             If line.StartsWith("        <value>") Then
  34.                 Dim line2 As String
  35.                 Dim line2l As Integer
  36.                 line2 = line.Remove(0, 15)
  37.                 line2l = line2.Count - 8
  38.                 line2 = line2.Remove(line2l, 8)
  39.                 LatestVersionFile = line2
  40.             End If
  41.         Next
  42.  
  43.         UrlDownload = CraftBukkitUrl & LatestVersionFolder & "/craftbukkit-" & LatestVersionFile & ".jar"
  44.         FileURLCalculator.Dispose()
  45.  
  46.     End Sub