' ===================================================================
'  OUTILS-CAD  —  Installateur (test SolidWorks)
'  -----------------------------------------------------------------
'  UN SEUL fichier. Le client double-clique dessus :
'     1) il installe le petit pont vers SolidWorks
'     2) il enregistre le raccourci  outilscad://
'     3) il confirme  « Installation reussie »
'  Aucun droit administrateur requis.
' ===================================================================
Option Explicit
Dim sh, fso, appDir, pont, cmd, w, f

Set sh  = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' 1) Dossier prive de l'application (dans le profil de l'utilisateur)
appDir = sh.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\OUTILSCAD"
If Not fso.FolderExists(appDir) Then fso.CreateFolder appDir
pont = appDir & "\pont-solidworks.vbs"

' 2) On ecrit le petit pont vers SolidWorks
w = ""
w = w & "Dim swApp" & vbCrLf
w = w & "On Error Resume Next" & vbCrLf
w = w & "Set swApp = GetObject(, ""SldWorks.Application"")" & vbCrLf
w = w & "If swApp Is Nothing Then Set swApp = CreateObject(""SldWorks.Application"")" & vbCrLf
w = w & "If Not swApp Is Nothing Then swApp.Visible = True" & vbCrLf
w = w & "If swApp Is Nothing Then" & vbCrLf
w = w & "  MsgBox ""SolidWorks est introuvable. Ouvre SolidWorks puis reessaie."", 16, ""OUTILS-CAD""" & vbCrLf
w = w & "Else" & vbCrLf
w = w & "  swApp.SendMsgToUser2 ""ca marche !"" & vbCrLf & vbCrLf & ""Le bouton du site web vient d'executer une action dans SolidWorks."", 2, 2" & vbCrLf
w = w & "End If" & vbCrLf

Set f = fso.CreateTextFile(pont, True)
f.Write w
f.Close

' 3) Enregistrement du raccourci  outilscad://  (utilisateur, sans admin)
cmd = "wscript.exe " & Chr(34) & pont & Chr(34) & " " & Chr(34) & "%1" & Chr(34)
On Error Resume Next
sh.RegWrite "HKCU\Software\Classes\outilscad\", "URL:OUTILS-CAD Protocol", "REG_SZ"
sh.RegWrite "HKCU\Software\Classes\outilscad\URL Protocol", "", "REG_SZ"
sh.RegWrite "HKCU\Software\Classes\outilscad\shell\open\command\", cmd, "REG_SZ"

' 4) Confirmation claire
If Err.Number = 0 Then
    MsgBox "OUTILS-CAD est installe !" & vbCrLf & vbCrLf & _
           "Tu peux maintenant :" & vbCrLf & _
           "   1) Ouvrir SolidWorks" & vbCrLf & _
           "   2) Cliquer le bouton  TEST  sur la page web", _
           64, "OUTILS-CAD  -  Installation reussie"
Else
    MsgBox "Une erreur est survenue :" & vbCrLf & Err.Description, _
           16, "OUTILS-CAD  -  Installation"
End If
