Skip to content

Commit 228c39b

Browse files
committed
refactor: rename freeze remediation helper and stabilize pre-cleanup
1 parent 86b32ea commit 228c39b

5 files changed

Lines changed: 276 additions & 42 deletions

File tree

Private/Fix-InstallerFreeze.ps1 renamed to Private/Invoke-InstallerFreezeRemediation.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
Company: Linktech Engineering LLC
88
Created: 2026-07-06
99
Modified: 2026-07-06
10-
File: Fix-InstallerFreeze.ps1
10+
File: Invoke-InstallerFreezeRemediation.ps1
1111
Version: 1.0.0
1212
Description: Description goes here
1313
#>
14-
function Fix-InstallerFreeze {
14+
function Invoke-InstallerFreezeRemediation {
1515
[CmdletBinding()]
1616
param()
1717

@@ -29,16 +29,31 @@ function Fix-InstallerFreeze {
2929
}
3030
}
3131

32-
# 2. VS Code install root — CLEAN CONTENTS ONLY, DO NOT DELETE ROOT
32+
# 2. VS Code install root — REMOVE ONLY KNOWN DEBRIS
3333
$installRoot = "$env:LOCALAPPDATA\Programs\Microsoft VS Code"
3434
if (Test-Path $installRoot) {
3535
try {
36-
Write-Log "[FIX] Cleaning VS Code install root contents (preserving directory)"
37-
Get-ChildItem $installRoot -Force -ErrorAction SilentlyContinue |
38-
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
36+
Write-Log "[FIX] Cleaning VS Code install root debris (preserving valid files)"
37+
38+
$debris = @(
39+
"update.exe",
40+
"*.tmp",
41+
"*.partial",
42+
"is-*.tmp",
43+
"is-*.bin",
44+
"innosetup.tmp",
45+
"new_*",
46+
"tmp_*",
47+
"partial_*"
48+
)
49+
50+
foreach ($pattern in $debris) {
51+
Get-ChildItem -Path $installRoot -Filter $pattern -ErrorAction SilentlyContinue |
52+
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
53+
}
3954
}
4055
catch {
41-
Write-Log "[WARN] Failed to clean install root: $($_.Exception.Message)"
56+
Write-Log "[WARN] Failed to clean install root debris: $($_.Exception.Message)"
4257
}
4358
}
4459

Private/UnifiedPreCleanup.ps1

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<#
2+
SPDX-License-Identifier: MIT
3+
Copyright (c) 2026 Leon McClatchey, Linktech Engineering LLC
4+
5+
Package: VSCode-Updater
6+
Author: Leon McClatchey
7+
Company: Linktech Engineering LLC
8+
Created: 2026-07-11
9+
Modified: 2026-07-11
10+
File: Private/UnifiedPreCleanup.ps1
11+
Version: 1.0.0
12+
Description: Description goes here
13+
#>
14+
15+
16+
function Invoke-VSUPreCleanup {
17+
18+
param(
19+
[string]$InstallRoot
20+
)
21+
22+
Write-Log "[PRE] Starting unified pre‑installation cleanup"
23+
24+
# =====================================================================
25+
# 1. Kill ALL VS Code processes
26+
# =====================================================================
27+
28+
$vsProcesses = @(
29+
"Code",
30+
"Code - Insiders",
31+
"CodeHelper",
32+
"CodeHelper.exe",
33+
"CodeHelper64",
34+
"CodeHelper32"
35+
)
36+
37+
foreach ($p in $vsProcesses) {
38+
Get-Process -Name $p -ErrorAction SilentlyContinue |
39+
ForEach-Object {
40+
Write-Log "[PRE] Killing VS Code process: $($_.Name) (PID=$($_.Id))"
41+
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
42+
}
43+
}
44+
45+
# =====================================================================
46+
# 2. Kill ALL installer/bootstrapper/worker processes
47+
# =====================================================================
48+
49+
$installerProcesses = @(
50+
"VSCodeSetup",
51+
"CodeSetup",
52+
"setup",
53+
"is-",
54+
"innosetup"
55+
)
56+
57+
foreach ($p in $installerProcesses) {
58+
Get-Process -Name $p -ErrorAction SilentlyContinue |
59+
ForEach-Object {
60+
Write-Log "[PRE] Killing installer/bootstrapper: $($_.Name) (PID=$($_.Id))"
61+
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
62+
}
63+
}
64+
65+
# =====================================================================
66+
# 3. Remove symlink if it exists
67+
# =====================================================================
68+
69+
$symlinkPath = Join-Path $InstallRoot "VSCode"
70+
71+
if (Test-Path $symlinkPath) {
72+
$item = Get-Item $symlinkPath -Force
73+
74+
if ($item.Attributes -match "ReparsePoint") {
75+
Write-Log "[PRE] Removing VSCode junction: $symlinkPath"
76+
Remove-Item $symlinkPath -Force -ErrorAction SilentlyContinue
77+
}
78+
else {
79+
Write-Log "[PRE] VSCode path exists but is not a junction — removing"
80+
Remove-Item $symlinkPath -Recurse -Force -ErrorAction SilentlyContinue
81+
}
82+
}
83+
84+
# =====================================================================
85+
# 4. Prune old installation folders (keep newest two)
86+
# =====================================================================
87+
88+
Write-Log "[PRE] Pruning old installation folders"
89+
90+
$patternOld = '^VSCode-\d{8}-\d{6}$'
91+
$patternNew = '^VSCode-\d{14}$'
92+
93+
$folders = Get-ChildItem $InstallRoot -Directory |
94+
Where-Object {
95+
$_.Name -match $patternOld -or
96+
$_.Name -match $patternNew
97+
} |
98+
Sort-Object Name -Descending
99+
100+
if ($folders.Count -gt 2) {
101+
$toDelete = $folders | Select-Object -Skip 2
102+
foreach ($f in $toDelete) {
103+
Write-Log "[PRE] Removing old version folder: $($f.FullName)"
104+
Remove-Item $f.FullName -Recurse -Force -ErrorAction SilentlyContinue
105+
}
106+
}
107+
108+
# =====================================================================
109+
# 5. Remove debris (staging, partial installs, temp folders)
110+
# =====================================================================
111+
112+
Write-Log "[PRE] Removing debris"
113+
114+
$debrisPatterns = @(
115+
"new_*",
116+
"tmp_*",
117+
"partial_*",
118+
"is-*.tmp",
119+
"is-*.bin",
120+
"innosetup.tmp"
121+
)
122+
123+
foreach ($pattern in $debrisPatterns) {
124+
Get-ChildItem $InstallRoot -Filter $pattern -ErrorAction SilentlyContinue |
125+
ForEach-Object {
126+
Write-Log "[PRE] Removing debris: $($_.FullName)"
127+
Remove-Item $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
128+
}
129+
}
130+
131+
# =====================================================================
132+
# 6. Clean installation path (your existing function)
133+
# =====================================================================
134+
135+
Write-Log "[PRE] Cleaning installation path"
136+
CleanCodePath | Out-Null
137+
138+
# =====================================================================
139+
# 7. Validate environment
140+
# =====================================================================
141+
142+
Write-Log "[PRE] Validating installer environment"
143+
Test-InstallerEnvironment | Out-Null
144+
145+
# =====================================================================
146+
# 8. Freeze remediation (optional)
147+
# =====================================================================
148+
149+
if ($script:VSU_SafeInstallerMode) {
150+
Write-Log "[PRE] Safe installer mode enabled — applying freeze remediation"
151+
Invoke-InstallerFreezeRemediation | Out-Null
152+
}
153+
else {
154+
Write-Log "[PRE] Safe installer mode disabled — skipping freeze remediation"
155+
}
156+
157+
Write-Log "[PRE] Unified pre‑installation cleanup complete"
158+
}

Private/Update-VSCodeVersions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Update-VSCodeVersions {
2626
$active = $null
2727
if (Test-Path $linkPath) {
2828
try {
29-
$active = (Get-Item $linkPath).Target
29+
$active = (Get-Item $linkPath).Target | Resolve-Path
3030
}
3131
catch {
3232
Write-Log "[CLEANUP] Warning: Failed to resolve active symlink"

Public/Invoke-ZipFallback.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Invoke-ZipFallback {
6464
}
6565

6666
# Extract
67-
$version = (Get-Date).ToString("yyyyMMdd-HHmmss")
67+
$version = (Get-Date).ToString("yyyyMMddHHmmss")
6868
$targetDir = Join-Path $env:LOCALAPPDATA "Programs\VSCode-$version"
6969

7070
Write-Log "[FALLBACK] Extracting ZIP to $targetDir"

0 commit comments

Comments
 (0)