forked from telegramdesktop/tdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_version.bat
166 lines (149 loc) · 6.49 KB
/
set_version.bat
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
@echo OFF
setlocal enabledelayedexpansion
set "FullScriptPath=%~dp0"
set "InputVersion=%1"
for /F "tokens=1,2,3,4 delims=. " %%a in ("%InputVersion%") do (
set "VersionMajor=%%a"
set "VersionMinor=%%b"
set "VersionPatch=%%c"
if "%%d" == "" (
set "VersionBeta=0"
set "VersionAlpha=0"
) else if "%%d" == "alpha" (
set "VersionBeta=0"
set "VersionAlpha=1"
) else (
set "VersionBeta=%%d"
set "VersionAlpha=0"
)
)
set /a "VersionMajorCleared=%VersionMajor% %% 1000"
if "%VersionMajorCleared%" neq "%VersionMajor%" (
echo Bad major version!
exit /b 1
)
set /a "VersionMinorCleared=%VersionMinor% %% 1000"
if "%VersionMinorCleared%" neq "%VersionMinor%" (
echo Bad minor version!
exit /b 1
)
set /a "VersionPatchCleared=%VersionPatch% %% 1000"
if "%VersionPatchCleared%" neq "%VersionPatch%" (
echo Bad patch version!
exit /b 1
)
if "%VersionAlpha%" neq "0" (
if "%VersionAlpha%" neq "1" (
echo Bad alpha version!
exit /b 1
)
set "VersionAlphaBool=true"
) else (
set "VersionAlphaBool=false"
)
set /a "VersionFull=%VersionMajor% * 1000000 + %VersionMinor% * 1000 + %VersionPatch%"
if "%VersionBeta%" neq "0" (
set /a "VersionBetaCleared=%VersionBeta% %% 1000"
if "!VersionBetaCleared!" neq "%VersionBeta%" (
echo Bad beta version!
exit /b 1
)
set /a "VersionBetaMul=1000 + %VersionBeta%"
set "VersionFullBeta=%VersionFull%!VersionBetaMul:~1!"
) else (
set "VersionFullBeta=0"
)
set "VersionStr=%VersionMajor%.%VersionMinor%.%VersionPatch%"
if "%VersionPatch%" neq "0" (
set "VersionStrSmall=%VersionStr%"
) else (
set "VersionStrSmall=%VersionMajor%.%VersionMinor%"
)
if "%VersionAlpha%" neq "0" (
echo Setting version: %VersionStr% alpha
) else if "%VersionBeta%" neq "0" (
echo Setting version: %VersionStr%.%VersionBeta% closed beta
) else (
echo Setting version: %VersionStr% stable
)
echo Checking changelog...
set "ChangelogFile=%FullScriptPath%..\..\changelog.txt"
call :count "Argument=^%VersionStr% " "Filename=%ChangelogFile%"
if "%FoundCount%" equ "0" (
call :count "Argument=^%VersionStrSmall% " "Filename=%ChangelogFile%"
if "!FoundCount!" equ "0" (
echo Changelog entry not found!
exit /b 1
) else if "!FoundCount!" neq "1" (
echo Wrong changelog entries count found: %FoundCount%
exit /b 1
)
) else if "%FoundCount%" neq "1" (
echo Wrong changelog entries count found: %FoundCount%
exit /b 1
)
echo Patching build/version...
set "VersionFilePath=%FullScriptPath%version"
call :repl "Argument=(AppVersion) (\s*)\d+/$1$2 %VersionFull%" "Filename=%VersionFilePath%" || goto :error
call :repl "Argument=(AppVersionStrMajor) (\s*)[\d\.]+/$1$2 %VersionMajor%.%VersionMinor%" "Filename=%VersionFilePath%" || goto :error
call :repl "Argument=(AppVersionStrSmall) (\s*)[\d\.]+/$1$2 %VersionStrSmall%" "Filename=%VersionFilePath%" || goto :error
call :repl "Argument=(AppVersionStr) (\s*)[\d\.]+/$1$2 %VersionStr%" "Filename=%VersionFilePath%" || goto :error
call :repl "Argument=(AlphaChannel) (\s*)[\d\.]+/$1$2 %VersionAlpha%" "Filename=%VersionFilePath%" || goto :error
call :repl "Argument=(BetaVersion) (\s*)\d+/$1$2 %VersionFullBeta%" "Filename=%VersionFilePath%" || goto :error
echo Patching core/version.h...
set "VersionHeaderPath=%FullScriptPath%..\SourceFiles\core\version.h"
call :repl "Argument=(BETA_VERSION_MACRO\s+)\(\d+ULL\)/$1(%VersionFullBeta%ULL)" "Filename=%VersionHeaderPath%" || goto :error
call :repl "Argument=(AppVersion\s+=) (\s*)\d+/$1$2 %VersionFull%" "Filename=%VersionHeaderPath%" || goto :error
call :repl "Argument=(AppVersionStr\s+=) (\s*)[&hat;;]+/$1$2 "%VersionStrSmall%"" "Filename=%VersionHeaderPath%" || goto :error
call :repl "Argument=(AppAlphaVersion\s+=) (\s*)[a-z]+/$1$2 %VersionAlphaBool%" "Filename=%VersionHeaderPath%" || goto :error
echo Patching Telegram.rc...
set "ResourcePath=%FullScriptPath%..\Resources\winrc\Telegram.rc"
call :repl "Argument=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
echo Patching Updater.rc...
set "ResourcePath=%FullScriptPath%..\Resources\winrc\Updater.rc"
call :repl "Argument=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
call :repl "Argument=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
echo Patching appxmanifest.xml...
set "ResourcePath=%FullScriptPath%..\Resources\uwp\AppX\AppxManifest.xml"
call :repl "Argument= (Version=)"\d+.\d+.\d+.\d+"/ $1"%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
exit /b
:error
(
set ErrorCode=%errorlevel%
echo Error !ErrorCode!
exit /b !ErrorCode!
)
:repl
(
set %1
set %2
set "TempFilename=!Filename!__tmp__"
cscript //Nologo "%FullScriptPath%replace.vbs" "Replace" "!Argument!" < "!Filename!" > "!TempFilename!" || goto :repl_finish
xcopy /Y !TempFilename! !Filename! >NUL || goto :repl_finish
goto :repl_finish
)
:count
(
set %1
set %2
set "TempFilename=!Filename!__tmp__"
cscript //Nologo "%FullScriptPath%replace.vbs" "Count" "!Argument!" < "!Filename!" > "!TempFilename!" || goto :repl_finish
FOR /F "tokens=1,2* delims= " %%i in (!TempFilename!) do set "FoundCount=%%i"
goto :repl_finish
)
:repl_finish
(
set ErrorCode=%errorlevel%
if !ErrorCode! neq 0 (
echo Replace error !ErrorCode!
echo While replacing "%Replace%"
echo In file "%Filename%"
)
del %TempFilename%
exit /b !ErrorCode!
)