Advertisement
elenalotus

Untitled

Apr 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Xml
  3. Imports System.Xml.Serialization
  4.  
  5. Public Class Form1
  6.  
  7. #Region " Attributs "
  8.  
  9. Private aInfoFichier As Entites.FichierXml
  10. Private aEstFichierExist As Boolean
  11.  
  12. #End Region
  13.  
  14.  
  15. #Region " Propriétés "
  16.  
  17. Public Property InfoFichier() As Entites.FichierXml
  18. Get
  19. If aInfoFichier Is Nothing Then
  20. aInfoFichier = New Entites.FichierXml
  21. End If
  22. Return aInfoFichier
  23. End Get
  24. Set(ByVal value As Entites.FichierXml)
  25. aInfoFichier = value
  26. End Set
  27. End Property
  28.  
  29. Public Property EstFichierExist() As Boolean
  30. Get
  31. Return aEstFichierExist
  32. End Get
  33. Set(ByVal value As Boolean)
  34. aEstFichierExist = value
  35. End Set
  36. End Property
  37.  
  38.  
  39. #End Region
  40.  
  41. #Region " Constantes "
  42.  
  43. Const cheminInfo As String = "C:\inetpub\wwwroot"
  44. Const infoFileMod As String = "infos.xml"
  45. Const infoFileSound As String = "infosSound.xml"
  46. Const cheminMod As String = "C:\inetpub\wwwroot\@LLD"
  47. Const cheminSound As String = "C:\inetpub\wwwroot\Musique"
  48. Const directoryNameSound As String = "Musique\"
  49.  
  50. #End Region
  51.  
  52. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  53. CompileCB.SelectedIndex = 0
  54.  
  55. If File.Exists(String.Format("{0}\{1}", cheminInfo, infoFileMod)) Then
  56.  
  57. Dim objStringReader As New StreamReader(String.Format("{0}\{1}", cheminInfo, infoFileMod))
  58. Dim x As New XmlSerializer(InfoFichier.GetType)
  59. InfoFichier = DirectCast(x.Deserialize(objStringReader), Entites.FichierXml)
  60. objStringReader.Close()
  61. EstFichierExist = True
  62. OldVersionLabel.Text = InfoFichier.Version
  63. NewVersionLabel.Text = (Convert.ToInt32(InfoFichier.Version) + 1).ToString
  64. InfoFichier = Nothing
  65. Else
  66. EstFichierExist = False
  67. NewVersionLabel.Text = "1"
  68. End If
  69. End Sub
  70.  
  71. Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
  72.  
  73. Dim infoReader As FileInfo
  74. Dim path As String
  75. Dim sx() As String
  76. Try
  77. If CompileCB.SelectedIndex = 0 Then
  78. If EstFichierExist Then
  79. File.Delete(String.Format("{0}\{1}", cheminInfo, infoFileMod))
  80. End If
  81.  
  82.  
  83.  
  84. InfoFichier = New Entites.FichierXml With {.Version = NewVersionLabel.Text,
  85. .ListeFichier = New List(Of Entites.Fichier)}
  86.  
  87.  
  88. For Each foundFile As String In My.Computer.FileSystem.GetFiles(cheminMod,
  89. FileIO.SearchOption.SearchAllSubDirectories,
  90. "*")
  91. If Not System.IO.Path.GetFileName(foundFile).ToLower = "web.config" Then
  92. infoReader = My.Computer.FileSystem.GetFileInfo(foundFile)
  93.  
  94. sx = Split(foundFile, "@")
  95. path = "@" & sx(1)
  96.  
  97. InfoFichier.ListeFichier.Add(New Entites.Fichier With
  98. {.Path = path,
  99. .TotalBytes = infoReader.Length})
  100. End If
  101.  
  102.  
  103. Next
  104.  
  105. Dim objStreamWriter As New StreamWriter(String.Format("{0}\{1}", cheminInfo, infoFileMod))
  106. Dim x As New XmlSerializer(InfoFichier.GetType)
  107. x.Serialize(objStreamWriter, InfoFichier)
  108. Else
  109. If EstFichierExist Then
  110. File.Delete(String.Format("{0}\{1}", cheminInfo, infoFileSound))
  111. End If
  112.  
  113.  
  114.  
  115. InfoFichier = New Entites.FichierXml With {.Version = NewVersionLabel.Text,
  116. .ListeFichier = New List(Of Entites.Fichier)}
  117.  
  118.  
  119. For Each foundFile As String In My.Computer.FileSystem.GetFiles(cheminSound)
  120. If Not System.IO.Path.GetFileName(foundFile).ToLower = "web.config" Then
  121. InfoFichier.ListeFichier.Add(New Entites.Fichier With
  122. {.Path = directoryNameSound & System.IO.Path.GetFileName(foundFile),
  123. .TotalBytes = 0})
  124. End If
  125.  
  126.  
  127. Next
  128.  
  129. Dim objStreamWriter As New StreamWriter(String.Format("{0}\{1}", cheminInfo, infoFileSound))
  130. Dim x As New XmlSerializer(InfoFichier.GetType)
  131. x.Serialize(objStreamWriter, InfoFichier)
  132. End If
  133.  
  134. Catch ex As Exception
  135.  
  136. MessageBox.Show(String.Format(
  137. "Une erreur est survenu lors de la génération du fichier XML : {0}",
  138. ex.Message))
  139.  
  140. End Try
  141.  
  142. Me.Close()
  143. End Sub
  144.  
  145. Private Sub CompileCB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CompileCB.SelectedIndexChanged
  146. If CompileCB.SelectedIndex = 0 Then
  147. If File.Exists(String.Format("{0}\{1}", cheminInfo, infoFileMod)) Then
  148.  
  149. Dim objStringReader As New StreamReader(String.Format("{0}\{1}", cheminInfo, infoFileMod))
  150. Dim x As New XmlSerializer(InfoFichier.GetType)
  151. InfoFichier = DirectCast(x.Deserialize(objStringReader), Entites.FichierXml)
  152. objStringReader.Close()
  153. EstFichierExist = True
  154. OldVersionLabel.Text = InfoFichier.Version
  155. NewVersionLabel.Text = (Convert.ToInt32(InfoFichier.Version) + 1).ToString
  156. InfoFichier = Nothing
  157. Else
  158. EstFichierExist = False
  159. NewVersionLabel.Text = "1"
  160. End If
  161.  
  162. Else
  163. OldVersionLabel.Text = "N.A."
  164. NewVersionLabel.Text = "N.A."
  165. End If
  166. End Sub
  167.  
  168. Private Sub OldVersionLabel_Click(sender As Object, e As EventArgs) Handles OldVersionLabel.Click
  169.  
  170. End Sub
  171. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement