From b4fb59ae5df8d904aacc775fec157d9d52c64574 Mon Sep 17 00:00:00 2001 From: Peter Crabtree Date: Thu, 28 Aug 2025 20:03:12 -0400 Subject: [PATCH] dev: Standardize ps1 files to tabs --- BuildTools/bom-classify-encodings.ps1 | 222 +++++++++--------- BuildTools/bom-strip.ps1 | 248 ++++++++++----------- BuildTools/create-filelists.ps1 | 38 ++-- BuildTools/ghactions-install.ps1 | 4 +- BuildTools/update-assemblyinfo.ps1 | 182 +++++++-------- ICSharpCode.Decompiler.PowerShell/Demo.ps1 | 4 +- 6 files changed, 349 insertions(+), 349 deletions(-) diff --git a/BuildTools/bom-classify-encodings.ps1 b/BuildTools/bom-classify-encodings.ps1 index 269d25894..415223659 100644 --- a/BuildTools/bom-classify-encodings.ps1 +++ b/BuildTools/bom-classify-encodings.ps1 @@ -5,17 +5,17 @@ Classify text files by encoding under the current subtree, respecting .gitignore .DESCRIPTION Enumerates tracked files and untracked-but-not-ignored files (via Git) beneath PWD. Skips likely-binary files (NUL probe). Classifies remaining files as: - - 'utf8' : valid UTF-8 (no BOM) or empty file - - 'utf8-with-bom' : starts with UTF-8 BOM (EF BB BF) - - 'other' : text but not valid UTF-8 (e.g., UTF-16/ANSI) + - 'utf8' : valid UTF-8 (no BOM) or empty file + - 'utf8-with-bom' : starts with UTF-8 BOM (EF BB BF) + - 'other' : text but not valid UTF-8 (e.g., UTF-16/ANSI) Outputs: - 1) Relative paths of files classified as 'other' - 2) A table by extension: UTF8 / UTF8-with-BOM / Other / Total + 1) Relative paths of files classified as 'other' + 2) A table by extension: UTF8 / UTF8-with-BOM / Other / Total Notes: - - Read-only: this script makes no changes. - - Requires Git and must be run inside a Git work tree. + - Read-only: this script makes no changes. + - Requires Git and must be run inside a Git work tree. #> [CmdletBinding()] @@ -26,93 +26,93 @@ $ErrorActionPreference = 'Stop' # --- Git enumeration --------------------------------------------------------- function Assert-InGitWorkTree { - # Throws if not inside a Git work tree. - $inside = (& git rev-parse --is-inside-work-tree 2>$null).Trim() - if ($LASTEXITCODE -ne 0 -or $inside -ne 'true') { - throw 'Not in a Git work tree.' - } + # Throws if not inside a Git work tree. + $inside = (& git rev-parse --is-inside-work-tree 2>$null).Trim() + if ($LASTEXITCODE -ne 0 -or $inside -ne 'true') { + throw 'Not in a Git work tree.' + } } function Get-GitFilesUnderPwd { - <# - Returns full paths to tracked + untracked-not-ignored files under PWD. - #> - Assert-InGitWorkTree + <# + Returns full paths to tracked + untracked-not-ignored files under PWD. + #> + Assert-InGitWorkTree - $repoRoot = (& git rev-parse --show-toplevel).Trim() - $pwdPath = (Get-Location).Path + $repoRoot = (& git rev-parse --show-toplevel).Trim() + $pwdPath = (Get-Location).Path - # cached (tracked) + others (untracked not ignored) - $nulSeparated = & git -C $repoRoot ls-files -z --cached --others --exclude-standard + # cached (tracked) + others (untracked not ignored) + $nulSeparated = & git -C $repoRoot ls-files -z --cached --others --exclude-standard - $relativePaths = $nulSeparated.Split( - [char]0, [System.StringSplitOptions]::RemoveEmptyEntries) + $relativePaths = $nulSeparated.Split( + [char]0, [System.StringSplitOptions]::RemoveEmptyEntries) - foreach ($relPath in $relativePaths) { - $fullPath = Join-Path $repoRoot $relPath + foreach ($relPath in $relativePaths) { + $fullPath = Join-Path $repoRoot $relPath - # Only include files under the current subtree. - if ($fullPath.StartsWith($pwdPath, - [System.StringComparison]::OrdinalIgnoreCase)) { - if (Test-Path -LiteralPath $fullPath -PathType Leaf) { $fullPath } - } - } + # Only include files under the current subtree. + if ($fullPath.StartsWith($pwdPath, + [System.StringComparison]::OrdinalIgnoreCase)) { + if (Test-Path -LiteralPath $fullPath -PathType Leaf) { $fullPath } + } + } } # --- Probes ------------------------------------------------------------------ function Test-ProbablyBinary { - # Heuristic: treat as binary if the first 8 KiB contains any NUL byte. - param([Parameter(Mandatory)][string]$Path) - - try { - $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') - try { - $len = [int][Math]::Min(8192,$stream.Length) - if ($len -le 0) { return $false } - - $buffer = [byte[]]::new($len) - [void]$stream.Read($buffer,0,$len) - return ($buffer -contains 0) - } - finally { $stream.Dispose() } - } - catch { return $false } + # Heuristic: treat as binary if the first 8 KiB contains any NUL byte. + param([Parameter(Mandatory)][string]$Path) + + try { + $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') + try { + $len = [int][Math]::Min(8192,$stream.Length) + if ($len -le 0) { return $false } + + $buffer = [byte[]]::new($len) + [void]$stream.Read($buffer,0,$len) + return ($buffer -contains 0) + } + finally { $stream.Dispose() } + } + catch { return $false } } function Get-TextEncodingCategory { - # Returns 'utf8', 'utf8-with-bom', 'other', or $null for likely-binary. - param([Parameter(Mandatory)][string]$Path) - - $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') - try { - $fileLength = $stream.Length - if ($fileLength -eq 0) { return 'utf8' } - - # BOM check (EF BB BF) - $header = [byte[]]::new([Math]::Min(3,$fileLength)) - [void]$stream.Read($header,0,$header.Length) - if ($header.Length -ge 3 -and - $header[0] -eq 0xEF -and $header[1] -eq 0xBB -and $header[2] -eq 0xBF) { - return 'utf8-with-bom' - } - - # Quick binary probe before expensive decoding - $stream.Position = 0 - $sampleLen = [int][Math]::Min(8192,$fileLength) - $sample = [byte[]]::new($sampleLen) - [void]$stream.Read($sample,0,$sampleLen) - if ($sample -contains 0) { return $null } - } - finally { $stream.Dispose() } - - # Validate UTF-8 by decoding with throw-on-invalid option (no BOM). - try { - $bytes = [System.IO.File]::ReadAllBytes($Path) - $utf8 = [System.Text.UTF8Encoding]::new($false,$true) - [void]$utf8.GetString($bytes) - return 'utf8' - } - catch { return 'other' } + # Returns 'utf8', 'utf8-with-bom', 'other', or $null for likely-binary. + param([Parameter(Mandatory)][string]$Path) + + $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') + try { + $fileLength = $stream.Length + if ($fileLength -eq 0) { return 'utf8' } + + # BOM check (EF BB BF) + $header = [byte[]]::new([Math]::Min(3,$fileLength)) + [void]$stream.Read($header,0,$header.Length) + if ($header.Length -ge 3 -and + $header[0] -eq 0xEF -and $header[1] -eq 0xBB -and $header[2] -eq 0xBF) { + return 'utf8-with-bom' + } + + # Quick binary probe before expensive decoding + $stream.Position = 0 + $sampleLen = [int][Math]::Min(8192,$fileLength) + $sample = [byte[]]::new($sampleLen) + [void]$stream.Read($sample,0,$sampleLen) + if ($sample -contains 0) { return $null } + } + finally { $stream.Dispose() } + + # Validate UTF-8 by decoding with throw-on-invalid option (no BOM). + try { + $bytes = [System.IO.File]::ReadAllBytes($Path) + $utf8 = [System.Text.UTF8Encoding]::new($false,$true) + [void]$utf8.GetString($bytes) + return 'utf8' + } + catch { return 'other' } } # --- Main -------------------------------------------------------------------- @@ -122,50 +122,50 @@ $byExtension = @{} $allFiles = Get-GitFilesUnderPwd foreach ($fullPath in $allFiles) { - # Avoid decoding likely-binary files. - if (Test-ProbablyBinary $fullPath) { continue } + # Avoid decoding likely-binary files. + if (Test-ProbablyBinary $fullPath) { continue } - $category = Get-TextEncodingCategory $fullPath - if (-not $category) { continue } + $category = Get-TextEncodingCategory $fullPath + if (-not $category) { continue } - $ext = [IO.Path]::GetExtension($fullPath).ToLower() - if (-not $byExtension.ContainsKey($ext)) { - $byExtension[$ext] = @{ 'utf8' = 0; 'utf8-with-bom' = 0; 'other' = 0 } - } + $ext = [IO.Path]::GetExtension($fullPath).ToLower() + if (-not $byExtension.ContainsKey($ext)) { + $byExtension[$ext] = @{ 'utf8' = 0; 'utf8-with-bom' = 0; 'other' = 0 } + } - $byExtension[$ext][$category]++ + $byExtension[$ext][$category]++ - if ($category -eq 'other') { - $otherFiles += (Resolve-Path -LiteralPath $fullPath -Relative) - } + if ($category -eq 'other') { + $otherFiles += (Resolve-Path -LiteralPath $fullPath -Relative) + } } # 1) Files in 'other' if ($otherFiles.Count -gt 0) { - 'Files classified as ''other'':' - $otherFiles | Sort-Object | ForEach-Object { " $_" } - '' + 'Files classified as ''other'':' + $otherFiles | Sort-Object | ForEach-Object { " $_" } + '' } # 2) Table by extension $rows = foreach ($kv in $byExtension.GetEnumerator()) { - $ext = if ($kv.Key) { $kv.Key } else { '[noext]' } - $u = [int]$kv.Value['utf8'] - $b = [int]$kv.Value['utf8-with-bom'] - $o = [int]$kv.Value['other'] - - [PSCustomObject]@{ - Extension = $ext - UTF8 = $u - 'UTF8-with-BOM' = $b - Other = $o - Total = $u + $b + $o - } + $ext = if ($kv.Key) { $kv.Key } else { '[noext]' } + $u = [int]$kv.Value['utf8'] + $b = [int]$kv.Value['utf8-with-bom'] + $o = [int]$kv.Value['other'] + + [PSCustomObject]@{ + Extension = $ext + UTF8 = $u + 'UTF8-with-BOM' = $b + Other = $o + Total = $u + $b + $o + } } $rows | - Sort-Object -Property ( - @{Expression='Total';Descending=$true}, - @{Expression='Extension';Descending=$false} - ) | - Format-Table -AutoSize + Sort-Object -Property ( + @{Expression='Total';Descending=$true}, + @{Expression='Extension';Descending=$false} + ) | + Format-Table -AutoSize diff --git a/BuildTools/bom-strip.ps1 b/BuildTools/bom-strip.ps1 index 7d89d98ac..0f92d6195 100644 --- a/BuildTools/bom-strip.ps1 +++ b/BuildTools/bom-strip.ps1 @@ -14,7 +14,7 @@ Supports -WhatIf/-Confirm via ShouldProcess. [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')] param( - [switch]$Force + [switch]$Force ) Set-StrictMode -Version Latest @@ -22,130 +22,130 @@ $ErrorActionPreference = 'Stop' # --- File sets (ILSpy) ------------------------------------------------------ $Dotfiles = @( - '.gitignore', '.editorconfig', '.gitattributes', '.gitmodules', - '.tgitconfig', '.vsconfig' + '.gitignore', '.editorconfig', '.gitattributes', '.gitmodules', + '.tgitconfig', '.vsconfig' ) $AllowedExts = @( - '.bat','.config','.cs','.csproj','.css','.filelist','.fs','.html','.il', - '.ipynb','.js','.json','.less','.manifest','.md','.projitems','.props', - '.ps1','.psd1','.ruleset','.shproj','.sln','.slnf','.svg','.template', - '.tt', '.txt','.vb','.vsct','.vsixlangpack','.wxl','.xaml','.xml','.xshd','.yml' + '.bat','.config','.cs','.csproj','.css','.filelist','.fs','.html','.il', + '.ipynb','.js','.json','.less','.manifest','.md','.projitems','.props', + '.ps1','.psd1','.ruleset','.shproj','.sln','.slnf','.svg','.template', + '.tt', '.txt','.vb','.vsct','.vsixlangpack','.wxl','.xaml','.xml','.xshd','.yml' ) $IncludeNoExt = $true # include names like LICENSE # --- Git checks / enumeration ----------------------------------------------- function Assert-InGitWorkTree { - $inside = (& git rev-parse --is-inside-work-tree 2>$null).Trim() - if ($LASTEXITCODE -ne 0 -or $inside -ne 'true') { - throw 'Not in a Git work tree.' - } + $inside = (& git rev-parse --is-inside-work-tree 2>$null).Trim() + if ($LASTEXITCODE -ne 0 -or $inside -ne 'true') { + throw 'Not in a Git work tree.' + } } function Assert-CleanWorkingTree { - if ($Force) { return } + if ($Force) { return } - $status = & git status --porcelain -z - if ($LASTEXITCODE -ne 0) { throw 'git status failed.' } + $status = & git status --porcelain -z + if ($LASTEXITCODE -ne 0) { throw 'git status failed.' } - if (-not [string]::IsNullOrEmpty($status)) { - throw 'Working tree not clean. Commit/stash changes or use -Force.' - } + if (-not [string]::IsNullOrEmpty($status)) { + throw 'Working tree not clean. Commit/stash changes or use -Force.' + } } function Get-GitFilesUnderPwd { - Assert-InGitWorkTree - - $repoRoot = (& git rev-parse --show-toplevel).Trim() - $pwdPath = (Get-Location).Path - - $tracked = & git -C $repoRoot ls-files -z - $others = & git -C $repoRoot ls-files --others --exclude-standard -z - - $allRel = ("$tracked$others").Split( - [char]0, [System.StringSplitOptions]::RemoveEmptyEntries) - - foreach ($relPath in $allRel) { - $fullPath = Join-Path $repoRoot $relPath - if ($fullPath.StartsWith($pwdPath, - [System.StringComparison]::OrdinalIgnoreCase)) { - if (Test-Path -LiteralPath $fullPath -PathType Leaf) { - $fullPath - } - } - } + Assert-InGitWorkTree + + $repoRoot = (& git rev-parse --show-toplevel).Trim() + $pwdPath = (Get-Location).Path + + $tracked = & git -C $repoRoot ls-files -z + $others = & git -C $repoRoot ls-files --others --exclude-standard -z + + $allRel = ("$tracked$others").Split( + [char]0, [System.StringSplitOptions]::RemoveEmptyEntries) + + foreach ($relPath in $allRel) { + $fullPath = Join-Path $repoRoot $relPath + if ($fullPath.StartsWith($pwdPath, + [System.StringComparison]::OrdinalIgnoreCase)) { + if (Test-Path -LiteralPath $fullPath -PathType Leaf) { + $fullPath + } + } + } } # --- Probes ----------------------------------------------------------------- function Test-HasUtf8Bom { - param([Parameter(Mandatory)][string]$Path) - - try { - $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') - try { - if ($stream.Length -lt 3) { return $false } - - $header = [byte[]]::new(3) - [void]$stream.Read($header,0,3) - - return ($header[0] -eq 0xEF -and - $header[1] -eq 0xBB -and - $header[2] -eq 0xBF) - } - finally { - $stream.Dispose() - } - } - catch { return $false } + param([Parameter(Mandatory)][string]$Path) + + try { + $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') + try { + if ($stream.Length -lt 3) { return $false } + + $header = [byte[]]::new(3) + [void]$stream.Read($header,0,3) + + return ($header[0] -eq 0xEF -and + $header[1] -eq 0xBB -and + $header[2] -eq 0xBF) + } + finally { + $stream.Dispose() + } + } + catch { return $false } } function Test-ProbablyBinary { - # Binary if the first 8 KiB contains any NUL byte. - param([Parameter(Mandatory)][string]$Path) - - try { - $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') - try { - $len = [int][Math]::Min(8192,$stream.Length) - if ($len -le 0) { return $false } - - $buffer = [byte[]]::new($len) - [void]$stream.Read($buffer,0,$len) - - return ($buffer -contains 0) - } - finally { - $stream.Dispose() - } - } - catch { return $false } + # Binary if the first 8 KiB contains any NUL byte. + param([Parameter(Mandatory)][string]$Path) + + try { + $stream = [System.IO.File]::Open($Path,'Open','Read','ReadWrite') + try { + $len = [int][Math]::Min(8192,$stream.Length) + if ($len -le 0) { return $false } + + $buffer = [byte[]]::new($len) + [void]$stream.Read($buffer,0,$len) + + return ($buffer -contains 0) + } + finally { + $stream.Dispose() + } + } + catch { return $false } } # --- Mutation --------------------------------------------------------------- function Remove-Utf8BomInPlace { - # Write the existing buffer from offset 3, no extra full-size allocation. - param([Parameter(Mandatory)][string]$Path) - - $bytes = [System.IO.File]::ReadAllBytes($Path) - if ($bytes.Length -lt 3) { return $false } - - if ($bytes[0] -ne 0xEF -or - $bytes[1] -ne 0xBB -or - $bytes[2] -ne 0xBF) { - return $false - } - - $stream = [System.IO.File]::Open($Path,'Create','Write','ReadWrite') - try { - $stream.Write($bytes, 3, $bytes.Length - 3) - $stream.SetLength($bytes.Length - 3) - } - finally { - $stream.Dispose() - } - - return $true + # Write the existing buffer from offset 3, no extra full-size allocation. + param([Parameter(Mandatory)][string]$Path) + + $bytes = [System.IO.File]::ReadAllBytes($Path) + if ($bytes.Length -lt 3) { return $false } + + if ($bytes[0] -ne 0xEF -or + $bytes[1] -ne 0xBB -or + $bytes[2] -ne 0xBF) { + return $false + } + + $stream = [System.IO.File]::Open($Path,'Create','Write','ReadWrite') + try { + $stream.Write($bytes, 3, $bytes.Length - 3) + $stream.SetLength($bytes.Length - 3) + } + finally { + $stream.Dispose() + } + + return $true } # --- Main ------------------------------------------------------------------- @@ -155,16 +155,16 @@ Assert-CleanWorkingTree $allFiles = Get-GitFilesUnderPwd $targets = $allFiles | % { - $fileName = [IO.Path]::GetFileName($_) - $ext = [IO.Path]::GetExtension($fileName) + $fileName = [IO.Path]::GetFileName($_) + $ext = [IO.Path]::GetExtension($fileName) - $isDot = $Dotfiles -contains $fileName - $isNoExt = -not $fileName.Contains('.') + $isDot = $Dotfiles -contains $fileName + $isNoExt = -not $fileName.Contains('.') - if ($isDot -or ($AllowedExts -contains $ext) -or - ($IncludeNoExt -and $isNoExt -and -not $isDot)) { - $_ - } + if ($isDot -or ($AllowedExts -contains $ext) -or + ($IncludeNoExt -and $isNoExt -and -not $isDot)) { + $_ + } } | ? { Test-HasUtf8Bom $_ } | ? { -not (Test-ProbablyBinary $_) } @@ -174,35 +174,35 @@ $byExtension = @{} $dotfileChanges = 0 $targets | % { - $relative = Resolve-Path -LiteralPath $_ -Relative + $relative = Resolve-Path -LiteralPath $_ -Relative - if ($PSCmdlet.ShouldProcess($relative,'Strip UTF-8 BOM')) { - if (Remove-Utf8BomInPlace -Path $_) { - $changed++ + if ($PSCmdlet.ShouldProcess($relative,'Strip UTF-8 BOM')) { + if (Remove-Utf8BomInPlace -Path $_) { + $changed++ - $fileName = [IO.Path]::GetFileName($_) - if ($Dotfiles -contains $fileName) { $dotfileChanges++ } + $fileName = [IO.Path]::GetFileName($_) + if ($Dotfiles -contains $fileName) { $dotfileChanges++ } - $ext = [IO.Path]::GetExtension($fileName) - if (-not $byExtension.ContainsKey($ext)) { $byExtension[$ext] = 0 } - $byExtension[$ext]++ + $ext = [IO.Path]::GetExtension($fileName) + if (-not $byExtension.ContainsKey($ext)) { $byExtension[$ext] = 0 } + $byExtension[$ext]++ - "stripped BOM: $relative" - } - } + "stripped BOM: $relative" + } + } } "Done. Stripped BOM from $changed file(s)." if ($byExtension.Keys.Count -gt 0) { - "" - "By extension:" - $byExtension.GetEnumerator() | Sort-Object Name | % { - $key = if ([string]::IsNullOrEmpty($_.Name)) { '[noext]' } else { $_.Name } - " {0}: {1}" -f $key, $_.Value - } + "" + "By extension:" + $byExtension.GetEnumerator() | Sort-Object Name | % { + $key = if ([string]::IsNullOrEmpty($_.Name)) { '[noext]' } else { $_.Name } + " {0}: {1}" -f $key, $_.Value + } } if ($dotfileChanges -gt 0) { - " [dotfiles]: $dotfileChanges" + " [dotfiles]: $dotfileChanges" } diff --git a/BuildTools/create-filelists.ps1 b/BuildTools/create-filelists.ps1 index 79d908fd3..920667dda 100644 --- a/BuildTools/create-filelists.ps1 +++ b/BuildTools/create-filelists.ps1 @@ -3,23 +3,23 @@ $ErrorActionPreference = "Stop"; $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False gci -Include *.vsix, *.msi -recurse | foreach ($_) { - if (-not ($_.FullName -contains "\bin\Debug\")) { - continue; - } - $idx=-1; - $body=$false; - $outputFileName = ".\BuildTools\$($_.Name -replace '-\d+\.\d+\.\d+\.\d+', '').filelist"; - $lines = 7z l $_.FullName | foreach { - if ($idx -eq -1) { - $idx = $_.IndexOf("Name"); - } - $p = $body; - if ($idx -gt 0) { - $body = ($body -ne ($_ -match ' *-[ -]+')) - } - if ($p -and $body) { - $_.Substring($idx) - } - } | sort - [System.IO.File]::WriteAllLines($outputFileName, $lines, $Utf8NoBomEncoding) + if (-not ($_.FullName -contains "\bin\Debug\")) { + continue; + } + $idx=-1; + $body=$false; + $outputFileName = ".\BuildTools\$($_.Name -replace '-\d+\.\d+\.\d+\.\d+', '').filelist"; + $lines = 7z l $_.FullName | foreach { + if ($idx -eq -1) { + $idx = $_.IndexOf("Name"); + } + $p = $body; + if ($idx -gt 0) { + $body = ($body -ne ($_ -match ' *-[ -]+')) + } + if ($p -and $body) { + $_.Substring($idx) + } + } | sort + [System.IO.File]::WriteAllLines($outputFileName, $lines, $Utf8NoBomEncoding) } diff --git a/BuildTools/ghactions-install.ps1 b/BuildTools/ghactions-install.ps1 index bb2b88b91..fc3bd9417 100644 --- a/BuildTools/ghactions-install.ps1 +++ b/BuildTools/ghactions-install.ps1 @@ -17,9 +17,9 @@ $build = $versionParts.Build; $versionName = $versionParts.VersionName; if ($versionName -ne "null") { - $versionName = "-$versionName"; + $versionName = "-$versionName"; } else { - $versionName = ""; + $versionName = ""; } Write-Host "GITHUB_REF: '$env:GITHUB_REF'"; diff --git a/BuildTools/update-assemblyinfo.ps1 b/BuildTools/update-assemblyinfo.ps1 index 2bf3dd731..a6cd4acdc 100644 --- a/BuildTools/update-assemblyinfo.ps1 +++ b/BuildTools/update-assemblyinfo.ps1 @@ -1,6 +1,6 @@ if (-not ($PSVersionTable.PSCompatibleVersions -contains "5.0")) { - Write-Error "This script requires at least powershell version 5.0!"; - return 255; + Write-Error "This script requires at least powershell version 5.0!"; + return 255; } $ErrorActionPreference = "Stop" @@ -14,11 +14,11 @@ $masterBranches = '^(master|release/.+)$'; $decompilerVersionInfoTemplateFile = "ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.template.cs"; function Test-File([string]$filename) { - return [System.IO.File]::Exists((Join-Path (Get-Location) $filename)); + return [System.IO.File]::Exists((Join-Path (Get-Location) $filename)); } function Test-Dir([string]$name) { - return [System.IO.Directory]::Exists((Join-Path (Get-Location) $name)); + return [System.IO.Directory]::Exists((Join-Path (Get-Location) $name)); } function Find-Git() { @@ -44,63 +44,63 @@ function Find-Git() { } function No-Git() { - return -not (((Test-Dir ".git") -or (Test-File ".git")) -and (Find-Git)); + return -not (((Test-Dir ".git") -or (Test-File ".git")) -and (Find-Git)); } function gitVersion() { - if (No-Git) { - return 0; - } - try { - return [Int32]::Parse((git rev-list --count "$baseCommit..HEAD" 2>&1 | Tee-Object -Variable cmdOutput)) + $baseCommitRev; - } catch { - Write-Host $cmdOutput - return 0; - } + if (No-Git) { + return 0; + } + try { + return [Int32]::Parse((git rev-list --count "$baseCommit..HEAD" 2>&1 | Tee-Object -Variable cmdOutput)) + $baseCommitRev; + } catch { + Write-Host $cmdOutput + return 0; + } } function gitCommitHash() { - if (No-Git) { - return "0000000000000000000000000000000000000000"; - } - try { - return (git rev-list --max-count 1 HEAD 2>&1 | Tee-Object -Variable cmdOutput); - } catch { - Write-Host $cmdOutput - return "0000000000000000000000000000000000000000"; - } + if (No-Git) { + return "0000000000000000000000000000000000000000"; + } + try { + return (git rev-list --max-count 1 HEAD 2>&1 | Tee-Object -Variable cmdOutput); + } catch { + Write-Host $cmdOutput + return "0000000000000000000000000000000000000000"; + } } function gitShortCommitHash() { - if (No-Git) { - return "00000000"; - } - try { - return (git rev-parse --short=8 (git rev-list --max-count 1 HEAD 2>&1 | Tee-Object -Variable cmdOutput) 2>&1 | Tee-Object -Variable cmdOutput); - } catch { - Write-Host $cmdOutput - return "00000000"; - } + if (No-Git) { + return "00000000"; + } + try { + return (git rev-parse --short=8 (git rev-list --max-count 1 HEAD 2>&1 | Tee-Object -Variable cmdOutput) 2>&1 | Tee-Object -Variable cmdOutput); + } catch { + Write-Host $cmdOutput + return "00000000"; + } } function gitBranch() { - if (No-Git) { - return "no-branch"; - } + if (No-Git) { + return "no-branch"; + } if ($env:APPVEYOR_REPO_BRANCH -ne $null) { - return $env:APPVEYOR_REPO_BRANCH; - } elseif ($env:BUILD_SOURCEBRANCHNAME -ne $null) { - return $env:BUILD_SOURCEBRANCHNAME; - } else { - return ((git branch --no-color).Split([System.Environment]::NewLine) | where { $_ -match "^\* " } | select -First 1).Substring(2); - } + return $env:APPVEYOR_REPO_BRANCH; + } elseif ($env:BUILD_SOURCEBRANCHNAME -ne $null) { + return $env:BUILD_SOURCEBRANCHNAME; + } else { + return ((git branch --no-color).Split([System.Environment]::NewLine) | where { $_ -match "^\* " } | select -First 1).Substring(2); + } } $templateFiles = ( - @{Input=$decompilerVersionInfoTemplateFile; Output="ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs"}, - @{Input="ILSpy.AddIn/source.extension.vsixmanifest.template"; Output = "ILSpy.AddIn/source.extension.vsixmanifest"}, - @{Input="ILSpy.AddIn.VS2022/source.extension.vsixmanifest.template"; Output = "ILSpy.AddIn.VS2022/source.extension.vsixmanifest"} + @{Input=$decompilerVersionInfoTemplateFile; Output="ICSharpCode.Decompiler/Properties/DecompilerVersionInfo.cs"}, + @{Input="ILSpy.AddIn/source.extension.vsixmanifest.template"; Output = "ILSpy.AddIn/source.extension.vsixmanifest"}, + @{Input="ILSpy.AddIn.VS2022/source.extension.vsixmanifest.template"; Output = "ILSpy.AddIn.VS2022/source.extension.vsixmanifest"} ); [string]$mutexId = "ILSpyUpdateAssemblyInfo" + (Get-Location).ToString().GetHashCode(); @@ -108,43 +108,43 @@ Write-Host $mutexId; [bool]$createdNew = $false; $mutex = New-Object System.Threading.Mutex($true, $mutexId, [ref]$createdNew); try { - if (-not $createdNew) { - try { - $mutex.WaitOne(10000); - } catch [System.Threading.AbandonedMutexException] { - } - return 0; - } - - if (-not (Test-File "ILSpy.sln")) { - Write-Error "Working directory must be the ILSpy repo root!"; - return 2; - } - - $versionParts = @{}; - Get-Content $decompilerVersionInfoTemplateFile | where { $_ -match 'string (\w+) = "?(\w+)"?;' } | foreach { $versionParts.Add($Matches[1], $Matches[2]) } - - $major = $versionParts.Major; - $minor = $versionParts.Minor; - $build = $versionParts.Build; - $versionName = $versionParts.VersionName; - $revision = gitVersion; - $branchName = gitBranch; - $gitCommitHash = gitCommitHash; + if (-not $createdNew) { + try { + $mutex.WaitOne(10000); + } catch [System.Threading.AbandonedMutexException] { + } + return 0; + } + + if (-not (Test-File "ILSpy.sln")) { + Write-Error "Working directory must be the ILSpy repo root!"; + return 2; + } + + $versionParts = @{}; + Get-Content $decompilerVersionInfoTemplateFile | where { $_ -match 'string (\w+) = "?(\w+)"?;' } | foreach { $versionParts.Add($Matches[1], $Matches[2]) } + + $major = $versionParts.Major; + $minor = $versionParts.Minor; + $build = $versionParts.Build; + $versionName = $versionParts.VersionName; + $revision = gitVersion; + $branchName = gitBranch; + $gitCommitHash = gitCommitHash; $gitShortCommitHash = gitShortCommitHash; - if ($branchName -match $masterBranches) { - $postfixBranchName = ""; - } else { - $postfixBranchName = "-$branchName"; + if ($branchName -match $masterBranches) { + $postfixBranchName = ""; + } else { + $postfixBranchName = "-$branchName"; } - if ($versionName -eq "null") { - $versionName = ""; - $postfixVersionName = ""; - } else { - $postfixVersionName = "-$versionName"; - } + if ($versionName -eq "null") { + $versionName = ""; + $postfixVersionName = ""; + } else { + $postfixVersionName = "-$versionName"; + } $buildConfig = $args[0].ToString().ToLower(); if ($buildConfig -eq "release") { @@ -153,13 +153,13 @@ try { $buildConfig = "-" + $buildConfig; } - $fullVersionNumber = "$major.$minor.$build.$revision"; - if ((-not (Test-File "VERSION")) -or (((Get-Content "VERSION") -Join [System.Environment]::NewLine) -ne "$fullVersionNumber$postfixVersionName")) { - "$fullVersionNumber$postfixVersionName" | Out-File -Encoding utf8 -NoNewLine "VERSION"; - } + $fullVersionNumber = "$major.$minor.$build.$revision"; + if ((-not (Test-File "VERSION")) -or (((Get-Content "VERSION") -Join [System.Environment]::NewLine) -ne "$fullVersionNumber$postfixVersionName")) { + "$fullVersionNumber$postfixVersionName" | Out-File -Encoding utf8 -NoNewLine "VERSION"; + } - foreach ($file in $templateFiles) { - [string]$in = (Get-Content $file.Input) -Join [System.Environment]::NewLine; + foreach ($file in $templateFiles) { + [string]$in = (Get-Content $file.Input) -Join [System.Environment]::NewLine; $out = $in.Replace('$INSERTVERSION$', $fullVersionNumber); $out = $out.Replace('$INSERTMAJORVERSION$', $major); @@ -169,18 +169,18 @@ try { $out = $out.Replace('$INSERTDATE$', [System.DateTime]::Now.ToString("MM/dd/yyyy")); $out = $out.Replace('$INSERTYEAR$', [System.DateTime]::Now.Year.ToString()); $out = $out.Replace('$INSERTBRANCHNAME$', $branchName); - $out = $out.Replace('$INSERTBRANCHPOSTFIX$', $postfixBranchName); + $out = $out.Replace('$INSERTBRANCHPOSTFIX$', $postfixBranchName); $out = $out.Replace('$INSERTVERSIONNAME$', $versionName); - $out = $out.Replace('$INSERTVERSIONNAMEPOSTFIX$', $postfixVersionName); - $out = $out.Replace('$INSERTBUILDCONFIG$', $buildConfig); + $out = $out.Replace('$INSERTVERSIONNAMEPOSTFIX$', $postfixVersionName); + $out = $out.Replace('$INSERTBUILDCONFIG$', $buildConfig); - if ((-not (Test-File $file.Output)) -or (((Get-Content $file.Output) -Join [System.Environment]::NewLine) -ne $out)) { + if ((-not (Test-File $file.Output)) -or (((Get-Content $file.Output) -Join [System.Environment]::NewLine) -ne $out)) { $utf8NoBom = New-Object System.Text.UTF8Encoding($false); [System.IO.File]::WriteAllText($file.Output, $out, $utf8NoBom); - } - } + } + } } finally { - $mutex.ReleaseMutex(); - $mutex.Close(); + $mutex.ReleaseMutex(); + $mutex.Close(); } \ No newline at end of file diff --git a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 index 3b8092a72..660bc4de1 100644 --- a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 +++ b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 @@ -1,7 +1,7 @@ $basePath = $PSScriptRoot if ([string]::IsNullOrEmpty($basePath)) { - $basePath = Split-Path -parent $psISE.CurrentFile.Fullpath + $basePath = Split-Path -parent $psISE.CurrentFile.Fullpath } $modulePath = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.Powershell.dll' @@ -21,7 +21,7 @@ $classes.Count foreach ($c in $classes) { - Write-Output $c.FullName + Write-Output $c.FullName }