Imports System.ComponentModel
Imports System.IO

Public Class Form9
    Dim selct = Form4.profilselect
    Dim listsel = ""
    Public encours As Integer = 0
    Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BackColor = Form4.BackColor
        ForeColor = Form4.ForeColor
        ListBox1.BackColor = BackColor
        ContextMenuStrip1.BackColor = BackColor
        ListBox1.ForeColor = ForeColor
        ContextMenuStrip1.ForeColor = ForeColor
        selct = Form4.profilselect
        listsel = ""
        encours = 0
        Text = "Les sauvegarde de: " & Form4.profilselect
        ListBox1.Items.Clear()

        For Each fichier As String In IO.Directory.GetFiles(profil & "/" & Form4.profilselect & "/Backup/")
            Dim info As New IO.FileInfo(fichier)
            ListBox1.Items.Add(info.Name.ToString.Replace(".zip", ""))
        Next
    End Sub

    Private Sub ListBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedValueChanged
        SuppimerToolStripMenuItem.Text = "Suppimer: " & ListBox1.SelectedItem
    End Sub

    Private Sub SuppimerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SuppimerToolStripMenuItem.Click
        Dim msg = MsgBox("voulez vous supprimer le sauvegarde:" & ListBox1.SelectedItem & " ?", MsgBoxStyle.YesNo)
        If msg = MsgBoxResult.Yes Then
            File.Delete(profil & "/" & Form4.profilselect & "/Backup/" & ListBox1.SelectedItem & ".zip")
            MsgBox("La sauvegarde: " & ListBox1.SelectedItem & " à bien êtê supprimer", MsgBoxStyle.Information)
            recharche()
        Else
            MsgBox("action annuler", MsgBoxStyle.Information)
        End If
    End Sub
    Sub recharche()
        ListBox1.Items.Clear()
        For Each fichier As String In IO.Directory.GetFiles(profil & "/" & Form4.profilselect & "/Backup/")
            Dim info As New IO.FileInfo(fichier)
            ListBox1.Items.Add(info.Name.ToString.Replace(".zip", ""))
        Next
        Form4.file = ListBox1.Items.Count
        If ListBox1.Items.Count = 0 Then
            Close()
        End If
    End Sub

    Private Sub ExporterVerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExporterVerToolStripMenuItem.Click
        If FolderBrowserDialog1.ShowDialog = 1 Then
            encours = 1
            listsel = ListBox1.SelectedItem
            Form10.Text = "Exportation de la sauvegarde: " & ListBox1.SelectedItem
            BackgroundWorker1.RunWorkerAsync()
            Form10.ShowDialog()
        End If
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        File.Copy(profil.ToString & selct.ToString & "/Backup/" & listsel.ToString & ".zip", FolderBrowserDialog1.SelectedPath.ToString & "/" & listsel.ToString & ".zip")
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        encours = 0
        Form10.Close()
        MsgBox("La sauvegarde: " & ListBox1.SelectedItem & " a bien êtê exporter", MsgBoxStyle.Information)
    End Sub

    Private Sub Form9_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        selct = Form4.profilselect
        listsel = ""
        encours = 0
    End Sub
End Class