forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revision.jse
63 lines (51 loc) · 1.87 KB
/
revision.jse
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
var ForReading = 1;
var ForWriting = 2;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var rev;
var filename = "revision.h";
var file;
var file_ts;
var errorcode;
// First, get the file, if it doesn't exist create it.
if (!fso.FileExists(filename)) {
fso.CreateTextFile(filename);
file = fso.GetFile(filename);
file_ts = file.OpenAsTextStream(ForWriting, -2);
file_ts.WriteLine("#define REVISION UNDEFINED");
file_ts.Close();
errorcode = 0;
}
else {
file = fso.GetFile(filename);
errorcode = 1;
}
var errormsg = !errorcode
? " Revision number will be set to zero. You won't be able to play online with this build."
: " A revision file already exists and its revision number won't be updated. Make sure the revision number is correct or you won't be able to play online with this build.";
// Try to get revision number
try {
var svnRevNum = shell.Exec("svnversion");
rev = svnRevNum.StdOut.ReadAll();
// Check if SVN output is valid
if (typeof parseInt(rev) !== "number") {
WSH.Echo("svnversion : Unversioned directory warning SVNUD" + errorcode + ":SVN output not valid! Check if the folder is actually versioned." + errormsg);
rev = 0;
}
}
catch (e) {
WSH.Echo("svnversion : SVN not found warning SVNNF" + errorcode + ":SVN could not be found!" + errormsg);
rev = 0;
}
// Read revision.h
file_ts = file.OpenAsTextStream(ForReading, -2);
var current_line = file_ts.ReadLine() + "\r\n";
file_ts.Close();
var new_line = !rev ? "" : "#define REVISION " + String(rev);
if (!errorcode || (!!rev && new_line !== current_line)) {
// It has changed, update the .h
WSH.Echo("revision.h(0) : info SVNUPD:" + (!rev ? "No revision number set!" : "SVN version updated! " + String(rev)));
file_ts = file.OpenAsTextStream(ForWriting, -2);
file_ts.WriteLine(new_line);
file_ts.Close();
}