Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Xml
- Imports System.Xml.Serialization
- Public Class Form1
- #Region " Attributs "
- Private aInfoFichier As Entites.FichierXml
- Private aEstFichierExist As Boolean
- #End Region
- #Region " Propriétés "
- Public Property InfoFichier() As Entites.FichierXml
- Get
- If aInfoFichier Is Nothing Then
- aInfoFichier = New Entites.FichierXml
- End If
- Return aInfoFichier
- End Get
- Set(ByVal value As Entites.FichierXml)
- aInfoFichier = value
- End Set
- End Property
- Public Property EstFichierExist() As Boolean
- Get
- Return aEstFichierExist
- End Get
- Set(ByVal value As Boolean)
- aEstFichierExist = value
- End Set
- End Property
- #End Region
- #Region " Constantes "
- Const cheminInfo As String = "C:\inetpub\wwwroot"
- Const infoFileMod As String = "infos.xml"
- Const infoFileSound As String = "infosSound.xml"
- Const cheminMod As String = "C:\inetpub\wwwroot\@LLD"
- Const cheminSound As String = "C:\inetpub\wwwroot\Musique"
- Const directoryNameSound As String = "Musique\"
- #End Region
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- CompileCB.SelectedIndex = 0
- If File.Exists(String.Format("{0}\{1}", cheminInfo, infoFileMod)) Then
- Dim objStringReader As New StreamReader(String.Format("{0}\{1}", cheminInfo, infoFileMod))
- Dim x As New XmlSerializer(InfoFichier.GetType)
- InfoFichier = DirectCast(x.Deserialize(objStringReader), Entites.FichierXml)
- objStringReader.Close()
- EstFichierExist = True
- OldVersionLabel.Text = InfoFichier.Version
- NewVersionLabel.Text = (Convert.ToInt32(InfoFichier.Version) + 1).ToString
- InfoFichier = Nothing
- Else
- EstFichierExist = False
- NewVersionLabel.Text = "1"
- End If
- End Sub
- Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
- Dim infoReader As FileInfo
- Dim path As String
- Dim sx() As String
- Try
- If CompileCB.SelectedIndex = 0 Then
- If EstFichierExist Then
- File.Delete(String.Format("{0}\{1}", cheminInfo, infoFileMod))
- End If
- InfoFichier = New Entites.FichierXml With {.Version = NewVersionLabel.Text,
- .ListeFichier = New List(Of Entites.Fichier)}
- For Each foundFile As String In My.Computer.FileSystem.GetFiles(cheminMod,
- FileIO.SearchOption.SearchAllSubDirectories,
- "*")
- If Not System.IO.Path.GetFileName(foundFile).ToLower = "web.config" Then
- infoReader = My.Computer.FileSystem.GetFileInfo(foundFile)
- sx = Split(foundFile, "@")
- path = "@" & sx(1)
- InfoFichier.ListeFichier.Add(New Entites.Fichier With
- {.Path = path,
- .TotalBytes = infoReader.Length})
- End If
- Next
- Dim objStreamWriter As New StreamWriter(String.Format("{0}\{1}", cheminInfo, infoFileMod))
- Dim x As New XmlSerializer(InfoFichier.GetType)
- x.Serialize(objStreamWriter, InfoFichier)
- Else
- If EstFichierExist Then
- File.Delete(String.Format("{0}\{1}", cheminInfo, infoFileSound))
- End If
- InfoFichier = New Entites.FichierXml With {.Version = NewVersionLabel.Text,
- .ListeFichier = New List(Of Entites.Fichier)}
- For Each foundFile As String In My.Computer.FileSystem.GetFiles(cheminSound)
- If Not System.IO.Path.GetFileName(foundFile).ToLower = "web.config" Then
- InfoFichier.ListeFichier.Add(New Entites.Fichier With
- {.Path = directoryNameSound & System.IO.Path.GetFileName(foundFile),
- .TotalBytes = 0})
- End If
- Next
- Dim objStreamWriter As New StreamWriter(String.Format("{0}\{1}", cheminInfo, infoFileSound))
- Dim x As New XmlSerializer(InfoFichier.GetType)
- x.Serialize(objStreamWriter, InfoFichier)
- End If
- Catch ex As Exception
- MessageBox.Show(String.Format(
- "Une erreur est survenu lors de la génération du fichier XML : {0}",
- ex.Message))
- End Try
- Me.Close()
- End Sub
- Private Sub CompileCB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CompileCB.SelectedIndexChanged
- If CompileCB.SelectedIndex = 0 Then
- If File.Exists(String.Format("{0}\{1}", cheminInfo, infoFileMod)) Then
- Dim objStringReader As New StreamReader(String.Format("{0}\{1}", cheminInfo, infoFileMod))
- Dim x As New XmlSerializer(InfoFichier.GetType)
- InfoFichier = DirectCast(x.Deserialize(objStringReader), Entites.FichierXml)
- objStringReader.Close()
- EstFichierExist = True
- OldVersionLabel.Text = InfoFichier.Version
- NewVersionLabel.Text = (Convert.ToInt32(InfoFichier.Version) + 1).ToString
- InfoFichier = Nothing
- Else
- EstFichierExist = False
- NewVersionLabel.Text = "1"
- End If
- Else
- OldVersionLabel.Text = "N.A."
- NewVersionLabel.Text = "N.A."
- End If
- End Sub
- Private Sub OldVersionLabel_Click(sender As Object, e As EventArgs) Handles OldVersionLabel.Click
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement