diff --git a/versionfiles.ps1 b/versionfiles.ps1 index 9f45b5e..f20add9 100644 --- a/versionfiles.ps1 +++ b/versionfiles.ps1 @@ -23,7 +23,7 @@ if (! [string]::IsNullOrEmpty($BuildString)) { $verBuildString += " `"-$BuildString`"" } -$contents=@" +$NtVerpContents=@" #pragma once // // Generated file: DO NOT EDIT! @@ -149,12 +149,17 @@ if (!(test-path -path $incPath)) { $verpropfile = "$($incPath)\version.props" $buildpropfile = "$($incPath)\buildnumber.props" [bool] $createdMutex = $false -[bool] $mutexHeld = $false $mutexName = ($incPath -replace "\\","-") -replace ":","" -$lock = new-object System.Threading.Mutex($false, $mutexName, [ref] $createdMutex); +$lock = new-object System.Threading.Mutex($true, $mutexName, [ref] $createdMutex); try { - $mutexHeld = $lock.WaitOne() + if (!$createdMutex) { + $lock.WaitOne() + log "mutex acquired after WaitOne." + } else { + log "created mutex $mutexName" + } if ($generateProps -and !(test-path $verpropfile)) { + log "creating $verpropfile" $verprops | Set-Content $verpropfile } [string] $current = "" @@ -164,26 +169,43 @@ try { $current = $current.Trim() } } - $tempContents = $contents.Trim() + $tempContents = $NtVerpContents.Trim() if (($current.Length -ne $tempContents.Length) -or ($current -cne $tempContents)) { - log "creating $($incPath)\ntverp.h" - $contents | set-content "$($incPath)\ntverp.h" + log "creating $($incPath)\ntverp.h current: $($current.Length) new: $($tempContents.Length)" + Remove-Item $incPath\ntverp.h -Force -ErrorAction SilentlyContinue + $tempContents | Set-Content "$($incPath)\ntverp.h" -Force + $current2 = (get-content "$($incPath)\ntverp.h" -raw) + if ($current2.Length) { + $current2 = $current2.Trim() + } + log "New $($incPath)\ntverp.h length $($current2.Length)" + if ($current2.Length -ne $tempContents.Length) { + log "Error truncated $($incPath)\ntverp.h now: $($current2.Length) tempContents: $($tempContents.Length)" + } } if (!(test-path $buildpropfile)) { log "creating $buildpropfile" $buildNumberProps | Set-Content $buildpropfile } else { - log "updating $buildpropfile" - $buildNumberProps | Set-Content $buildpropfile -Force + $current = (get-content $buildpropfile -raw) + if ($current.Length) { + $current = $current.Trim() + } + $buildNumberProps = $buildNumberProps.Trim() + if (($current.Length -ne $buildNumberProps.Length) -or ($current -cne $buildNumberProps)) { + log "updating $buildpropfile" + $buildNumberProps | Set-Content $buildpropfile -Force + } } - $mutexHeld = $false $lock.ReleaseMutex() + log "mutex released." } catch { + Write-Output $_ | Format-List * -Force | Out-String } finally { - if ($mutexHeld) { - $lock.ReleaseMutex(); + if ($lock) { + $lock.Dispose() } } $verfile = "$incPath\version.h"