diff --git a/Update_Version.ps1 b/Update_Version.ps1 new file mode 100644 index 0000000..81a998d --- /dev/null +++ b/Update_Version.ps1 @@ -0,0 +1,85 @@ +# Update_Version.ps1 + +$date = Get-Date + +function ParseString ([string]$searchString) { + [string]$result = (Select-String -Path '.\VersionInfo.h' -Pattern $searchString -SimpleMatch).Line + if ([string]::IsNullOrEmpty($result)) { return -1 } + return ($result -split "\s+", 3).Trim('"')[2] +} + +$currentYear = $date.Year +$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))" +$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays) +$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds) + +if (-not (Test-Path .\Version.h)) { + Write-Host "Can't find file 'Version.h'" + Start-Sleep -Seconds 3 + exit +} +Copy-Item .\Version.h .\VersionInfo.h + +$verMajor = ParseString("V_MAJOR") +$verMinor = ParseString("V_MINOR") +$verPatch = ParseString("V_PATCH") +$pn = ParseString("PRODUCT_NAME") +$pa = ParseString("PRODUCT_AUTHORS") +$pys = ParseString("PRODUCT_YEAR_START") +$aboutBuild = "" +$pnf = "" + +if ($pys -eq $currentYear) { + $pcf = "Copyright (C) $pys by $pa" +} else { + $pcf = "Copyright (C) $pys-$currentYear by $pa" +} + +if (Test-Path .\.git) { + $gitCommitCount = Invoke-Expression -Command "git rev-list --count HEAD" + $gitRevBranch = Invoke-Expression -Command "git symbolic-ref --short HEAD" + $gitRevDate = Invoke-Expression -Command "git log -1 --date=rfc --pretty=format:%ad%n" + $gitVerStr = Invoke-Expression -Command "git describe --long" + + if ($LastExitCode -eq 0) { + $gitVerStr = $gitVerStr.Replace('-g', '-') + $gitRevCount = $gitVerStr.Split('-')[-2] + } else { + $gitVerStr = "" + $gitRevCount = $gitCommitCount + } + + $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch, $gitRevCount) + $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch, $gitRevCount) + + if ($gitVerStr -eq "") { + $pnf = "$pn v$vs" + } else { + $pnf = "$pn $gitVerStr".Trim() + } + + "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_BRANCH `"$gitRevBranch`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + $aboutBuild = "Git date: $gitRevDate" +} else { + $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch) + $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch) + $pnf = "$pn v$vs" + $aboutBuild = $buildDateTime +} + +$intName = "$pn`C++" +$origName = "$pn.exe" + +"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define INTERNAL_NAME `"$intName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define ORIG_FILE_NAME `"$origName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_COPYRIGHT `"$pcf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define VERSION_STR `"$vs`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append diff --git a/Update_version.bat b/Update_version.bat deleted file mode 100644 index f4ad142..0000000 --- a/Update_version.bat +++ /dev/null @@ -1,90 +0,0 @@ -@ECHO OFF -CHCP 1251 >nul -SETLOCAL ENABLEDELAYEDEXPANSION - -SET CURRENT_TIME=%TIME% -SET CURRENT_DATE=%DATE% - -SET BUILDTIME=%CURRENT_TIME:~0,8% -SET BUILDDATE=%CURRENT_DATE% -SET BUILD_DATETIME=Build time: %BUILDDATE% %BUILDTIME% -SET CURRENT_YEAR=%CURRENT_DATE:~6,4% -SET BUILDSECS=0 - -SET GIT_COUNT=0 -SET GIT_TIME=0 -SET GIT_DATE=0 -SET GIT_DATETIME=0 - -SET VerMajor=0 -SET VerMinor=0 -SET VerPatch=0 - -SET INT_NAME=0 -SET PN=0 -SET VS=0 -SET VSF=0 -SET PCF=0 -SET PYS=0 -SET PA=0 - -CD /D %~dp0 -IF NOT EXIST "Version.h" ( - ECHO Can't find file 'Version.h' - TIMEOUT /T 3 - EXIT /B 1 -) -COPY /Y "Version.h" "VersionInfo.h" >nul - -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MAJOR" "VersionInfo.h"') DO (SET "VerMajor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MINOR" "VersionInfo.h"') DO (SET "VerMinor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_PATCH" "VersionInfo.h"') DO (SET "VerPatch=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_NAME" "VersionInfo.h"') DO (SET "PN=%%~A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_YEAR_START" "VersionInfo.h"') DO (SET "PYS=%%A") -FOR /F "tokens=2*" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_AUTHORS" "VersionInfo.h"') DO (SET "PA=%%~B") -FOR /F "tokens=1-4 delims=:., " %%A IN ("%BUILDTIME%") DO (SET /A "BUILDSECS=%%A * 3600 + %%B * 60 + %%C") - -IF EXIST ".git" ( - FOR /F "delims=" %%A IN ('git rev-list --count HEAD') DO (SET /A GIT_COUNT=%%A) - FOR /F "tokens=1,2 delims= " %%A IN ('git log -1 --date=format:%%d.%%m.%%Y ^| find /I "Date:"') DO (SET "GIT_DATE=%%B") - FOR /F "tokens=2-4 delims=, " %%A IN ('git log -1 --date=format:"%%a,%%d-%%h-%%Y,%%T" ^| find /I "Date:"') DO ( - SET "GIT_DATETIME=Git time: %%A, %%B %%C" - SET "GIT_TIME=%%C" - ) -) - -SET VSF=%VerMajor%.%VerMinor%.%VerPatch%.%GIT_COUNT% -SET VS=%VerMajor%.%VerMinor%.%VerPatch% -SET VNF=%VerMajor%,%VerMinor%,%VerPatch%,%GIT_COUNT% -SET VN=%VerMajor%,%VerMinor%,%VerPatch% - -SET PNF=%PN% v%VSF% (C++) -SET PCF=Copyright (C) %PYS%-%CURRENT_YEAR% by %PA% - -SET INT_NAME=%PN%C++ -SET ORIG_NAME=%PN%.exe - -ECHO #define BUILD_DATE "%BUILDDATE%">> VersionInfo.h -ECHO #define BUILD_TIME "%BUILDTIME%">> VersionInfo.h -ECHO #define BUILD_DATETIME "%BUILD_DATETIME%">> VersionInfo.h - -IF EXIST ".git" ( - ECHO #define GIT_DATE "%GIT_DATE%">> VersionInfo.h - ECHO #define GIT_TIME "%GIT_TIME%">> VersionInfo.h - ECHO #define GIT_DATETIME "%GIT_DATETIME%">> VersionInfo.h - ECHO #define GIT_COUNT %GIT_COUNT% >> VersionInfo.h -) - -ECHO #define V_SECS %BUILDSECS% >> VersionInfo.h -ECHO #define INTERNAL_NAME "%INT_NAME%">> VersionInfo.h -ECHO #define ORIG_FILE_NAME "%ORIG_NAME%">> VersionInfo.h -ECHO #define PRODUCT_NAME_FULL "%PNF%">> VersionInfo.h -ECHO #define PRODUCT_COPYRIGHT "%PCF%">> VersionInfo.h -ECHO #define VERSION_NUM %VN% >> VersionInfo.h -ECHO #define VERSION_STR "%VS%">> VersionInfo.h -ECHO #define VERSION_NUM_FULL %VNF% >> VersionInfo.h -ECHO #define VERSION_STR_FULL "%VSF%">> VersionInfo.h - -ENDLOCAL -TIMEOUT /T 1 >nul -EXIT diff --git a/pre-build.cmd b/pre-build.cmd new file mode 100644 index 0000000..a5d6210 --- /dev/null +++ b/pre-build.cmd @@ -0,0 +1,22 @@ +@ECHO OFF + +REM In VisualStudio add to Pre-Build events: +REM "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" +REM Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives' + +IF "%~1" == "" GOTO :no_args +IF "%~2" == "" GOTO :no_args +SET solutionDir=%1 +SET projectDir=%2 + +ECHO solutionDir: %solutionDir% +ECHO projectDir: %projectDir% + +CD /D %solutionDir% +powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1 +MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h +EXIT + +:no_args +ECHO Not enough arguments! +EXIT 1 diff --git a/wCenterWindow.sln b/wCenterWindow.sln index fe3ab9e..8f2ed13 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -7,8 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}" ProjectSection(SolutionItems) = preProject - Update_version.bat = Update_version.bat - Version.h = Version.h + Update_Version.ps1 = Update_Version.ps1 EndProjectSection EndProject Global diff --git a/wCenterWindow/VersionInfo.rc b/wCenterWindow/VersionInfo.rc index 8e7e879..bf98286 100644 Binary files a/wCenterWindow/VersionInfo.rc and b/wCenterWindow/VersionInfo.rc differ diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 679329f..aa34978 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -514,7 +514,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) WCHAR szAboutHelp[MAX_LOADSTRING * 12]; MultiByteToWideChar(1251, 0, PRODUCT_NAME_FULL, _countof(PRODUCT_NAME_FULL), szAboutProgName, MAX_LOADSTRING); MultiByteToWideChar(1251, 0, PRODUCT_COPYRIGHT, _countof(PRODUCT_COPYRIGHT), szAboutCopyright, MAX_LOADSTRING); - MultiByteToWideChar(1251, 0, BUILD_DATETIME, _countof(BUILD_DATETIME), szAboutBuildTime, MAX_LOADSTRING); + MultiByteToWideChar(1251, 0, ABOUT_BUILD, _countof(ABOUT_BUILD), szAboutBuildTime, MAX_LOADSTRING); LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp)); SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName); SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright); diff --git a/wCenterWindow/wCenterWindow.vcxproj b/wCenterWindow/wCenterWindow.vcxproj index 3c2f0d1..55588b8 100644 --- a/wCenterWindow/wCenterWindow.vcxproj +++ b/wCenterWindow/wCenterWindow.vcxproj @@ -112,8 +112,7 @@ - start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" - + "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" @@ -138,8 +137,7 @@ %(AdditionalManifestFiles) - start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" - + powershell -ExecutionPolicy RemoteSigned -File "$(SolutionDir)Update_Version.ps1" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" @@ -159,7 +157,7 @@ %(AdditionalManifestFiles) - "$(SolutionDir)Update_version.bat" + powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" @@ -184,7 +182,7 @@ %(AdditionalManifestFiles) - "$(SolutionDir)Update_version.bat" + powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"