3 ' This file is part of OpenTTD.
4 ' OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
5 ' OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6 ' See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9 Set FSO
= CreateObject("Scripting.FileSystemObject")
11 Sub FindReplaceInFile(filename
, to_find
, replacement
)
13 Set file
= FSO
.OpenTextFile(filename
, 1, 0, 0)
16 data
= Replace(data
, to_find
, replacement
)
17 Set file
= FSO
.CreateTextFile(filename
, -1, 0)
22 Sub UpdateFile(modified
, isodate
, version
, cur_date
, githash
, istag
, isstabletag
, filename
)
23 FSO
.CopyFile filename
& ".in", filename
24 FindReplaceInFile filename
, "!!MODIFIED!!", modified
25 FindReplaceInFile filename
, "!!ISODATE!!", isodate
26 FindReplaceInFile filename
, "!!VERSION!!", version
27 FindReplaceInFile filename
, "!!DATE!!", cur_date
28 FindReplaceInFile filename
, "!!GITHASH!!", githash
29 FindReplaceInFile filename
, "!!ISTAG!!", istag
30 FindReplaceInFile filename
, "!!ISSTABLETAG!!", isstabletag
33 Sub UpdateFiles(version
)
34 Dim modified
, isodate
, cur_date
, githash
, istag
, isstabletag
35 cur_date
= DatePart("D", Date) & "." & DatePart("M", Date) & "." & DatePart("YYYY", Date)
37 If InStr(version
, Chr(9)) Then
38 ' Split string into field with tails
39 isodate
= Mid(version
, InStr(version
, Chr(9)) + 1)
40 modified
= Mid(isodate
, InStr(isodate
, Chr(9)) + 1)
41 githash
= Mid(modified
, InStr(modified
, Chr(9)) + 1)
42 istag
= Mid(githash
, InStr(githash
, Chr(9)) + 1)
43 isstabletag
= Mid(istag
, InStr(istag
, Chr(9)) + 1)
44 ' Remove tails from fields
45 version
= Mid(version
, 1, InStr(version
, Chr(9)) - 1)
46 isodate
= Mid(isodate
, 1, InStr(isodate
, Chr(9)) - 1)
47 modified
= Mid(modified
, 1, InStr(modified
, Chr(9)) - 1)
48 githash
= Mid(githash
, 1, InStr(githash
, Chr(9)) - 1)
49 istag
= Mid(istag
, 1, InStr(istag
, Chr(9)) - 1)
58 UpdateFile modified
, isodate
, version
, cur_date
, githash
, istag
, isstabletag
, "../src/rev.cpp"
59 UpdateFile modified
, isodate
, version
, cur_date
, githash
, istag
, isstabletag
, "../src/os/windows/ottdres.rc"
62 Function DetermineVersion()
63 Dim WshShell
, branch
, tag
, modified
, isodate
, oExec
, line
, hash
, shorthash
64 Set WshShell
= CreateObject("WScript.Shell")
74 ' Set the environment to english
75 WshShell
.Environment("PROCESS")("LANG") = "en"
77 Set oExec
= WshShell
.Exec("git rev-parse --verify HEAD")
78 If Err
.Number
= 0 Then
79 ' Wait till the application is finished ...
80 Do While oExec
.Status
= 0
83 If oExec
.ExitCode
= 0 Then
84 hash
= oExec
.StdOut
.ReadLine()
85 shorthash
= Mid(hash
, 1, 10)
86 ' Make sure index is in sync with disk
87 Set oExec
= WshShell
.Exec("git update-index --refresh")
88 If Err
.Number
= 0 Then
89 ' StdOut and StdErr share a 4kB buffer so prevent it from filling up as we don't care about the output
92 ' Wait till the application is finished ...
93 Do While oExec
.Status
= 0
97 Set oExec
= WshShell
.Exec("git diff-index --exit-code --quiet HEAD ../")
98 If Err
.Number
= 0 Then
99 ' Wait till the application is finished ...
100 Do While oExec
.Status
= 0
103 If oExec
.ExitCode
= 1 Then
105 End If ' oExec.ExitCode = 1
107 Set oExec
= WshShell
.Exec("git show -s --pretty=format:%ci")
108 if Err
.Number
= 0 Then
109 isodate
= Mid(oExec
.StdOut
.ReadLine(), 1, 10)
110 isodate
= Replace(isodate
, "-", "")
111 End If ' Err.Number = 0
115 Set oExec
= WshShell
.Exec("git symbolic-ref HEAD")
116 If Err
.Number
= 0 Then
117 line
= oExec
.StdOut
.ReadLine()
118 branch
= Mid(line
, InStrRev(line
, "/") + 1)
119 End If ' Err.Number = 0
121 ' Check if a tag is currently checked out
123 Set oExec
= WshShell
.Exec("git name-rev --name-only --tags --no-undefined HEAD")
124 If Err
.Number
= 0 Then
125 ' Wait till the application is finished ...
126 Do While oExec
.Status
= 0
128 If oExec
.ExitCode
= 0 Then
129 tag
= oExec
.StdOut
.ReadLine()
130 If Right(tag
, 2) = "^0" Then
131 tag
= Left(tag
, Len(tag
) - 2)
133 End If ' oExec.ExitCode = 0
134 End If ' Err.Number = 0
135 End If ' Err.Number = 0
136 End If ' oExec.ExitCode = 0
137 End If ' Err.Number = 0
139 If hash
= "" And FSO
.FileExists("../.ottdrev") Then
141 Set rev_file
= FSO
.OpenTextFile("../.ottdrev", 1, True, 0)
142 DetermineVersion
= rev_file
.ReadLine()
144 ElseIf hash
= "" Then
145 DetermineVersion
= "norev000"
148 Dim version
, hashprefix
, istag
, isstabletag
151 ElseIf modified
= 2 Then
161 Set stable_regexp
= New RegExp
162 stable_regexp
.Pattern
= "^[0-9.]*$"
163 If stable_regexp.Test(tag) Then
169 version = isodate & "-" & branch & hashprefix & shorthash
174 DetermineVersion = version & Chr(9) & isodate & Chr(9) & modified & Chr(9) & hash & Chr(9) & istag & Chr(9) & isstabletag
178 Function IsCachedVersion(ByVal version)
179 Dim cache_file, cached_version
181 Set cache_file = FSO.OpenTextFile("../config
.cache
.version
", 1, True, 0)
182 If Not cache_file.atEndOfStream Then
183 cached_version = cache_file.ReadLine()
187 If InStr(version, Chr(9)) Then
188 version = Mid(version, 1, Instr(version, Chr(9)) - 1)
191 If version <> cached_version Then
192 Set cache_file = fso.CreateTextFile("../config
.cache
.version
", True)
193 cache_file.WriteLine(version)
195 IsCachedVersion = False
197 IsCachedVersion = True
201 Function CheckFile(filename)
202 CheckFile = FSO.FileExists(filename)
203 If CheckFile Then CheckFile = (FSO.GetFile(filename).DateLastModified >= FSO.GetFile(filename & ".in").DateLastModified)
207 version = DetermineVersion
208 If Not (IsCachedVersion(version) And CheckFile("../src
/rev
.cpp
") And CheckFile("../src
/os
/windows
/ottdres
.rc
")) Then