' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Imports System.Xml

Public Class Main

    Public config As Config

    Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load

        Me.WindowState = FormWindowState.Minimized

        config = New Config
        config.load_config()


        Nettoyage_Fichiers.Suppression_fichiers_affichage()
        Application.DoEvents()
        Dim arguments As String() = Environment.GetCommandLineArgs()
        Nettoyage_Fichiers.Suppression_fichiers_Action()
        FTP.CEPS_upload()
        FTP.LOI_upload()
        FTP.LPP_upload()
        FTP.officine_exe_upload()
        FTP.OfficineLib_dll__upload()
        FTP.Officine_ScriptSQL_upload()
        Me.Close()
    End Sub

    Private Sub Nettoyage_Fichiers_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Nettoyage_Fichiers_LinkLabel.LinkClicked
        Nettoyage_Fichiers.Visible = True
    End Sub
    Public Sub writelog(ByVal txt As String)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & Format(Now, "yyyyMMdd") & "_log.txt", Chr(10) & txt & Chr(10), True)
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        FTP.Visible = True
    End Sub

    Public Sub log(ByVal texte As String)
        Try


            My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\maintenance.log", Now.ToString & vbCrLf & _
                                                (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name & vbCrLf & _
                                                texte & vbCrLf & "------------------------------------------------" & vbCrLf, True)
        Catch ex As Exception

        End Try
    End Sub



    Private Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub Main_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            NotifyIcon1.Visible = True
            Me.Opacity = 0
        Else
            NotifyIcon1.Visible = False
            Me.Opacity = 100

        End If
    End Sub

    Private Sub NotifyIcon1_Click(sender As Object, e As EventArgs) Handles NotifyIcon1.Click
        Me.WindowState = FormWindowState.Normal
    End Sub
End Class