2016-04-27 12:03:10 +00:00
|
|
|
@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"
|
2016-04-27 13:59:08 +00:00
|
|
|
set "VersionPatch=%%c"
|
2016-04-27 12:03:10 +00:00
|
|
|
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
|
|
|
|
)
|
2016-04-27 13:59:08 +00:00
|
|
|
set /a "VersionPatchCleared=%VersionPatch% %% 1000"
|
|
|
|
if "%VersionPatchCleared%" neq "%VersionPatch%" (
|
|
|
|
echo Bad patch version!
|
2016-04-27 12:03:10 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2016-04-27 13:59:08 +00:00
|
|
|
set /a "VersionFull=%VersionMajor% * 1000000 + %VersionMinor% * 1000 + %VersionPatch%"
|
2016-04-27 12:03:10 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2016-04-27 13:59:08 +00:00
|
|
|
set "VersionStr=%VersionMajor%.%VersionMinor%.%VersionPatch%"
|
|
|
|
if "%VersionPatch%" neq "0" (
|
|
|
|
set "VersionStrSmall=%VersionStr%"
|
|
|
|
) else (
|
|
|
|
set "VersionStrSmall=%VersionMajor%.%VersionMinor%"
|
2016-04-27 12:03:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if "%VersionAlpha%" neq "0" (
|
2016-04-27 13:59:08 +00:00
|
|
|
echo Setting version: %VersionStr% alpha
|
2016-04-27 12:03:10 +00:00
|
|
|
) else if "%VersionBeta%" neq "0" (
|
2016-04-27 13:59:08 +00:00
|
|
|
echo Setting version: %VersionStr%.%VersionBeta% closed beta
|
2016-04-27 12:03:10 +00:00
|
|
|
) else (
|
2016-04-27 13:59:08 +00:00
|
|
|
echo Setting version: %VersionStr% stable
|
2016-04-27 12:03:10 +00:00
|
|
|
)
|
|
|
|
|
2017-03-01 18:42:36 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2016-04-27 12:03:10 +00:00
|
|
|
echo Patching build/version...
|
|
|
|
set "VersionFilePath=%FullScriptPath%version"
|
2017-03-01 18:42:36 +00:00
|
|
|
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
|
2016-04-27 12:03:10 +00:00
|
|
|
|
|
|
|
echo Patching core/version.h...
|
|
|
|
set "VersionHeaderPath=%FullScriptPath%..\SourceFiles\core\version.h"
|
2017-03-01 18:42:36 +00:00
|
|
|
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
|
2016-04-27 12:03:10 +00:00
|
|
|
|
|
|
|
echo Patching Telegram.rc...
|
|
|
|
set "ResourcePath=%FullScriptPath%..\Resources\winrc\Telegram.rc"
|
2017-03-01 18:42:36 +00:00
|
|
|
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
|
2016-04-27 12:03:10 +00:00
|
|
|
|
|
|
|
echo Patching Updater.rc...
|
|
|
|
set "ResourcePath=%FullScriptPath%..\Resources\winrc\Updater.rc"
|
2017-03-01 18:42:36 +00:00
|
|
|
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
|
2016-04-27 12:03:10 +00:00
|
|
|
|
2017-02-01 10:12:52 +00:00
|
|
|
echo Patching appxmanifest.xml...
|
2017-02-03 20:07:26 +00:00
|
|
|
set "ResourcePath=%FullScriptPath%..\Resources\uwp\AppX\AppxManifest.xml"
|
2017-03-01 18:42:36 +00:00
|
|
|
call :repl "Argument= (Version=)"\d+.\d+.\d+.\d+"/ $1"%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error
|
2017-02-01 10:12:52 +00:00
|
|
|
|
2016-04-27 12:03:10 +00:00
|
|
|
exit /b
|
|
|
|
|
|
|
|
:error
|
|
|
|
(
|
|
|
|
set ErrorCode=%errorlevel%
|
|
|
|
echo Error !ErrorCode!
|
|
|
|
exit /b !ErrorCode!
|
|
|
|
)
|
|
|
|
|
|
|
|
:repl
|
|
|
|
(
|
|
|
|
set %1
|
|
|
|
set %2
|
|
|
|
set "TempFilename=!Filename!__tmp__"
|
2017-03-01 18:42:36 +00:00
|
|
|
cscript //Nologo "%FullScriptPath%replace.vbs" "Replace" "!Argument!" < "!Filename!" > "!TempFilename!" || goto :repl_finish
|
2016-04-27 12:03:10 +00:00
|
|
|
xcopy /Y !TempFilename! !Filename! >NUL || goto :repl_finish
|
|
|
|
goto :repl_finish
|
|
|
|
)
|
|
|
|
|
2017-03-01 18:42:36 +00:00
|
|
|
: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
|
|
|
|
)
|
|
|
|
|
2016-04-27 12:03:10 +00:00
|
|
|
: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!
|
|
|
|
)
|