-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprebuild.ps1
More file actions
174 lines (155 loc) · 4.53 KB
/
prebuild.ps1
File metadata and controls
174 lines (155 loc) · 4.53 KB
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
165
166
167
168
169
170
171
172
173
174
function parse_version($filename) {
$version_content = Get-Content $filename
$version_lines = $version_content -split $newline
$VERSION = $null
$str = "#define";
foreach ($line in $version_lines) {
if ($line -match ("\s*" + $str + "\s+\S+\s+")) {
$pos = $line.IndexOf($str);
$pos += $str.Length;
while ($line[$pos] -le 32) {
++$pos;
}
while ($line[$pos] -gt 32) {
++$pos;
}
$VERSION = $line.Substring($pos).Trim()
if ($VERSION[0] -eq "`"") {
$VERSION = $VERSION.Substring(1);
}
if ($VERSION[$VERSION.Length - 1] -eq "`"") {
$VERSION = $VERSION.Substring(0, $VERSION.Length - 1);
}
return $VERSION;
}
}
if (($null -eq $VERSION) -or (-not ($VERSION -is [String]))) {
throw "Could not parse version."
}
}
function replace_about_dlg($content_lines) {
$inside_dialog = $false
for ($i = 0; $i -lt $content_lines.Count; ++$i) {
$line = $content_lines[$i];
if ($line -match "\s*IDD_ABOUTBOX DIALOGEX") {
$inside_dialog = $true;
} elseif ($inside_dialog -and ($line -match ("\s*LTEXT\s+`"\S+\s+[^`"\s]+`""))) {
$pos1 = $line.IndexOf("`"");
++$pos1; # skip quote
while ($line[$pos1] -gt 32) {
++$pos1;
}
while ($line[$pos1] -le 32) {
++$pos1;
}
$pos2 = $line.IndexOf("`"", $pos1);
$old_version = $line.Substring($pos1, $pos2 - $pos1);
if ($old_version -ne $VERSION) {
$content_lines[$i] = $line.Substring(0, $pos1) + $VERSION + $line.Substring($pos2);
return $true;
}
return $false;
}
}
return $false;
}
function replace_app_title($content_lines) {
for ($i = 0; $i -lt $content_lines.Count; ++$i) {
$line = $content_lines[$i];
if ($line -match "\s*IDS_APP_TITLE\s+`"\S+\s+[^`"\s]+`"") {
$parsing_step = 0
for ($pos = $line.IndexOf("`"") + 1; $pos -lt $line.Length; ++$pos) {
$chr = $line[$pos];
if ($parsing_step -eq 0) {
if ($chr -le 32) {
$parsing_step = 1;
}
} elseif ($parsing_step -eq 1) {
if ($chr -gt 32) {
$parsing_step = 2;
--$pos;
}
} else {
# pos should be pointing to the start of the old VERSION
$pos2 = $line.IndexOf("`"", $pos);
$old_version = $line.Substring($pos, $pos2 - $pos);
if ($old_version -ne $VERSION) {
$content_lines[$i] = $line.Substring(0, $pos) + $VERSION + $line.Substring($pos2);
return $true;
}
return $false;
}
}
return $false;
}
}
return $false;
}
function replace_file_and_product_versions($content_lines, $new_version) {
$need_write = $false;
$new_version_with_dots = $new_version.Replace(",", ".");
$new_version_with_commas = $new_version.Replace(".", ",");
for ($i = 0; $i -lt $content_lines.Count; ++$i) {
$line = $content_lines[$i];
$str1 = "FILEVERSION";
$str2 = "PRODUCTVERSION";
if ((
$line -match "\s*VALUE\s+`"FileVersion`",\s*`"[^`"\s]+`""
) -or (
$line -match "\s*VALUE\s+`"ProductVersion`",\s*`"[^`"\s]+`""
)
) {
$pos = $line.IndexOf("`"");
$pos = $line.IndexOf("`"", $pos + 1);
$pos = $line.IndexOf("`"", $pos + 1);
$pos2 = $line.IndexOf("`"", $pos + 1);
$old_version = $line.Substring($pos + 1, $pos2 - $pos - 1);
if ($old_version -ne $new_version_with_dots) {
$need_write = $true;
$content_lines[$i] = $line.Substring(0, $pos + 1) + $new_version_with_dots + $line.Substring($pos2);
}
} elseif ((
$line -match ("\s*" + $str1 + "\s+\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+")
) -or (
$line -match ("\s*" + $str2 + "\s+\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+")
)
) {
$pos = 0;
while ($line[$pos] -le 32) {
++$pos;
}
while ($line[$pos] -gt 32) {
++$pos;
}
$old_version = $line.Substring($pos).Replace(" ", "").Replace($tab, "");
if ($old_version -ne $new_version_with_commas) {
$need_write = $true;
$content_lines[$i] = $line.Substring(0, $pos) + " " + $new_version_with_commas;
}
}
}
return $need_write;
}
$content = Get-Content "GGXrdFasterLoadingTimes.rc"
$newline = "`
"
$tab = " ";
$TRUE_VERSION = parse_version("Version.h")
$content_lines = $content -split $newline
$need_write = $false
$VERSION = "v" + $TRUE_VERSION
if (replace_about_dlg $content_lines) {
$need_write = $true;
}
if (replace_app_title $content_lines) {
$need_write = $true;
}
$VERSION = $TRUE_VERSION;
$dotpos = $VERSION.IndexOf(".");
$new_version = $VERSION.Substring(0, $dotpos) + ",0," + $VERSION.Substring($dotpos + 1) + ",0";
if (replace_file_and_product_versions $content_lines $new_version) {
$need_write = $true;
}
if ($need_write) {
Set-Content -Value ($content_lines -join $newline) "GGXrdFasterLoadingTimes.rc" -Encoding Unicode
}