forked from forcedotcom/SalesforceMobileSDK-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.vbs
164 lines (145 loc) · 6.62 KB
/
install.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
Option Explicit
On Error Resume Next
' *** ***
' * *
' * ATTENTION: Windows Users *
' * *
' * Run this script to initialize the submodules of your repository, and fix *
' * symlinks, which otherwise won't work on Windows. You *must* run this *
' * script if you plan to work with the Salesforce Mobile SDK for Android on *
' * Windows. *
' * From the command line: cscript install.vbs *
' *** ***
Dim strWorkingDirectory, strSymlinkFilesListPath, objShell, intReturnVal, _
strErrorDescription, objFso
' Set the working folder to the script location (i.e. the repo root)
strWorkingDirectory = GetDirectoryName(WScript.ScriptFullName)
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = strWorkingDirectory
strSymlinkFilesListPath = strWorkingDirectory & "tools\symlink_files.txt"
' If the symlink files list does not exist, we can't continue.
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
If Not objFso.FileExists(strSymlinkFilesListPath) Then
WScript.Echo "The file '" & strSymlinkFilesListPath & "' does not exist. Cannot continue."
Set objFso = Nothing
WScript.Quit 9
End If
Set objFso = Nothing
' If git is not in the path, this script cannot run.
Set objShell = WScript.CreateObject("WScript.Shell")
intReturnVal = objShell.Run("git status", 1, True)
If Err.number <> 0 Then
strErrorDescription = Err.Description
Err.Clear
WScript.Echo "There was an error getting the status of the git repository: '" & strErrorDescription & "' Make sure the 'git' executable is on your PATH variable."
WScript.Quit 1
End If
If intReturnVal <> 0 Then
If intReturnVal = 128 Then
WScript.Echo "Git repository not initialized! You must clone this repository via the 'git clone' command to run this script."
WScript.Quit 7
Else
WScript.Echo "Unknown error getting the git repository status (" & intReturnVal & "). Make sure git is installed and part of your PATH, and that you've cloned the git repository using the 'git clone' command."
WScript.Quit 8
End If
End If
' Initialze and update the submodules.
intReturnVal = objShell.Run("git submodule init", 1, True)
If intReturnVal <> 0 Then
WScript.Echo "Error initializing the submodules!"
WScript.Quit 2
End If
intReturnVal = objShell.Run("git submodule sync", 1, True)
If intReturnVal <> 0 Then
WScript.Echo "Error syncing the submodules!"
WScript.Quit 6
End If
intReturnVal = objShell.Run("git submodule update", 1, True)
If intReturnVal <> 0 Then
WScript.Echo "Error updating the submodules!"
WScript.Quit 3
End If
' Copy the hard files to where their symlinks would be.
Call CopySymlinkFiles()
WScript.Echo vbCrLf & "Successfully initialized submodules and fixed symlinks."
WScript.Quit 0
' -------------------------------------------------------------------
' - Reads a list of generated source and destination files associated
' - with symlinks, and copies the source into the destination.
' -------------------------------------------------------------------
Sub CopySymlinkFiles
Dim objAdoStream, strFilesLine, objFso, objRegExp, objMatches, objMatch, strSrcFile, strDestFile, bIsFolder
' Open the list of source and destination files for reading.
Set objAdoStream = WScript.CreateObject("ADODB.Stream")
objAdoStream.Open
objAdoStream.Type = 2 ' Text stream
objAdoStream.Charset = "utf-8"
'objAdoStream.Mode = 1 ' Read-only
WScript.Echo
objAdoStream.LoadFromFile strSymlinkFilesListPath
If Err.number <> 0 Then
strErrorDescription = Err.Description
Err.Clear
WScript.Echo "Error opening '" & strSymlinkFilesListPath & "' for reading: " & strErrorDescription
Set objAdoStream = Nothing
WScript.Quit 4
End If
' Parse the entries in the file, make the file copies.
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
Set objRegExp = New RegExp
objRegExp.Pattern = """([^""]+)"" +""([^""]+)"""
objRegExp.Global = True
While Not objAdoStream.EOS
strFilesLine = objAdoStream.ReadText(-2) ' Line by line.
strFilesLine = Trim(strFilesLine)
If strFilesLine <> "" Then
Set objMatches = objRegExp.Execute(strFilesLine)
Set objMatch = objMatches.Item(0)
strSrcFile = objMatch.SubMatches.Item(0)
strDestFile = objMatch.SubMatches.Item(1)
' Make sure source file exists.
If Not objFso.FileExists(strSrcFile) And Not objFso.FolderExists(strSrcFile) Then
WScript.Echo "Source file '" & strSrcFile & "' does not exist! Cannot continue."
Set objFso = Nothing
objAdoStream.Close
Set objAdoStream = Nothing
WScript.Quit 10
End If
WScript.Echo "Copying '" & strSrcFile & "' to '" & strDestFile & "'"
If objFso.FileExists(strDestFile) Then
objFso.DeleteFile strDestFile, True
End If
bIsFolder = objFso.FolderExists(strSrcFile)
If Not bIsFolder Then
objFso.CopyFile strSrcFile, strDestFile, True ' Overwrite
Else
objFso.CopyFolder strSrcFile, strDestFile, True ' Overwrite
End If
If Err.number <> 0 Then
strErrorDescription = Err.Description
Err.Clear
WScript.Echo "Error copying '" & strSrcFile & "' to '" & strDestFile & "': " & strErrorDescription
Set objFso = Nothing
objAdoStream.Close
Set objAdoStream = Nothing
WScript.Quit 5
End If
End If
Wend
' Cleanup.
Set objFso = Nothing
objAdoStream.Close
Set objAdoStream = Nothing
End Sub
' -------------------------------------------------------------------
' - Gets the directory name, from a file path.
' -------------------------------------------------------------------
Function GetDirectoryName(ByVal strFilePath)
Dim strFinalSlash
strFinalSlash = InStrRev(strFilePath, "\")
If strFinalSlash = 0 Then
GetDirectoryName = strFilePath
Else
GetDirectoryName = Left(strFilePath, strFinalSlash)
End If
End Function