VBScript自动配置Go语言的环境变量及LiteIDE的配置文件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

Option Explicit

Function IsMatch(Str, Patrn)  
  Dim r
  Set r = new RegExp
  r.Pattern = Patrn  
  IsMatch = r.test(Str)
  Set r = Nothing 
End Function  
  
Sub SetEnv(pPath, pValue)  
    Dim ExistValueOfPath
    IF pValue <> "" Then
        ExistValueOfPath = pSysEnv(pPath)
        IF Right(pValue, 1) = "\" Then pValue = Left(pValue, Len(pValue)-1)
        If IsMatch(ExistValueOfPath, "\*?" & Replace(pValue, "\", "\\") & "\\?(\b|;)") Then Exit Sub
        If ExistValueOfPath <> "" Then pValue = ";" & pValue
        pSysEnv(pPath) = ExistValueOfPath & pValue
    Else
        pSysEnv.Remove(pPath)
    End IF
End Sub

Sub WriteEnv(pPath, pValue)
    pSysEnv(pPath) = pValue
End Sub

Dim pSysEnv
Dim objFSO,f,vbCrLf
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
Set pSysEnv = oShell.Environment("System")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set f = objFSO.OpenTextFile(".\share\liteide\liteenv\win32.env", 2, True)
vbCrLf=Chr(13) & Chr(10)
f.Write "# native compiler windows 386" & vbCrLf & vbCrLf
f.Write "GOROOT=" & objFSO.GetFolder(".").Path & "\go" & vbCrLf
f.Write "GOBIN=" & vbCrLf
f.Write "GOARCH=386" & vbCrLf
f.Write "GOOS=windows" & vbCrLf
f.Write "CGO_ENABLED=1" & vbCrLf & vbCrLf
f.Write "PATH=%GOROOT%\bin;%PATH%" & vbCrLf & vbCrLf
f.Write "LITEIDE_GDB=gdb" & vbCrLf
f.Write "LITEIDE_MAKE=mingw32-make" & vbCrLf
f.Write "LITEIDE_TERM=%COMSPEC%" & vbCrLf
f.Write "LITEIDE_TERMARGS=" & vbCrLf
f.Write "LITEIDE_EXEC=%COMSPEC%" & vbCrLf & vbCrLf
f.Write "LITEIDE_EXECOPT=/C" & vbCrLf
f.Close
WriteEnv "GOROOT", objFSO.GetFolder(".").Path & "\go"
SetEnv "Path", "%GOROOT%\bin"
Set pSysEnv = Nothing
Set f = Nothing
oShell.Exec objFSO.GetFolder(".").Path & "\bin\liteide.exe"
Set oShell = Nothing
Set objFSO = Nothing