From 8cd54374abb4f3bf35a1f66dfcee6c06c95c93c3 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Sat, 8 Apr 2023 11:00:40 +0300 Subject: [PATCH] Update versioning script. --- Update_Version.ps1 | 194 ++++++++++++++++++++++++++++++++------------- Version.ini | Bin 0 -> 998 bytes wCenterWindow.sln | 2 +- 3 files changed, 138 insertions(+), 58 deletions(-) create mode 100644 Version.ini diff --git a/Update_Version.ps1 b/Update_Version.ps1 index 81a998d..7e91af4 100644 --- a/Update_Version.ps1 +++ b/Update_Version.ps1 @@ -1,85 +1,165 @@ -# Update_Version.ps1 +# Update Version v2.0 +# Required module: PSIni +# Installation: Install-Module -Name PsIni $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] +function addLeadingZero([int]$nvar) { + [string]$svar = $null + if ($nvar -lt 10) { $svar = '0' + $nvar.ToString() } + else { $svar = $nvar.ToString() } + return $svar } -$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 +function getValue([string]$var) { + switch -CaseSensitive ($var) { + "%y" { $var = $currentYear; break } + "%m" { $var = $currentMonth; break } + "%d" { $var = $currentDay; break } + "%t" { $var = -join ((addLeadingZero($currentHour)), (addLeadingZero($currentMinute)), (addLeadingZero($currentSecond))); break } + "%D" { $var = $spanDays; break } + "%S" { $var = $spanSecs; break } + "%C" { $var = $gitCommitCount; break } + "%c" { $var = $gitRevCount; break } + } + return $var } -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 = "" +function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string]$vrev) { + [string]$vstr = $null + if ($vmin -eq "") { $vmin = $vbld = $vrev = 0; $vstr = ($vmaj) -join '.' } + else { + if ($vbld -eq "") { $vbld = $vrev = 0; $vstr = ($vmaj, $vmin) -join '.' } + else { + if ($vrev -eq "") { $vrev = 0; $vstr = ($vmaj, $vmin, $vbld) -join '.' } + else { $vstr = ($vmaj, $vmin, $vbld, $vrev) -join '.' } + } + } + [string]$nstr = ($vmaj, $vmin, $vbld, $vrev) -join ',' + $res = @($vstr, $nstr) + return $res +} -if ($pys -eq $currentYear) { - $pcf = "Copyright (C) $pys by $pa" -} else { - $pcf = "Copyright (C) $pys-$currentYear by $pa" -} +#region Initializing variables +[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verRevision = $null +[string]$pn = [string]$pa = [string]$aboutBuild = [string]$pnf = [string]$pcf = $null +[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null +[int]$pys = [int]$spanDays = [int]$spanSecs = $null +[int]$currentYear = [int]$currentMonth = [int]$currentDay = [int]$currentHour = [int]$currentMinute = [int]$currentSecond = $null +[string]$iniFile = ".\Version.ini" +#endregion -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 (-not (Test-Path $iniFile)) { + Write-Error "Can't find file '$iniFile'" + # Start-Sleep -Seconds 3 + exit 1 +} +[bool]$isGit = $false +if (Test-Path ".\.git") { + $isGit = $true + [int]$gitCommitCount = [int]$gitRevCount = $null + [string]$gitRevDate = [string]$gitVerStr = $null + $gitCommitCount = $(git rev-list --count HEAD) + $gitRevDate = $(git log -1 HEAD --date=rfc --pretty=format:%ad%n) + $gitVerStr = $(git describe HEAD --long) if ($LastExitCode -eq 0) { $gitVerStr = $gitVerStr.Replace('-g', '-') $gitRevCount = $gitVerStr.Split('-')[-2] - } else { + } + 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() - } +#region Reading values from INI file +$config = $null +$config = (Get-IniContent -FilePath $iniFile)["Config"] +$verMajor = $config.Major +$verMinor = $config.Minor +$verBuild = $config.Build +$verRevision = $config.Revision +$pys = $config.ProductYearStart +$pn = $config.ProductName +$pa = $config.ProductAutors +$pd = $config.ProductDescription +#endregion - "#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 -} +if ($verMajor -eq "") { + Write-Error "Major version cannot be empty!" + # Start-Sleep -Seconds 3 + exit 2 +} -$intName = "$pn`C++" +#region Variables preparation +$currentYear = $date.Year +$currentMonth = $date.Month +$currentDay = $date.Day +$currentHour = $date.Hour +$currentMinute = $date.Minute +$currentSecond = $date.Second +$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 ($pys -eq $currentYear) { $pcf = "Copyright (C) $pys by $pa" } else { $pcf = "Copyright (C) $pys-$currentYear by $pa" } +$intName = "$pn-C++" $origName = "$pn.exe" +$verMajor = getValue $verMajor +$verMinor = getValue $verMinor +$verBuild = getValue $verBuild +$verRevision = getValue $verRevision +#endregion -"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +$vs = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[0] +$vn = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[1] + +if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" } +if ($isGit) { $aboutBuild = "Git date: $gitRevDate" } else { $aboutBuild = $buildDateTime } + +#region Save all variables to file +"// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode +"// VersionInfo.h" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#pragma once" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_NAME `"$pn`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_AUTHORS `"$pa`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_DESCRIPTION `"$pd`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define ABOUT_BUILD `"$aboutBuild`"" | 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 +# "#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# "#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +if ($isGit) { + "#define GIT_VERSION_STR `"$gitVerStr`"" | 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 +} +#endregion + +#region Print out all variables +# echo " verMajor: [$verMajor]" +# echo " verMinor: [$verMinor]" +# echo " verBuild: [$verBuild]" +# echo " verRevision: [$verRevision]" +# echo "" +# echo " aboutBuild: [$aboutBuild]" +# echo " productNameFull: [$pnf]" +# echo "productCopyrightFull: [$pcf]" +# echo " internalName: [$intName]" +# echo " originalName: [$origName]" +# echo " versionStr: [$vs]" +# echo " versionNum: [$vn]" +# echo " spanDays: [$spanDays]" +# echo " spanSecs: [$spanSecs]" +# echo "" +# echo " gitCommitCount: [$gitCommitCount]" +# echo " gitRevCount: [$gitRevCount]" +# echo " gitRevDate: [$gitRevDate]" +# echo " gitVerStr: [$gitVerStr]" +#endregion diff --git a/Version.ini b/Version.ini new file mode 100644 index 0000000000000000000000000000000000000000..204fc66586c2b6ae0b5849a8473db05a4ac7cc0a GIT binary patch literal 998 zcmaizPfx-?5XI+g;&-SA!byYZ&3I6V@gT;?ff(ZfT7(J((iTj=y!v~)#a4xwN&n33 z%zJNUcRxR#tz%1D*sH}hu@^hE1G})m8dmT=<_T?WDK;i6$1nIB;#Zl;p3KA{=Qge7 zMtgE2FpFBAn0B$}=uA)$@Llk}#d=sD3+Q5rvZRL7Epaki!JrDyl)3Dbe5r5QshyPX zHeXrQpOB@c!pKk%y6z&P;@u)8=!)RcG^fm~Lg|z!IdwT&=J>)`mvfy^qplT8FnL+6 zJ}m41uc_;q!<0E(aZbMRdU$UzrJ!!;CM7Gz*MvgW7MOGfHgeM*qiBU+*pb7i*I$y= zE~DBNkE-aIi(b=XOuyQDMbBOI5!?;&idSn5&ZB1b;3gVT8N&KRuFhPae|@FPv$kON zd-b#8o;-g}l=lv*Kfmg90P6xZOX7dIuHe)jX(FCw0K=W#;0n>R0rtuXIbbor*{Ry$lcm0t2xned857n D0U)4b literal 0 HcmV?d00001 diff --git a/wCenterWindow.sln b/wCenterWindow.sln index 8f2ed13..2e42ca0 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -7,7 +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.ps1 = Update_Version.ps1 + Version.h = Version.h EndProjectSection EndProject Global