Imports System.ComponentModel
Imports System.IO
Imports System.Math
Public Class Form5

    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BackColor = Form4.BackColor
        ForeColor = Form4.ForeColor
        Button1.BackColor = BackColor
        Button2.BackColor = BackColor
        Button3.BackColor = BackColor
        ListBox1.BackColor = BackColor
        ListBox1.ForeColor = ForeColor
        Label5.Text = Form4.profilselect
        Dim lines1() As String = File.ReadAllLines(profil & "/" & Form4.profilselect & "/des.txt")
        Label6.Text = lines1(0)
        PictureBox1.Image = Image.FromFile(profil & "/" & Form4.profilselect & "/icon.png")
        For Each fichier As String In IO.Directory.GetFiles(profil & "/" & Form4.profilselect & "/serveur/")
            Dim info As New IO.FileInfo(fichier)
            ListBox1.Items.Add(info.Name.ToString.Replace(".txt", ""))
        Next
        If ListBox1.Items.Count = 0 Then
            Button2.Hide()
        End If
        Dim folderSize As Long = FolderSizeCalculator.GetFolderSize(profil & "/" & Form4.profilselect & "/Backup/")
        Dim toutlesdossier = func_RoundTaille(LaTaille:=folderSize)
        Label7.Text = toutlesdossier
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Form6.ShowDialog()
    End Sub

    Private Sub Form5_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        PictureBox1.Image.Dispose()
        ListBox1.Items.Clear()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Form7.ShowDialog()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If OpenFileDialog1.ShowDialog = 1 Then
            PictureBox1.Image.Dispose()
            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
            File.Delete(profil & "/" & Form4.profilselect & "/icon.png")
            PictureBox1.Image.Save(profil & "/" & Form4.profilselect & "/icon.png")
            MsgBox("L'image du profil: " & Form4.profilselect & " a bien êtê changer", MsgBoxStyle.Information)
        End If
    End Sub
    Public Class FolderSizeCalculator
        Public Shared Function GetFolderSize(ByVal folderPath As String) As Long
            Dim size As Long = 0
            Try
                Dim files As String() = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories)
                For Each file As String In files
                    Dim fileInfo As New FileInfo(file)
                    size += fileInfo.Length
                Next
            Catch ex As Exception
                ' Handle any exceptions that may occur
            End Try
            Return size
        End Function
    End Class
    Public Function func_RoundTaille(ByVal LaTaille As Long) As String
        Select Case LaTaille
            Case Is < 1024
                Return Round(LaTaille) & " Octets"
            Case Is < 1048576
                Return Round(LaTaille / 2 ^ 10, 3) & " Ko"
            Case Is < 1073741824
                Return Round(LaTaille / 2 ^ 20, 3) & " Mo"
            Case Else
                Return Round(LaTaille / 2 ^ 30, 3) & " Go"
        End Select
    End Function
End Class