-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion.ps1
More file actions
139 lines (127 loc) · 5.54 KB
/
Copy pathVersion.ps1
File metadata and controls
139 lines (127 loc) · 5.54 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
# ------------------------------------------------------------
# PowerShell script to perform Version patching for Notepad3
# ToDo:
# - adapt $Build number in case of local machine builds
# ------------------------------------------------------------
param(
[string]$VerPatch = ""
)
# ------------------------------------------------------------
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop" ## Write-Error should throw ...
# ------------------------------------------------------------
$ScriptDir = Split-Path -Path "$(if ($PSVersionTable.PSVersion.Major -ge 3) { $PSCommandPath } else { & { $MyInvocation.ScriptName } })" -Parent
# ------------------------------------------------------------
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$LastExitCode = 0
# ------------------------------------------------------------
# ============================================================
function DebugOutput($msg)
# ------------------------------------------------------------
{
#~return ## disabled debug output
if ($msg -ne $null) {
Write-Host ""
Write-Host "$msg"
}
}
# ------------------------------------------------------------
# ============================================================
try
{
$AppName = "LumPad"
$Major = 7
$Minor = [int]$(Get-Date -format yy)
$Revis = [int]$(Get-Date -format Mdd)
$BuildPath = "Versions\build.txt"
if (!(Test-Path $BuildPath)) {
New-Item -Path $BuildPath -ItemType "file" -Value "101"
}
$Build = [int](Get-Content $BuildPath)
if (!$Build) { $Build = 0 }
$DayPath = "Versions\day.txt"
if (!(Test-Path $DayPath)) {
New-Item -Path $DayPath -ItemType "file" -Value "0"
}
$LastBuildDay = [string](Get-Content $DayPath)
if (!$LastBuildDay) { $LastBuildDay = 0 }
if ($LastBuildDay -ne "$Revis") {
$Revis | Set-Content -Path $DayPath
$Build = 0 # reset (local build)
}
# locally: increase build number and persist it
$Build = $Build + 1
# locally: read short commit ID from .git\refs\heads\<first ref> (optional)
$HeadDir = Join-Path $ScriptDir ".git\refs\heads"
$CommitID = ""
if (Test-Path -LiteralPath $HeadDir) {
$headFile = Get-ChildItem -LiteralPath $HeadDir -Force -Recurse -File -ErrorAction SilentlyContinue | Select-Object -First 1
if ($null -ne $headFile) {
$CommitID = [string](Get-Content -LiteralPath $headFile.FullName -TotalCount 1 -ErrorAction SilentlyContinue)
}
}
if (!$CommitID) {
$length = ([string]($env:computername)).length
$CommitID = ([string]($env:computername)).substring(0,[math]::min($length,8)).ToLower()
}
$CommitID = $CommitID -replace '"', ''
$CommitID = $CommitID -replace "'", ''
$length = $CommitID.length
$CommitID = $CommitID.substring(0,[math]::min($length,8))
if (!$CommitID) { $CommitID = "---" }
$Build | Set-Content -Path $BuildPath
$CompleteVer = "$Major.$Minor.$Revis.$Build"
DebugOutput("LumPad version number: 'v$CompleteVer $VerPatch'")
DebugOutput("LumPad commit ID: '$CommitID'")
$SciVer = [string](Get-Content "scintilla\version.txt")
if (!$SciVer) { $SciVer = 0 }
$LxiVer = [string](Get-Content "lexilla\version.txt")
if (!$LxiVer) { $LxiVer = 0 }
$PCRE2Ver = [string](Get-Content "scintilla\pcre2\version.txt")
if (!$PCRE2Ver) { $PCRE2Ver = "0.0" }
$UChardetVer = [string](Get-Content "src\uchardet\version.txt")
if (!$UChardetVer) { $UChardetVer = "0.0.0" }
$TinyExprVer = [string](Get-Content "src\tinyexprcpp\version.txt")
if (!$TinyExprVer) { $TinyExprVer = "0.0.0" }
$UtHashVer = [string](Get-Content "src\uthash\version.txt")
if (!$UtHashVer) { $UtHashVer = "0.0.0" }
#~if ($VerPatch) { $VerPatch = " $VerPatch" } # ensure space in front of string
$VersionContent = Get-Content "Versions\VersionEx.h.tpl" -Raw
$VersionContent = $VersionContent -replace '\$APPNAME\$', "$AppName"
$VersionContent = $VersionContent -replace '\$SAPPNAME\$', "$AppName"
$VersionContent = $VersionContent -replace '\$WCH_APPEXE_STEM\$', "$AppName"
$VersionContent = $VersionContent -replace '\$MAJOR\$', "$Major"
$VersionContent = $VersionContent -replace '\$MINOR\$', "$Minor"
$VersionContent = $VersionContent -replace '\$MAINT\$', "$Revis"
$VersionContent = $VersionContent -replace '\$BUILD\$', "$Build"
$VersionContent = $VersionContent -replace '\$SCIVER\$', "$SciVer"
$VersionContent = $VersionContent -replace '\$LXIVER\$', "$LxiVer"
$VersionContent = $VersionContent -replace '\$PCRE2VER\$', "$PCRE2Ver"
$VersionContent = $VersionContent -replace '\$UCHARDETVER\$', "$UChardetVer"
$VersionContent = $VersionContent -replace '\$TINYEXPRVER\$', "$TinyExprVer"
$VersionContent = $VersionContent -replace '\$UTHASHVER\$', "$UtHashVer"
$VersionContent = $VersionContent -replace '\$VERPATCH\$', "$VerPatch"
$VersionContent = $VersionContent -replace '\$COMMITID\$', "$CommitID"
Set-Content -Path "src\VersionEx.h" -Value $VersionContent -NoNewline
$ConfManifest = "res\$AppName.exe.conf.manifest"
$ManifestContent = Get-Content "Versions\Notepad3.exe.manifest.tpl" -Raw
$ManifestContent = $ManifestContent -replace '\$APPNAME\$', "$AppName"
$ManifestContent = $ManifestContent -replace '\$VERPATCH\$', "$VerPatch"
$ManifestContent = $ManifestContent -replace '\$VERSION\$', "$CompleteVer"
Set-Content -Path $ConfManifest -Value $ManifestContent -NoNewline
}
catch
{
if ($LastExitCode -eq 0) { $LastExitCode = 99 }
$errorMessage = $_.Exception.Message
Write-Warning "Exception caught: `"$errorMessage`"!"
throw $_
}
finally
{
[Environment]::SetEnvironmentVariable("LASTEXITCODE", $LastExitCode, "User")
$host.SetShouldExit($LastExitCode)
Write-Host ""
Write-Host "VersionPatching: Done! Elapsed time: $($stopwatch.Elapsed)."
Exit $LastExitCode
}