Rem ************************************
Rem Get the Shell object
Rem ************************************

Set shell = CreateObject("WScript.Shell")


Rem ************************************
Rem Set path
Rem ************************************

system32Path = shell.Environment("PROCESS")("SYSTEMROOT") & "\System32\"


Rem ************************************
Rem Setup
Rem ************************************

Sub Setup(mode, vstudio)
  installPath  = shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Visual Haskell\" & vstudio & "\InstallDir")
  
  Rem *** Register vs_haskell.dll
  
  res = shell.Run ("""" & system32Path & "regsvr32.exe"" /i:" & vstudio & " " & mode & " /n /s """ & installPath & "bin\vs_haskell.dll""",0,true)
  If res <> 0 Then
    shell.Popup "Failed to setup vs_haskell.dll"
    Stop
  End If


  Rem *** Register vs_haskell_babel.dll
 
  res = shell.Run ("""" & system32Path & "regsvr32.exe"" /i:" & vstudio & " " & mode & " /n /s """ & installPath & "bin\vs_haskell_babel.dll""",0,true)
  If res <> 0 Then
    shell.Popup "Failed to setup vs_haskell_babel.dll"
    Stop
  End If


  Rem *** Register vs_haskell_dlg.dll

  res = shell.Run ("""" & system32Path & "regsvr32.exe"" /i:" & vstudio & " " & mode & " /n /s """ & installPath & "bin\vs_haskell_dlg.dll""",0,true)
  If res <> 0 Then
    shell.Popup "Failed to setup vs_haskell_dlg.dll"
    Stop
  End If


  Rem *** VStudioSetup

  vstudioPath  = shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\" & vstudio & "\InstallDir")
  res = shell.Run ("""" & vstudioPath & "devenv.exe"" /Setup",0,true)
  If res <> 0 Then
    shell.Popup "Failed to setup VStudio"
    Stop
  End If
End Sub


Rem ************************************
Rem Entry Points
Rem ************************************

sub Install71()
  Setup "", "7.1"
end sub

sub UnInstall71()
  Setup "/u", "7.1"
end sub

sub Install80()
  Setup "", "8.0"
end sub

sub UnInstall80()
  Setup "/u", "8.0"
end sub
